<template>
|
<div>
|
<el-dialog
|
v-model="dialogFormVisible"
|
title="自动派工"
|
width="80%"
|
@close="closeDia"
|
>
|
<el-form :model="form" label-width="140px" label-position="top" ref="formRef">
|
<el-divider content-position="left">派工列表</el-divider>
|
|
<el-table
|
:data="dispatchList"
|
border
|
style="width: 100%; margin-top: 20px;"
|
:row-class-name="tableRowClassName"
|
>
|
<el-table-column label="序号" type="index" width="60" align="center" />
|
<el-table-column label="合同号" prop="salesContractNo" width="200" />
|
<el-table-column label="客户名称" prop="customerName" width="200" />
|
<el-table-column label="项目名称" prop="projectName" width="250" />
|
<el-table-column label="产品大类" prop="productCategory" width="150" />
|
<el-table-column label="规格型号" prop="specificationModel" width="200" />
|
<!-- <el-table-column label="绑定机器" prop="speculativeTradingName" width="120" />-->
|
<el-table-column label="总数量" prop="quantity" width="100" align="right" />
|
<el-table-column label="已排产" prop="schedulingNum" width="100" align="right" fixed="right" />
|
<el-table-column label="待排产" prop="pendingQuantity" width="100" align="right" fixed="right" />
|
<el-table-column label="本次排产" width="150" align="center" fixed="right">
|
<template #default="{ row }">
|
<el-input-number
|
v-model="row.schedulingNum"
|
:min="0"
|
:max="row.pendingQuantity"
|
:step="1"
|
:precision="0"
|
size="small"
|
style="width: 120px"
|
@change="(value) => changeCurrentNum(value, row)"
|
/>
|
</template>
|
</el-table-column>
|
</el-table>
|
</el-form>
|
|
<template #footer>
|
<div class="dialog-footer">
|
<el-button type="primary" @click="submitForm">确认派工</el-button>
|
<el-button @click="closeDia">取消</el-button>
|
</div>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script setup>
|
import {ref, reactive, toRefs, computed} from "vue";
|
import {productionDispatch, productionDispatchList} from "@/api/productionManagement/productionOrder.js";
|
|
const { proxy } = getCurrentInstance()
|
const emit = defineEmits(['close'])
|
|
const dialogFormVisible = ref(false);
|
const operationType = ref('')
|
|
const data = reactive({
|
form: {},
|
dispatchList: [], // 派工列表数据
|
});
|
|
const { form, dispatchList } = toRefs(data);
|
|
|
// 表格行样式
|
const tableRowClassName = ({ rowIndex }) => {
|
if (rowIndex % 2 === 1) {
|
return 'even-row'
|
}
|
return ''
|
}
|
|
// 修改本次排产数量
|
const changeCurrentNum = (value, row) => {
|
if (value > row.pendingQuantity) {
|
row.schedulingNum = row.pendingQuantity
|
proxy.$modal.msgWarning('排产数量不可大于待排产数量')
|
}
|
}
|
|
// 打开弹框
|
const openDialog = (type, rows) => {
|
operationType.value = type;
|
dialogFormVisible.value = true;
|
|
// 处理传入的数据
|
dispatchList.value = rows.map(row => ({
|
...row,
|
schedulingNum: 0, // 初始化本次排产数量为0
|
pendingQuantity: (Number(row.quantity) || 0) - (Number(row.schedulingNum) || 0) // 计算待排产数量
|
}))
|
}
|
|
// 提交表单
|
const submitForm = () => {
|
// 检查是否有排产数据
|
const hasSchedulingData = dispatchList.value.some(item => item.schedulingNum > 0)
|
if (!hasSchedulingData) {
|
proxy.$modal.msgWarning('请至少为一条记录设置排产数量')
|
return
|
}
|
|
// 构造提交数据 - 直接传递数组,不过滤
|
const submitData = dispatchList.value
|
|
console.log('提交自动派工数据:', submitData)
|
|
// 调用API(这里需要根据实际接口调整)
|
productionDispatchList(submitData).then(res => {
|
proxy.$modal.msgSuccess(res.msg);
|
closeDia();
|
}).catch(err => {
|
proxy.$modal.msgError("派工失败");
|
console.error('派工失败:', err);
|
})
|
}
|
|
// 关闭弹框
|
const closeDia = () => {
|
proxy.resetForm("formRef");
|
dialogFormVisible.value = false;
|
dispatchList.value = []
|
emit('close')
|
};
|
|
defineExpose({
|
openDialog,
|
});
|
</script>
|
|
<style scoped>
|
:deep(.even-row) {
|
background-color: #fafafa;
|
}
|
|
:deep(.el-table .cell) {
|
padding: 8px 12px;
|
}
|
|
:deep(.el-table th) {
|
background-color: #f5f7fa;
|
color: #606266;
|
font-weight: 600;
|
}
|
</style>
|