index.vue 6.1 KB

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