dialog-selectEquipment.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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
  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. init();
  44. })
  45. function init() {
  46. let reqParam = {
  47. userId: userId.value,
  48. processId: store.dayworkInfo.currentProcess.id
  49. }
  50. getUserequipmentList(reqParam).then(res => {
  51. console.log(res)
  52. equiments.value = res.rows
  53. })
  54. }
  55. function open(data) {
  56. firstItem.value = data;
  57. console.log(firstItem.value)
  58. baseDialog.value.open()
  59. }
  60. function close() {
  61. baseDialog.value.close()
  62. }
  63. defineExpose({
  64. open
  65. })
  66. function isSelected(item) {
  67. return selection.value.includes(item);
  68. }
  69. function handleSelection(item) {
  70. const buttonIndex = selection.value.findIndex(selectedItem => selectedItem === item);
  71. if (buttonIndex > -1) {
  72. selection.value.splice(buttonIndex, 1); // 取消选中
  73. } else {
  74. selection.value.push(item); // 选中
  75. }
  76. }
  77. function handleStart() {
  78. console.log(selection.value)
  79. if (firstItem.value) {
  80. for (var i = 0; i < selection.value.length; i++) {
  81. sendReqParam.value.push(firstItem.value);
  82. sendReqParam.value[i].equipmentDetailId = selection.value[i].equipmentId;
  83. sendReqParam.value[i].equipmentDetailCode = selection.value[i].equipmentCode;
  84. sendReqParam.value[i].startTime = timestampToTime(new Date());
  85. sendReqParam.value[i].status = 1;
  86. if (i > 0) {
  87. sendReqParam.value.value[i].id = null;
  88. }
  89. }
  90. emit('handleAddDayWorkItem', sendReqParam.value)
  91. }
  92. emit('handleAddDayWorkItem', selection.value)
  93. close();
  94. }
  95. </script>
  96. <style lang="scss">
  97. .dialog-body {
  98. .equipment-container {
  99. height: 300rpx;
  100. overflow: auto;
  101. flex-wrap: wrap;
  102. justify-content: flex-start;
  103. margin: 24rpx 0 0 7%;
  104. .item {
  105. width: 236rpx;
  106. height: 60rpx;
  107. text-align: center;
  108. line-height: 60rpx;
  109. border-radius: 6rpx;
  110. margin: 16rpx;
  111. flex: 0 0 40%;
  112. border: 1px solid #000000;
  113. }
  114. .selected {
  115. background-color: #1684fc;
  116. color: #FFF;
  117. }
  118. }
  119. .add-btn-container {
  120. margin-top: 32rpx;
  121. .btn {
  122. flex: 1;
  123. }
  124. }
  125. }
  126. </style>