index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <view class="container">
  3. <view class="title">已绑设备</view>
  4. <view class="prompt">长按设备解绑</view>
  5. <view class="equipmentList">
  6. <view class="entry uni-row" v-for="(item,index) in equipmentList">
  7. <view class="equipmentList-item" @longpress="handleShowUnbind(item)">{{item.equipmentCode}}</view>
  8. <view :class="{'unbind': true,'visible': showUnbind === item}" @click="handleUnbind(item)">解绑</view>
  9. </view>
  10. </view>
  11. <view>
  12. <button class="btn" @click="handleScanCode">扫码</button>
  13. </view>
  14. </view>
  15. <dialog-confirm ref="confirm" @reflush="reflush"></dialog-confirm>
  16. </template>
  17. <script setup>
  18. import {
  19. ref
  20. } from 'vue'
  21. import {
  22. onLoad
  23. } from '@dcloudio/uni-app'
  24. import {
  25. getUserInfo
  26. } from '@/api/login/index.js'
  27. import {
  28. saveUserequipment,
  29. getUserequipmentList,
  30. unbindQuipment
  31. } from '@/api/business/userEquipment/userEquipment.js'
  32. import {
  33. getEquipmentUserList
  34. } from '@/api/business/equipmentUser.js'
  35. const showUnbind = ref({}) // 解绑按钮显示于隐藏
  36. const equipmentList = ref([]) // 回显用
  37. const userEquipmentData = ref({}) // 保存用
  38. const curBindDetails = ref([]) // 分配给员工的设备信息
  39. const curBindEquipmentIds = ref([]) // 分配给当前员工的设备id列表
  40. const userInfo = ref({}) // 当前登录用信息
  41. const confirm = ref(null)
  42. onLoad(() => {
  43. init();
  44. })
  45. /**
  46. * 页面初始化
  47. */
  48. function init() {
  49. let data = {}
  50. getUserInfo().then(response => {
  51. userInfo.value = response.data;
  52. data.userId = response.data.userId;
  53. getUserequipmentList(data).then(res => {
  54. equipmentList.value = res.rows;
  55. })
  56. getEquipmentUserList(data).then(res => {
  57. curBindDetails.value = res.rows;
  58. for (var i = 0; i < curBindDetails.value.length; i++) {
  59. curBindEquipmentIds.value.push(curBindDetails.value[i].equipmentDetailId)
  60. }
  61. })
  62. })
  63. }
  64. /**
  65. * 刷新
  66. */
  67. function reflush(){
  68. console.log('111111111111111111111111111113')
  69. init();
  70. }
  71. /**
  72. * 长按显示解绑按钮
  73. * @param {Object} item
  74. */
  75. function handleShowUnbind(item) {
  76. if (showUnbind.value === item) {
  77. showUnbind.value = {};
  78. } else {
  79. showUnbind.value = item;
  80. }
  81. }
  82. /**
  83. * 解绑
  84. * @param {Object} item 当前选择要解绑的对象
  85. */
  86. function handleUnbind(item) {
  87. unbindQuipment(item.id).then(res => {
  88. init();
  89. })
  90. }
  91. /**
  92. * 扫码
  93. */
  94. function handleScanCode() {
  95. uni.scanCode({
  96. scanType: ['qrCode'], // 条形码扫描
  97. onlyFromCamera: true, // 只允许相机扫码
  98. success: function(res) {
  99. let equipment = JSON.parse(res.result);
  100. for (let i = 0; i < equipmentList.value.length; i++) {
  101. // 判断是否已经扫码
  102. if (equipmentList.value[i].equipmentId == equipment.equipmentId) {
  103. uni.showToast({
  104. icon: "error",
  105. title: "载具已存在"
  106. })
  107. return;
  108. }
  109. }
  110. // 设置绑定员工的信息
  111. userEquipmentData.value = JSON.parse(res.result);
  112. userEquipmentData.value.userId = userInfo.value.userId;
  113. userEquipmentData.value.nickName = userInfo.value.nickName;
  114. // 判断该设备是否分配给改员工
  115. if (!curBindEquipmentIds.value.includes(equipment.equipmentId)) {
  116. let msg = '当前员工没有分配到该设备,确定继续绑定吗?';
  117. confirm.value.open(msg,userEquipmentData.value);
  118. }else{
  119. handleSaveInfo();
  120. }
  121. }
  122. });
  123. }
  124. /**
  125. * 绑定设备
  126. */
  127. function handleSaveInfo() {
  128. // console.log(userEquipmentData.value)
  129. saveUserequipment(userEquipmentData.value).then(res => {
  130. if(res.code === 200){
  131. init();
  132. uni.showToast({
  133. icon: "success",
  134. title: "设备绑定成功"
  135. })
  136. }
  137. })
  138. }
  139. </script>
  140. <style lang="scss">
  141. .container {
  142. height: 100%;
  143. background-color: rgba(245, 245, 245, 1);
  144. .title {
  145. width: 100%;
  146. font-size: 42rpx;
  147. font-weight: bold;
  148. height: 100rpx;
  149. text-align: center;
  150. line-height: 100rpx;
  151. }
  152. .prompt {
  153. width: 100%;
  154. text-align: center;
  155. color: lightgrey;
  156. }
  157. .btn {
  158. background-color: rgba(0, 226, 166, 1);
  159. color: white;
  160. margin: 20rpx auto;
  161. width: 80%;
  162. position: fixed;
  163. bottom: 0;
  164. left: 0;
  165. right: 0;
  166. }
  167. .equipmentList {
  168. width: 94%;
  169. height: calc(90% - 100rpx);
  170. background-color: rgba(255, 255, 255, 1);
  171. margin: 10rpx auto;
  172. padding: 20rpx 0 0 0;
  173. border-radius: 18rpx;
  174. overflow: auto;
  175. .entry {
  176. justify-content: center;
  177. margin: 10rpx 0;
  178. position: relative;
  179. .equipmentList-item {
  180. position: relative;
  181. width: 75%;
  182. height: 80rpx;
  183. color: rgba(255, 255, 255, 1);
  184. background-color: rgba(22, 132, 252, 1);
  185. border-radius: 12rpx;
  186. text-align: center;
  187. line-height: 80rpx;
  188. }
  189. .unbind {
  190. position: relative;
  191. z-index: 2;
  192. margin-left: -15%;
  193. width: 15%;
  194. height: 80rpx;
  195. color: rgba(255, 255, 255, 1);
  196. background-color: red;
  197. border-radius: 0 12rpx 12rpx 0;
  198. text-align: center;
  199. line-height: 80rpx;
  200. visibility: hidden;
  201. }
  202. .visible {
  203. visibility: visible;
  204. }
  205. }
  206. }
  207. }
  208. </style>