spring
7 小时以前 6361501810a76b6809162cac99b0d9c1faba3715
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<template>
  <div>
    <el-dialog v-model="dialogVisible" title="领料详情" width="1400px" @close="handleClose">
      <el-table v-loading="materialDetailLoading" :data="materialDetailTableData" border row-key="id">
        <el-table-column label="工序名称" prop="processName" min-width="180" />
        <el-table-column label="原料名称" prop="materialName" min-width="160" />
        <el-table-column label="原料型号" prop="materialModel" min-width="180" />
        <el-table-column label="需求数量" prop="requiredQty" min-width="110" />
        <el-table-column label="计量单位" prop="unit" width="100" />
        <el-table-column label="领用数量" prop="pickQty" min-width="110" />
        <el-table-column label="补料数量" min-width="120">
          <template #default="{ row }">
            <el-button type="primary" link @click="handleViewSupplementRecord(row)">
              {{ row.supplementQty ?? 0 }}
            </el-button>
          </template>
        </el-table-column>
        <el-table-column label="退料数量" prop="returnQty" min-width="110" />
        <el-table-column label="实际数量" prop="actualQty" min-width="110" />
      </el-table>
      <template #footer>
        <span class="dialog-footer">
          <el-button
            type="warning"
            :loading="materialReturnConfirming"
            :disabled="!canOpenReturnSummary"
            @click="openReturnSummaryDialog"
          >
            退料确认
          </el-button>
          <el-button @click="dialogVisible = false">取消</el-button>
        </span>
      </template>
    </el-dialog>
 
    <el-dialog v-model="supplementRecordDialogVisible" title="补料记录" width="800px">
      <el-table v-loading="supplementRecordLoading" :data="supplementRecordTableData" border row-key="id">
        <el-table-column label="补料数量" prop="supplementQty" min-width="120" />
        <el-table-column label="补料时间" prop="supplementTime" min-width="180" />
        <el-table-column label="备注" prop="remark" min-width="200" />
      </el-table>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="supplementRecordDialogVisible = false">关闭</el-button>
        </span>
      </template>
    </el-dialog>
 
    <el-dialog v-model="returnSummaryDialogVisible" title="退料汇总确认" width="900px">
      <el-table :data="returnSummaryList" border row-key="summaryKey">
        <el-table-column label="原料名称" prop="materialName" min-width="180" />
        <el-table-column label="原料型号" prop="materialModel" min-width="180" />
        <el-table-column label="计量单位" prop="unit" min-width="100" />
        <el-table-column label="退料汇总数量" prop="returnQtyTotal" min-width="140" />
      </el-table>
 
      <el-card class="approver-card" shadow="never">
        <template #header>
          <div class="card-header-wrapper">
            <span class="card-title">审批人选择</span>
            <el-button type="primary" size="small" @click="addApproverNode">新增节点</el-button>
          </div>
        </template>
        <div class="approver-nodes-container">
          <div v-for="(node, index) in approverNodes" :key="node.id" class="approver-node-item">
            <div class="approver-node-label">
              <span class="node-step">{{ index + 1 }}</span>
              <span class="node-text">审批人</span>
            </div>
            <el-select v-model="node.userId" placeholder="选择人员" class="approver-select" clearable>
              <el-option v-for="user in userList" :key="user.userId" :label="user.nickName" :value="user.userId" />
            </el-select>
            <el-button v-if="approverNodes.length > 1" type="danger" size="small" @click="removeApproverNode(index)">
              删除
            </el-button>
          </div>
        </div>
      </el-card>
 
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" :loading="materialReturnConfirming" @click="handleReturnConfirm">确认提交</el-button>
          <el-button @click="returnSummaryDialogVisible = false">取消</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
 
<script setup>
import { computed, ref, watch } from "vue";
import { ElMessage } from "element-plus";
import { listMaterialPickingDetail, listMaterialSupplementRecord, confirmMaterialReturn } from "@/api/productionManagement/productionOrder.js";
import { userListNoPageByTenantId } from "@/api/system/user.js";
 
const props = defineProps({
  modelValue: { type: Boolean, default: false },
  orderRow: { type: Object, default: null },
});
const emit = defineEmits(["update:modelValue", "confirmed"]);
 
