update ---

This commit is contained in:
lb 2023-04-03 10:58:58 +08:00
parent 8ef8d32e19
commit 13753f0c6c
2 changed files with 21 additions and 6 deletions

View File

@ -142,6 +142,7 @@ export default {
const savedDatalist = {};
const cachedList = {};
const watchList = [];
const promiseChain = {};
this.configs.form.rows.forEach((row) => {
row.forEach((col) => {
@ -152,8 +153,8 @@ export default {
savedDatalist[col.prop] = [];
}
if (col.fetchData && typeof col.fetchData === "function") {
col.fetchData().then(({ data: res }) => {
if (col.fetchData && typeof col.fetchData === "function" && !col.fetchDataWait) {
const ps = col.fetchData().then(({ data: res }) => {
if (res.code === 0) {
if ("list" in res.data) {
if ("injectTo" in col) {
@ -196,6 +197,8 @@ export default {
}
// dataForm[col.prop] = col.default ?? null; // not perfect!
});
promiseChain[col.prop] = ps;
} else if (col.fetchTreeData && typeof col.fetchTreeData === "function") {
// parentId 0
col.fetchTreeData().then(({ data: res }) => {
@ -220,6 +223,7 @@ export default {
savedDatalist,
cachedList,
watchList,
promiseChain,
detailMode: false,
baseDialogConfig: null,
defaultQuillConfig: {
@ -278,8 +282,14 @@ export default {
if ("toggleFetchData" in col) {
const unwatch = this.$watch(
() => this.dataForm[col.toggleFetchData],
(carId) => {
col.fetchData(carId).then(({ data: res }) => {
(val) => {
const { search, get } = col.fetchDataParam; // toggleFetchData
const chosenObject = this.cachedList[col.toggleFetchData]?.find((i) => i[search] === val);
const paramValue = chosenObject ? chosenObject[get] : "";
console.log("((( chosenObject )))", chosenObject);
col.fetchData(paramValue).then(({ data: res }) => {
console.log("((( col.fetchData )))", paramValue, data);
if (res.code === 0) {
if ("list" in res.data) {
if ("injectTo" in col) this.$set(this.cachedList, col.prop, res.data.list);

View File

@ -102,9 +102,10 @@ export default function () {
options: [],
optionLabel: 'code',
optionValue: 'carId',
needCache: true,
fetchData: () => this.$http.post("/pms/carHandle/pageView", { page: 1, limit: 999 }),
rules: { required: true, message: "必填项不能为空", trigger: "blur" },
elparams: { placeholder: "请输入批次编码", filterable: true },
elparams: { placeholder: "请输入窑车号", filterable: true },
injectTo: [
['posCode', 'posCode'], // TODO
['carState', 'stateDictValue']
@ -150,7 +151,11 @@ export default function () {
options: [],
optionLabel: 'orderCode',
toggleFetchData: 'carId', // 当 carId 改变的时候,也会 fetchData
fetchData: (carId) => this.$http.post("/pms/carHandle/getCurrent", { id: carId ?? null, page: 1, limit: 999 }),
// 需要保存当前状态
needCache: true,
fetchDataParam: { search: 'carId', get: 'id' }, // 伴随着 toggleFetchData 出现
fetchData: (hisId) => this.$http.get(`/pms/carHandle/${hisId}`),
fetchDataWait: true,
rules: { required: true, message: "必选项不能为空", trigger: "blur" },
elparams: { placeholder: "请选择订单" },
injectTo: [