<template>
|
<a-spin :spinning="confirmLoading">
|
<j-form-container :disabled="formDisabled">
|
<!-- 主表单区域 -->
|
<a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
|
<a-row>
|
<a-col :span="12" >
|
<a-form-model-item label="物料编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialNumber">
|
<a-input v-model="model.materialNumber" placeholder="请输入物料编码" ></a-input>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="12" >
|
<a-form-model-item label="物料名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialName">
|
<a-input v-model="model.materialName" placeholder="请输入物料名称" ></a-input>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="12" >
|
<a-form-model-item label="物料型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialModel">
|
<a-input v-model="model.materialModel" placeholder="请输入物料型号" ></a-input>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="12" >
|
<a-form-model-item label="物料类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialCategory">
|
<j-dict-select-tag type="list" v-model="model.materialCategory" dictCode="material_category" placeholder="请选择物料类型" />
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="12" >
|
<a-form-model-item label="单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialUnit">
|
<a-input v-model="model.materialUnit" placeholder="请输入单位" ></a-input>
|
</a-form-model-item>
|
</a-col>
|
</a-row>
|
</a-form-model>
|
</j-form-container>
|
<!-- 子表单区域 -->
|
<a-tabs v-model="activeKey" @change="handleChangeTabs">
|
<a-tab-pane tab="物料库存信息" :key="refKeys[0]" :forceRender="true">
|
<j-vxe-table
|
keep-source
|
:ref="refKeys[0]"
|
:loading="lswMaterialInventoryTable.loading"
|
:columns="lswMaterialInventoryTable.columns"
|
:dataSource="lswMaterialInventoryTable.dataSource"
|
:maxHeight="300"
|
:disabled="formDisabled"
|
:rowNumber="true"
|
:rowSelection="true"
|
:toolbar="true"
|
/>
|
</a-tab-pane>
|
</a-tabs>
|
</a-spin>
|
</template>
|
|
<script>
|
|
import { getAction } from '@/api/manage'
|
import { JVxeTableModelMixin } from '@/mixins/JVxeTableModelMixin.js'
|
import { JVXETypes } from '@/components/jeecg/JVxeTable'
|
import { getRefPromise,VALIDATE_FAILED} from '@/components/jeecg/JVxeTable/utils/vxeUtils.js'
|
import { validateDuplicateValue } from '@/utils/util'
|
import JFormContainer from '@/components/jeecg/JFormContainer'
|
|
export default {
|
name: 'LswMaterialForm',
|
mixins: [JVxeTableModelMixin],
|
components: {
|
JFormContainer,
|
},
|
data() {
|
return {
|
warehouseColOptions: [],
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 5 },
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 16 },
|
},
|
model:{
|
},
|
// 新增时子表默认添加几行空数据
|
addDefaultRowNum: 1,
|
refKeys: ['lswMaterialInventory', ],
|
tableKeys:['lswMaterialInventory', ],
|
activeKey: 'lswMaterialInventory',
|
// 物料库存信息
|
lswMaterialInventoryTable: {
|
loading: false,
|
dataSource: [],
|
columns: [
|
{
|
title: '批次号',
|
key: 'batchNumber',
|
type: JVXETypes.input,
|
width:"200px",
|
placeholder: '请输入${title}',
|
defaultValue:'',
|
},
|
{
|
title: '库存类型',
|
key: 'inventoryCategory',
|
type: JVXETypes.select,
|
width:"200px",
|
placeholder: '请选择${title}',
|
defaultValue:'',
|
options:[],
|
dictCode: 'inventoryCategory'
|
},
|
{
|
title: '数量',
|
key: 'quantity',
|
type: JVXETypes.input,
|
width:"200px",
|
placeholder: '请输入${title}',
|
defaultValue:'',
|
},
|
{
|
title: '库存地',
|
key: 'warehouseId',
|
type: JVXETypes.select,
|
width: "200px",
|
options: this.warehouseColOptions,
|
},
|
{
|
title: '库存状态',
|
key: 'inventoryStatus',
|
type: JVXETypes.select,
|
width:"200px",
|
placeholder: '请输入${title}',
|
defaultValue:'',
|
options:[],
|
dictCode: 'inventory_status'
|
},
|
]
|
},
|
validatorRules: {
|
materialNumber: [
|
{ required: true, message: '物料编码是必选项', trigger: 'change' }
|
],
|
materialName: [
|
{ required: true, message: '物料名称是必选项', trigger: 'change' }
|
],
|
materialModel: [
|
{ required: true, message: '物料型号是必选项', trigger: 'change' }
|
],
|
materialCategory: [
|
{ required: true, message: '物料类型是必选项', trigger: 'change' }
|
],
|
materialUnit: [
|
{ required: true, message: '单位是必选项', trigger: 'change' }
|
],
|
},
|
url: {
|
add: "/lswmaterial/lswMaterial/add",
|
edit: "/lswmaterial/lswMaterial/edit",
|
queryById: "/lswmaterial/lswMaterial/queryById",
|
warehouseList:"/base/lineSideWarehouse/list",
|
lswMaterialInventory: {
|
list: '/lswmaterial/lswMaterial/queryLswMaterialInventoryByMainId'
|
},
|
}
|
}
|
},
|
props: {
|
//表单禁用
|
disabled: {
|
type: Boolean,
|
default: false,
|
required: false
|
}
|
},
|
computed: {
|
formDisabled(){
|
return this.disabled
|
},
|
},
|
created () {
|
this.loadWarehouseOptions();
|
},
|
methods: {
|
async loadWarehouseOptions() {
|
try {
|
const res = await getAction(this.url.warehouseList);
|
console.log("仓库API响应:", res);
|
let data = [];
|
data = res.result.records;
|
console.log("处理后的仓库数据:", data);
|
const options = data.map(item => ({
|
text: item.warehouseName || `仓库(${item.id})`, // 显示文本
|
value: item.id // 实际值
|
}));
|
console.log("格式化后的选项:", options);
|
const warehouseCol = this.lswMaterialInventoryTable.columns.find(
|
col => col.key === 'warehouseId'
|
);
|
if (warehouseCol) {
|
this.$set(warehouseCol, 'options', options);
|
this.warehouseColOptions = warehouseCol.options
|
console.log("更新后的列选项:", warehouseCol.options);
|
}
|
this.$nextTick(() => {
|
this.$forceUpdate();
|
console.log("已强制更新视图");
|
});
|
} catch (error) {
|
console.error('加载仓库列表失败:', error);
|
}
|
},
|
addBefore(){
|
this.lswMaterialInventoryTable.dataSource=[]
|
},
|
getAllTable() {
|
let values = this.tableKeys.map(key => getRefPromise(this, key))
|
return Promise.all(values)
|
},
|
/** 调用完edit()方法之后会自动调用此方法 */
|
editAfter() {
|
this.$nextTick(() => {
|
})
|
// 加载子表数据
|
if (this.model.id) {
|
let params = { id: this.model.id }
|
this.requestSubTableData(this.url.lswMaterialInventory.list, params, this.lswMaterialInventoryTable)
|
}
|
},
|
//校验所有一对一子表表单
|
validateSubForm(allValues){
|
return new Promise((resolve,reject)=>{
|
Promise.all([
|
]).then(() => {
|
resolve(allValues)
|
}).catch(e => {
|
if (e.error === VALIDATE_FAILED) {
|
// 如果有未通过表单验证的子表,就自动跳转到它所在的tab
|
this.activeKey = e.index == null ? this.activeKey : this.refKeys[e.index]
|
} else {
|
console.error(e)
|
}
|
})
|
})
|
},
|
/** 整理成formData */
|
classifyIntoFormData(allValues) {
|
let main = Object.assign(this.model, allValues.formValue)
|
return {
|
...main, // 展开
|
lswMaterialInventoryList: allValues.tablesValue[0].tableData,
|
}
|
},
|
validateError(msg){
|
this.$message.error(msg)
|
},
|
|
}
|
}
|
</script>
|
|
<style scoped>
|
</style>
|