dialog-selectProduction.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 dayworkCarrierlist = ref([])
  44. const carrierList = ref([])
  45. function open(data) {
  46. reset();
  47. console.log(store.planDetails)
  48. isNormalLot.value = true
  49. if (!data) {
  50. isNormalLot.value = false
  51. }
  52. console.log(isNormalLot.value)
  53. Promise.all([getProcessList({
  54. deptId: store.curDeptDetails.deptId,
  55. planDetailId: store.planDetails.id
  56. }), getAvailableCarrierList({
  57. planDetailId: store.planDetails.id,
  58. deptId: store.curDeptDetails.deptId
  59. }), selectProcessList({
  60. productionPlanDetailId: store.planDetails.id,
  61. isNormalLot:isNormalLot.value,
  62. deptId: store.curDeptDetails.deptId
  63. })
  64. ])
  65. .then(([res, response,resp]) => {
  66. if (resp.code == 200) {
  67. dayworkCarrierlist.value = response.data
  68. //过滤出工序交集
  69. let filteredData = resp.data.filter((item1) =>
  70. res.data.some((item2) => item2.processCode === item1.processCode)
  71. );
  72. var processAliasList = [];
  73. for (let i = 0; i < filteredData.length; i++) {
  74. if(processAliasList.includes(filteredData[i].processAlias)) {
  75. continue;
  76. }else {
  77. processAliasList.push(filteredData[i].processAlias)
  78. processList.value[i] = {
  79. text: filteredData[i].processAlias,
  80. value: filteredData[i].processId,
  81. }
  82. }
  83. }
  84. console.log(processList.value)
  85. /* 处理结果格式 */
  86. carrierList.value = changeResultStructure(response.data)
  87. baseDialog.value.open();
  88. }
  89. else {
  90. uni.showToast({
  91. icon: "none",
  92. title: "没有周转到该工段批次",
  93. duration: 1000
  94. })
  95. }
  96. })
  97. }
  98. /**
  99. * 处理响应结果
  100. */
  101. function changeResultStructure(data) {
  102. console.log(data)
  103. // 用于存放处理后的结果
  104. const result = {};
  105. // 遍历原始数组的每个对象
  106. data.forEach(item => {
  107. const { lotCode, place,carrierCode } = item;
  108. // 如果lotCode不存在于结果中,则以该lotCode为键,创建一个新对象
  109. if (!result[lotCode]) {
  110. result[lotCode] = {
  111. lotCode: lotCode,
  112. place: place,
  113. carrierCode: carrierCode
  114. };
  115. // 如果lotCode已存在于结果中,则将place进行字符串拼接
  116. } else {
  117. if (result[lotCode].place !== place){
  118. result[lotCode].place += `, ${place}`;
  119. }
  120. result[lotCode].carrierCode += `, ${carrierCode}`;
  121. }
  122. });
  123. return Object.values(result);
  124. }
  125. function close() {
  126. baseDialog.value.close()
  127. }
  128. function reset() {
  129. selectedProcess.value = 0;
  130. processList.value = [];
  131. curProcessId.value = '';
  132. carrierList.value = [];
  133. }
  134. function handleProcessChange(e) {
  135. console.log(store)
  136. if (e == '' || e == null) {
  137. Promise.all([getProcessList({
  138. deptId: store.curDeptDetails.deptId,
  139. planDetailId: store.planDetails.id
  140. }), getAvailableCarrierList({
  141. planDetailId: store.planDetails.id,
  142. deptId: store.curDeptDetails.deptId
  143. }), selectProcessList({
  144. productionPlanDetailId: store.planDetails.id,
  145. isNormalLot: isNormalLot.value,
  146. deptId: store.curDeptDetails.deptId
  147. })]).then(([res, response, resp]) => {
  148. if (res.code == 200) {
  149. // //过滤出工序交集
  150. // let filteredData = store.planDetails.processSequence.filter((item1) =>
  151. // res.data.some((item2) => item2.processCode === item1.processCode)
  152. // );
  153. // for (let i = 0; i < filteredData.length; i++) {
  154. // processList.value[i] = {
  155. // text: filteredData[i].processAlias,
  156. // value: filteredData[i].id
  157. // }
  158. // }
  159. // console.log(processList.value)
  160. let filteredData = resp.data.filter((item1) =>
  161. res.data.some((item2) => item2.processCode === item1.processCode)
  162. );
  163. for (let i = 0; i < filteredData.length; i++) {
  164. if(processAliasList.includes(filteredData[i].processAlias)) {
  165. continue;
  166. }else {
  167. processAliasList.push(filteredData[i].processAlias)
  168. processList.value[i] = {
  169. text: filteredData[i].processAlias,
  170. value: filteredData[i].processId,
  171. }
  172. }
  173. }
  174. }
  175. /* 处理结果格式 */
  176. carrierList.value = changeResultStructure(response.data);
  177. baseDialog.value.open();
  178. })
  179. } else {
  180. var tempList = []
  181. for(let i = 0;i<dayworkCarrierlist.value.length;i++) {
  182. var processIds = dayworkCarrierlist.value[i].processSequence.map(obj => obj.id);
  183. if(processIds.includes(selectedProcess.value)) {
  184. tempList.push(dayworkCarrierlist.value[i])
  185. }
  186. }
  187. carrierList.value = changeResultStructure(tempList);
  188. }
  189. }
  190. defineExpose({
  191. open
  192. })
  193. </script>
  194. <style lang="scss">
  195. $nav-height: 60rpx;
  196. .dialog-body {
  197. overflow: auto;
  198. .selectedProcess {
  199. width: 88%;
  200. margin: 20rpx auto 40rpx;
  201. }
  202. .carrierList-title {
  203. width: 100%;
  204. border-bottom: 1rpx solid #999999;
  205. padding-bottom: 16rpx;
  206. margin-bottom: 16rpx;
  207. }
  208. .carrierList {
  209. width: 100%;
  210. flex-wrap: wrap;
  211. justify-items: flex-start;
  212. align-content: flex-start;
  213. text-align: center;
  214. height: auto;
  215. max-height: 300rpx;
  216. overflow: auto;
  217. // padding-left: calc((100% - 54rpx - 6rpx - 84%) / 2);
  218. .carrierItem {
  219. width: 100%;
  220. height: auto;
  221. line-height: 64rpx;
  222. text-align: center;
  223. justify-content: flex-start;
  224. align-items: center;
  225. border-bottom: 1rpx solid #999999;
  226. }
  227. }
  228. }
  229. </style>