491 lines
20 KiB
Plaintext
491 lines
20 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" />
|
|
</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-input v-model="form.sourceCode" style="width: 100%" ref="sourceCodeRef" @@keydown.enter="focusNext('numInput')"/>
|
|
</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-input v-model="form.operatorId" ref="operatorIdRef" placeholder="请扫描员工码" @@keydown.enter="focusNext('operatorInfoRef')" />
|
|
</a-form-item>
|
|
|
|
<a-form-item label="检验员信息" field="operatorInfo">
|
|
<a-input v-model="form.operatorInfo" ref="operatorInfoRef" placeholder="请扫描检验员信息" @@keydown.enter="submitForm" />
|
|
</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 numInput = ref(null);
|
|
const operatorIdRef = ref(null);
|
|
const operatorInfoRef = ref(null);
|
|
const trayTypeOptions = ref([]);
|
|
|
|
const inputRefs = {
|
|
palletCodeRef,
|
|
materialCodeRef,
|
|
sourceCodeRef,
|
|
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:'',
|
|
name:'',
|
|
type:'',
|
|
qty:null,
|
|
isQualified: true,
|
|
operatorInfo: ''
|
|
});
|
|
const processOptions = 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'] }
|
|
],
|
|
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;
|
|
focusNext('sourceCodeRef');
|
|
}
|
|
|
|
// 加载工序列表
|
|
const loadProcesses = () => {
|
|
$.ajax({
|
|
type: "post",
|
|
dataType: "json",
|
|
url: "/receipt/ReceiptIn/GetProcesses",
|
|
success: (json) => {
|
|
if (json.Code == 200) {
|
|
processOptions.value = json.Data;
|
|
} else {
|
|
Message.error(json.Msg || '加载工序列表失败');
|
|
}
|
|
},
|
|
error: (xhr, status, error) => {
|
|
Message.error('加载工序列表失败:' + error);
|
|
}
|
|
});
|
|
};
|
|
|
|
// 根据物料加载工序列表
|
|
const loadProcessesByMaterial = (materialCode) => {
|
|
if (!materialCode) {
|
|
form.processId = '';
|
|
processOptions.value = [];
|
|
return;
|
|
}
|
|
processOptions.value = [];
|
|
$.ajax({
|
|
type: "post",
|
|
dataType: "json",
|
|
data: { materialCode: materialCode },
|
|
url: "/receipt/ReceiptIn/GetProcessesByMaterial",
|
|
success: (json) => {
|
|
if (json.Code == 200) {
|
|
|
|
const newOptions = json.Data.map(item => ({
|
|
...item,
|
|
value: item.value,
|
|
label: `${item.processCode} - ${item.processName}`
|
|
}));
|
|
// 使用新数组赋值,强制组件重新渲染
|
|
processOptions.value = [...newOptions];
|
|
|
|
} else {
|
|
Message.error(json.Msg || '加载物料工序失败');
|
|
processOptions.value = [];
|
|
}
|
|
},
|
|
error: (xhr, status, error) => {
|
|
Message.error('加载物料工序失败:' + error);
|
|
processOptions.value = [];
|
|
}
|
|
});
|
|
};
|
|
|
|
// 扫描托盘码
|
|
const scanPallet = () => {
|
|
if (!form.palletCode) return;
|
|
// TODO: 实现托盘码验证逻辑
|
|
};
|
|
|
|
// 处理物料搜索
|
|
const handleMaterialSearch = (value) => {
|
|
if (searchTimer) {
|
|
clearTimeout(searchTimer);
|
|
}
|
|
searchTimer = setTimeout(() => {
|
|
if (value) {
|
|
searchMaterials(value);
|
|
} else {
|
|
materialOptions.value = [];
|
|
}
|
|
}, 300);
|
|
};
|
|
|
|
// 搜索物料
|
|
|
|
const searchMaterials = (keyword) => {
|
|
axios.get(`/receipt/SimpleReceiptIn/SearchMaterials?keyword=${encodeURIComponent(keyword)}`)
|
|
.then(function (json) {
|
|
if (json.data.Code == 200) {
|
|
materialOptions.value = json.data.Data.map(item => ({
|
|
...item,
|
|
value: item.MaterialCode,
|
|
label: `${item.MaterialCode} - ${item.MaterialType} - ${item.MaterialName}`
|
|
}));
|
|
} else {
|
|
Message.error(json.data.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 = '';
|
|
|
|
// 清除现有工序选项,触发重新渲染
|
|
processOptions.value = [];
|
|
|
|
// 延迟加载新工序,确保先清空再加载
|
|
nextTick(() => {
|
|
loadProcessesByMaterial(selectedMaterial.MaterialCode);
|
|
});
|
|
}
|
|
};
|
|
|
|
// 扫描物料码
|
|
const scanMaterial = () => {
|
|
if (!form.materialCode) return;
|
|
loadProcessesByMaterial(form.materialCode);
|
|
};
|
|
|
|
// 提交表单
|
|
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 = [];
|
|
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();
|
|
});
|
|
|
|
return {
|
|
formRef,
|
|
form,
|
|
loading,
|
|
processOptions,
|
|
rules,
|
|
scanPallet,
|
|
validateContainer,
|
|
scanMaterial,
|
|
submitForm,
|
|
submitEmptyPallet,
|
|
emptyPalletOut,
|
|
resetForm,
|
|
materialOptions,
|
|
handleMaterialSearch,
|
|
handleMaterialSelect,
|
|
palletCodeRef,
|
|
materialCodeRef,
|
|
sourceCodeRef,
|
|
numInput,
|
|
operatorIdRef,
|
|
operatorInfoRef,
|
|
focusNext,
|
|
loadProcesses,
|
|
loadProcessesByMaterial,
|
|
processSelect,
|
|
trayTypeOptions
|
|
};
|
|
}
|
|
});
|
|
|
|
app.use(ArcoVue);
|
|
app.mount('#plapp');
|
|
</script> |