You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

332 lines
13 KiB
Vue

<template>
<div>
<el-card>
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
<el-divider content-position="left"><span style="font-weight: bold; font-size: larger;">工单信息</span></el-divider>
<el-row :gutter="10">
<el-col :span="12">
<el-form-item label="工单号:">{{ form.orderCode }}</el-form-item>
<el-form-item label="成品编码:">{{ form.materialCode }}</el-form-item>
<el-form-item label="计划开始时间:">{{ parseTime(form.planBeginTime) }}</el-form-item>
<el-form-item label="计划数量/已派工数量/完成数量:" label-width="220px">
{{ form.planAmount }}/{{ form.dispatchAmount }}/{{ form.completeAmount }}
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="工艺路线:">{{ form.dispatchName }}</el-form-item>
<el-form-item label="成品名称:">{{ form.materialName }}</el-form-item>
<el-form-item label="计划结束时间:">{{ parseTime(form.planEndTime) }}</el-form-item>
</el-col>
</el-row>
<el-divider content-position="left"><span style="font-weight: bold; font-size: larger;">派工信息</span></el-divider>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button icon="el-icon-plus" size="mini" type="primary" @click="handleAddMesProductPlan">
</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteMesProductPlan"
:disabled="single">删除
</el-button>
</el-col>
</el-row>
<el-table ref="mesProductPlan" :data="mesProductPlanList"
:row-class-name="rowMesProductPlanIndex" @selection-change="handleMesProductPlanSelectionChange">
<el-table-column align="center" type="selection" width="50"/>
<el-table-column align="center" label="序号" prop="index" width="50" v-if="false"/>
<el-table-column align="center" label="派工单号" prop="dispatchCode" width="290">
<template slot-scope="scope">
<el-input v-model="scope.row.dispatchCode" :disabled="true"/>
</template>
</el-table-column>
<el-table-column align="center" label="工序" prop="processName" width="140">
<template slot-scope="scope">
<el-input v-model="scope.row.processName" :disabled="true"/>
</template>
</el-table-column>
<el-table-column align="center" label="步骤" prop="processOrder">
<template slot-scope="scope">
<el-input v-model="scope.row.processOrder" :disabled="true"/>
</template>
</el-table-column>
<el-table-column align="center" label="工位" prop="stationName" width="140">
<template slot-scope="scope">
<el-input v-model="scope.row.stationName" :disabled="true"/>
</template>
</el-table-column>
<el-table-column align="center" label="派工数量" prop="planAmount" width="100">
<template slot-scope="scope">
<el-input v-model="scope.row.planAmount" :disabled="scope.row.oldRowFlag"/>
</template>
</el-table-column>
<el-table-column align="center" label="派工标准工时" prop="productionTime" width="100">
<template slot-scope="scope">
<el-input v-model="scope.row.productionTime" :disabled="scope.row.oldRowFlag"/>
</template>
</el-table-column>
<el-table-column align="center" label="计划开始时间" prop="planBeginTime" width="230">
<template slot-scope="scope">
<el-date-picker v-model="scope.row.planBeginTime" :disabled="scope.row.oldRowFlag" clearable
placeholder="请选择计划开始时间"
type="datetime" value-format="yyyy-MM-dd HH:mm:ss"/>
</template>
</el-table-column>
<el-table-column align="center" label="计划完成时间" prop="planEndTime" width="230">
<template slot-scope="scope">
<el-date-picker v-model="scope.row.planEndTime" :disabled="scope.row.oldRowFlag" clearable
placeholder="请选择计划完成时间"
type="datetime" value-format="yyyy-MM-dd HH:mm:ss"/>
</template>
</el-table-column>
<el-table-column align="center" label="状态" prop="planStatus" width="150">
<template slot-scope="scope">
<el-select v-model="scope.row.planStatus" :disabled="true" placeholder="请选择状态">
<el-option
v-for="dict in dict.type.product_status"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</template>
</el-table-column>
</el-table>
</el-form>
<el-form label-width="100px">
<el-form-item style="text-align: center;margin-left:-100px;margin-top:10px;">
<el-button type="primary" @click="submitForm()"></el-button>
<el-button @click="close()"></el-button>
</el-form-item>
</el-form>
</el-card>
</div>
</template>
<script>
import { getProdOrderInfo, listProdOrderInfo } from '@/api/mes/prod/prodOrderInfo'
export default {
name: "productPlanEdit",
dicts: ['product_status'],
data() {
return {
blueprintModel: false,
sopViewModel: false,
pictureDetailModel: false,
// 图片预览地址
dialogImageUrl: '',
// 非单个禁用
single: true,
checkedMesProductPlanList: [],
// 上传的文件服务器地址
uploadImgUrl: process.env.VUE_APP_BASE_API,
// 选中选项卡的 name
activeName: "columnInfo",
// 表格的高度
tableHeight: document.documentElement.scrollHeight - 245 + "px",
// 表信息
tables: [],
// 表列信息
columns: [],
// 生产计划表格数据
mesProductPlanList: [],
// 表详细信息
info: {},
// 表单参数
form: {},
// 表单校验
rules: {
materialId: [
{required: true, message: "物料ID不能为空", trigger: "blur"}
],
},
};
},
created() {
const objId = this.$route.params && this.$route.params.objId;
console.log(123,objId)
if (objId) {
// 获取表详细信息
getProdOrderInfo(objId).then(res => {
this.form = res.data;
});
// getProductPlan({objId: objId}).then(res => {
// res.data.forEach(e => {
// this.mesProductPlanList.push(e);
// })
// })
}
},
methods: {
/** 提交按钮 */
submitForm() {
let dataList = this.mesProductPlanList.filter(plan => !plan.oldRowFlag);
if (dataList.length === 0) {
this.close();
return;
}
// 校验派工数量(已派工数量 + 派工数量 <= 计划数量)
// 按照processId分组所有分组的planAmount之和是否相等相等后输出planAmount之和的值
const sumList = dataList.reduce((result, {processId, planAmount}) => {
const numericAmount = parseInt(planAmount, 10);
if (!this.isPositiveInteger(numericAmount)) {
this.$modal.msgError("派工数量须为大于等于0的正整数");
return;
}
result[processId] = (result[processId] || 0) + numericAmount;
return result;
}, {});
const uniqueSum = new Set(Object.values(sumList));
if (uniqueSum.size === 1) {
const finalSum = Array.from(uniqueSum)[0];
let dispatchedAmount = this.form.dispatchAmount + finalSum;
if (dispatchedAmount > this.form.planAmount) {
this.$modal.msgError("每个工序的派工数量之和需小于等于该工单计划数量!");
return;
}
dataList.forEach(e => {
e.dispatchedAmount = dispatchedAmount;
}
)
} else {
this.$modal.msgError("每个工序的派工数量之和需相等!");
return;
}
orderAddMesProductPlanList(dataList).then(res => {
this.$modal.msgSuccess(res.msg);
this.close();
});
},
/** 删除按钮操作 */
// handleDeleteMesProductPlan() {
// let productPlan = this.checkedMesProductPlanList[0];
// this.$modal.confirm('是否确认删除生产派工编号为"' + productPlan.dispatchCode + '"的数据项?').then(function () {
// return true;
// }).then(() => {
// if (productPlan.planId === undefined || productPlan.planId === null) {
// //新增删除
// const mesProductPlanDetailList = this.mesProductPlanList;
// this.mesProductPlanList = mesProductPlanDetailList.filter(function (item) {
// return productPlan.dispatchCode !== item.dispatchCode
// });
// } else {
// //历史删除
// const delList = this.mesProductPlanList;
// let dispatchSum = 0;
// try {
// const planIds = delList.filter(function (item) {
// return productPlan.dispatchCode === item.dispatchCode
// }).map(item => {
// if (item.planStatus !== '1') {
// throw Error("只能删除未派工状态的生产派工单!");
// }
// if (item.processId === productPlan.processId) {
// dispatchSum = dispatchSum + item.planAmount;
// }
// return item.planId;
// });
// dispatchSum = this.form.dispatchAmount - dispatchSum;
// delProductplan(planIds).then(res =>{
// // 更新生产工单
// updateProductOrder({
// productOrderId: this.form.productOrderId,
// dispatchAmount: dispatchSum
// })
// getProductOrder(this.form.productOrderId).then(res => {
// this.form = res.data;
// });
// });
// const mesProductPlanDetailList = this.mesProductPlanList;
// this.mesProductPlanList = mesProductPlanDetailList.filter(function (item) {
// return productPlan.dispatchCode !== item.dispatchCode
// });
// this.$modal.msgSuccess("删除成功");
// } catch (e) {
// this.$modal.msgError(e);
// }
// }
// }).catch(() => {
// });
// },
/** 生产计划明细序号 */
rowMesProductPlanIndex({row, rowIndex}) {
row.index = rowIndex + 1;
},
/** 复选框选中数据 */
handleMesProductPlanSelectionChange(selection) {
this.checkedMesProductPlanList = selection
this.single = selection.length !== 1
},
/** 关闭按钮 */
close() {
const obj = {path: "/mes/plan/productOrder", query: {t: Date.now(), queryParams: this.$route.query.queryParams}};
this.$tab.closeOpenPage(obj);
},
/** 生产计划添加按钮操作 */
handleAddMesProductPlan() {
let dispatchCode = "";
getDispatchCode().then(res => {
dispatchCode = res.msg;
getStationByRouteId(this.form.dispatchId).then(res => {
if (res.data.length === 0) {
this.$modal.msgError("工艺路线未维护工位信息!");
}
let lastProcessId = null;
res.data.forEach((e, index) => {
let obj = {};
obj.dispatchCode = dispatchCode;
obj.processId = e.processId;
obj.processName = e.processName;
obj.processOrder = e.processOrder;
obj.stationId = e.stationId;
obj.stationName = e.stationName;
obj.productionTime = 0;
obj.planBeginTime = this.form.planBeginTime;
obj.planEndTime = this.form.planEndTime;
obj.planStatus = '1';
// multiStationFlag一个工序对应工位个数
if (e.multiStationFlag > 1) {
obj.planAmount = 0;
} else {
obj.planAmount = this.form.planAmount - this.form.dispatchAmount;
}
obj.materialId = this.form.materialId;
obj.materialBomId = this.form.materialBomId;
obj.productOrderId = this.form.productOrderId;
// 上一工序ID
if (lastProcessId == null) {
obj.lastProcessId = 0;
} else if(lastProcessId === obj.processId){
obj.lastProcessId = this.mesProductPlanList[index - 1].lastProcessId;
} else {
obj.lastProcessId = lastProcessId;
}
lastProcessId = e.processId;
// 新添加列标识 false=新添加true=历史行
obj.oldRowFlag = false;
this.mesProductPlanList.push(obj);
})
})
})
},
},
mounted() {
}
}
;
</script>