dialog-selectEquipment.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <dialog-base ref="baseDialog" title="请选择">
  3. <!-- <view class="equipment-container uni-row ">
  4. <view v-for="(item, index) in equipments" :class="{'item':true,'selected': isSelected(item)}" :key="index"
  5. @click="handleSelection(item)"><text class="label">{{item['equipmentDetailCode']}}</text></view>
  6. </view> -->
  7. <view>
  8. <uni-section title="工序" type="line">
  9. <uni-data-select v-model="selectedProcess" :localdata="processList" :clear="false"
  10. @change="handleProcessChange"></uni-data-select>
  11. </uni-section>
  12. </view>
  13. <view>
  14. <uni-section title="设备" type="line">
  15. <uni-data-select v-model="selectedEquipment" :localdata="equipmentList" :clear="false"
  16. @change="handleEquipmentChange"></uni-data-select>
  17. </uni-section>
  18. </view>
  19. <view class="switch uni-row">
  20. <text class="label">是否邀请协作者</text>
  21. <view class="uni-row" style="align-items: center;">
  22. <text>否</text>
  23. <switch class="switch" @change="switchChange" />
  24. <text>是</text>
  25. </view>
  26. </view>
  27. <view v-if="flag">
  28. <uni-easyinput class="uni-mt-5" suffixIcon="search" focus v-model="userName" placeholder="请输入协作者编号"
  29. @iconClick="iconClick"></uni-easyinput>
  30. </view>
  31. <view class="add-btn-container uni-row">
  32. <button type="primary" class="btn" @click="handleStart">开始</button>
  33. </view>
  34. </dialog-base>
  35. </template>
  36. <script setup>
  37. import {
  38. ref
  39. } from 'vue'
  40. import {
  41. onLoad
  42. } from '@dcloudio/uni-app'
  43. import {
  44. getProcessList
  45. } from '@/api/business/deptProcess.js'
  46. import {
  47. getUserequipmentList
  48. } from '@/api/business/userEquipment/userEquipment.js'
  49. import {
  50. getUserInfo
  51. } from '@/api/login/index.js'
  52. import {
  53. saveDayWorkItem,
  54. getDayWorkItemList
  55. } from '@/api/business/dayWorkItem.js'
  56. import {
  57. store
  58. } from '@/store/index.js'
  59. import {
  60. getEquipmentByUidAndDid
  61. } from '@/api/resourceGroup/resourceGroupDetail.js'
  62. import {
  63. timestampToTime
  64. } from '@/utils/common.js'
  65. const baseDialog = ref(null)
  66. const equipments = ref([]) // 接收设备列表信息
  67. const equipmentList = ref([])
  68. const emit = defineEmits(['handleAddDayWorkItem'])
  69. const userId = ref(null)
  70. const firstItem = ref(null);
  71. const sendReqParam = ref({})
  72. const processList = ref([])
  73. const selectedProcess = ref(null)
  74. const selectedEquipment = ref(null)
  75. const flag = ref(false)
  76. const userName = ref(null)
  77. onLoad(() => {
  78. userId.value = store.userInfo.userId || "";
  79. })
  80. function init() {
  81. getProcessList({
  82. // tenantId: store.tenantId,
  83. deptId: store.curDeptDetails
  84. }).then(res => {
  85. console.log(res)
  86. if (res.code == 200) {
  87. for (var i = 0; i < res.data.length; i++) {
  88. processList.value[i] = {
  89. text: res.data[i].processAlias,
  90. value: res.data[i].processId
  91. }
  92. };
  93. selectedProcess.value = res.data[0].processId;
  94. }
  95. })
  96. getEquipmentByUidAndDid(store.userInfo.userId, store.curDeptDetails).then(res => {
  97. if (res.code == 200) {
  98. getDayWorkItemList({
  99. userId: store.userInfo.userId,
  100. dayworkId: store.dayworkInfo.id,
  101. status: 1
  102. }).then(response => {
  103. equipmentList.value = res.rows
  104. if (response.code = 200) {
  105. for (let i = 0; i < res.rows.length; i++) {
  106. for (let j = 0; j < response.rows.length; j++) {
  107. if (response.rows[j].equipmentDetailId == res.rows[i].commonId) {
  108. equipmentList.value.splice(j, 1)
  109. }
  110. }
  111. };
  112. for (var i = 0; i < equipmentList.value.length; i++) {
  113. equipmentList.value[i] = {
  114. text: equipmentList.value[i].commonCode,
  115. value: equipmentList.value[i]
  116. }
  117. };
  118. selectedEquipment.value = equipmentList.value[0].value;
  119. }
  120. baseDialog.value.open()
  121. })
  122. }
  123. })
  124. }
  125. function open(data) {
  126. firstItem.value = data;
  127. init();
  128. }
  129. function close() {
  130. baseDialog.value.close()
  131. }
  132. defineExpose({
  133. open
  134. })
  135. function handleProcessChange() {
  136. }
  137. function handleEquipmentChange() {
  138. }
  139. function switchChange(e) {
  140. flag.value = e.detail.value;
  141. }
  142. // function handleSelection(item) {
  143. // // const buttonIndex = selection.value.findIndex(selectedItem => selectedItem === item);
  144. // // if (buttonIndex > -1) {
  145. // // selection.value.splice(buttonIndex, 1); // 取消选中
  146. // // } else {
  147. // // selection.value.push(item); // 选中
  148. // // }
  149. // selection.value[0] = item;
  150. // }
  151. function handleStart() {
  152. if (!selectedProcess.value || !selectedEquipment.value) {
  153. uni.showToast({
  154. icon: "none",
  155. title: "未选择工序或设备"
  156. })
  157. selectedProcess.value = null;
  158. selectedEquipment.value = null;
  159. return;
  160. }
  161. close();
  162. if (firstItem.value) {
  163. sendReqParam.value = {
  164. ...firstItem.value,
  165. processId: selectedProcess.value,
  166. equipmentDetailId: selectedEquipment.value.commonId,
  167. equipmentDetailCode: selectedEquipment.value.commonCode,
  168. startTime: timestampToTime(new Date()),
  169. status: 1
  170. };
  171. emit('handleAddDayWorkItem', sendReqParam.value);
  172. } else {
  173. emit('handleAddDayWorkItem', {
  174. processId: selectedProcess.value,
  175. equipmentDetailId: selectedEquipment.value.commonId,
  176. equipmentDetailCode: selectedEquipment.value.commonCode
  177. });
  178. }
  179. }
  180. </script>
  181. <style lang="scss">
  182. .dialog-body {
  183. .equipment-container {
  184. height: 300rpx;
  185. overflow: auto;
  186. flex-wrap: wrap;
  187. justify-content: flex-start;
  188. margin: 24rpx 0 0 7%;
  189. .item {
  190. width: 236rpx;
  191. height: 60rpx;
  192. text-align: center;
  193. line-height: 60rpx;
  194. border-radius: 6rpx;
  195. margin: 16rpx;
  196. flex: 0 0 40%;
  197. border: 1px solid #000000;
  198. }
  199. .selected {
  200. background-color: #1684fc;
  201. color: #FFF;
  202. }
  203. }
  204. .add-btn-container {
  205. margin-top: 32rpx;
  206. .btn {
  207. flex: 1;
  208. }
  209. }
  210. .switch {
  211. font-size: 26rpx;
  212. align-items: center;
  213. justify-content: space-between;
  214. margin: 16rpx;
  215. }
  216. }
  217. </style>