dialog-lot.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. selectedProcess.value = null;
  59. processList.value = [];
  60. getProcesses();
  61. }
  62. const close = () => {
  63. baseDialog.value.close()
  64. }
  65. defineExpose({
  66. open
  67. })
  68. function getProcesses() {
  69. getProcessList({
  70. deptId: store.curDeptDetails.deptId,
  71. }).then(res => {
  72. if (res.code == 200) {
  73. //过滤工序列表将上道序及之前的工序去掉, 然后过滤出工序交集
  74. let curProcessSequence = [...store.planDetails.processSequence];
  75. console.log(curProcessSequence)
  76. console.log(form.value[0])
  77. for (let i = 0; i < curProcessSequence.length; i++) {
  78. if (curProcessSequence[i].id == form.value[0].processId) {
  79. curProcessSequence.splice(0,i + 1);
  80. console.log(curProcessSequence)
  81. break;
  82. }
  83. }
  84. console.log(curProcessSequence)
  85. let filteredData = curProcessSequence.filter((item1) =>
  86. res.data.some((item2) => item2.processCode === item1.processCode)
  87. );
  88. for (let i = 0; i < filteredData.length; i++) {
  89. processList.value[i] = {
  90. text: filteredData[i].processAlias,
  91. value: filteredData[i].id
  92. }
  93. }
  94. // selectedProcess.value = filteredData[0].processId;
  95. }
  96. })
  97. }
  98. function handleProcessChange() {
  99. }
  100. function handleConfirm() {
  101. // 添加选择的工序
  102. for (let i = 0; i < selection.value.length; i++) {
  103. selection.value[i].daywork.processId = selectedProcess.value;
  104. }
  105. console.log(selection.value)
  106. // 执行确认
  107. if (selectedProcess.value && selection.value.length > 0) {
  108. close();
  109. emit('submit', selection.value);
  110. uni.$emit('dayworkItemUpdate');
  111. } else {
  112. uni.showToast({
  113. icon: 'none',
  114. title: '请选择工序、批次后再确认'
  115. })
  116. }
  117. }
  118. function isSelected(item) {
  119. return selection.value.includes(item);
  120. }
  121. function handleSelection(item, index) {
  122. const buttonIndex = selection.value.findIndex(selectedItem => selectedItem === item);
  123. if (buttonIndex > -1) {
  124. selection.value.splice(buttonIndex, 1); // 取消选中
  125. } else {
  126. selection.value.push(item); // 选中
  127. }
  128. console.log(selection.value, "selection");
  129. }
  130. </script>
  131. <style lang="scss">
  132. .selected {
  133. border: 3rpx solid #1684fc;
  134. border-radius: 8rpx;
  135. }
  136. .dialog-body {
  137. overflow: auto;
  138. .list-title {
  139. margin: 10rpx 0 20rpx 0;
  140. .label {
  141. font-size: 32rpx;
  142. font-weight: bold;
  143. }
  144. }
  145. .prompt {
  146. color: red;
  147. margin: 8rpx auto 0;
  148. }
  149. .list-container {
  150. width: 96%;
  151. display: flex;
  152. align-items: flex-start;
  153. margin: 10rpx auto;
  154. padding: 2%;
  155. border-radius: 8rpx;
  156. overflow: auto;
  157. .list-container-item {
  158. width: 100%;
  159. border-bottom: 1px solid #e1e1e1;
  160. border-left: 1px solid #e1e1e1;
  161. border-right: 1px solid #e1e1e1;
  162. padding: 12rpx 8rpx;
  163. box-sizing: border-box;
  164. .label {
  165. font-size: 28rpx;
  166. color: gray;
  167. width: 144rpx;
  168. &.value {
  169. flex: 1;
  170. }
  171. }
  172. }
  173. }
  174. .add-btn-container {
  175. margin-top: 32rpx;
  176. .btn {
  177. flex: 1;
  178. }
  179. }
  180. }
  181. .selectedProcess {
  182. width: 88%;
  183. margin: 20rpx auto 40rpx;
  184. }
  185. </style>