index.vue 6.0 KB

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