deviceManage.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. <template>
  2. <view class="container">
  3. <u-navbar leftIconColor="#fff" titleStyle="color:#fff;fontSize:36rpx;" :autoBack="true" bgColor="#2C6FF3"
  4. :placeholder="true" title="团队成员设备授权"></u-navbar>
  5. <view class="content">
  6. <view class="search">
  7. <u-search animation placeholder="搜索设备" :clearabled="false" v-model="keyword" :showAction="false"
  8. @search="search"></u-search>
  9. <view class="scan-icon" @click="scan">
  10. <u-icon name="scan" size="22" color="#909399"></u-icon>
  11. </view>
  12. <view class="search-history flex flex-wrap flex-start">
  13. <view class="history-item" v-for="(item,index) in historyList" :key="index"
  14. @click="searchFast(item)">
  15. {{item}}
  16. </view>
  17. </view>
  18. </view>
  19. <view class="tab-wrap">
  20. <view class="tab">
  21. <u-tabs :list="tabList" :activeStyle="{color: '#333',fontWeight: 'bold',fontSize:'36rpx'}"
  22. :inactiveStyle="{fontSize:'32rpx'}" :scrollable="false" :current="current" @click="tabClick"
  23. lineColor="#2C6FF3">
  24. </u-tabs>
  25. </view>
  26. </view>
  27. <scroll-view class="scrollview" :scroll-with-animation="true" scroll-y lower-threshold="100"
  28. @scrolltolower="scrolltolower" :style="{height:fullHeight}">
  29. <view class="list" v-if="list&&list.length>0">
  30. <block v-for="(item, index) in list" :key="index">
  31. <view class="thumb-box" @click.stop="commItemSelect(item)">
  32. <view>
  33. <image class="select-img"
  34. src="https://cdn.ossfile.mxrvending.com/assets/xy_merc_mini/images/commodity/no_selected.png"
  35. mode="widthFix" v-show="item.noSelect"></image>
  36. <image class="select-img"
  37. src="https://cdn.ossfile.mxrvending.com/assets/xy_merc_mini/images/commodity/selected.png"
  38. mode="widthFix" v-show="!item.noSelect&&item.checked"></image>
  39. <image class="select-img"
  40. src="https://cdn.ossfile.mxrvending.com/assets/xy_merc_mini/images/commodity/select.png"
  41. mode="widthFix" v-show="!item.noSelect&&!item.checked"></image>
  42. </view>
  43. <view class="check-content">
  44. <view class="comm-main">
  45. <view>
  46. {{item.deviceName}}
  47. </view>
  48. <view>
  49. 设备id:{{item.deviceId}}
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </block>
  55. <view class="more" style="overflow: hidden;">
  56. <u-loadmore :status="status" v-if="list.length>=1" />
  57. </view>
  58. </view>
  59. <view class="empty" v-if="list.length==0">
  60. <u-empty mode="list" text="没有设备!"></u-empty>
  61. </view>
  62. </scroll-view>
  63. </view>
  64. <view class="btn safe-bottom">
  65. <xbutton size="large" round="82rpx" @click="submit">{{current==0?'解绑':'绑定'}}</xbutton>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. import {
  71. mercDeviceList,
  72. addDevice,
  73. userDeviceList,
  74. delDevice
  75. } from "@/api/device/device.js"
  76. export default {
  77. data() {
  78. return {
  79. keyword: '',
  80. list: [], //商品列表
  81. page: 1, //商品分页
  82. size: 10,
  83. status: 'loadmore', //加载更多
  84. type: null,
  85. storeName: null,
  86. title: '私有商品库',
  87. btnName: '添加到商品私库',
  88. selectList: [],
  89. id: null,
  90. historyList: [],
  91. tabList: [{
  92. name: '已授权'
  93. },
  94. {
  95. name: '未授权'
  96. }
  97. ],
  98. current: 0,
  99. fullHeight: 0,
  100. userId: null,
  101. }
  102. },
  103. onLoad(o) {
  104. let _this = this;
  105. const query = uni.createSelectorQuery().in(this);
  106. query.select(".scrollview").boundingClientRect((data) => {
  107. uni.getSystemInfo({
  108. success(res) {
  109. // 针对iPhone X等机型底部安全距离做适配
  110. const model = res.model;
  111. const modelInclude = [
  112. "iPhone X",
  113. 'iPhone XR',
  114. "iPhone XS",
  115. "iPhone XS MAX",
  116. "iPhone 12/13 mini",
  117. "iPhone 12/13 (Pro)",
  118. "iPhone 12/13 Pro Max",
  119. "iPhone 14 Pro Max"
  120. ];
  121. let safeDistance = modelInclude.includes(model)
  122. //动态设置商品区域高度
  123. if (safeDistance) {
  124. _this.fullHeight = res.windowHeight - data.top - 34 + 'px';
  125. } else {
  126. _this.fullHeight = res.windowHeight - data.top + 'px';
  127. }
  128. },
  129. });
  130. }).exec();
  131. this.userId = o.id;
  132. this.getList()
  133. },
  134. computed: {
  135. deviceIdList() {
  136. let list = [];
  137. this.list.forEach(i => {
  138. if (i.checked) {
  139. list.push(i.deviceId)
  140. }
  141. })
  142. return list
  143. }
  144. },
  145. methods: {
  146. search(val) {
  147. this.saveKeyWord('goods', this.keyword)
  148. this.reset();
  149. this.getList()
  150. },
  151. tabClick(e) {
  152. this.current = e.index
  153. this.search()
  154. },
  155. saveKeyWord(type, val) {
  156. if (val) {
  157. let arr = []
  158. if (uni.getStorageSync(type)) {
  159. let arr = JSON.parse(uni.getStorageSync(type))
  160. if (arr.indexOf(val) != -1) {
  161. arr.splice(arr.indexOf(val), 1)
  162. }
  163. arr.unshift(val)
  164. if (arr.length > 6) {
  165. arr.pop()
  166. }
  167. this.historyList = JSON.parse(JSON.stringify(arr))
  168. uni.setStorageSync(type, JSON.stringify(arr))
  169. } else {
  170. arr.unshift(val)
  171. this.historyList = JSON.parse(JSON.stringify(arr))
  172. uni.setStorageSync(type, JSON.stringify(arr))
  173. }
  174. } else {
  175. return
  176. }
  177. },
  178. searchFast(e) {
  179. this.keyword = e
  180. this.search()
  181. },
  182. //扫码
  183. scan() {
  184. uni.scanCode({
  185. success: (res) => {
  186. this.keyword = res.result;
  187. this.getList()
  188. }
  189. });
  190. },
  191. //根据类目获取商品列表
  192. getList(id) {
  193. if (this.current == 0) {
  194. userDeviceList({
  195. page: {
  196. current: this.page,
  197. size: this.size
  198. },
  199. keyword: this.keyword,
  200. userInfoId: this.userId,
  201. }).then(res => {
  202. let newData = res.data.records;
  203. newData.forEach(i => {
  204. i.checked = false
  205. })
  206. if (newData.length < 10) {
  207. this.status = "nomore"
  208. } else {
  209. this.status = "loadmore"
  210. }
  211. this.list = this.list.concat(newData)
  212. console.log(this.list)
  213. })
  214. }
  215. if (this.current == 1) {
  216. mercDeviceList({
  217. page: {
  218. current: this.page,
  219. size: this.size
  220. },
  221. keyword: this.keyword,
  222. userInfoId: this.userId,
  223. }).then(res => {
  224. let newData = res.data;
  225. newData.forEach(i => {
  226. i.checked = false
  227. })
  228. if (newData.length < 10) {
  229. this.status = "nomore"
  230. } else {
  231. this.status = "loadmore"
  232. }
  233. this.list = this.list.concat(newData)
  234. })
  235. }
  236. },
  237. //触底加载更多
  238. scrolltolower() {
  239. if (this.status == 'nomore') return
  240. this.page++
  241. this.getList()
  242. },
  243. reset() {
  244. this.status == 'loadmore'
  245. this.page = 1;
  246. this.size = 10;
  247. this.list = [];
  248. },
  249. // 商品选中状态改变
  250. commItemSelect(e) {
  251. e.checked = !e.checked
  252. },
  253. submit() {
  254. uni.showModal({
  255. title: '提示',
  256. content: `是否确认${this.current==0?'解绑':'绑定'}`,
  257. success: res => {
  258. if (res.confirm) {
  259. if (this.current == 0) {
  260. delDevice({
  261. "userInfoId": this.userId,
  262. "deviceIdList": this.deviceIdList
  263. }).then(res => {
  264. this.$modal.msg('解绑成功')
  265. this.search()
  266. })
  267. } else {
  268. addDevice({
  269. "userInfoId": this.userId,
  270. "deviceIdList": this.deviceIdList
  271. }).then(res => {
  272. this.$modal.msg('绑定成功')
  273. this.search()
  274. })
  275. }
  276. } else if (res.cancel) {
  277. console.log('用户点击取消');
  278. }
  279. }
  280. });
  281. }
  282. }
  283. }
  284. </script>
  285. <style lang="scss" scoped>
  286. .container {
  287. .content {
  288. padding-bottom: 88rpx;
  289. .search {
  290. padding: 24rpx 24rpx 12rpx;
  291. background-color: #fff;
  292. position: relative;
  293. .scan-icon {
  294. position: absolute;
  295. right: 36rpx;
  296. top: 38rpx;
  297. z-index: 2;
  298. }
  299. .search-history {
  300. .history-item {
  301. margin-right: 24rpx;
  302. padding: 0 12rpx;
  303. background-color: #f2f2f2;
  304. color: #333;
  305. font-size: 24rpx;
  306. line-height: 40rpx;
  307. border-radius: 40rpx;
  308. margin-top: 24rpx;
  309. }
  310. }
  311. }
  312. .tab-wrap {
  313. background-color: #fff;
  314. .tab{
  315. width:50%;
  316. }
  317. }
  318. .list {
  319. width: 100%;
  320. padding: 0rpx 13rpx 12rpx;
  321. padding-bottom: calc(110rpx + env(safe-area-inset-bottom) / 2);
  322. overflow: hidden;
  323. .thumb-box {
  324. border-bottom: 1rpx solid #f4f4f4;
  325. display: flex;
  326. flex-flow: row nowrap;
  327. padding: 20rpx;
  328. background-color: #fff;
  329. border-radius: 12rpx;
  330. margin-top: 12rpx;
  331. }
  332. .select-img {
  333. width: 40rpx;
  334. height: 40rpx;
  335. margin-top: 14rpx;
  336. }
  337. .check-content {
  338. display: flex;
  339. flex-direction: row;
  340. align-items: center;
  341. padding-left: 12rpx;
  342. .comm-img {
  343. width: 130rpx;
  344. height: 130rpx;
  345. display: flex;
  346. flex-direction: row;
  347. align-items: center;
  348. justify-content: space-around;
  349. image {
  350. width: 100%;
  351. }
  352. }
  353. .comm-main {
  354. box-sizing: border-box;
  355. padding-left: 18rpx;
  356. color: #999;
  357. line-height: 60rpx;
  358. >view {
  359. padding: 4rpx 0;
  360. }
  361. >view:nth-child(1) {
  362. font-size: 30rpx;
  363. font-weight: bold;
  364. color: #333;
  365. }
  366. >view:nth-child(2) {
  367. font-size: 28rpx;
  368. }
  369. }
  370. }
  371. }
  372. }
  373. .btn {
  374. width: 100%;
  375. position: fixed;
  376. left: 0;
  377. padding: 0 24rpx;
  378. }
  379. .empty {
  380. position: absolute;
  381. left: 50%;
  382. top: 50%;
  383. transform: translate(-50%, -50%);
  384. }
  385. }
  386. </style>