Files
WMS/HHWMS.Web/Areas/Receipt/Views/ReceiptIn/Index.cshtml
T

297 lines
11 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" @@change="scanPallet" ref="palletCodeRef" placeholder="请扫描托盘码" @@keydown.enter.prevent="focusNext('materialCodeRef')" />
</a-form-item>
<a-form-item label="物料码" field="materialCode">
<a-input v-model="form.materialCode" @@change="scanMaterial" ref="materialCodeRef" placeholder="请扫描物料码" @@keydown.enter.prevent="focusNext('quantityInput')" />
</a-form-item>
<a-form-item label="生产订单" field="orderId">
<a-select v-model="form.orderId" placeholder="请选择生产订单" @@change="handleOrderChange" ref="orderSelect">
<a-option v-for="item in orderOptions"
:key="item.value"
:value="item.value">
{{ item.label }}
</a-option>
</a-select>
</a-form-item>
<a-form-item label="当前工序" field="processId">
<a-select v-model="form.processId" placeholder="请选择工序" ref="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="quantity">
<a-input-number v-model="form.quantity" :min="1" :precision="0" ref="quantityInput" />
</a-form-item>
<a-form-item label="是否合格" field="isQualified">
<a-switch v-model="form.isQualified" ref="isQualifiedSwitch" />
</a-form-item>
<a-form-item label="操作员工" field="operatorId">
<a-select v-model="form.operatorId" placeholder="请选择操作员工" ref="operatorSelect">
<a-option v-for="item in operatorOptions"
:key="item.value"
:value="item.value">
{{ item.label }}
</a-option>
</a-select>
</a-form-item>
<a-form-item label="检验员信息" field="operatorInfo">
<a-input v-model="form.operatorInfo" placeholder="请输入检验员信息" />
</a-form-item>
<a-form-item>
<a-space>
<a-button type="primary" @@click="submitForm" :loading="loading">上架入库</a-button>
<a-button @@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 palletCodeRef = ref(null);
const materialCodeRef = ref(null);
const orderSelect = ref(null);
const processSelect = ref(null);
const operatorSelect = ref(null);
const quantityInput = ref(null);
const isQualifiedSwitch = ref(null);
const loading = ref(false);
const form = reactive({
palletCode: '',
materialCode: '',
orderId: '',
operatorId: '',
processId: '',
quantity: 1,
isQualified: true,
operatorInfo: ''
});
const orderOptions = ref([]);
const operatorOptions = ref([]);
const processOptions = ref([]);
const rules = {
palletCode: [
{ required: true, message: '请输入托盘码', trigger: ['change', 'blur'] }
],
materialCode: [
{ required: true, message: '请输入物料码', trigger: ['change', 'blur'] }
],
orderId: [
{ required: true, message: '请选择生产订单', trigger: ['change', 'blur'] }
],
operatorId: [
{ required: true, message: '请选择操作员工', trigger: ['change', 'blur'] }
],
processId: [
{ required: true, message: '请选择工序', trigger: ['change', 'blur'] }
],
quantity: [
{ required: true, type: 'number', message: '请输入数量', trigger: ['change', 'blur'] }
],
operatorInfo: [
{ required: true, message: '请输入检验员信息', trigger: ['change', 'blur'] }
]
};
// 加载操作员列表
const loadOperators = () => {
$.ajax({
type: "post",
dataType: "json",
url: "/receipt/ReceiptIn/GetOperators",
success: (json) => {
operatorOptions.value = json.Data;
}
});
};
// 加载工序列表
const loadProcesses = () => {
$.ajax({
type: "post",
dataType: "json",
url: "/receipt/ReceiptIn/GetProcesses",
success: (json) => {
processOptions.value = json.Data;
}
});
};
// 加载当前操作员信息
const loadOperatorInfo = () => {
$.ajax({
type: "post",
dataType: "json",
url: "/receipt/ReceiptIn/GetOperatorInfo",
success: (json) => {
form.operatorInfo = json.Data;
}
});
};
// 扫描托盘码
const scanPallet = () => {
if (!form.palletCode) return;
// TODO: 实现托盘码验证逻辑
};
// 扫描物料码
const scanMaterial = () => {
if (!form.materialCode) return;
$.ajax({
type: "post",
dataType: "json",
data: { materialCode: form.materialCode },
url: "/receipt/ReceiptIn/GetOrdersByMaterial",
success: (json) => {
orderOptions.value = json.Data;
}
});
};
// 生产订单变更
const handleOrderChange = () => {
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(json.Msg || '入库失败!');
}
},
error: (xhr, status, error) => {
Message.error('提交失败:' + error);
},
complete: () => {
loading.value = false;
}
});
} else {
Message.error('请填写所有必填项!');
}
});
};
// 重置表单
const resetForm = () => {
formRef.value.resetFields();
orderOptions.value = [];
processOptions.value = [];
setTimeout(() => {
if (palletCodeRef.value) {
palletCodeRef.value.focus();
}
}, 100);
};
// 焦点跳转到下一个输入框
const focusNext = (nextRef) => {
const refMap = {
materialCodeRef: materialCodeRef,
quantityInput: quantityInput
};
const nextElement = refMap[nextRef];
if (nextElement?.value) {
// 先让当前元素失去焦点
if (document.activeElement) {
document.activeElement.blur();
}
// 使用 nextTick 确保 DOM 更新完成
nextTick(() => {
if (nextElement.value.$el) {
// 处理 Input 组件
const input = nextElement.value.$el.querySelector('input');
if (input) {
input.focus();
}
} else {
// 处理基础组件
nextElement.value.focus();
}
});
}
};
// 生命周期钩子
onMounted(() => {
loadOperators();
loadOperatorInfo();
// 页面加载时自动聚焦第一个输入框
setTimeout(() => {
if (palletCodeRef.value) {
palletCodeRef.value.focus();
}
}, 100);
});
return {
formRef,
palletCodeRef,
materialCodeRef,
orderSelect,
processSelect,
operatorSelect,
quantityInput,
isQualifiedSwitch,
form,
loading,
orderOptions,
operatorOptions,
processOptions,
rules,
scanPallet,
scanMaterial,
handleOrderChange,
submitForm,
resetForm,
focusNext
};
}
});
app.use(ArcoVue);
app.mount('#plapp');
</script>