| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <div> |
| | | <el-dialog |
| | | v-model="dialogVisible" |
| | | title="ç©æ" |
| | | width="1200px" |
| | | @close="handleCloseMaterialDialog" |
| | | > |
| | | <el-table v-loading="materialTableLoading" :data="materialTableData" border row-key="id"> |
| | | <el-table-column label="å·¥åºåç§°" prop="processName" min-width="140" /> |
| | | <el-table-column label="åæåç§°" prop="materialName" min-width="140" /> |
| | | <el-table-column label="åæåå·" prop="materialModel" min-width="140" /> |
| | | <el-table-column label="计éåä½" prop="unit" min-width="100" /> |
| | | <el-table-column label="çº¿è¾¹ä»æ°é" prop="pickQty" min-width="100" /> |
| | | <el-table-column label="è¡¥ææ°é" prop="supplementQty" min-width="100" /> |
| | | <el-table-column label="å®é
æ°é" min-width="140"> |
| | | <template #default="{ row }"> |
| | | <el-input-number |
| | | v-model="row.actualQty" |
| | | :min="0" |
| | | :precision="3" |
| | | :step="1" |
| | | controls-position="right" |
| | | style="width: 100%;" |
| | | /> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="æä½" align="center" fixed="right" width="180"> |
| | | <template #default="{ row }"> |
| | | <el-button type="primary" link @click="openSupplementDialog(row)">è¡¥æ</el-button> |
| | | <el-button type="info" link @click="openSupplementRecordDialog(row)">è¡¥æè®°å½</el-button> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | | <template #footer> |
| | | <span class="dialog-footer"> |
| | | <el-button type="primary" :loading="pickSubmitting" @click="handleSubmitPick">é¢ç¨</el-button> |
| | | <el-button @click="dialogVisible = false">åæ¶</el-button> |
| | | </span> |
| | | </template> |
| | | </el-dialog> |
| | | |
| | | <FormDialog |
| | | v-model="supplementDialogVisible" |
| | | title="è¡¥æ" |
| | | width="500px" |
| | | @confirm="handleSubmitSupplement" |
| | | > |
| | | <el-form ref="supplementFormRef" :model="supplementForm" :rules="supplementRules" label-width="100px"> |
| | | <el-form-item label="è¡¥ææ°é" prop="supplementQty"> |
| | | <el-input-number |
| | | v-model="supplementForm.supplementQty" |
| | | :min="0.001" |
| | | :precision="3" |
| | | :step="1" |
| | | style="width: 100%;" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="è¡¥æåå " prop="supplementReason"> |
| | | <el-input |
| | | v-model="supplementForm.supplementReason" |
| | | type="textarea" |
| | | :rows="3" |
| | | maxlength="200" |
| | | show-word-limit |
| | | placeholder="请è¾å
¥è¡¥æåå " |
| | | /> |
| | | </el-form-item> |
| | | </el-form> |
| | | <template #footer> |
| | | <span class="dialog-footer"> |
| | | <el-button type="primary" :loading="supplementSubmitting" @click="handleSubmitSupplement">ç¡®å®</el-button> |
| | | <el-button @click="supplementDialogVisible = false">åæ¶</el-button> |
| | | </span> |
| | | </template> |
| | | </FormDialog> |
| | | |
| | | <el-dialog v-model="supplementRecordDialogVisible" title="è¡¥æè®°å½" width="900px"> |
| | | <el-table v-loading="supplementRecordLoading" :data="supplementRecordTableData" border row-key="id"> |
| | | <el-table-column label="è¡¥ææ°é" prop="supplementQty" min-width="100" /> |
| | | <el-table-column label="è¡¥æåå " prop="supplementReason" min-width="200" /> |
| | | <el-table-column label="è¡¥æäºº" prop="supplementUserName" min-width="120" /> |
| | | <el-table-column label="è¡¥ææ¥æ" prop="supplementTime" min-width="160" /> |
| | | </el-table> |
| | | <template #footer> |
| | | <span class="dialog-footer"> |
| | | <el-button @click="supplementRecordDialogVisible = false">å
³é</el-button> |
| | | </span> |
| | | </template> |
| | | </el-dialog> |
| | | </div> |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { computed, nextTick, reactive, ref, watch } from "vue"; |
| | | import { ElMessage } from "element-plus"; |
| | | import FormDialog from "@/components/Dialog/FormDialog.vue"; |
| | | import { |
| | | listWorkOrderMaterialLedger, |
| | | addWorkOrderMaterialSupplement, |
| | | listWorkOrderMaterialSupplementRecord, |
| | | pickWorkOrderMaterial, |
| | | } from "@/api/productionManagement/workOrder.js"; |
| | | |
| | | const props = defineProps({ |
| | | modelValue: { |
| | | type: Boolean, |
| | | default: false, |
| | | }, |
| | | rowData: { |
| | | type: Object, |
| | | default: () => null, |
| | | }, |
| | | }); |
| | | |
| | | const emit = defineEmits(["update:modelValue", "refresh"]); |
| | | |
| | | const dialogVisible = computed({ |
| | | get: () => props.modelValue, |
| | | set: val => emit("update:modelValue", val), |
| | | }); |
| | | |
| | | const materialTableLoading = ref(false); |
| | | const materialTableData = ref([]); |
| | | const currentMaterialRow = ref(null); |
| | | const currentMaterialOrderRow = ref(null); |
| | | const pickSubmitting = ref(false); |
| | | |
| | | const supplementDialogVisible = ref(false); |
| | | const supplementSubmitting = ref(false); |
| | | const supplementFormRef = ref(null); |
| | | const supplementForm = reactive({ |
| | | supplementQty: null, |
| | | supplementReason: "", |
| | | }); |
| | | |
| | | const supplementRecordDialogVisible = ref(false); |
| | | const supplementRecordLoading = ref(false); |
| | | const supplementRecordTableData = ref([]); |
| | | |
| | | const supplementRules = { |
| | | supplementQty: [{ required: true, message: "请è¾å
¥è¡¥ææ°é", trigger: "blur" }], |
| | | supplementReason: [{ required: true, message: "请è¾å
¥è¡¥æåå ", trigger: "blur" }], |
| | | }; |
| | | const loadMaterialTable = async row => { |
| | | if (!row?.id) return; |
| | | currentMaterialOrderRow.value = row; |
| | | materialTableLoading.value = true; |
| | | materialTableData.value = []; |
| | | try { |
| | | const res = await listWorkOrderMaterialLedger({ |
| | | workOrderId: row.id, |
| | | processId: row.processId, |
| | | productProcessRouteItemId: row.productProcessRouteItemId, |
| | | }); |
| | | materialTableData.value = res.data || []; |
| | | } catch (e) { |
| | | console.error("è·åç©æå°è´¦å¤±è´¥", e); |
| | | ElMessage.error("è·åç©æå°è´¦å¤±è´¥"); |
| | | } finally { |
| | | materialTableLoading.value = false; |
| | | } |
| | | }; |
| | | |
| | | watch( |
| | | () => props.modelValue, |
| | | visible => { |
| | | if (visible && props.rowData) { |
| | | loadMaterialTable(props.rowData); |
| | | } |
| | | } |
| | | ); |
| | | |
| | | const handleCloseMaterialDialog = () => { |
| | | materialTableData.value = []; |
| | | currentMaterialRow.value = null; |
| | | currentMaterialOrderRow.value = null; |
| | | }; |
| | | |
| | | const openSupplementDialog = row => { |
| | | currentMaterialRow.value = row; |
| | | supplementForm.supplementQty = null; |
| | | supplementForm.supplementReason = ""; |
| | | supplementDialogVisible.value = true; |
| | | nextTick(() => { |
| | | supplementFormRef.value?.clearValidate(); |
| | | }); |
| | | }; |
| | | |
| | | const handleSubmitSupplement = () => { |
| | | supplementFormRef.value?.validate(async valid => { |
| | | if (!valid || !currentMaterialRow.value?.id) { |
| | | ElMessage.warning("缺å°ç©ææç»ID"); |
| | | return; |
| | | } |
| | | supplementSubmitting.value = true; |
| | | try { |
| | | await addWorkOrderMaterialSupplement({ |
| | | materialLedgerId: currentMaterialRow.value.id, |
| | | supplementQty: Number(supplementForm.supplementQty), |
| | | supplementReason: supplementForm.supplementReason, |
| | | workOrderId: currentMaterialOrderRow.value?.id, |
| | | }); |
| | | supplementDialogVisible.value = false; |
| | | await loadMaterialTable(currentMaterialOrderRow.value); |
| | | ElMessage.success("è¡¥ææå"); |
| | | emit("refresh"); |
| | | } catch (e) { |
| | | console.error("è¡¥æå¤±è´¥", e); |
| | | ElMessage.error("è¡¥æå¤±è´¥"); |
| | | } finally { |
| | | supplementSubmitting.value = false; |
| | | } |
| | | }); |
| | | }; |
| | | |
| | | const openSupplementRecordDialog = async row => { |
| | | supplementRecordDialogVisible.value = true; |
| | | supplementRecordLoading.value = true; |
| | | supplementRecordTableData.value = []; |
| | | try { |
| | | const res = await listWorkOrderMaterialSupplementRecord({ |
| | | materialLedgerId: row.id, |
| | | }); |
| | | supplementRecordTableData.value = res.data || []; |
| | | } catch (e) { |
| | | console.error("è·åè¡¥æè®°å½å¤±è´¥", e); |
| | | ElMessage.error("è·åè¡¥æè®°å½å¤±è´¥"); |
| | | } finally { |
| | | supplementRecordLoading.value = false; |
| | | } |
| | | }; |
| | | |
| | | const validatePickRows = () => { |
| | | if (materialTableData.value.length === 0) { |
| | | return { valid: false, message: "ææ å¯é¢ç¨ç©æ" }; |
| | | } |
| | | const invalidRow = materialTableData.value.find(item => item.actualQty === null || item.actualQty === undefined || item.actualQty === ""); |
| | | if (invalidRow) { |
| | | return { valid: false, message: "请填åå®é
æ°éååé¢ç¨" }; |
| | | } |
| | | const exceedRow = materialTableData.value.find(item => { |
| | | const maxQty = Number(item.pickQty || 0) + Number(item.supplementQty || 0); |
| | | return Number(item.actualQty || 0) > maxQty; |
| | | }); |
| | | if (exceedRow) { |
| | | return { valid: false, message: "å®é
æ°éä¸è½å¤§äºé¢ç¨æ°é+è¡¥ææ°é" }; |
| | | } |
| | | return { valid: true, message: "" }; |
| | | }; |
| | | |
| | | const handleSubmitPick = async () => { |
| | | if (!currentMaterialOrderRow.value?.id) return; |
| | | const validateResult = validatePickRows(); |
| | | if (!validateResult.valid) { |
| | | ElMessage.warning(validateResult.message); |
| | | return; |
| | | } |
| | | pickSubmitting.value = true; |
| | | try { |
| | | await pickWorkOrderMaterial({ |
| | | workOrderId: currentMaterialOrderRow.value.id, |
| | | items: materialTableData.value.map(item => ({ |
| | | materialLedgerId: item.id, |
| | | actualQty: Number(item.actualQty || 0), |
| | | })), |
| | | }); |
| | | ElMessage.success("é¢ç¨æå"); |
| | | await loadMaterialTable(currentMaterialOrderRow.value); |
| | | emit("refresh"); |
| | | } catch (e) { |
| | | console.error("é¢ç¨å¤±è´¥", e); |
| | | ElMessage.error("é¢ç¨å¤±è´¥"); |
| | | } finally { |
| | | pickSubmitting.value = false; |
| | | } |
| | | }; |
| | | </script> |