const dialogVisible = computed({
  get: () => props.modelValue,
  set: val => emit("update:modelValue", val),
});
 
const materialDetailLoading = ref(false);
const materialDetailTableData = ref([]);
const materialReturnConfirming = ref(false);
const supplementRecordDialogVisible = ref(false);
const supplementRecordLoading = ref(false);
const supplementRecordTableData = ref([]);
const returnSummaryDialogVisible = ref(false);
const returnSummaryList = ref([]);
const userList = ref([]);
const approverNodes = ref([{ id: Date.now(), userId: undefined }]);
const canOpenReturnSummary = computed(() =>
  materialDetailTableData.value.some(item => Number(item.returnQty || 0) > 0)
);
 
const loadDetailList = async () => {
  if (!props.orderRow?.id) return;
  materialDetailLoading.value = true;
  materialDetailTableData.value = [];
  try {
    const res = await listMaterialPickingDetail({ orderId: props.orderRow.id });
    materialDetailTableData.value = res.data || [];
  } finally {
    materialDetailLoading.value = false;
  }
};
 
watch(
  () => dialogVisible.value,
  visible => {
    if (visible) {
      loadDetailList();
    }
  }
);
 
const handleClose = () => {
  materialDetailTableData.value = [];
};
 
const handleViewSupplementRecord = async row => {
  if (!row?.id) return;
  supplementRecordDialogVisible.value = true;
  supplementRecordLoading.value = true;
  supplementRecordTableData.value = [];
  try {
    const res = await listMaterialSupplementRecord({ materialDetailId: row.id });
    supplementRecordTableData.value = res.data || [];
  } finally {
    supplementRecordLoading.value = false;
  }
};
 
const buildReturnSummary = () => {
  const map = new Map();
  materialDetailTableData.value.forEach(item => {
    const key = `${item.materialModelId || ""}_${item.materialName || ""}_${item.materialModel || ""}_${item.unit || ""}`;
    const old = map.get(key) || {
      summaryKey: key,
      materialName: item.materialName || "",
      materialModel: item.materialModel || "",
      unit: item.unit || "",
      returnQtyTotal: 0,
    };
    old.returnQtyTotal += Number(item.returnQty || 0);
    map.set(key, old);
  });
  return Array.from(map.values());
};
 
const loadUserList = async () => {
  if (userList.value.length > 0) return;
  const res = await userListNoPageByTenantId();
  userList.value = res.data || [];
};
 
const openReturnSummaryDialog = async () => {
  if (!canOpenReturnSummary.value) {
    ElMessage.warning("退料数量大于0时才能退料确认");
    return;
  }
  returnSummaryList.value = buildReturnSummary();
  approverNodes.value = [{ id: Date.now(), userId: undefined }];
  await loadUserList();
  returnSummaryDialogVisible.value = true;
};
 
const addApproverNode = () => {
  approverNodes.value.push({ id: Date.now() + Math.random(), userId: undefined });
};
 
const removeApproverNode = index => {
  approverNodes.value.splice(index, 1);
};
 
const handleReturnConfirm = async () => {
  if (!props.orderRow?.id) return;
  const approverList = approverNodes.value
    .filter(item => item.userId)
    .map((item, index) => ({ userId: item.userId, sort: index + 1 }));
  if (approverList.length === 0) {
    ElMessage.warning("请至少选择一位审批人");
    return;
  }
  materialReturnConfirming.value = true;
  try {
    await confirmMaterialReturn({
      orderId: props.orderRow.id,
      returnSummaryList: returnSummaryList.value,
      approverList,
    });
    returnSummaryDialogVisible.value = false;
    dialogVisible.value = false;
    emit("confirmed");
  } finally {
    materialReturnConfirming.value = false;
  }
};
</script>
 
<style scoped lang="scss">
.approver-card {
  margin-top: 12px;
}
.card-header-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.approver-nodes-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.approver-node-item {
  display: flex;
  gap: 8px;
  align-items: center;
}
.approver-node-label {
  display: flex;
  gap: 4px;
  min-width: 88px;
  align-items: center;
}
.node-step {
  width: 20px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  border-radius: 50%;
  background: #409eff;
  color: #fff;
  font-size: 12px;
}
.approver-select {
  flex: 1;
}
</style>