This commit is contained in:
lb 2023-03-24 16:59:28 +08:00
parent 4f6d27692e
commit 4a6f395119
2 changed files with 37 additions and 2 deletions

View File

@ -21,6 +21,8 @@
<!-- 通过多个 col === null 可以控制更灵活的 span 大小 -->
<el-form-item v-if="col !== null" :label="col.label" :prop="col.prop" :rules="col.rules || null">
<el-input v-if="col.input" v-model="dataForm[col.prop]" clearable :disabled="detailMode" v-bind="col.elparams" />
<el-input v-if="col.forceDisabled && col.eraseOnSubmit" v-model="shadowDataForm[col.prop]" disabled v-bind="col.elparams" />
<el-input v-if="col.forceDisabled && !col.eraseOnSubmit" v-model="dataForm[col.prop]" disabled v-bind="col.elparams" />
<el-cascader
v-if="col.cascader"
v-model="dataForm[col.prop]"
@ -130,10 +132,17 @@ export default {
inject: ["urls"],
data() {
const dataForm = {};
const shadowDataForm = {};
const savedDatalist = {};
this.configs.form.rows.forEach((row) => {
row.forEach((col) => {
if (col.prop) dataForm[col.prop] = col.default ?? null;
if (!col.eraseOnSubmit && col.prop) dataForm[col.prop] = col.default ?? null;
else shadowDataForm[col.prop] = col.default ?? null;
if ("autoUpdateProp" in col) {
savedDatalist[col.prop] = [];
}
if (col.fetchData)
col.fetchData().then(({ data: res }) => {
@ -148,6 +157,10 @@ export default {
value: col.optionValue ? i[col.optionValue] : i.id,
}))
);
if ("autoUpdateProp" in col) {
this.$set(savedDatalist, col.prop, res.data.list);
}
} else if (Array.isArray(res.data)) {
this.$set(
col,
@ -157,6 +170,9 @@ export default {
value: col.optionValue ? i[col.optionValue] : i.id,
}))
);
if ("autoUpdateProp" in col) {
this.$set(savedDatalist, col.prop, res.data);
}
}
// col.options = res.data.list;
} else {
@ -184,6 +200,8 @@ export default {
return {
loadingStatus: false,
dataForm,
shadowDataForm,
savedDatalist,
detailMode: false,
baseDialogConfig: null,
defaultQuillConfig: {
@ -258,6 +276,9 @@ export default {
if (excludeId && key === "id") return;
this.dataForm[key] = null;
});
Object.keys(this.shadowDataForm).forEach((key) => {
this.shadowDataForm[key] = null;
});
console.log("[DialogJustForm resetForm()] clearing form...");
this.$refs.dataForm.clearValidate();
this.$emit("dialog-closed"); //
@ -332,7 +353,12 @@ export default {
/** handlers */
handleSelectChange(col, eventValue) {
// console.log("[dialog] select change: ", col, eventValue);
if ("autoUpdateProp" in col) {
//
// console.log(col.options, eventValue, this.savedDatalist);
const item = this.savedDatalist[col.prop].find(item => item.id === eventValue)
this.shadowDataForm[col.autoUpdateProp] = item.cate ?? null
}
this.$forceUpdate();
},

View File

@ -141,8 +141,17 @@ export default function () {
label: "订单号",
options: [],
fetchData: () => this.$http.post('/pms/order/pageCom', { limit: 999, page: 1, code: '', type: 1 }),
optionLabel: 'code',
rules: { required: true, message: "必填项不能为空", trigger: "blur" },
elparams: { filterable: true, placeholder: "请选择订单" },
autoUpdateProp: 'cate' // 改变时自动更新 cate 字段
},
{
forceDisabled: true,
prop: 'cate',
label: '订单子号',
elparams: {},
eraseOnSubmit: true
},
{
input: true,