dialog-selectEquipment.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. if (res.code == 200) {
  86. for (var i = 0; i < res.rows.length; i++) {
  87. processList.value[i] = {
  88. text: res.rows[i].processAlias,
  89. value: res.rows[i].processId
  90. }
  91. };
  92. selectedProcess.value = res.rows[0].processId;
  93. }
  94. })
  95. getEquipmentByUidAndDid(store.userInfo.userId, store.curDeptDetails).then(res => {
  96. if (res.code == 200) {
  97. getDayWorkItemList({
  98. userId: store.userInfo.userId,
  99. dayworkId: store.dayworkInfo.id,
  100. status: 1
  101. }).then(response => {
  102. equipmentList.value = res.rows
  103. if (response.code = 200) {
  104. for (let i = 0; i < res.rows.length; i++) {
  105. for (let j = 0; j < response.rows.length; j++) {
  106. if (response.rows[j].equipmentDetailId == res.rows[i].commonId) {
  107. equipmentList.value.splice(j, 1)
  108. }
  109. }
  110. };
  111. for (var i = 0; i < equipmentList.value.length; i++) {
  112. equipmentList.value[i] = {
  113. text: equipmentList.value[i].commonName,
  114. value: equipmentList.value[i]
  115. }
  116. };
  117. selectedEquipment.value = equipmentList.value[0];
  118. console.log(selectedEquipment.value)
  119. }
  120. })
  121. selectedEquipment.value = equipmentList.value[0];
  122. }
  123. })
  124. // let reqParam = {
  125. // userId: userId.value,
  126. // processId: store.dayworkInfo.currentProcess.id,
  127. // }
  128. // getUserequipmentList(reqParam).then(res => {
  129. // if (res.code == 200) {
  130. // equipments.value = res.rows
  131. // getDayWorkItemList({
  132. // userId: store.userInfo.userId,
  133. // dayworkId: store.dayworkInfo.id,
  134. // status: 1
  135. // }).then(response => {
  136. // // 过滤人员可选择的设备列表(选择之后不予展示)
  137. // for (let i = 0; i < response.rows.length; i++) {
  138. // for (let j = 0; j < equipments.value.length; j++) {
  139. // if (response.rows[i].equipmentDetailId == equipments.value[j]
  140. // .equipmentDetailId) {
  141. // equipments.value.splice(j, 1);
  142. // }
  143. // }
  144. // }
  145. // console.log(equipments.value)
  146. // baseDialog.value.open()
  147. // })
  148. // }
  149. // })
  150. baseDialog.value.open()
  151. }
  152. function open(data) {
  153. firstItem.value = data;
  154. init();
  155. }
  156. function close() {
  157. baseDialog.value.close()
  158. }
  159. defineExpose({
  160. open
  161. })
  162. function handleProcessChange() {
  163. }
  164. function handleEquipmentChange() {
  165. }
  166. function switchChange(e) {
  167. flag.value = e.detail.value;
  168. }
  169. // function handleSelection(item) {
  170. // // const buttonIndex = selection.value.findIndex(selectedItem => selectedItem === item);
  171. // // if (buttonIndex > -1) {
  172. // // selection.value.splice(buttonIndex, 1); // 取消选中
  173. // // } else {
  174. // // selection.value.push(item); // 选中
  175. // // }
  176. // selection.value[0] = item;
  177. // }
  178. function handleStart() {
  179. if (!selectedProcess.value || !selectedEquipment.value) {
  180. uni.showToast({
  181. icon: "none",
  182. title: "未选择工序或设备"
  183. })
  184. selectedProcess.value = null;
  185. selectedEquipment.value = null;
  186. return;
  187. }
  188. close();
  189. if (firstItem.value) {
  190. sendReqParam.value = {
  191. ...firstItem.value,
  192. processId: selectedProcess.value,
  193. equipmentDetailId: selectedEquipment.value.commonId,
  194. equipmentDetailCode: selectedEquipment.value.commonCode,
  195. startTime: timestampToTime(new Date()),
  196. status: 1
  197. };
  198. emit('handleAddDayWorkItem', sendReqParam.value);
  199. } else {
  200. emit('handleAddDayWorkItem', {
  201. processId: selectedProcess.value,
  202. equipmentDetailId: selectedEquipment.value.commonId,
  203. equipmentDetailCode: selectedEquipment.value.commonCode
  204. });
  205. }
  206. }
  207. </script>
  208. <style lang="scss">
  209. .dialog-body {
  210. .equipment-container {
  211. height: 300rpx;
  212. overflow: auto;
  213. flex-wrap: wrap;
  214. justify-content: flex-start;
  215. margin: 24rpx 0 0 7%;
  216. .item {
  217. width: 236rpx;
  218. height: 60rpx;
  219. text-align: center;
  220. line-height: 60rpx;
  221. border-radius: 6rpx;
  222. margin: 16rpx;
  223. flex: 0 0 40%;
  224. border: 1px solid #000000;
  225. }
  226. .selected {
  227. background-color: #1684fc;
  228. color: #FFF;
  229. }
  230. }
  231. .add-btn-container {
  232. margin-top: 32rpx;
  233. .btn {
  234. flex: 1;
  235. }
  236. }
  237. .switch {
  238. font-size: 26rpx;
  239. align-items: center;
  240. justify-content: space-between;
  241. margin: 16rpx;
  242. }
  243. }
  244. </style>