index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <view class="container">
  3. <view class="title">已绑设备</view>
  4. <view class="prompt">长按设备解绑</view>
  5. <view class="equipmentList">
  6. <view style="height: calc(100% - 400rpx);">
  7. <view class="entry uni-row" v-for="(item,index) in equipmentList">
  8. <view class="equipmentList-item" @longpress="handleShowUnbind(item)">{{item.equipmentDetailCode}}
  9. </view>
  10. <view :class="{'unbind': true,'visible': showUnbind === item}" @click="handleUnbind(item)">解绑</view>
  11. </view>
  12. </view>
  13. <view v-if="curScanEquipment.length > 0" class="scanEquiementList uni-row">
  14. <view class="equipmentNo uni-row" v-for="(item,index) in curScanEquipment">
  15. <text>{{item.equipmentDetailCode}}</text>
  16. <text @click="handleDelEquipmentNo(item,index)">×</text>
  17. </view>
  18. </view>
  19. </view>
  20. <view class="bottom uni-row">
  21. <button class="btn" @click="handleScanCode">扫码</button>
  22. <button class="btn" style="background-color: #1684fc;" @click="handleSubmit">提交</button>
  23. </view>
  24. </view>
  25. <dialog-confirm ref="confirm" @submit="handleConfirmUnbind" @reflush="reflush"></dialog-confirm>
  26. <QrScanner v-if="showQrCodeReader" @decode="onDecodeHandler" @close="qrReaderClose" />
  27. </template>
  28. <script setup>
  29. import {
  30. ref
  31. } from 'vue'
  32. import {
  33. onLoad
  34. } from '@dcloudio/uni-app'
  35. import {
  36. getUserInfo
  37. } from '@/api/login/index.js'
  38. import QrScanner from '../vueQrCode/index.vue'
  39. import {
  40. saveUserequipment,
  41. getUserequipmentList,
  42. unbindQuipment
  43. } from '@/api/business/userEquipment/equipmentGroup.js'
  44. import {
  45. getEquipmentUserList
  46. } from '@/api/business/equipmentUser.js'
  47. import {
  48. store
  49. } from '@/store/index.js'
  50. const showUnbind = ref({}) // 解绑按钮显示于隐藏
  51. const equipmentList = ref([]) // 回显用
  52. const userEquipmentData = ref({}) // 保存用
  53. const curScanEquipment = ref([])
  54. const confirm = ref(null)
  55. const showQrCodeReader = ref(false);
  56. onLoad(() => {
  57. init();
  58. })
  59. /**
  60. * 页面初始化
  61. */
  62. function init() {
  63. equipmentList.value = [];
  64. getUserequipmentList({
  65. userId: store.userInfo.userId
  66. }).then(res => {
  67. if (res.code == 200) {
  68. equipmentList.value = [...res.rows];
  69. }
  70. })
  71. }
  72. /**
  73. * 刷新
  74. */
  75. function reflush() {
  76. init();
  77. }
  78. function handleConfirmUnbind() {
  79. handleSaveInfo();
  80. }
  81. /**
  82. * 长按显示解绑按钮
  83. * @param {Object} item
  84. */
  85. function handleShowUnbind(item) {
  86. if (showUnbind.value === item) {
  87. showUnbind.value = {};
  88. } else {
  89. showUnbind.value = item;
  90. }
  91. }
  92. /**
  93. * 解绑
  94. * @param {Object} item 当前选择要解绑的对象
  95. */
  96. function handleUnbind(item) {
  97. unbindQuipment(item.id).then(res => {
  98. init();
  99. })
  100. }
  101. function handleDelEquipmentNo(item, index) {
  102. curScanEquipment.value.splice(index, 1);
  103. }
  104. //H5扫码器回调
  105. function onDecodeHandler(data) {
  106. showQrCodeReader.value = false;
  107. let equipment = JSON.parse(data);
  108. // 判断二维码对不对
  109. if (!equipment.equipmentDetailId || equipment.equipmentDetailId == "") {
  110. uni.showToast({
  111. icon: "none",
  112. title: "请扫设备码"
  113. })
  114. return;
  115. }
  116. for (let i = 0; i < curScanEquipment.value.length; i++) {
  117. if (curScanEquipment.value[i].equipmentDetailId === equipment.equipmentDetailId) {
  118. uni.showToast({
  119. icon: "none",
  120. title: "请勿重复扫码"
  121. })
  122. return;
  123. }
  124. }
  125. curScanEquipment.value.push(equipment)
  126. // 设置绑定员工的信息
  127. userEquipmentData.value = {
  128. userId: store.userInfo.userId,
  129. nickName: store.userInfo.nickName,
  130. deptId: store.curDeptDetails.deptId,
  131. userEquipmentList: curScanEquipment.value
  132. }
  133. }
  134. //H5扫码器关闭
  135. function qrReaderClose() {
  136. showQrCodeReader.value = false;
  137. }
  138. function handleScanCode() {
  139. showQrCodeReader.value = true;
  140. // 引入原生插件
  141. // const mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module");
  142. // // 调用插件的 mpaasScan 方法
  143. // mpaasScanModule.mpaasScan({
  144. // // 扫码识别类型,参数可多选,qrCode、barCode,
  145. // // 如不设置,默认识别所有扫码类型,可能有些许影响识别效率
  146. // scanType: ["qrCode", "barCode"],
  147. // // 是否隐藏相册,默认false不隐藏
  148. // hideAlbum: false,
  149. // },
  150. // (ret) => {
  151. // let equipment = JSON.parse(ret.resp_result);
  152. // // 判断二维码对不对
  153. // if (!equipment.equipmentDetailId || equipment.equipmentDetailId == "") {
  154. // uni.showToast({
  155. // icon: "none",
  156. // title: "请扫设备码"
  157. // })
  158. // return;
  159. // }
  160. // for (let i = 0; i < curScanEquipment.value.length; i++) {
  161. // if (curScanEquipment.value[i].equipmentDetailId === equipment.equipmentDetailId) {
  162. // uni.showToast({
  163. // icon: "none",
  164. // title: "请勿重复扫码"
  165. // })
  166. // return;
  167. // }
  168. // }
  169. // curScanEquipment.value.push(equipment)
  170. // // 设置绑定员工的信息
  171. // userEquipmentData.value = {
  172. // userId: store.userInfo.userId,
  173. // nickName: store.userInfo.nickName,
  174. // deptId: store.curDeptDetails.deptId,
  175. // userEquipmentList: curScanEquipment.value
  176. // }
  177. // }
  178. // );
  179. }
  180. console.log(store)
  181. function handleSubmit() {
  182. handleSaveInfo(userEquipmentData.value);
  183. }
  184. /**
  185. * 绑定设备
  186. */
  187. function handleSaveInfo(data) {
  188. if(data.length != 0){
  189. saveUserequipment(data).then(res => {
  190. if (res.code === 200) {
  191. init();
  192. uni.showToast({
  193. icon: "success",
  194. title: "设备绑定成功"
  195. })
  196. }
  197. })
  198. }
  199. }
  200. </script>
  201. <style lang="scss">
  202. .container {
  203. height: 100%;
  204. background-color: rgba(245, 245, 245, 1);
  205. .title {
  206. width: 100%;
  207. font-size: 42rpx;
  208. font-weight: bold;
  209. height: 100rpx;
  210. text-align: center;
  211. line-height: 100rpx;
  212. }
  213. .prompt {
  214. width: 100%;
  215. text-align: center;
  216. color: lightgrey;
  217. }
  218. .bottom {
  219. justify-content: space-between;
  220. position: fixed;
  221. bottom: 0;
  222. left: 0;
  223. right: 0;
  224. .btn {
  225. background-color: rgba(0, 226, 166, 1);
  226. color: white;
  227. margin: 20rpx auto;
  228. width: 44%;
  229. }
  230. }
  231. .equipmentList {
  232. width: 94%;
  233. height: calc(90% - 144rpx);
  234. background-color: rgba(255, 255, 255, 1);
  235. margin: 10rpx auto;
  236. padding: 20rpx 0 0 0;
  237. border-radius: 18rpx;
  238. overflow: auto;
  239. .scanEquiementList {
  240. height: 380rpx;
  241. width: 94%;
  242. border-top: 1rpx solid #999;
  243. margin: 0 auto;
  244. justify-content: flex-start;
  245. align-content: flex-start;
  246. flex-wrap: wrap;
  247. overflow: auto;
  248. .equipmentNo {
  249. padding: 0 10rpx;
  250. margin: 10rpx 24rpx;
  251. justify-content: space-between;
  252. align-items: center;
  253. width: 260rpx;
  254. height: 60rpx;
  255. border: 1px solid rgba(213, 213, 213, 1);
  256. border-radius: 6rpx;
  257. }
  258. }
  259. .entry {
  260. justify-content: center;
  261. margin: 10rpx 0;
  262. position: relative;
  263. .equipmentList-item {
  264. position: relative;
  265. width: 75%;
  266. height: 80rpx;
  267. color: rgba(255, 255, 255, 1);
  268. background-color: rgba(22, 132, 252, 1);
  269. border-radius: 12rpx;
  270. text-align: center;
  271. line-height: 80rpx;
  272. }
  273. .unbind {
  274. position: relative;
  275. z-index: 2;
  276. margin-left: -15%;
  277. width: 15%;
  278. height: 80rpx;
  279. color: rgba(255, 255, 255, 1);
  280. background-color: red;
  281. border-radius: 0 12rpx 12rpx 0;
  282. text-align: center;
  283. line-height: 80rpx;
  284. visibility: hidden;
  285. }
  286. .visible {
  287. visibility: visible;
  288. }
  289. }
  290. }
  291. }
  292. </style>