dialog-selectEquipment.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <dialog-base ref="baseDialog" title="选择设备">
  3. <view class="equipment-container uni-row ">
  4. <view v-for="(item, index) in equiments" :class="{'item':true,'selected': isSelected(item)}" :key="index"
  5. @click="handleSelection(item)"><text class="label">{{item['equipmentDetailCode']}}</text></view>
  6. </view>
  7. <view class="add-btn-container uni-row">
  8. <button type="primary" class="btn" @click="handleStart">开始</button>
  9. </view>
  10. </dialog-base>
  11. </template>
  12. <script setup>
  13. import {
  14. ref
  15. } from 'vue'
  16. import {
  17. onLoad
  18. } from '@dcloudio/uni-app'
  19. import {
  20. getUserequipmentList
  21. } from '@/api/business/userEquipment/userEquipment.js'
  22. import {
  23. getUserInfo
  24. } from '@/api/login/index.js'
  25. import {
  26. saveDayWorkItem,getDayWorkItemList
  27. } from '@/api/business/dayWorkItem.js'
  28. import {
  29. store
  30. } from '@/store/index.js'
  31. import {
  32. timestampToTime
  33. } from '@/utils/common.js'
  34. const baseDialog = ref(null)
  35. const selection = ref([])
  36. const equiments = ref([]) // 接收设备列表信息
  37. const emit = defineEmits(['handleAddDayWorkItem'])
  38. const userId = ref(null)
  39. const firstItem = ref(null);
  40. const sendReqParam = ref([])
  41. onLoad(() => {
  42. userId.value = store.userInfo.userId || "";
  43. })
  44. function init() {
  45. let reqParam = {
  46. userId: userId.value,
  47. processId: store.dayworkInfo.currentProcess.id,
  48. }
  49. getUserequipmentList(reqParam).then(res => {
  50. if(res.code == 200){
  51. equiments.value = res.rows
  52. getDayWorkItemList({
  53. userId: store.userInfo.userId,
  54. dayworkId: store.dayworkInfo.id,
  55. status: 1
  56. }).then(response => {
  57. // 过滤人员可选择的设备列表(选择之后不予展示)
  58. for (let i = 0; i < response.rows.length; i++) {
  59. for (let j = 0; j < equiments.value.length; j++) {
  60. if(response.rows[i].equipmentDetailId == equiments.value[j].equipmentDetailId){
  61. equiments.value.splice(j,1);
  62. }
  63. }
  64. }
  65. console.log(equiments.value)
  66. baseDialog.value.open()
  67. })
  68. }
  69. })
  70. }
  71. function open(data) {
  72. firstItem.value = data;
  73. init();
  74. }
  75. function close() {
  76. baseDialog.value.close()
  77. }
  78. defineExpose({
  79. open
  80. })
  81. function isSelected(item) {
  82. return selection.value.includes(item);
  83. }
  84. function handleSelection(item) {
  85. // const buttonIndex = selection.value.findIndex(selectedItem => selectedItem === item);
  86. // if (buttonIndex > -1) {
  87. // selection.value.splice(buttonIndex, 1); // 取消选中
  88. // } else {
  89. // selection.value.push(item); // 选中
  90. // }
  91. selection.value[0] = item;
  92. }
  93. function handleStart() {
  94. if(selection.value.length == 0){
  95. uni.showToast({
  96. icon: "error",
  97. title: "未选择设备"
  98. })
  99. close();
  100. return;
  101. }
  102. close();
  103. if (firstItem.value) {
  104. for (var i = 0; i < selection.value.length; i++) {
  105. sendReqParam.value.push(firstItem.value);
  106. sendReqParam.value[i].equipmentDetailId = selection.value[i].equipmentDetailId;
  107. sendReqParam.value[i].equipmentDetailCode = selection.value[i].equipmentDetailCode;
  108. sendReqParam.value[i].startTime = timestampToTime(new Date());
  109. sendReqParam.value[i].status = 1;
  110. if (i > 0) {
  111. sendReqParam.value[i].id = null;
  112. }
  113. }
  114. emit('handleAddDayWorkItem', sendReqParam.value);
  115. selection.value = [];
  116. equiments.value = [];
  117. }else{
  118. console.log(selection.value);
  119. emit('handleAddDayWorkItem', selection.value);
  120. equiments.value = [];
  121. selection.value = [];
  122. }
  123. }
  124. </script>
  125. <style lang="scss">
  126. .dialog-body {
  127. .equipment-container {
  128. height: 300rpx;
  129. overflow: auto;
  130. flex-wrap: wrap;
  131. justify-content: flex-start;
  132. margin: 24rpx 0 0 7%;
  133. .item {
  134. width: 236rpx;
  135. height: 60rpx;
  136. text-align: center;
  137. line-height: 60rpx;
  138. border-radius: 6rpx;
  139. margin: 16rpx;
  140. flex: 0 0 40%;
  141. border: 1px solid #000000;
  142. }
  143. .selected {
  144. background-color: #1684fc;
  145. color: #FFF;
  146. }
  147. }
  148. .add-btn-container {
  149. margin-top: 32rpx;
  150. .btn {
  151. flex: 1;
  152. }
  153. }
  154. }
  155. </style>