Files
WMS/HHWMS.Web/Areas/Receipt/Views/ReceiptIn/Index.cshtml
T
sunwang b6c3ef8b2c feature:
成品入库页面分配库存弹窗字段完善
2026-11-05 08:38:53 +08:00

559 lines
23 KiB
Plaintext

<div id="plapp">
<a-row :gutter="20">
<a-col :span="24">
<a-card class="general-card">
<a-form :model="form" :rules="rules" ref="formRef" auto-label-width>
<a-form-item label="托盘码" field="palletCode">
<a-input v-model="form.palletCode" ref="palletCodeRef" placeholder="请扫描托盘码"
@@keyup.enter="validateContainer"
@@blur="validateContainer" />
</a-form-item>
<a-form-item label="物料码" field="materialCode">
<a-auto-complete
v-model="form.materialCode"
:data="materialOptions"
ref="materialCodeRef"
placeholder="请扫描或输入物料码"
@@search="handleMaterialSearch"
@@select="handleMaterialSelect"
>
</a-auto-complete>
</a-form-item>
<a-form-item label="图号" field="name">
<a-input v-model="form.name"/>
</a-form-item>
<a-form-item label="当前工序" field="processId">
<a-select v-model="form.processId" placeholder="请选择工序" @@change="processSelect">
<a-option v-for="item in processOptions"
:key="item.value"
:value="item.value">
{{ item.label }}
</a-option>
</a-select>
</a-form-item>
<a-form-item label="工序名称" field="processName" v-show="false">
<a-input v-model="form.processName" />
</a-form-item>
<a-form-item field="sourceCode" label="生产单号">
<a-select v-model="form.sourceCode" placeholder="请选择生产单号" allow-search ref="sourceCodeRef" @@change="orderSelect">
<a-option v-for="item in orderOptions"
:key="item.value"
:value="item.value">
{{ item.value }}
</a-option>
</a-select>
</a-form-item>
<a-form-item label="客户单号" field="billCode">
<a-input v-model="form.billCode" ref="billCodeRef" placeholder="请输入客户单号"/>
</a-form-item>
<a-form-item field="type" label="小托盘类型" >
<a-radio-group v-model="form.type" type="button">
<a-radio
v-for="item in trayTypeOptions"
:key="item.value"
:value="item.value">
{{ item.label }}
</a-radio>
</a-radio-group>
</a-form-item>
<a-form-item field="qty" label="小托盘数量">
<a-input-number v-model="form.qty" :min="0" style="width: 100%" ref="numInput" @@keydown.enter="focusNext('operatorIdRef')"/>
</a-form-item>
<a-form-item label="是否合格" field="isQualified">
<a-switch v-model="form.isQualified" />
</a-form-item>
<a-form-item label="操作员工" field="operatorId">
<a-select v-model="form.operatorId" ref="operatorIdRef" placeholder="请选择或搜索操作员工" allow-search @@change="focusNext('operatorInfoRef')">
<a-option v-for="item in operatorOptions" :key="item.value" :value="item.value">
{{ item.value }}:{{ item.label }}
</a-option>
</a-select>
</a-form-item>
<a-form-item label="检验员信息" field="operatorInfo">
<a-select v-model="form.operatorInfo" ref="operatorInfoRef" placeholder="请选择或搜索检验员" allow-search>
<a-option v-for="item in operatorOptions" :key="item.value" :value="item.value">
{{ item.value }}:{{ item.label }}
</a-option>
</a-select>
</a-form-item>
<a-form-item>
<a-space>
<a-button type="primary" status="success" @@click="submitForm" :loading="loading">上架入库</a-button>
<a-button type="primary" status="warning" @@click="submitEmptyPallet" :loading="loading">空托盘入库</a-button>
<a-button type="primary" status="danger" @@click="emptyPalletOut" :loading="loading">空托盘出库</a-button>
<a-button type="outline" @@click="resetForm">重置</a-button>
</a-space>
</a-form-item>
</a-form>
</a-card>
</a-col>
</a-row>
</div>
<script>
const { createApp, reactive, ref, onMounted, nextTick } = Vue;
const { Message } = ArcoVue;
const app = createApp({
setup() {
const formRef = ref(null);
const loading = ref(false);
const palletCodeRef = ref(null);
const materialCodeRef = ref(null);
const sourceCodeRef = ref(null);
const billCodeRef = ref(null);
const numInput = ref(null);
const operatorIdRef = ref(null);
const operatorInfoRef = ref(null);
const trayTypeOptions = ref([]);
const inputRefs = {
palletCodeRef,
materialCodeRef,
sourceCodeRef,
billCodeRef,
numInput,
operatorIdRef,
operatorInfoRef
};
const focusNext = (nextRefName) => {
nextTick(() => {
if (inputRefs[nextRefName] && inputRefs[nextRefName].value && inputRefs[nextRefName].value.focus) {
inputRefs[nextRefName].value.focus();
}
});
};
const form = reactive({
palletCode: '',
materialCode: '',
sourceCode:'',
orderId: '',
operatorId: '',
processId: '',
processName:'',
processCode:'',
name:'',
type:'',
qty:null,
isQualified: true,
operatorInfo: ''
});
const processOptions = ref([]);
const orderOptions = ref([]);
const materialOptions = ref([]);
let searchTimer = null;
const rules = {
palletCode: [
{ required: true, message: '请输入托盘码', trigger: ['change', 'blur'] }
],
materialCode: [
{ required: true, message: '请输入物料码', trigger: ['change', 'blur'] }
],
qty: [
{ required: true, message: '请输入数量', trigger: ['change', 'blur'] }
],
type: [
{ required: true, message: '请选择托盘类型', trigger: ['change', 'blur'] }
],
//sourceCode: [
//{ required: true, message: '请选择生产单号', trigger: ['change', 'blur'] }
//],
//billCode: [
//{ required: true, message: '请输入客户单据', trigger: ['change', 'blur'] }
//],
processId: [
{ required: true, message: '请选择工序', trigger: ['change', 'blur'] }
],
operatorId: [
{ required: true, message: '请输入操作员工信息', trigger: ['change', 'blur'] }
],
operatorInfo: [
{ required: true, message: '请输入检验员信息', trigger: ['change', 'blur'] }
]
};
const validateContainer = (value) => {
if (!form.palletCode) return;
axios.get(`/receipt/SimpleReceiptIn/ValidateContainer?containerCode=${encodeURIComponent(form.palletCode)}`)
.then((json) => {
if (json.data.Code == 200) {
Message.success("容器验证成功");
focusNext('materialCodeRef')
} else {
Message.error(json.data.Msg || "容器验证失败");
resetForm();
}
})
.catch((error) => {
Message.error("容器验证失败");
resetForm()
});
};
const processSelect = (value) => {
form.processName = processOptions.value.find(item => item.value === value).processName;
form.processCode = processOptions.value.find(item => item.value === value).processCode;
// 选择工序后,加载订单列表
loadOrdersByMaterial(form.materialCode,form.processCode);
focusNext('sourceCodeRef');
}
const orderSelect = (value) => {
form.orderId = orderOptions.value.find(item => item.value === value).label;
focusNext('numInput');
}
// 根据物料加载订单列表
const loadOrdersByMaterial = (materialCode,batch) => {
form.sourceCode = '';
form.orderId = '';
orderOptions.value = [];
$.ajax({
type: "post",
dataType: "json",
data: { materialCode: materialCode,batch: batch},
url: "/receipt/ReceiptIn/GetOrdersByMaterial",
success: (json) => {
if (json.Code == 200) {
orderOptions.value = json.Data || [];
if (orderOptions.value.length === 0) {
Message.warning('该物料暂无关联订单');
}
//console.log(orderOptions.value);
} else {
Message.error(json.Msg || "获取订单列表失败");
}
},
error: (error) => {
console.error("获取订单列表失败", error);
Message.error("获取订单列表失败");
}
});
}
// 加载工序列表:默认展示全部工序,选完工序再由生产订单决定用哪道
const loadProcesses = () => {
processOptions.value = [];
$.ajax({
type: "post",
dataType: "json",
url: "/receipt/ReceiptIn/GetProcessesByMaterial",
success: (json) => {
if (json.Code == 200) {
processOptions.value = (json.Data || []).map(item => ({
...item,
value: item.value,
label: `${item.processCode} - ${item.processName}`
}));
} else {
Message.error(json.Msg || '加载工序列表失败');
processOptions.value = [];
}
},
error: (xhr, status, error) => {
Message.error('加载工序列表失败:' + error);
processOptions.value = [];
}
});
};
// 处理物料搜索
const handleMaterialSearch = (value) => {
if (searchTimer) {
clearTimeout(searchTimer);
}
searchTimer = setTimeout(() => {
if (value) {
searchMaterials(value);
} else {
materialOptions.value = [];
}
}, 1000);
};
// 搜索物料
const searchMaterials = (keyword) => {
axios.get(`/receipt/ReceiptIn/SearchMaterials?keyword=${encodeURIComponent(keyword)}`)
.then(function (response) {
// axios 返回的是响应对象,接口数据在 response.data 里
const json = response.data;
if (json.Code == 200) {
materialOptions.value = (json.Data || []).map(item => ({
...item,
value: item.MaterialCode,
label: `${item.MaterialCode} - ${item.MaterialType} - ${item.MaterialName}`
}));
// 扫描/输入完整物料编码时,自动带出图号并加载工序
const exactCode = (form.materialCode || '').trim();
const exactItem = materialOptions.value.find(item => item.MaterialCode === exactCode);
if (exactItem) {
handleMaterialSelect(exactItem.value, null);
}
} else {
Message.error(json.Msg || '获取物料列表失败');
materialOptions.value = [];
}
})
.catch(function (error) {
Message.error(error);
materialOptions.value = [];
});
};
// 处理物料选择
const handleMaterialSelect = (value, option) => {
const selectedMaterial = materialOptions.value.find(item => item.value === value);
if (selectedMaterial) {
form.materialCode = selectedMaterial.MaterialCode;
form.name = selectedMaterial.MaterialType;
// 选择物料后重新加载全部工序(工序由后续的生产订单决定)
// 先清空当前工序选择,避免显示旧数据
form.processId = '';
form.processName = '';
form.sourceCode = '';
form.orderId = '';
// 清除现有工序选项,触发重新渲染
processOptions.value = [];
orderOptions.value = [];
// 延迟加载工序,确保先清空再加载
nextTick(() => {
loadProcesses();
});
}
};
// 扫描物料码
const scanMaterial = () => {
if (!form.materialCode) return;
loadProcesses();
};
// 提交表单
const submitForm = () => {
formRef.value.validate((errors) => {
if (!errors) {
loading.value = true;
$.ajax({
type: "post",
dataType: "json",
contentType: "application/json",
data: JSON.stringify(form),
url: "/receipt/ReceiptIn/SubmitReceipt",
success: (json) => {
if (json.Code == 200) {
Message.success('入库成功!');
resetForm();
} else {
Message.error({
content: json.Msg || '入库失败!',
duration: 5000 // 设置为 5 秒
});
}
},
error: (xhr, status, error) => {
Message.error('提交失败:' + error);
},
complete: () => {
loading.value = false;
}
});
} else {
Message.error('请填写所有必填项!');
}
});
};
// 空托盘入库
const submitEmptyPallet = () => {
if (!form.palletCode) {
Message.error('请输入托盘码!');
return;
}
loading.value = true;
const emptyPalletData = {
palletCode: form.palletCode,
operatorId: form.operatorId || 'SYSTEM'
};
$.ajax({
type: "post",
dataType: "json",
contentType: "application/json",
data: JSON.stringify(emptyPalletData),
url: "/receipt/ReceiptIn/SubmitEmptyPallet",
success: (json) => {
if (json.Code == 200) {
Message.success('空托盘入库成功!');
resetForm();
} else {
Message.error({
content: json.Msg || '空托盘入库失败!',
duration: 5000
});
}
},
error: (xhr, status, error) => {
Message.error('提交失败:' + error);
},
complete: () => {
loading.value = false;
}
});
};
// 呼叫空托盘出库
const emptyPalletOut = () => {
loading.value = true;
$.ajax({
type: "post",
dataType: "json",
contentType: "application/json",
url: "/receipt/ReceiptIn/EmptyPalletOut",
success: (json) => {
if (json.Code == 200) {
Message.success('空托盘出库任务创建成功!');
resetForm();
} else {
Message.error({
content: json.Msg || '空托盘出库任务创建失败!',
duration: 5000
});
}
},
error: (xhr, status, error) => {
Message.error('提交失败:' + error);
},
complete: () => {
loading.value = false;
}
});
};
// 重置表单
const resetForm = () => {
formRef.value.resetFields();
processOptions.value = [];
orderOptions.value = [];
setTimeout(() => {
if (palletCodeRef.value) {
palletCodeRef.value.focus();
}
}, 100);
};
// 从后端获取托盘类型列表
const loadTrayTypes = () => {
// 调用后端接口获取数据
axios.get('/receipt/ReceiptIn/GetTrayTypes')
.then(response => {
const result = response.data;
console.log(result)
if (result.Code == 200) {
// 假设后端返回格式:[{value: 'mini', label: 'Mini'}, ...]
trayTypeOptions.value = result.Data;
// 可选:设置默认值(取第一个选项)
if (trayTypeOptions.value.length > 0) {
form.type = trayTypeOptions.value[0].value;
}
} else {
Message.error('获取托盘类型失败:' + result.Msg);
}
})
.catch(error => {
Message.error('请求失败:' + error.message);
});
};
// 生命周期钩子
onMounted(() => {
// 页面加载时自动聚焦第一个输入框
setTimeout(() => {
if (palletCodeRef.value) {
palletCodeRef.value.focus();
}
}, 100);
loadTrayTypes();
loadOperators();
// 页面加载即展示全部工序,不依赖物料工序配置
loadProcesses();
});
const operatorOptions = ref([]);
const loadOperators = () => {
$.ajax({
type: "post",
url: "/receipt/ReceiptIn/GetOperators",
success: (json) => {
if (json.Code == 200) {
operatorOptions.value = json.Data;
} else {
Message.error(json.Msg || "获取员工列表失败");
}
},
error: (error) => {
Message.error("获取员工列表失败");
}
});
}
return {
formRef,
form,
loading,
processOptions,
orderOptions,
rules,
validateContainer,
scanMaterial,
submitForm,
submitEmptyPallet,
emptyPalletOut,
resetForm,
materialOptions,
handleMaterialSearch,
handleMaterialSelect,
palletCodeRef,
materialCodeRef,
sourceCodeRef,
billCodeRef,
numInput,
operatorIdRef,
operatorInfoRef,
focusNext,
loadProcesses,
processSelect,
orderSelect,
trayTypeOptions,
operatorOptions
};
}
});
app.use(ArcoVue);
app.mount('#plapp');
</script>