dialog-selectProduction.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <dialog-base class="dialog-body" ref="baseDialog" title="箱号">
  3. <view class="selectedProcess">
  4. <uni-section title="可根据工艺列表筛选箱号" type="square">
  5. <uni-data-select v-model="selectedProcess" :localdata="processList" :clear="true"
  6. @change="handleProcessChange"></uni-data-select>
  7. </uni-section>
  8. </view>
  9. <view class="carrierList-title uni-row">
  10. <view class="uni-row" style="width: 46%;justify-content: center;">批次号</view>
  11. <view class="uni-row" style="width: 18%;justify-content: center;">箱号</view>
  12. <view class="uni-row" style="width: 32%;justify-content: center;">位置</view>
  13. </view>
  14. <view class="carrierList uni-row">
  15. <view class="carrierItem uni-row" v-for="(item,index) in carrierList">
  16. <view style="width: 46%;text-align: left;">{{ item.lotCode }}</view>
  17. <view style="width: 27%;text-align: center;">{{ item.carrierCode }}</view>
  18. <view style="width: 27%;word-wrap: break-word;text-align: left;">{{ item.place }}</view>
  19. </view>
  20. </view>
  21. </dialog-base>
  22. </template>
  23. <script setup>
  24. import {
  25. ref,
  26. getCurrentInstance
  27. } from 'vue'
  28. import {
  29. store
  30. } from '../../store';
  31. import {
  32. getAvailableCarrierList,
  33. selectProcessList
  34. } from '@/api/business/dayWork.js'
  35. import {
  36. getProcessList
  37. } from '@/api/business/deptProcess.js'
  38. const baseDialog = ref(null)
  39. const selectedProcess = ref(0)
  40. const processList = ref([])
  41. const isNormalLot = ref("true")
  42. const curProcessId = ref('')
  43. const processSquence = ref([])
  44. const carrierList = ref([])
  45. function open(data) {
  46. reset();
  47. console.log(store.planDetails)
  48. console.log(data)
  49. if(data == 1) {
  50. isNormalLot.value = "false"
  51. }
  52. // getProcessList({
  53. // deptId: store.curDeptDetails.deptId,
  54. // planDetailId: store.planDetails.id
  55. // }).then(res => {
  56. // if (res.code == 200) {
  57. // for (let i = 0; i < res.data.length; i++) {
  58. // processList.value[i] = {
  59. // text: res.data[i].processAlias,
  60. // value: res.data[i].processId
  61. // }
  62. // }
  63. // }
  64. // baseDialog.value.open()
  65. // })
  66. // return
  67. Promise.all([getProcessList({
  68. deptId: store.curDeptDetails.deptId,
  69. planDetailId: store.planDetails.id
  70. }), getAvailableCarrierList({
  71. planDetailId: store.planDetails.id,
  72. deptId: store.curDeptDetails.deptId
  73. }), selectProcessList({
  74. productionPlanDetailId: store.planDetails.id,
  75. isNormalLot:isNormalLot.value,
  76. deptId: store.curDeptDetails.deptId
  77. })
  78. ])
  79. .then(([res, response,resp]) => {
  80. if (resp.code == 200) {
  81. processSquence.value = resp.data
  82. //过滤出工序交集
  83. let filteredData = resp.data.filter((item1) =>
  84. res.data.some((item2) => item2.processCode === item1.processCode)
  85. );
  86. for (let i = 0; i < filteredData.length; i++) {
  87. var processAliasList = [];
  88. if(processAliasList.includes(filteredData[i].processAlias)) {
  89. continue;
  90. }else {
  91. processAliasList.push(filteredData[i].processAlias)
  92. processList.value[i] = {
  93. text: filteredData[i].processAlias,
  94. value: filteredData[i].id
  95. }
  96. }
  97. }
  98. console.log(processList.value)
  99. /* 处理结果格式 */
  100. carrierList.value = changeResultStructure(response.data)
  101. console.log(carrierList.value)
  102. console.log(store.userInfo)
  103. baseDialog.value.open();
  104. }
  105. else {
  106. uni.showToast({
  107. icon: "error",
  108. title: "请重新选择是否正常批次",
  109. duration: 1000
  110. })
  111. }
  112. })
  113. }
  114. /**
  115. * 处理响应结果
  116. */
  117. function changeResultStructure(data){
  118. console.log(data)
  119. // 用于存放处理后的结果
  120. const result = {};
  121. // 遍历原始数组的每个对象
  122. data.forEach(item => {
  123. const { lotCode, place,carrierCode } = item;
  124. // 如果lotCode不存在于结果中,则以该lotCode为键,创建一个新对象
  125. if (!result[lotCode]) {
  126. result[lotCode] = {
  127. lotCode: lotCode,
  128. place: place,
  129. carrierCode: carrierCode
  130. };
  131. // 如果lotCode已存在于结果中,则将place进行字符串拼接
  132. } else {
  133. if (result[lotCode].place !== place){
  134. result[lotCode].place += `, ${place}`;
  135. }
  136. result[lotCode].carrierCode += `, ${carrierCode}`;
  137. }
  138. });
  139. return Object.values(result);
  140. }
  141. function close() {
  142. baseDialog.value.close()
  143. }
  144. function reset() {
  145. selectedProcess.value = 0;
  146. processList.value = [];
  147. curProcessId.value = '';
  148. carrierList.value = [];
  149. }
  150. function handleProcessChange(e) {
  151. console.log(store)
  152. if (e == '' || e == null) {
  153. Promise.all([getProcessList({
  154. deptId: store.curDeptDetails.deptId,
  155. planDetailId: store.planDetails.id
  156. }), getAvailableCarrierList({
  157. planDetailId: store.planDetails.id,
  158. deptId: store.curDeptDetails.deptId
  159. }), selectProcessList({
  160. productionPlanDetailId: store.planDetails.id,
  161. isNormalLot:isNormalLot.value,
  162. deptId: store.curDeptDetails.deptId
  163. })]).then(([res, response,resp]) => {
  164. if (res.code == 200) {
  165. // //过滤出工序交集
  166. // let filteredData = store.planDetails.processSequence.filter((item1) =>
  167. // res.data.some((item2) => item2.processCode === item1.processCode)
  168. // );
  169. // for (let i = 0; i < filteredData.length; i++) {
  170. // processList.value[i] = {
  171. // text: filteredData[i].processAlias,
  172. // value: filteredData[i].id
  173. // }
  174. // }
  175. // console.log(processList.value)
  176. let filteredData = resp.data.filter((item1) =>
  177. res.data.some((item2) => item2.processCode === item1.processCode)
  178. );
  179. for (let i = 0; i < filteredData.length; i++) {
  180. var processAliasList = [];
  181. if(processAliasList.includes(filteredData[i].processAlias)) {
  182. continue;
  183. }else {
  184. processAliasList.push(filteredData[i].processAlias)
  185. processList.value[i] = {
  186. text: filteredData[i].processAlias,
  187. value: filteredData[i].id
  188. }
  189. }
  190. }
  191. }
  192. /* 处理结果格式 */
  193. carrierList.value = changeResultStructure(response.data);
  194. baseDialog.value.open();
  195. })
  196. } else {
  197. let processIds = []
  198. for (let i = 0; i < processSquence.value.length; i++) {
  199. processIds.push(processSquence.value[i].id)
  200. if (processSquence.value[i].id == selectedProcess.value) {
  201. break;
  202. }
  203. }
  204. curProcessId.value = processIds.join(',')
  205. getAvailableCarrierList({
  206. planDetailId: store.planDetails.id,
  207. deptId: store.curDeptDetails.deptId,
  208. processId: curProcessId.value
  209. }).then(res => {
  210. if (res.code == 200) {
  211. carrierList.value = changeResultStructure(res.data);
  212. }
  213. console.log(res)
  214. })
  215. }
  216. }
  217. defineExpose({
  218. open
  219. })
  220. </script>
  221. <style lang="scss">
  222. $nav-height: 60rpx;
  223. .dialog-body {
  224. overflow: auto;
  225. .selectedProcess {
  226. width: 88%;
  227. margin: 20rpx auto 40rpx;
  228. }
  229. .carrierList-title {
  230. width: 100%;
  231. border-bottom: 1rpx solid #999999;
  232. padding-bottom: 16rpx;
  233. margin-bottom: 16rpx;
  234. }
  235. .carrierList {
  236. width: 100%;
  237. flex-wrap: wrap;
  238. justify-items: flex-start;
  239. align-content: flex-start;
  240. text-align: center;
  241. height: auto;
  242. max-height: 300rpx;
  243. overflow: auto;
  244. // padding-left: calc((100% - 54rpx - 6rpx - 84%) / 2);
  245. .carrierItem {
  246. width: 100%;
  247. height: auto;
  248. line-height: 64rpx;
  249. text-align: center;
  250. justify-content: flex-start;
  251. align-items: center;
  252. border-bottom: 1rpx solid #999999;
  253. }
  254. }
  255. }
  256. </style>