dialog-lot.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <dialog-base class="dialog-body" ref="baseDialog" title="添加新批次">
  3. <view class="prompt">
  4. <text>请选择工序、批次后再确认</text>
  5. </view>
  6. <uni-section title="请选择当前工序" type="square">
  7. <uni-data-select v-model="selectedProcess" :localdata="processList" :clear="false"
  8. @change="handleProcessChange"></uni-data-select>
  9. </uni-section>
  10. <view style="overflow: auto;">
  11. <view :class="{'list-container':true, 'selected':isSelected(item)}" @click="handleSelection(item,index)"
  12. v-for="(item, index) in form" :key="item.id">
  13. <view class="list-title"><text class="label">批次号:{{item.lotCode}}</text></view>
  14. <view class="list-container-item uni-row"
  15. style="border-top: 1px solid #e1e1e1;border-radius: 8rpx 8rpx 0 0;">
  16. <text class="label">产品描述</text>
  17. <text class="label value" style="word-wrap: break-word;">{{item['productDescription']}}</text>
  18. </view>
  19. <view class="list-container-item uni-row">
  20. <text class="label">关联箱号</text>
  21. <text class="label value">{{item['carrierName']}}</text>
  22. </view>
  23. <view class="list-container-item uni-row">
  24. <text class="label">投产数量</text>
  25. <text class="label value">{{item['daywork'].temporaryProcessQualifiedNum}}</text>
  26. </view>
  27. <view class="list-container-item uni-row" style="border-radius: 0 0 8rpx 8rpx;">
  28. <text class="label">上道工序</text>
  29. <text class="label value">{{item['process'].processAlias}}</text>
  30. </view>
  31. </view>
  32. </view>
  33. <view class="add-btn-container uni-row">
  34. <button type="primary" class="btn" @click="handleConfirm">确认</button>
  35. </view>
  36. </dialog-base>
  37. </template>
  38. <script setup>
  39. import {
  40. ref,
  41. getCurrentInstance
  42. } from 'vue'
  43. import {
  44. getProcessListByLot
  45. } from "@/api/business/lot.js"
  46. import {
  47. getProcessList
  48. } from '@/api/business/deptProcess.js'
  49. import {
  50. getExamine
  51. } from '@/api/business/dayworkItemExamine.js'
  52. import {
  53. store
  54. } from '@/store/index.js'
  55. const baseDialog = ref(null)
  56. const selectedButton = ref(null)
  57. const form = ref([])
  58. const emit = defineEmits(['submit'])
  59. const selection = ref([])
  60. const selectedProcess = ref({})
  61. const allProcessList = ref([])
  62. const processList = ref([])
  63. const open = (data) => {
  64. console.log(data)
  65. form.value = data;
  66. baseDialog.value.open();
  67. selection.value = [];
  68. selectedProcess.value = {};
  69. processList.value = [];
  70. getProcesses();
  71. }
  72. const close = () => {
  73. baseDialog.value.close()
  74. }
  75. defineExpose({
  76. open
  77. })
  78. function getProcesses() {
  79. Promise.all([getProcessList({
  80. deptId: store.curDeptDetails.deptId,
  81. dayworkId: form.value.dayworkId
  82. }), getProcessListByLot({
  83. id: form.value[0].daywork.lotId,
  84. isWasteRecycling: form.value[0].daywork.isWasteRecycling,
  85. isAmend: form.value[0].daywork.isAmend,
  86. technologicalProcessId: form.value[0].technologicalProcessId
  87. })]).then(([res, response]) => {
  88. if (res.code == 200) {
  89. //过滤工序列表将上道序及之前的工序去掉, 然后过滤出工序交集
  90. // let curProcessSequence = [...store.planDetails.processSequence];
  91. let curProcessSequence = response.data
  92. allProcessList.value = curProcessSequence
  93. // 这里根据前一序当前工序 过滤工序列表。
  94. // 假设单批单改部分修改后 需要做其他修改
  95. /* // 20240408 前毛宇辰版本
  96. for (let i = 0; i < curProcessSequence.length; i++) {
  97. if (curProcessSequence[i].id == form.value[0].processId) {
  98. curProcessSequence.splice(0,i + 1);
  99. console.log(curProcessSequence)
  100. break;
  101. }
  102. }
  103. */
  104. /* 20240408后版本 */
  105. // 过滤前序
  106. curProcessSequence = curProcessSequence.filter(v => (v.processStepNumber > form.value[0]
  107. .technologicalProcessDetail.processStepNumber))
  108. /* 20240408 修改完成 */
  109. console.log(curProcessSequence)
  110. let filteredData = curProcessSequence.filter((item1) =>
  111. res.data.some((item2) => item2.processCode === item1.processCode)
  112. );
  113. console.log(filteredData)
  114. for (let i = 0; i < filteredData.length; i++) {
  115. processList.value[i] = {
  116. text: filteredData[i].processAlias,
  117. value: filteredData[i].technologicalProcessDetailId ? filteredData[i]
  118. .technologicalProcessDetailId : filteredData[i].id,
  119. processId: filteredData[i].processId,
  120. processStepNumber: filteredData[i].processStepNumber
  121. }
  122. }
  123. console.log(processList.value)
  124. selectedProcess.value = filteredData[0].value;
  125. console.log(selectedProcess.value)
  126. }
  127. // console.log(selectedProcess.value)
  128. })
  129. }
  130. function handleProcessChange() {
  131. console.log(selectedProcess.value)
  132. }
  133. function handleConfirm() {
  134. // 添加选择的工序
  135. for (let i = 0; i < selection.value.length; i++) {
  136. selection.value[i].daywork.technologicalProcessDetailId = selectedProcess.value;
  137. selection.value[i].daywork.processStepNumber = processList.value.find(v => v.value === selectedProcess.value)
  138. ?.processStepNumber;
  139. selection.value[i].daywork.processId = processList.value.findIndex(v => v.value === selectedProcess.value) >=
  140. 0 ? processList.value.find(v => v.value === selectedProcess.value).processId : null
  141. console.log(processList.value.findIndex(v => v.value === selectedProcess.value) >= 0 ? processList.value.find(
  142. v => v.value === selectedProcess.value).processId : null)
  143. }
  144. console.log(selection.value)
  145. //执行确认
  146. var msg = ""
  147. if (selectedProcess.value && selection.value.length > 0) {
  148. //判断选择的批次里是否有废品回用的
  149. for (let i = 0; i < selection.value.length; i++) {
  150. if (selection.value[i].daywork.isWaste == 0) {
  151. msg += selection.value[i].lotCode + ","
  152. }
  153. }
  154. if (msg === "") {
  155. uni.showToast({
  156. icon: 'none',
  157. title: msg + "已被废弃"
  158. })
  159. } else {
  160. //判断选择最后一道序的时候是否审核通过
  161. let dayworkIds = []
  162. for (let i = 0; i < selection.value.length; i++) {
  163. // console.log(selection.value[i].daywork.processStepNumber)
  164. // console.log(selection.value[i].processSequence[selection.value[i].processSequence.length - 1]
  165. // .processStepNumber)
  166. if (selection.value[i].daywork.processStepNumber == allProcessList.value[allProcessList.value.length -
  167. 1].processStepNumber) {
  168. dayworkIds.push(selection.value[i].dayworkId)
  169. }
  170. }
  171. if (dayworkIds.length > 0) {
  172. getExamine({
  173. dayworkIds: dayworkIds
  174. })
  175. .then(res => {
  176. console.log(res.code);
  177. if (res.code === 200) {
  178. //处理成功情况
  179. close();
  180. emit('submit', selection.value);
  181. uni.$emit('dayworkItemUpdate');
  182. } else {
  183. uni.showModal({
  184. title: '提示',
  185. content: res.msg,
  186. });
  187. }
  188. })
  189. } else {
  190. close();
  191. emit('submit', selection.value);
  192. uni.$emit('dayworkItemUpdate');
  193. }
  194. // console.log(selection.value)
  195. }
  196. } else {
  197. uni.showToast({
  198. icon: 'none',
  199. title: '请选择工序、批次后再确认'
  200. })
  201. }
  202. }
  203. function isSelected(item) {
  204. return selection.value.includes(item);
  205. }
  206. function handleSelection(item, index) {
  207. const buttonIndex = selection.value.findIndex(selectedItem => selectedItem === item);
  208. if (buttonIndex > -1) {
  209. selection.value.splice(buttonIndex, 1); // 取消选中
  210. } else {
  211. selection.value.push(item); // 选中
  212. }
  213. console.log(selection.value, "selection");
  214. }
  215. </script>
  216. <style lang="scss">
  217. .selected {
  218. border: 3rpx solid #1684fc;
  219. border-radius: 8rpx;
  220. }
  221. .dialog-body {
  222. overflow: auto;
  223. .list-title {
  224. margin: 10rpx 0 20rpx 0;
  225. .label {
  226. font-size: 32rpx;
  227. font-weight: bold;
  228. }
  229. }
  230. .prompt {
  231. color: red;
  232. margin: 8rpx auto 0;
  233. }
  234. .list-container {
  235. width: 94%;
  236. display: flex;
  237. align-items: flex-start;
  238. margin: 10rpx auto;
  239. padding: 8px 2% 16px 2%;
  240. border-radius: 8rpx;
  241. .list-container-item {
  242. width: 100%;
  243. border-bottom: 1px solid #e1e1e1;
  244. border-left: 1px solid #e1e1e1;
  245. border-right: 1px solid #e1e1e1;
  246. padding: 12rpx 8rpx;
  247. box-sizing: border-box;
  248. .label {
  249. font-size: 28rpx;
  250. color: gray;
  251. width: 140rpx;
  252. &.value {
  253. flex: 1;
  254. }
  255. }
  256. }
  257. }
  258. .add-btn-container {
  259. margin-top: 32rpx;
  260. .btn {
  261. flex: 1;
  262. }
  263. }
  264. }
  265. .selectedProcess {
  266. width: 88%;
  267. margin: 20rpx auto 40rpx;
  268. }
  269. </style>