|
//此js文件是用来自定义扩展业务代码,可以扩展一些自定义页面或者重新配置生成的代码
|
import http from '@/api/http.js'
|
import { h,createVNode, render,reactive } from 'vue';
|
import { ElDialog , ElForm, ElFormItem, ElInput, ElButton, ElMessage } from 'element-plus'; // 引入ElMessage,解决提示无反应
|
|
let extension = {
|
components: {
|
//查询界面扩展组件
|
gridHeader: '',
|
gridBody: '',
|
gridFooter: '',
|
//新建、编辑弹出框扩展组件
|
modelHeader: '',
|
modelBody: '',
|
modelFooter: ''
|
},
|
tableAction: '', //指定某张表的权限(这里填写表名,默认不用填写)
|
buttons: { view: [
|
{
|
name: '组盘',
|
type: 'primary',
|
value: '组盘',
|
onClick: function () { // 修复1:移除无用row参数,加日志调试
|
console.log('组盘按钮被点击,开始校验');
|
const selectedRows = this.$refs.table.getSelected();
|
|
// 校验1:是否选中行
|
if (selectedRows.length === 0) {
|
console.log('校验不通过:未选中任何单据');
|
ElMessage.warning('请选择一条单据');
|
return;
|
}
|
// 校验2:是否选中单行
|
if (selectedRows.length > 1) {
|
console.log('校验不通过:选中多行单据');
|
ElMessage.warning('只能选择一条单据');
|
return;
|
}
|
|
const targetRow = selectedRows[0];
|
|
|
|
|
this.$emit('openPalletDialog', targetRow.inboundOrderNo);
|
}
|
},
|
{
|
name: '空托盘入库',
|
type: 'primary',
|
value: '空托盘入库',
|
onClick: function () {
|
const mountNode = document.createElement('div');
|
document.body.appendChild(mountNode);
|
|
// 响应式表单数据:料箱码改为可选填(初始空字符串)
|
const formData = reactive({
|
boxCode: '' // 料箱码(string类型,可空)
|
});
|
|
const vnode = createVNode(ElDialog, {
|
title: '空托盘入库',
|
width: '400px',
|
modelValue: true,
|
appendToBody: true,
|
'onUpdate:modelValue': (isVisible) => {
|
if (!isVisible) {
|
render(null, mountNode);
|
document.body.removeChild(mountNode);
|
}
|
}
|
}, {
|
default: () => h(ElForm, {
|
model: formData,
|
rules: {
|
// 料箱码校验:仅保留字符串类型,移除必填要求(空值可通过)
|
boxCode: [
|
{ type: 'string', message: '料箱码必须为字符串', trigger: 'blur' }
|
]
|
},
|
ref: 'batchInForm'
|
}, [
|
// 料箱码输入项(可选填)
|
h(ElFormItem, { label: '料箱码', prop: 'boxCode' }, [
|
h(ElInput, {
|
type: 'text',
|
placeholder: '可选输入料箱码,不填则默认入库', // 提示可空规则
|
modelValue: formData.boxCode,
|
'onUpdate:modelValue': (val) => {
|
formData.boxCode = val;
|
}
|
})
|
]),
|
// 底部按钮区(保持不变)
|
h('div', { style: { textAlign: 'right', marginTop: '16px' } }, [
|
h(ElButton, {
|
type: 'text',
|
onClick: () => {
|
render(null, mountNode);
|
document.body.removeChild(mountNode);
|
ElMessage.info('取消入库任务');
|
}
|
}, '取消'),
|
h(ElButton, {
|
type: 'primary',
|
onClick: async () => {
|
const formRef = vnode.component.refs.batchInForm;
|
try {
|
await formRef.validate(); // 空值可通过校验
|
} catch (err) {
|
return;
|
}
|
|
// 入库接口提交:料箱码为空时传递空字符串,后端需支持该字段可选
|
http.post('/api/wmsTask/BatchInboundTask', {
|
boxCode: formData.boxCode // 可空:用户输入或空字符串
|
}).then(({ data, status, message }) => {
|
if (status) {
|
ElMessage.success(`入库成功${formData.boxCode ? ',料箱码:' + formData.boxCode : ''}`);
|
this.refresh();
|
render(null, mountNode);
|
document.body.removeChild(mountNode);
|
} else {
|
ElMessage.error(message || data?.message || '入库失败');
|
}
|
}).catch(() => {
|
ElMessage.error('请求失败,请稍后重试');
|
});
|
}
|
}, '确定')
|
])
|
])
|
});
|
|
vnode.appContext = this.$.appContext;
|
render(vnode, mountNode);
|
}
|
}
|
], box: [], detail: [] }, //扩展的按钮
|
methods: {
|
//下面这些方法可以保留也可以删除
|
onInit() {
|
},
|
onInited() {
|
//框架初始化配置后
|
//如果要配置明细表,在此方法操作
|
//this.detailOptions.columns.forEach(column=>{ });
|
},
|
searchBefore(param) {
|
//界面查询前,可以给param.wheres添加查询参数
|
//返回false,则不会执行查询
|
return true;
|
},
|
searchAfter(result) {
|
//查询后,result返回的查询数据,可以在显示到表格前处理表格的值
|
return true;
|
},
|
addBefore(formData) {
|
//新建保存前formData为对象,包括明细表,可以给给表单设置值,自己输出看formData的值
|
return true;
|
},
|
updateBefore(formData) {
|
//编辑保存前formData为对象,包括明细表、删除行的Id
|
return true;
|
},
|
rowClick({ row, column, event }) {
|
//查询界面点击行事件
|
this.$refs.table.$refs.table.toggleRowSelection(row); //单击行时选中当前行;
|
},
|
modelOpenAfter(row) {
|
//点击编辑、新建按钮弹出框后,可以在此处写逻辑,如,从后台获取数据
|
//(1)判断是编辑还是新建操作: this.currentAction=='Add';
|
//(2)给弹出框设置默认值
|
//(3)this.editFormFields.字段='xxx';
|
//如果需要给下拉框设置默认值,请遍历this.editFormOptions找到字段配置对应data属性的key值
|
//看不懂就把输出看:console.log(this.editFormOptions)
|
}
|
}
|
};
|
export default extension;
|
|