update order--edit

This commit is contained in:
lb 2023-07-28 14:49:51 +08:00
parent 5961000f53
commit 7f7e9d3b85
2 changed files with 341 additions and 270 deletions

View File

@ -37,17 +37,7 @@
ref="order-dialog" ref="order-dialog"
v-if="renderDialog" v-if="renderDialog"
fullscreen fullscreen
:configs="dialogConfig" @destroy="renderDialog = false"
@destroy-dialog="renderDialog = false"
@refreshDataList="getAList(Object.assign({}, listQuery, extraSearchConditions, params))" />
<DialogWithMenu
modal-append-to-body
ref="menu-dialog"
v-if="renderMenuDialog"
fullscreen
:configs="dialogConfig"
@destroy-dialog="renderMenuDialog = false"
@refreshDataList="getAList(Object.assign({}, listQuery, extraSearchConditions, params))" /> @refreshDataList="getAList(Object.assign({}, listQuery, extraSearchConditions, params))" />
<DialogUpload <DialogUpload
@ -69,16 +59,15 @@
import BaseListTable from "./BaseListTable.vue"; import BaseListTable from "./BaseListTable.vue";
import BaseSearchForm from "./BaseSearchForm.vue"; import BaseSearchForm from "./BaseSearchForm.vue";
import DialogJustForm from "./DialogJustForm.vue"; import DialogJustForm from "./DialogJustForm.vue";
import DialogWithMenu from "./DialogWithMenu.vue";
import DialogUpload from "@/components/DialogUpload.vue"; import DialogUpload from "@/components/DialogUpload.vue";
import moment from "moment"; import moment from "moment";
import Overlay from "@/components/Overlay.vue"; import Overlay from "@/components/Overlay.vue";
import OrderEditDialog from './order--edit.vue' import OrderEditDialog from "./order--edit.vue";
// const dictList = JSON.parse(localStorage.getItem("dictList")); // const dictList = JSON.parse(localStorage.getItem("dictList"));
export default { export default {
name: "ListSectionWithHead", name: "ListSectionWithHead",
components: { OrderEditDialog, BaseSearchForm, BaseListTable, DialogWithMenu, DialogJustForm, DialogUpload, Overlay }, components: { OrderEditDialog, BaseSearchForm, BaseListTable, DialogJustForm, DialogUpload, Overlay },
props: { props: {
headConfig: { headConfig: {
type: Object, type: Object,
@ -94,10 +83,6 @@ export default {
column: null, column: null,
}), }),
}, },
dialogConfig: {
type: Object,
default: null,
},
pageUrl: { pageUrl: {
type: String, type: String,
default: "#", default: "#",
@ -112,11 +97,6 @@ export default {
required: true, required: true,
}, },
}, },
computed: {
dialogType() {
return this.dialogConfigs.menu ? DIALOG_WITH_MENU : DIALOG_JUST_FORM;
},
},
watch: { watch: {
refreshKey(newVal) { refreshKey(newVal) {
// //

View File

@ -4,23 +4,23 @@
:fullscreen="fullscreen" :fullscreen="fullscreen"
:visible="visible" :visible="visible"
@close="handleClose" @close="handleClose"
:destroy-on-close="false" @closed="$emit('destroy')"
:close-on-click-modal="false"> :close-on-click-modal="false"
<!-- title --> v-loading="optionsLoading || formLoading">
<div slot="title" class="dialog-title"> <div slot="title" class="dialog-title">
<h2 class=""> <h2 class="">
{{ detailMode ? "查看详情" : dataForm.id ? "修改订单" : "新增订单" }} {{ mode.includes("detail") ? "查看详情" : dataForm.id ? "修改订单" : "新增订单" }}
</h2> </h2>
</div> </div>
<!-- form --> <!-- form -->
<el-form ref="dataForm" :model="dataForm" v-loading="formLoading" size="small"> <el-form ref="dataForm" :model="dataForm" size="small">
<InputsArea title="生产订单"> <InputsArea title="生产订单">
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :span="6"> <el-col :span="6">
<el-form-item label="订单状态" prop="statusDictValue" :rules="null"> <el-form-item label="订单状态" prop="statusDictValue" :rules="null">
<span style="display: block; margin-top: 0">{{ dataForm.statusDictValue }}</span> <span style="display: block; margin-top: 32px">{{ dataForm.statusDictValue }}</span>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="6"> <el-col :span="6">
@ -41,7 +41,7 @@
type: 'number', type: 'number',
message: '输入正确的数字类型', message: '输入正确的数字类型',
trigger: 'blur', trigger: 'blur',
transform: '<<(val) => Number(val)>>', transform: (val) => Number(val),
}, },
]"> ]">
<el-input v-model="dataForm.cate" v-bind="{ placeholder: '输入订单子号' }"></el-input> <el-input v-model="dataForm.cate" v-bind="{ placeholder: '输入订单子号' }"></el-input>
@ -76,9 +76,15 @@
filterable filterable
clearable clearable
v-bind="{ placeholder: '选择压机', filterable: true }"> v-bind="{ placeholder: '选择压机', filterable: true }">
<el-option v-for="opt in options" :key="opt.label" :label="opt.label" :value="opt.value"> <el-option
v-for="opt in pressOptions"
:key="opt.label + opt.value"
:label="opt.label"
:value="opt.value">
<span>{{ opt.label }}</span> <span>{{ opt.label }}</span>
<span v-if="col.extraLabel" style="display: inline-block; margin-left: 12px; font-size: 0.9em"> <span
v-if="requestList[0].extraLabel"
style="display: inline-block; margin-left: 12px; font-size: 0.9em">
{{ opt.code }} {{ opt.code }}
</span> </span>
</el-option> </el-option>
@ -95,9 +101,15 @@
filterable filterable
clearable clearable
v-bind="{ placeholder: '选择混料机', filterable: true }"> v-bind="{ placeholder: '选择混料机', filterable: true }">
<el-option v-for="opt in options" :key="opt.label" :label="opt.label" :value="opt.value"> <el-option
v-for="opt in blenderOptions"
:key="opt.label + opt.value"
:label="opt.label"
:value="opt.value">
<span>{{ opt.label }}</span> <span>{{ opt.label }}</span>
<span v-if="col.extraLabel" style="display: inline-block; margin-left: 12px; font-size: 0.9em"> <span
v-if="requestList[1].extraLabel"
style="display: inline-block; margin-left: 12px; font-size: 0.9em">
{{ opt.code }} {{ opt.code }}
</span> </span>
</el-option> </el-option>
@ -111,9 +123,15 @@
filterable filterable
clearable clearable
v-bind="{ placeholder: '选择隧道窑', filterable: true }"> v-bind="{ placeholder: '选择隧道窑', filterable: true }">
<el-option v-for="opt in options" :key="opt.label" :label="opt.label" :value="opt.value"> <el-option
v-for="opt in kilnOptions"
:key="opt.label + opt.value"
:label="opt.label"
:value="opt.value">
<span>{{ opt.label }}</span> <span>{{ opt.label }}</span>
<span v-if="col.extraLabel" style="display: inline-block; margin-left: 12px; font-size: 0.9em"> <span
v-if="requestList[2].extraLabel"
style="display: inline-block; margin-left: 12px; font-size: 0.9em">
{{ opt.code }} {{ opt.code }}
</span> </span>
</el-option> </el-option>
@ -128,29 +146,51 @@
</el-row> </el-row>
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :span="6"> <el-col :span="6">
<el-form-item label="号" prop="bomId" :rules="null"> <el-form-item label="配方号" prop="bomId" :rules="null">
<el-select <el-select
v-model="dataForm.bomId" v-model="dataForm.bomId"
filterable filterable
clearable clearable
v-bind="{ placeholder: '选择牌号', filterable: true }"> @change="handleBomChange"
<el-option v-for="opt in options" :key="opt.label" :label="opt.label" :value="opt.value"> v-bind="{ placeholder: '选择配方号', filterable: true }">
<span>{{ opt.label }}</span> <el-option
<span v-if="col.extraLabel" style="display: inline-block; margin-left: 12px; font-size: 0.9em"> v-for="opt in bomOptions"
{{ opt.undefined }} :key="opt.label + opt.value"
:label="opt.label"
:value="opt.value"
style="display: flex; align-items: center">
<span style="display: inline-block; width: 128px; text-overflow: ellipsis">{{ opt.label }}</span>
<span
v-if="requestList[3].extraLabel"
style="display: inline-block; margin-left: 12px; font-size: 0.9em">
{{ opt.name }}
</span> </span>
</el-option> </el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="6"> <el-col :span="6">
<el-form-item label="配方号" prop="bomCode" :rules="null"> <el-form-item label="牌号" prop="brand" :rules="null">
<span style="display: block; margin-top: 0">{{ dataForm.bomCode }}</span> <span style="display: block; margin-top: 32px">{{ dataForm.brand }}</span>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="6"> <el-col :span="6">
<el-form-item label="版本号" prop="ai" :rules="null"> <el-form-item label="版本号" prop="ai" :rules="null">
<span style="display: block; margin-top: 0">{{ dataForm.ai }}</span> <!-- <span style="display: block; margin-top: 32px">{{ dataForm.ai }}</span> -->
<el-select
v-model="dataForm.ai"
filterable
clearable
v-bind="{ placeholder: '请选择版本' }"
@change="handleVersionChange">
<el-option
v-for="opt in versionList"
:key="opt.label + opt.value"
:label="opt.label"
:value="opt.value">
<span>{{ opt.label }}</span>
</el-option>
</el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="6"> <el-col :span="6">
@ -160,9 +200,15 @@
filterable filterable
clearable clearable
v-bind="{ placeholder: '选择包装代码', filterable: true }"> v-bind="{ placeholder: '选择包装代码', filterable: true }">
<el-option v-for="opt in options" :key="opt.label" :label="opt.label" :value="opt.value"> <el-option
v-for="opt in packOptions"
:key="opt.label + opt.value"
:label="opt.label"
:value="opt.value">
<span>{{ opt.label }}</span> <span>{{ opt.label }}</span>
<span v-if="col.extraLabel" style="display: inline-block; margin-left: 12px; font-size: 0.9em"> <span
v-if="requestList[4].extraLabel"
style="display: inline-block; margin-left: 12px; font-size: 0.9em">
{{ opt.code }} {{ opt.code }}
</span> </span>
</el-option> </el-option>
@ -178,9 +224,15 @@
filterable filterable
clearable clearable
v-bind="{ placeholder: '选择物料', filterable: true }"> v-bind="{ placeholder: '选择物料', filterable: true }">
<el-option v-for="opt in options" :key="opt.label" :label="opt.label" :value="opt.value"> <el-option
v-for="opt in productOptions"
:key="opt.label + opt.value"
:label="opt.label"
:value="opt.value">
<span>{{ opt.label }}</span> <span>{{ opt.label }}</span>
<span v-if="col.extraLabel" style="display: inline-block; margin-left: 12px; font-size: 0.9em"> <span
v-if="requestList[5].extraLabel"
style="display: inline-block; margin-left: 12px; font-size: 0.9em">
{{ opt.code }} {{ opt.code }}
</span> </span>
</el-option> </el-option>
@ -194,9 +246,15 @@
filterable filterable
clearable clearable
v-bind="{ placeholder: '选择砖型', filterable: true }"> v-bind="{ placeholder: '选择砖型', filterable: true }">
<el-option v-for="opt in options" :key="opt.label" :label="opt.label" :value="opt.value"> <el-option
v-for="opt in shapeOptions"
:key="opt.label + opt.value"
:label="opt.label"
:value="opt.value">
<span>{{ opt.label }}</span> <span>{{ opt.label }}</span>
<span v-if="col.extraLabel" style="display: inline-block; margin-left: 12px; font-size: 0.9em"> <span
v-if="requestList[6].extraLabel"
style="display: inline-block; margin-left: 12px; font-size: 0.9em">
{{ opt.code }} {{ opt.code }}
</span> </span>
</el-option> </el-option>
@ -213,7 +271,7 @@
type: 'number', type: 'number',
message: '输入正确的数字类型', message: '输入正确的数字类型',
trigger: 'blur', trigger: 'blur',
transform: '<<(val) => Number(val)>>', transform: (val) => Number(val),
}, },
]"> ]">
<el-input v-model="dataForm.sapParam6" v-bind="{ placeholder: '输入烧成温度' }"></el-input> <el-input v-model="dataForm.sapParam6" v-bind="{ placeholder: '输入烧成温度' }"></el-input>
@ -229,7 +287,7 @@
type: 'number', type: 'number',
message: '输入正确的数字类型', message: '输入正确的数字类型',
trigger: 'blur', trigger: 'blur',
transform: '<<(val) => Number(val)>>', transform: (val) => Number(val),
}, },
]"> ]">
<el-input v-model="dataForm.sapParam7" v-bind="{ placeholder: '输入烧成时间' }"></el-input> <el-input v-model="dataForm.sapParam7" v-bind="{ placeholder: '输入烧成时间' }"></el-input>
@ -255,7 +313,7 @@
type: 'number', type: 'number',
message: '输入正确的数字类型', message: '输入正确的数字类型',
trigger: 'blur', trigger: 'blur',
transform: '<<(val) => Number(val)>>', transform: (val) => Number(val),
}, },
]"> ]">
<el-input v-model="dataForm.prodqty" v-bind="{ placeholder: '输入要求生产的数量' }"></el-input> <el-input v-model="dataForm.prodqty" v-bind="{ placeholder: '输入要求生产的数量' }"></el-input>
@ -270,7 +328,7 @@
type: 'number', type: 'number',
message: '输入正确的数字类型', message: '输入正确的数字类型',
trigger: 'blur', trigger: 'blur',
transform: '<<(val) => Number(val)>>', transform: (val) => Number(val),
}, },
]"> ]">
<el-input v-model="dataForm.yieldqty" v-bind="{ placeholder: '输入已经生产的数量' }"></el-input> <el-input v-model="dataForm.yieldqty" v-bind="{ placeholder: '输入已经生产的数量' }"></el-input>
@ -286,7 +344,7 @@
type: 'number', type: 'number',
message: '输入正确的数字类型', message: '输入正确的数字类型',
trigger: 'blur', trigger: 'blur',
transform: '<<(val) => Number(val)>>', transform: (val) => Number(val),
}, },
]"> ]">
<el-input v-model="dataForm.pcsKilnCar" v-bind="{ placeholder: '输入托盘码放砖数' }"></el-input> <el-input v-model="dataForm.pcsKilnCar" v-bind="{ placeholder: '输入托盘码放砖数' }"></el-input>
@ -317,7 +375,7 @@
type: 'number', type: 'number',
message: '输入正确的数字类型', message: '输入正确的数字类型',
trigger: 'blur', trigger: 'blur',
transform: '<<(val) => Number(val)>>', transform: (val) => Number(val),
}, },
]"> ]">
<el-input v-model="dataForm.soqty" v-bind="{ placeholder: '输入销售订单砖数' }"></el-input> <el-input v-model="dataForm.soqty" v-bind="{ placeholder: '输入销售订单砖数' }"></el-input>
@ -339,9 +397,15 @@
prop="customerId" prop="customerId"
:rules="{ required: true, message: '必填项不能为空', trigger: 'blur' }"> :rules="{ required: true, message: '必填项不能为空', trigger: 'blur' }">
<el-select v-model="dataForm.customerId" filterable clearable v-bind="{ placeholder: '选择客户' }"> <el-select v-model="dataForm.customerId" filterable clearable v-bind="{ placeholder: '选择客户' }">
<el-option v-for="opt in options" :key="opt.label" :label="opt.label" :value="opt.value"> <el-option
v-for="opt in clientOptions"
:key="opt.label + opt.value"
:label="opt.label"
:value="opt.value">
<span>{{ opt.label }}</span> <span>{{ opt.label }}</span>
<span v-if="col.extraLabel" style="display: inline-block; margin-left: 12px; font-size: 0.9em"> <span
v-if="requestList[7].extraLabel"
style="display: inline-block; margin-left: 12px; font-size: 0.9em">
{{ opt.name }} {{ opt.name }}
</span> </span>
</el-option> </el-option>
@ -350,7 +414,7 @@
</el-col> </el-col>
<el-col :span="6"> <el-col :span="6">
<el-form-item label="物料号销售文本" prop="shortDesc" :rules="null"> <el-form-item label="物料号销售文本" prop="shortDesc" :rules="null">
<span style="display: block; margin-top: 0">{{ dataForm.shortDesc }}</span> <span style="display: block; margin-top: 32px">{{ dataForm.shortDesc }}</span>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="6"></el-col> <el-col :span="6"></el-col>
@ -368,23 +432,17 @@
<!-- footer --> <!-- footer -->
<div slot="footer"> <div slot="footer">
<!-- <template v-for="(operate, index) in configs.form.operations"> <!-- TODO: permission 相关内容 未添加 -->
<el-button <el-button v-if="mode.includes('create')" type="primary" @click="handleSave">保存</el-button>
v-if="showButton(operate)" <el-button v-if="mode.includes('edit')" type="primary" @click="handleUpdate">更新</el-button>
:key="'operation_' + index" <el-button v-if="mode.includes('reset')" type="warning" @click="handleReset">重置</el-button>
:type="operate.type" <el-button @click="handleClose">取消</el-button>
@click="handleBtnClick(operate)">
{{ operate.label }}
</el-button>
</template> -->
<el-button @click="handleBtnClick({ name: 'cancel' })">取消</el-button>
</div> </div>
</el-dialog> </el-dialog>
</template> </template>
<script> <script>
import { pick as __pick } from "@/utils/filters"; import { pick as __pick } from "@/utils/filters";
import Cookies from "js-cookie";
import moment from "moment"; import moment from "moment";
import InputsArea from "./InputsArea.vue"; import InputsArea from "./InputsArea.vue";
@ -392,13 +450,6 @@ export default {
name: "DialogJustForm", name: "DialogJustForm",
components: { InputsArea }, components: { InputsArea },
props: { props: {
configs: {
type: Object,
default: () => ({
clickModalToClose: false,
forms: null,
}),
},
fullscreen: { fullscreen: {
type: Boolean, type: Boolean,
default: false, default: false,
@ -406,172 +457,257 @@ export default {
}, },
inject: ["urls"], inject: ["urls"],
data() { data() {
const dataForm = {};
const watchList = [];
const cachedList = {};
this.configs.form.field.forEach((field) => {
field.rows.forEach((row) => {
row.forEach((col) => {
if (!col.prop) return;
dataForm[col.prop] = col.default ?? null;
if (col.fetchData)
col.fetchData().then(({ data: res }) => {
if (res.code === 0) {
if (typeof res.data === "object" && "list" in res.data) {
if ("injectTo" in col) {
//
cachedList[col.prop] = res.data.list;
}
this.$set(
col,
"options",
res.data.list.map((i) => ({
label: col.optionLabel ? i[col.optionLabel] : i.name,
value: col.optionValue ? i[col.optionValue] : i.id,
}))
);
} else if (Array.isArray(res.data)) {
this.$set(
col,
"options",
res.data.map((i) => ({
label: col.optionLabel ? i[col.optionLabel] : i.name,
value: col.optionValue ? i[col.optionValue] : i.id,
}))
);
}
} else {
// error
col.options.splice(0);
}
});
else if (col.fetchTreeData) {
// parentId 0
col.fetchTreeData().then(({ data: res }) => {
// console.log("[DialogJustForm fetchTreeData -->]", res.data);
if (res.code === 0 && res.data) {
if ("list" in res.data) {
this.$set(col, "options", res.data.list);
} else if (Array.isArray(res.data)) {
this.$set(col, "options", res.data);
}
} else {
col.options.splice(0);
}
});
}
});
});
});
return { return {
mode: "#edit#reset",
formLoading: false, formLoading: false,
dataForm, optionsLoading: false,
watchList, pressOptions: [], //
cachedList, blenderOptions: [], //
detailMode: false, kilnOptions: [], //
baseDialogConfig: null, bomOptions: [], //
visible: false, packOptions: [], //
}; productOptions: [], //
shapeOptions: [], //
clientOptions: [], //
versionList: [], //
cachedList: {}, //
dataForm: {
statusDictValue: null,
code: null,
cate: null,
planStartTime: null,
press: null,
blender: null,
kiln: null,
sapParam1: null,
bomId: null,
brand: null, //
ai: null, //
packTech: null,
productId: null,
shape: null,
sapParam6: null,
sapParam7: null,
specifications: null,
prodqty: null,
yieldqty: null,
pcsKilnCar: null,
saleNo: null,
saleOrderItem: null,
soqty: null,
deliveryTime: null,
customerId: null,
shortDesc: null,
remark: null,
}, },
mounted() { visible: false,
/** 处理 injectTo 选项 */ requestList: [
this.configs.form.field.forEach((field) => { {
field.rows.forEach((row) => { url: "/pms/equipment/search",
row.forEach((col) => { params: {
if (!col.prop) return; equipmentTypeCode: "Press",
if ("injectTo" in col && Array.isArray(col.injectTo)) { },
// console.log("watching options ..... ", col); method: "get",
col.injectTo.map((item) => { target: "pressOptions",
const unwatch = this.$watch( label: "code",
() => this.dataForm[col.prop],
(newVal) => {
const chosenObject = this.cachedList[col.prop].find((i) => i.id === newVal);
if (chosenObject) {
//
this.$set(this.dataForm, item[0], chosenObject[item[1]]);
}
}, },
{ {
immediate: false, url: "/pms/equipment/search",
} params: {
); equipmentTypeCode: "Mix",
this.watchList.push(unwatch);
});
}
});
});
});
}, },
computed: { method: "get",
uploadHeaders() { target: "blenderOptions",
return { label: "code",
token: Cookies.get("token") || "", },
{
url: "/pms/equipment/search",
params: {
equipmentTypeCode: "Kiln",
},
method: "get",
target: "kilnOptions",
label: "code",
},
{
url: "/pms/bom/page",
params: {
limit: 999,
page: 1,
key: "",
externalCode: "",
},
method: "get",
target: "bomOptions",
label: "code",
extraLabel: "name",
cache: true,
},
{
url: "/pms/equipmentTech/pageView",
params: {
limit: 999,
page: 1,
key: "",
shape: "",
wsId: 5,
},
method: "post",
target: "packOptions",
label: "code",
},
{
url: "/pms/product/page",
params: {
limit: 999,
page: 1,
key: "",
},
method: "get",
target: "productOptions",
label: "code",
},
{
url: "/pms/shape/page",
params: {
limit: 999,
page: 1,
key: "",
},
method: "get",
target: "shapeOptions",
label: "code",
},
{
url: "/pms/customer/page",
params: {
limit: 999,
page: 1,
name: "",
},
method: "get",
target: "clientOptions",
label: "name",
},
],
promiseList: [],
bomId: null,
}; };
}, },
},
methods: { methods: {
handleFilelistUpdate(newFilelist) { /**
// TODO: 访 .files * 打开弹窗后准备下拉选项数据
this.dataForm.files = newFilelist.map((file) => ({ * 复用方式
id: file.id, * 1. data 里定义 requestList
name: file.name, * 2. 复制本方法到组件中去
url: file.url, * 3. requestList 参考上面的 data
typeCode: file.typeCode, */
})); async prepareSelectOptions() {
// this.optionsLoading = true;
if ("id" in this.dataForm && this.dataForm.id !== null && this.dataForm.id !== undefined) this.addOrUpdate("PUT");
else
this.$notify({
title: "等待保存",
message: "已添加文件,请手动点击保存!",
type: "warning",
duration: 2500,
});
},
/** utitilities */ this.requestList.forEach((req) => {
showButton(operate) { this.promiseList.push(async () => {
const notDetailMode = !this.detailMode; const { data: res } = await this.$http[req.method](
const showAlways = operate.showAlways ?? false; req.url,
const editMode = operate.showOnEdit && this.dataForm.id; req.method.toLowerCase() == "post" ? req.params : { params: req.params }
const addMode = !operate.showOnEdit && !this.dataForm.id;
const permission = operate.permission ? this.$hasPermission(operate.permission) : true;
return notDetailMode && (showAlways || ((editMode || addMode) && permission));
},
resetForm(excludeId = false, immediate = false) {
setTimeout(
() => {
Object.keys(this.dataForm).forEach((key) => {
if (excludeId && key === "id") return;
this.dataForm[key] = null;
});
// console.log("[DialogJustForm resetForm()] clearing form...");
this.$refs.dataForm.clearValidate();
this.$emit("dialog-closed"); //
this.watchList.map((unwatch) => unwatch());
this.cachedList = {};
},
immediate ? 0 : 200
); );
if (res.code == 0) {
if ("list" in res.data) {
// target
if (req.cache) this.cachedList[req.target.replace(/options/i, "")] = res.data.list;
this[req.target] = res.data.list.map((item) =>
req.extraLabel
? {
[req.extraLabel]: item[req.extraLabel],
label: item[req.label],
value: item.id,
}
: {
label: item[req.label],
value: item.id,
}
);
} else if (Array.isArray(res.data)) {
if (req.cache) this.cachedList[req.target.replace(/options/i, "")] = res.data;
this[req.target] = res.data.map((item) =>
req.extraLabel
? {
[req.extraLabel]: item[req.extraLabel],
label: item[req.label],
value: item.id,
}
: {
label: item[req.label],
value: item.id,
}
);
}
}
});
});
try {
await Promise.all(this.promiseList.map((fn) => fn()));
} catch (err) {
this.$message.error("获取数据失败,请刷新页面重试");
this.optionsLoading = false;
}
this.optionsLoading = false;
}, },
/** init **/ /**
init(id, detailMode) { * 向这种select上的监听事件
* 不自动生成
* 因为每个页面也许有独立的需求链
*/
handleBomChange(bomID) {
console.log("[handleBomChange] val is: ", bomID);
const target = this.cachedList.bom.find((item) => item.id === bomID);
// bomId dataForm
this.bomId = bomID;
this.getBomVersionList(target);
this.$set(this.dataForm, "brand", target.name);
this.$set(this.dataForm, "ai", target.version);
},
async getBomVersionList(bom) {
try {
const { data: res } = await this.$http.get("/pms/bom/pageVersion", { params: { key: bom.code } });
console.log("[bom version list]", res.data.list);
this.versionList = res.data.list.map((item) => ({
label: item.version,
value: item.version,
id: item.id,
}));
} catch (err) {
this.$message.error("获取数据失败,请刷新页面重试");
}
},
/**
* 版本 变化更新 bomList
* @param {*} v
*/
handleVersionChange(v) {
const targetBom = this.versionList.find((item) => item.value === v);
// this.bomId this.dataForm.bomId
this.bomId = targetBom.id;
},
async init(id) {
this.visible = true; this.visible = true;
return; await this.prepareSelectOptions();
// console.log("[DialogJustForm] init", this.dataForm, id, detailMode);
if (this.$refs.dataForm) { if (this.$refs.dataForm) {
// console.log("[DialogJustForm] clearing form validation..."); // console.log("[DialogJustForm] clearing form validation...");
// dialog dataForm [0] // dialog dataForm [0]
this.$refs.dataForm.clearValidate(); this.$refs.dataForm.clearValidate();
} }
this.detailMode = detailMode ?? false; if (id) this.mode = "#edit#reset";
this.$nextTick(() => { this.$nextTick(() => {
this.dataForm.id = id || null; this.dataForm.id = id || null;
if (this.dataForm.id) { if (this.dataForm.id) {
@ -584,16 +720,6 @@ export default {
.then(({ data: res }) => { .then(({ data: res }) => {
if (res && res.code === 0) { if (res && res.code === 0) {
this.dataForm = __pick(res.data, Object.keys(this.dataForm)); this.dataForm = __pick(res.data, Object.keys(this.dataForm));
/** 格式化文件上传列表 */
if (Array.isArray(this.dataForm.files)) {
this.dataForm.files = this.dataForm.files.map((file) => ({
id: file.id,
name: file.fileUrl.split("/").pop(),
typeCode: file.typeCode,
url: file.fileUrl,
}));
}
// console.log("[DialogJustForm] init():", this.dataForm);
} else { } else {
this.$message({ this.$message({
message: `${res.code}: ${res.msg}`, message: `${res.code}: ${res.msg}`,
@ -620,19 +746,9 @@ export default {
/** handlers */ /** handlers */
handleSelectChange(col, eventValue) { handleSelectChange(col, eventValue) {
// console.log("[dialog] select change: ", col, eventValue);
this.$forceUpdate(); this.$forceUpdate();
}, },
handleSwitchChange(val) {
// console.log("[dialog] switch change: ", val, this.dataForm);
},
handleComponentModelUpdate(propName, { subject, payload: { data } }) {
this.dataForm[propName] = JSON.stringify(data);
// console.log("[DialogJustForm] handleComponentModelUpdate", this.dataForm[propName]);
},
addOrUpdate(method = "POST") { addOrUpdate(method = "POST") {
if ("parentId" in this.dataForm) { if ("parentId" in this.dataForm) {
// console.log("[DialogJustForm parentId]", this.dataForm.parentId); // console.log("[DialogJustForm parentId]", this.dataForm.parentId);
@ -724,39 +840,14 @@ export default {
}); });
}, },
handleBtnClick(payload) { handleSave() {},
// console.log("btn click payload: ", payload);
if ("name" in payload) { handleUpdate() {},
switch (payload.name) {
case "cancel":
this.handleClose();
break;
case "reset":
this.resetForm(true, true); // true means exclude id, immediate execution
break;
case "add":
case "update":
this.addOrUpdate(payload.name === "add" ? "POST" : "PUT");
break;
}
} else {
console.log("[x] 不是这么用的! 缺少name属性");
}
},
handleUploadChange(file, fileList) { handleReset() {},
// console.log("[Upload] handleUploadChange...", file, fileList);
},
handleClose() { handleClose() {
this.visible = false; this.visible = false;
setTimeout(() => {
this.$emit("destroy-dialog");
// this.resetForm();
// this.$emit("update:dialogVisible", false);
}, 200);
}, },
}, },
}; };