@@ -589,7 +581,7 @@ import {
addRoute,
updateRoute,
getDistinctProjectCodes,
- updateProcessPlan, generatePDFs, updateBom, addBom
+ updateProcessPlan, generatePDFs, updateBom, addBom, deleteBom
} from "@/api/system/route";
import upload from "svg-sprite-loader/examples/custom-runtime-generator/build/main";
import { getToken } from "../../../utils/auth";
@@ -598,6 +590,8 @@ import Bomfrom from './bomfrom'
import { getProcessInfoList, pushRouteBom, onSave, getBomInfo } from "@/api/system/route";
import { listMaterial } from "@/api/system/material";
+import axios from 'axios';
+
export default {
name: "",
components: {
@@ -792,25 +786,27 @@ export default {
id: 0,//动态增加表格列的ID
// 表单校验
rules: {
- workCenter: [
- { required: true, message: "工作中心不能为空", trigger: "blur" }
- ],
- processName: [
- { required: true, message: "工序名称不能为空", trigger: "blur" }
- ],
- // 添加物料相关的验证规则
- materialCode: [
- { required: true, message: "物料编码不能为空", trigger: "blur" }
- ],
- materialName: [
- { required: true, message: "物料名称不能为空", trigger: "blur" }
- ],
- material: [
- { required: true, message: "材质不能为空", trigger: "blur" }
- ],
- discWeight: [
- { required: true, message: "单重不能为空", trigger: "blur" }
- ],
+ id: [
+ { required: true, message: "主键ID不能为空", trigger: "blur" }
+ ],
+ routeDescription: [
+ { required: true, message: "工艺路线描述不能为空", trigger: "blur" }
+ ],
+ materialCode: [
+ { required: true, message: "物料编码不能为空", trigger: "blur" }
+ ],
+ materialName: [
+ { required: true, message: "物料名称不能为空", trigger: "blur" }
+ ],
+ processControl: [ // 添加工序控制码的验证
+ { required: true, message: "工序控制码不能为空", trigger: "blur" }
+ ],
+ processName: [ // 添加工序名称的验证
+ { required: true, message: "工序名称不能为空", trigger: "blur" }
+ ],
+ activityDuration: [ // 添加活动时长的验证
+ { required: true, message: "活动时长不能为空", trigger: "blur" }
+ ]
},
bomDialogVisible: false,
bomDialogTitle: '',
@@ -880,6 +876,10 @@ export default {
// 当路由参数 productionOrderNo 变化时,重新获取
this.setTotalWeight();
this.getList();
+ // 设置查询参数中的 routeDescription
+ if (newVal) {
+ this.queryParams.routeDescription = newVal;
+ }
}
},
mounted() {
@@ -897,25 +897,54 @@ export default {
}
},
methods: {
+
// 处理工作中心变化
handleWorkCenterChange(scope) {
- const { row, $index } = scope;
- // 如果是委外中心,自动设置工序控制为"委外+质量"
- if (row.workCenter === '委外中心') {
- row.processControl = '委外+质量';
- } else {
- // 非委外中心时,检查是否需要设置为"汇报+免检"
- this.setProcessControl(row, $index);
- }
-},
- // 处理工序控制变化
- handleProcessControlChange(row, index) {
- // 验证工序控制是否符合规则
- const validControl = this.validateProcessControl(row, index);
- if (!validControl.valid) {
- this.$message.warning(validControl.message);
- // 设置正确的工序控制值
- row.processControl = validControl.correctValue;
+ const { row } = scope;
+ const currentIndex = this.form.routeList.findIndex(item => item === row);
+
+ // 移除自动设置工序控制码的逻辑
+ // 只需记录工作中心的变化,不再自动填写
+ console.log("工作中心变化:", row.workCenter);
+ },
+
+ // 验证工序控制
+ validateProcessControl(row, index) {
+ // 验证逻辑保持不变
+ if (row.workCenter === '委外中心' && row.processControl !== '委外+质量') {
+ return {
+ valid: false,
+ message: '委外中心的工序控制必须为"委外+质量"',
+ correctValue: '委外+质量'
+ };
+ }
+
+ if (index > 0) {
+ const previousRow = this.form.routeList[index - 1];
+ if (previousRow.workCenter === row.workCenter &&
+ previousRow.workCenter !== '委外中心' &&
+ row.processControl !== '汇报+免检') {
+ return {
+ valid: false,
+ message: '与上道工序工作中心相同时,工序控制应为"汇报+免检"',
+ correctValue: '汇报+免检'
+ };
+ }
+ }
+
+ return { valid: true };
+ },
+
+ // 开始编辑行
+ handleRowEdit(scope) {
+ // 保存原始数据
+ scope.row.originalData = JSON.parse(JSON.stringify(scope.row));
+ // 设置编辑状态
+ this.$set(scope.row, 'isEdit', true);
+
+ // 如果是委外中心,确保工序控制正确
+ if (scope.row.workCenter === '委外中心') {
+ this.$set(scope.row, 'processControl', '委外+质量');
}
},
@@ -926,39 +955,17 @@ export default {
// 设置工序控制
setProcessControl(row, index) {
+ console.log('进入setProcessControl方法'); // 添加日志
if (row.workCenter === '委外中心') {
- // 委外中心必须是委外+质量
+ console.log('设置委外+质量'); // 添加日志
this.$set(row, 'processControl', '委外+质量');
} else if (this.shouldBeAutoFreeInspection(row, index)) {
- // 与上序工作中心相同时设置为汇报+免检
+ console.log('设置汇报+免检'); // 添加日志
this.$set(row, 'processControl', '汇报+免检');
}
},
// 验证工序控制
- validateProcessControl(row, index) {
- // 首先检查是否是委外中心
- if (row.workCenter === '委外中心') {
- if (row.processControl !== '委外+质量') {
- return {
- valid: false,
- message: '委外中心的工序控制必须为"委外+质量"',
- correctValue: '委外+质量'
- };
- }
- return { valid: true };
- }
- // 如果不是委外中心,检查是否需要自动免检
- if (this.shouldBeAutoFreeInspection(row, index) && row.processControl !== '汇报+免检') {
- return {
- valid: false,
- message: '与上序工作中心相同时,工序控制应为"汇报+免检"',
- correctValue: '汇报+免检'
- };
- }
-
- return { valid: true };
-},
// 判断是否应该自动设置为免检
shouldBeAutoFreeInspection(row, index) {
if (!row.parentId || index === 0 || row.workCenter === '委外中心') {
@@ -985,55 +992,7 @@ export default {
- /* // 查询单个物料库存
- async handleMaterialSelect(materialCode) {
- if (!materialCode) return;
- // 设置加载状态
- const row = this.form.routeList.find(item => item.materialCode === materialCode);
- if (row) {
- this.$set(row, 'loadingStock', true);
- }
-
- try {
- const response = await listMaterial({
- materialCode: materialCode
- });
-
- if (response.rows && response.rows.length > 0) {
- const material = response.rows[0];
- // 更新对应行的库存信息
- if (row) {
- this.$set(row, 'stock', material.singleWeight || 0);
- }
- }
- } catch (error) {
- console.error('查询库存失败:', error);
- this.$message.error('查询库存失败');
- } finally {
- if (row) {
- this.$set(row, 'loadingStock', false);
- }
- }
- },*/
- // 刷新所有物料库存
- // 修改刷新所有物料库存的方法
- async refreshAllStock() {
- this.loading = true;
- try {
- const promises = this.form.routeList
- .filter(row => row.materialCode) // 只处理有物料编码的行
- .map(row => this.handleMaterialSelect(row.materialCode));
-
- await Promise.all(promises);
- this.$message.success('库存刷新完成');
- } catch (error) {
- console.error('批量刷新库存失败:', error);
- this.$message.error('部分库存刷新失败');
- } finally {
- this.loading = false;
- }
- },
/** 导入时间按钮操作 */
handleImportTime() {
this.timeUpload.title = "导入时间";
@@ -1205,8 +1164,6 @@ export default {
}
});
-
-
},
// 删除子集
@@ -1275,11 +1232,9 @@ export default {
const response = await listRoute(this.queryParams);
this.form.routeList = response.rows;
this.total = response.total;
- // 自动刷新库存
- await this.refreshAllStock();
} catch (error) {
console.error('获取数据失败:', error);
- this.$message.error('数据加载失败');
+
} finally {
this.loading = false;
}
@@ -1409,16 +1364,15 @@ export default {
},
+
/**推送工艺 */
async pushRouteBom() {
// 获取生产订单号
const productionOrderNo = this.$route.query.productionOrderNo;
-
if (!productionOrderNo) {
this.$modal.msgError("未获取到生产订单号,请检查!");
return;
}
-
try {
// 显示确认对话框
await this.$confirm(
@@ -1430,7 +1384,6 @@ export default {
type: 'warning'
}
);
-
// 显示全屏 loading
const loading = this.$loading({
lock: true,
@@ -1438,10 +1391,8 @@ export default {
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
});
-
// 重置表单状态
this.reset();
-
// 设置超时检测
const timeout = 600000; // 10分钟超时
const timeoutPromise = new Promise((_, reject) => {
@@ -1449,17 +1400,29 @@ export default {
reject(new Error('推送操作超时,请检查后台处理状态'));
}, timeout);
});
-
// 调用推送 API 并设置超时
const response = await Promise.race([
pushRouteBom(productionOrderNo),
timeoutPromise
]);
-
- // 更新表单数据
- if (response && response.data) {
- this.form = response.data;
- }
+ // 处理后端返回的数据
+ const { duplicateRoutes, failedRoutes, successfulRoutes } = response;
+ // 提取物料编码
+ const duplicateCodes = duplicateRoutes.join(', ');
+ const failedCodes = failedRoutes.map(route => route.materialCode).join(', ');
+ const successfulCodes = successfulRoutes.map(route => route.materialCode).join(', ');
+ // 显示成功消息
+ this.$alert(`
+ 成功 (${successfulRoutes.length}):
+ ${successfulCodes || '无'}
+ 失败 (${failedRoutes.length}):
+ ${failedCodes || '无'}
+ 重复 (${duplicateRoutes.length}):
+ ${duplicateCodes || '无'}
+ `, '推送完成', {
+ dangerouslyUseHTMLString: true,
+ confirmButtonText: '确定'
+ });
// 刷新列表
await this.getList();
@@ -1467,14 +1430,6 @@ export default {
// 关闭 loading
loading.close();
- // 显示成功消息
- this.$notify({
- title: '推送成功',
- message: `工艺路线[${productionOrderNo}]推送完成`,
- type: 'success',
- duration: 5000
- });
-
} catch (error) {
// 错误处理
console.error('[推送工艺失败]:', error);
@@ -1496,7 +1451,7 @@ export default {
this.loading = false;
}
},
- /** 更新计划时间*/
+ /** 更新计划���间*/
updateProcessPlan(row) {
// 显示加载状态
this.loading = true;
@@ -1526,8 +1481,7 @@ export default {
this.loading = false;
});
},
- /** 更新计划时间*/
- generatePDFs(row) {
+ generatePDFs1(row) {
// 显示加载状态
this.loading = true;
// 调用 reset 方法,重置表单或状态
@@ -1539,8 +1493,14 @@ export default {
// 调用封装好的 API 方法
generatePDFs(rooteProdet)
.then(response => {
- // 假设后端返回的数据可以直接赋值给表单
- this.form = response;
+
+ let blob = new Blob([response], {type: 'application/zip'})
+ let url = window.URL.createObjectURL(blob)
+ const link = document.createElement('a') // 创建a标签
+ link.href = url
+ link.download = rooteProdet+'.zip' // 重命名文件
+ link.click()
+ URL.revokeObjectURL(url) // 释放内存
// 弹出成功消息
this.$modal.msgSuccess("生成" + rooteProdet + "的PDF 成功 ");
// 调用方法更新列表
@@ -1548,8 +1508,8 @@ export default {
})
.catch(error => {
// 处理错误,弹出错误提示
- this.$modal.msgError("更新,请重试!");
- console.error('更新工序计划失败:', error);
+ this.$modal.msgError("生成PDF失败,请重试!");
+ console.error('生成PDF失败:', error);
})
.finally(() => {
// 隐藏加载状态
@@ -1560,23 +1520,15 @@ export default {
/** 提交按钮 */
submitForm() {
- this.$refs["form"].validate(valid => {
+ this.$refs.form.validate(valid => {
if (valid) {
- // 添加工序控制验证
- const processControlValid = this.validateAllProcessControls();
- if (!processControlValid.valid) {
- this.$message.error(processControlValid.message);
- return;
- }
-
-
+ // 提交逻辑
this.buttonLoading = true;
if (this.form.id != null) {
updateRoute(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
- this.reset();
}).finally(() => {
this.buttonLoading = false;
});
@@ -1585,28 +1537,17 @@ export default {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
- this.reset();
}).finally(() => {
this.buttonLoading = false;
});
}
+ } else {
+ this.$message.error("请填写必填项");
}
});
},
// 验证所有工序控制
- validateAllProcessControls() {
- for (const row of this.form.routeList) {
- if (row.children) {
- for (let i = 0; i < row.children.length; i++) {
- const validResult = this.validateProcessControl(row.children[i], i);
- if (!validResult.valid) {
- return validResult;
- }
- }
- }
- }
- return { valid: true };
- },
+
/** 删除按钮操作 */
handleDelete(scope) {
const ids = [scope.row.id];
@@ -1638,7 +1579,7 @@ export default {
this.bomDialogTitle = '新增BOM';
this.bomForm = {
id: undefined,
- projectNumber: this.currentMaterial.productionOrderNo, // 使用当前的项目令号
+ projectNumber: this.currentMaterial.productionOrderNo, // 使用当��的项目令号
materialCode: '',
materialName: '',
materialType: '',
@@ -1734,17 +1675,6 @@ export default {
this.bomForm.unit = item.classificationName;
}
},
-
-
-
- // 开始编辑行
- handleRowEdit(scope) {
- // 保存原始数据,用于取消编辑时恢复
- scope.row.originalData = JSON.parse(JSON.stringify(scope.row));
- // 设置编辑状态
- this.$set(scope.row, 'isEdit', true);
- },
-
// 取消编辑
cancelEdit(scope) {
// 恢复原始数据
@@ -1752,14 +1682,14 @@ export default {
// 退出编辑状态
this.$set(scope.row, 'isEdit', false);
},
-
// 保存单行数据
onSaveRow(scope) {
// 显示加载状态
this.loading = true;
-
// 获取行数据并创建副本
const row = scope.row;
+ // 验证委外中心的工序控制
+
const saveData = {
id: row.id,
parentId: row.parentId,