dialog-selectEquipment.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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['equipmentCode']}}</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. const baseDialog = ref(null)
  32. const selection = ref([])
  33. const equiments = ref([])
  34. const emit = defineEmits(['handleAddDayWorkItem'])
  35. const userId = ref(null)
  36. onLoad(() => {
  37. userId.value = store.userInfo.userId || "";
  38. init();
  39. })
  40. function init() {
  41. let reqParam = {
  42. userId: userId.value,
  43. processId: store.dayworkInfo.currentProcess.id
  44. }
  45. getUserequipmentList(reqParam).then(res => {
  46. equiments.value = res.rows
  47. })
  48. }
  49. function open() {
  50. baseDialog.value.open()
  51. }
  52. function close() {
  53. baseDialog.value.close()
  54. }
  55. defineExpose({
  56. open
  57. })
  58. function isSelected(item) {
  59. return selection.value.includes(item);
  60. }
  61. function handleSelection(item) {
  62. const buttonIndex = selection.value.findIndex(selectedItem => selectedItem === item);
  63. if (buttonIndex > -1) {
  64. selection.value.splice(buttonIndex, 1); // 取消选中
  65. } else {
  66. selection.value.push(item); // 选中
  67. }
  68. }
  69. function handleStart() {
  70. console.log(selection.value)
  71. emit('handleAddDayWorkItem',selection.value)
  72. close();
  73. }
  74. </script>
  75. <style lang="scss">
  76. .dialog-body {
  77. .equipment-container {
  78. height: 300rpx;
  79. overflow: auto;
  80. flex-wrap: wrap;
  81. justify-content: flex-start;
  82. margin: 24rpx 0 0 7%;
  83. .item {
  84. width: 236rpx;
  85. height: 60rpx;
  86. text-align: center;
  87. line-height: 60rpx;
  88. border-radius: 6rpx;
  89. margin: 16rpx;
  90. flex: 0 0 40%;
  91. border: 1px solid #000000;
  92. }
  93. .selected {
  94. background-color: #1684fc;
  95. color: #FFF;
  96. }
  97. }
  98. .add-btn-container {
  99. margin-top: 32rpx;
  100. .btn {
  101. flex: 1;
  102. }
  103. }
  104. }
  105. </style>