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

View File

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