dialog-selectProduction.vue 5.8 KB

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