update DialogWithMenu在编辑时的初始化逻辑“

This commit is contained in:
lb 2023-02-24 14:13:47 +08:00
parent 3f405a3816
commit b0286bcc08
2 changed files with 81 additions and 41 deletions

View File

@ -422,6 +422,41 @@ export default {
); );
}, },
updateOptions() {
return new Promise((resolve, reject) => {
if (!this.dataForm?.id) resolve(null);
if (this.watingToRefreshQueue.length) {
this.watingToRefreshQueue.forEach((opt) => {
console.log("[刷新数据, ", opt, "]");
if ("fetchData" in opt) {
opt.fetchData(this.dataForm.id).then(({ data: res }) => {
if (res.code === 0) {
this.$set(
opt,
"options",
"list" in res.data
? res.data.list.map((i) => ({ label: i.name, value: i.id }))
: res.data.map((i) => ({ label: i.name, value: i.id }))
);
resolve({ done: true });
} else {
this.$message({
message: `${res.code}: ${res.msg}`,
type: "error",
duration: 1500,
});
resolve({ done: false });
}
});
}
});
} else resolve(null);
});
},
/** init **/ /** init **/
init(id, detailMode, menu) { init(id, detailMode, menu) {
// this.dialogVisible = true; // this.dialogVisible = true;
@ -440,6 +475,8 @@ export default {
// //
this.getSubList(); this.getSubList();
// //
this.updateOptions().then((result) => {
if (result === null || (typeof result === "object" && result.done)) {
this.$http.get(this.urls.base + `/${this.dataForm.id}`).then(({ data: res }) => { this.$http.get(this.urls.base + `/${this.dataForm.id}`).then(({ data: res }) => {
if (res && res.code === 0) { if (res && res.code === 0) {
const dataFormKeys = Object.keys(this.dataForm); const dataFormKeys = Object.keys(this.dataForm);
@ -463,6 +500,8 @@ export default {
this.activeMenu = this.configs.menu.find((item) => item.key === menu.key)?.name; this.activeMenu = this.configs.menu.find((item) => item.key === menu.key)?.name;
} }
}); });
}
});
} else { } else {
// //
// this.dialogVisible = true; // this.dialogVisible = true;
@ -682,25 +721,25 @@ export default {
this.loadingStatus = false; this.loadingStatus = false;
// watingToRefreshQueue // watingToRefreshQueue
if (this.watingToRefreshQueue.length) { // if (this.watingToRefreshQueue.length) {
// // //
this.watingToRefreshQueue.forEach((opt) => { // this.watingToRefreshQueue.forEach((opt) => {
console.log('[刷新数据, ', opt, ']') // console.log("[, ", opt, "]");
if ("fetchData" in opt) { // if ("fetchData" in opt) {
opt.fetchData().then(({ data: res }) => { // opt.fetchData().then(({ data: res }) => {
if (res.code === 0) { // if (res.code === 0) {
this.$set( // this.$set(
opt, // opt,
"options", // "options",
"list" in res.data // "list" in res.data
? res.data.list.map((i) => ({ label: i.name, value: i.id })) // ? res.data.list.map((i) => ({ label: i.name, value: i.id }))
: res.data.map((i) => ({ label: i.name, value: i.id })) // : res.data.map((i) => ({ label: i.name, value: i.id }))
); // );
} // }
}); // });
} // }
}); // });
} // }
this.handleClose(); this.handleClose();
} else { } else {

View File

@ -101,7 +101,8 @@ export default function () {
options: [], options: [],
refreshOptionsAfterConfirm: true, refreshOptionsAfterConfirm: true,
elparams: { clearable: true, filterable: true, placeholder: "请选择砖型" }, elparams: { clearable: true, filterable: true, placeholder: "请选择砖型" },
fetchData: () => this.$http.get("/pms/shape/listUnR", { params: { wsId: 2, externalCode: '', key: '' } }), // 下面参数的 techId 是为 /pms/xxx/listUnR 接口定制的,默认为 -1新增时使用编辑时传对应的 工艺id
fetchData: (techId = -1) => this.$http.get("/pms/shape/listUnR", { params: { wsId: 4, externalCode: '', key: '', techId } }),
}, },
], ],
// { // {