dialog-lot.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 :class="{'list-container':true, 'selected':isSelected(item)}" @click="handleSelection(item,index)"
  11. v-for="(item, index) in form" :key="item.id">
  12. <view class="list-title"><text class="label">批次号:{{item.lotCode}}</text></view>
  13. <view class="list-container-item uni-row" style="border-top: 1px solid #e1e1e1;border-radius: 8rpx 8rpx 0 0;">
  14. <text class="label">产品描述</text>
  15. <text class="label value">{{item['productDescription']}}</text>
  16. </view>
  17. <view class="list-container-item uni-row">
  18. <text class="label">关联箱号</text>
  19. <text class="label value">{{item['carrierName']}}</text>
  20. </view>
  21. <view class="list-container-item uni-row">
  22. <text class="label">投产数量</text>
  23. <text class="label value">{{item['prodNum']}}</text>
  24. </view>
  25. <view class="list-container-item uni-row" style="border-radius: 0 0 8rpx 8rpx;">
  26. <text class="label">上道工序</text>
  27. <text class="label value">{{item['process'].processAlias}}</text>
  28. </view>
  29. </view>
  30. <view class="add-btn-container uni-row">
  31. <button type="primary" class="btn" @click="handleConfirm">确认</button>
  32. </view>
  33. </dialog-base>
  34. </template>
  35. <script setup>
  36. import {
  37. ref,
  38. getCurrentInstance
  39. } from 'vue'
  40. import {
  41. getProcessList
  42. } from '@/api/business/deptProcess.js'
  43. import {
  44. store
  45. } from '@/store/index.js'
  46. const baseDialog = ref(null)
  47. const selectedButton = ref(null)
  48. const form = ref([])
  49. const emit = defineEmits(['submit'])
  50. const selection = ref([])
  51. const selectedProcess = ref(null)
  52. const processList = ref([])
  53. const open = (data) => {
  54. // console.log(dialog.value)
  55. form.value = data;
  56. baseDialog.value.open();
  57. selection.value = [];
  58. getProcesses();
  59. }
  60. const close = () => {
  61. baseDialog.value.close()
  62. }
  63. defineExpose({
  64. open
  65. })
  66. function getProcesses() {
  67. getProcessList({
  68. deptId: store.curDeptDetails.deptId,
  69. }).then(res => {
  70. if (res.code == 200) {
  71. //过滤工序列表将上道序及之前的工序去掉, 然后过滤出工序交集
  72. let curProcessSequence = [...store.planDetails.processSequence];
  73. console.log(curProcessSequence)
  74. console.log(form.value[0])
  75. for (let i = 0; i < curProcessSequence.length; i++) {
  76. if (curProcessSequence[i].id == form.value[0].processId) {
  77. curProcessSequence.splice(0,i + 1);
  78. console.log(curProcessSequence)
  79. break;
  80. }
  81. }
  82. console.log(curProcessSequence)
  83. let filteredData = curProcessSequence.filter((item1) =>
  84. res.data.some((item2) => item2.processCode === item1.processCode)
  85. );
  86. for (let i = 0; i < filteredData.length; i++) {
  87. processList.value[i] = {
  88. text: filteredData[i].processAlias,
  89. value: filteredData[i].id
  90. }
  91. }
  92. // selectedProcess.value = filteredData[0].processId;
  93. }
  94. })
  95. }
  96. function handleProcessChange() {
  97. }
  98. function handleConfirm() {
  99. // 添加选择的工序
  100. for (let i = 0; i < selection.value.length; i++) {
  101. selection.value[i].daywork.processId = selectedProcess.value;
  102. }
  103. console.log(selection.value)
  104. // 执行确认
  105. if (selectedProcess.value && selection.value.length > 0) {
  106. close();
  107. emit('submit', selection.value);
  108. uni.$emit('dayworkItemUpdate');
  109. } else {
  110. uni.showToast({
  111. icon: 'none',
  112. title: '请选择工序、批次后再确认'
  113. })
  114. }
  115. }
  116. function isSelected(item) {
  117. return selection.value.includes(item);
  118. }
  119. function handleSelection(item, index) {
  120. const buttonIndex = selection.value.findIndex(selectedItem => selectedItem === item);
  121. if (buttonIndex > -1) {
  122. selection.value.splice(buttonIndex, 1); // 取消选中
  123. } else {
  124. selection.value.push(item); // 选中
  125. }
  126. console.log(selection.value, "selection");
  127. }
  128. </script>
  129. <style lang="scss">
  130. .selected {
  131. border: 3rpx solid #1684fc;
  132. border-radius: 8rpx;
  133. }
  134. .dialog-body {
  135. overflow: auto;
  136. .list-title {
  137. margin: 10rpx 0 20rpx 0;
  138. .label {
  139. font-size: 32rpx;
  140. font-weight: bold;
  141. }
  142. }
  143. .prompt {
  144. color: red;
  145. margin: 8rpx auto 0;
  146. }
  147. .list-container {
  148. width: 96%;
  149. display: flex;
  150. align-items: flex-start;
  151. margin: 10rpx auto;
  152. padding: 2%;
  153. border-radius: 8rpx;
  154. overflow: auto;
  155. .list-container-item {
  156. width: 100%;
  157. border-bottom: 1px solid #e1e1e1;
  158. border-left: 1px solid #e1e1e1;
  159. border-right: 1px solid #e1e1e1;
  160. padding: 12rpx 8rpx;
  161. box-sizing: border-box;
  162. .label {
  163. font-size: 28rpx;
  164. color: gray;
  165. width: 144rpx;
  166. &.value {
  167. flex: 1;
  168. }
  169. }
  170. }
  171. }
  172. .add-btn-container {
  173. margin-top: 32rpx;
  174. .btn {
  175. flex: 1;
  176. }
  177. }
  178. }
  179. .selectedProcess {
  180. width: 88%;
  181. margin: 20rpx auto 40rpx;
  182. }
  183. </style>