update 混料批次
This commit is contained in:
parent
c4187de9a0
commit
87298d1c37
717
src/views/modules/pms/blenderBatch/components/DialogJustForm.vue
Normal file
717
src/views/modules/pms/blenderBatch/components/DialogJustForm.vue
Normal file
@ -0,0 +1,717 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
class="dialog-just-form"
|
||||
:visible="dialogVisible"
|
||||
@close="handleClose"
|
||||
:destroy-on-close="false"
|
||||
:close-on-click-modal="configs.clickModalToClose ?? false"
|
||||
:width="configs.dialogWidth ?? '50%'">
|
||||
<!-- title -->
|
||||
<div slot="title" class="dialog-title">
|
||||
<h1 class="">
|
||||
{{ detailMode ? "查看详情" : dataForm.id ? "编辑" : "新增" }}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<!-- form -->
|
||||
<el-form ref="dataForm" :model="dataForm" v-loading="loadingStatus">
|
||||
<el-row v-for="(row, rowIndex) in configs.form.rows" :key="'row_' + rowIndex" :gutter="20">
|
||||
<el-col v-for="(col, colIndex) in row" :key="colIndex" :span="24 / row.length">
|
||||
<!-- 通过多个 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="IsNotAvaliable(col)"
|
||||
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-button
|
||||
type=""
|
||||
plain
|
||||
v-if="col.button"
|
||||
v-bind="col.elparams"
|
||||
style="width: 100%"
|
||||
@click="handleButtonClick(col)">
|
||||
{{ col.label }}
|
||||
</el-button>
|
||||
<el-cascader
|
||||
v-if="col.cascader"
|
||||
v-model="dataForm[col.prop]"
|
||||
:options="col.options"
|
||||
:disabled="IsNotAvaliable(col)"
|
||||
v-bind="col.elparams"></el-cascader>
|
||||
<el-select
|
||||
v-if="col.forceDisabledSelect"
|
||||
disabled
|
||||
v-model="dataForm[col.prop]"
|
||||
clearable
|
||||
v-bind="col.elparams">
|
||||
<el-option
|
||||
v-for="(opt, optIdx) in col.options"
|
||||
:key="'option_' + optIdx"
|
||||
:label="opt.label"
|
||||
:value="opt.value" />
|
||||
</el-select>
|
||||
<el-select
|
||||
v-if="col.select"
|
||||
v-model="dataForm[col.prop]"
|
||||
clearable
|
||||
:disabled="IsNotAvaliable(col)"
|
||||
v-bind="col.elparams"
|
||||
@change="handleSelectChange(col, $event)">
|
||||
<el-option
|
||||
v-for="(opt, optIdx) in col.options"
|
||||
:key="'option_' + optIdx"
|
||||
:label="opt.label"
|
||||
:value="opt.value">
|
||||
<span>{{ opt.label }}</span>
|
||||
<span v-if="col.customLabel" style="display: inline-clock; margin-left: 12px; font-size: 0.9em">
|
||||
{{ opt[col.customLabel] || "无描述" }}
|
||||
</span>
|
||||
</el-option>
|
||||
</el-select>
|
||||
<el-switch
|
||||
v-if="col.switch"
|
||||
v-model="dataForm[col.prop]"
|
||||
:active-value="col.activeValue ?? 1"
|
||||
:inactive-value="col.activeValue ?? 0"
|
||||
@change="handleSwitchChange"
|
||||
:disabled="detailMode" />
|
||||
<el-input
|
||||
v-if="col.textarea"
|
||||
type="textarea"
|
||||
v-model="dataForm[col.prop]"
|
||||
:disabled="IsNotAvaliable(col)"
|
||||
v-bind="col.elparams" />
|
||||
<el-date-picker
|
||||
v-if="col.datetime"
|
||||
v-model="dataForm[col.prop]"
|
||||
:disabled="IsNotAvaliable(col)"
|
||||
v-bind="col.elparams" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
|
||||
<!-- footer -->
|
||||
<div slot="footer">
|
||||
<template v-for="(operate, index) in configs.form.operations">
|
||||
<el-button
|
||||
v-if="showButton(operate)"
|
||||
:key="'operation_' + index"
|
||||
:type="operate.type"
|
||||
@click="handleBtnClick(operate)">
|
||||
{{ operate.label }}
|
||||
</el-button>
|
||||
</template>
|
||||
<el-button @click="handleBtnClick({ name: 'cancel' })">取消</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { pick as __pick } from "@/utils/filters";
|
||||
import Cookies from "js-cookie";
|
||||
import moment from "moment";
|
||||
export default {
|
||||
name: "DialogJustForm",
|
||||
components: { },
|
||||
props: {
|
||||
configs: {
|
||||
type: Object,
|
||||
default: () => ({
|
||||
clickModalToClose: false,
|
||||
forms: null,
|
||||
}),
|
||||
},
|
||||
dialogVisible: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
// extraParams: {
|
||||
// type: Object,
|
||||
// default: () => ({})
|
||||
// }
|
||||
},
|
||||
inject: ["urls"],
|
||||
data() {
|
||||
const dataForm = {};
|
||||
const shadowDataForm = {};
|
||||
const savedDatalist = {};
|
||||
const cachedList = {};
|
||||
const watchList = [];
|
||||
const resetFields = [];
|
||||
|
||||
this.configs.form.rows.forEach((row) => {
|
||||
row.forEach((col) => {
|
||||
if (col == null) return;
|
||||
if (!col.disableOnEdit && !col.forceDisabled && !col.forceDisabledSelect) {
|
||||
resetFields.push(col.prop);
|
||||
}
|
||||
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 (this.configs.extraFields)
|
||||
this.configs.extraFields.forEach((cnf) => {
|
||||
dataForm[cnf.prop] = cnf.default ?? null;
|
||||
});
|
||||
|
||||
return {
|
||||
resetFields,
|
||||
loadingStatus: false,
|
||||
dataForm,
|
||||
shadowDataForm,
|
||||
savedDatalist,
|
||||
cachedList,
|
||||
watchList,
|
||||
detailMode: false,
|
||||
editMode: false,
|
||||
baseDialogConfig: null,
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
/** 临时保存所有发出的请求 */
|
||||
const promiseHistory = {};
|
||||
|
||||
const getData = (col, param) => {
|
||||
console.log("getData: ", col.prop, "/", param ?? "no param!");
|
||||
// 获取数据 - 不需要等待前置条件时
|
||||
promiseHistory[col.prop] = col.fetchData(param).then(({ data: res }) => {
|
||||
if (res.code === 0) {
|
||||
if ("list" in res.data) {
|
||||
console.log(
|
||||
"SdASD ",
|
||||
res.data.list.map((i) => ({
|
||||
label: col.optionLabel ? i[col.optionLabel] : i.name,
|
||||
value: col.optionValue ? i[col.optionValue] : i.id,
|
||||
[col.customLabel]: i[col.customLabel],
|
||||
}))
|
||||
);
|
||||
// 填充 options
|
||||
this.$set(
|
||||
col,
|
||||
"options",
|
||||
col.customLabel
|
||||
? res.data.list.map((i) => ({
|
||||
label: col.optionLabel ? i[col.optionLabel] : i.name,
|
||||
value: col.optionValue ? i[col.optionValue] : i.id,
|
||||
[col.customLabel]: i[col.customLabel],
|
||||
}))
|
||||
: res.data.list.map((i) => ({
|
||||
label: col.optionLabel ? i[col.optionLabel] : i.name,
|
||||
value: col.optionValue ? i[col.optionValue] : i.id,
|
||||
}))
|
||||
);
|
||||
|
||||
// 是否需要缓存数据列表
|
||||
if ("injectTo" in col || col.cached) {
|
||||
this.cachedList[col.prop] = res.data.list;
|
||||
}
|
||||
|
||||
// 设置监听
|
||||
if ("injectTo" in col) {
|
||||
console.log("set watcher: ", col.prop);
|
||||
|
||||
const valueProp = "optionValue" in col ? col.optionValue : "id";
|
||||
const unwatch = this.$watch(
|
||||
() => this.dataForm[col.prop],
|
||||
(val) => {
|
||||
console.log("do watcher: ", col.prop);
|
||||
if (col.disableWatcherOnEdit && this.editMode) return;
|
||||
if (!val) {
|
||||
col.injectTo.map((item) => {
|
||||
this.$set(this.dataForm, item[0], null);
|
||||
this.$forceUpdate();
|
||||
});
|
||||
return;
|
||||
}
|
||||
const chosenObject = this.cachedList[col.prop].find((i) => i[valueProp] === val);
|
||||
if (chosenObject) {
|
||||
col.injectTo.map((item) => {
|
||||
this.$set(this.dataForm, item[0], chosenObject[item[1]]);
|
||||
this.$forceUpdate();
|
||||
});
|
||||
} else {
|
||||
console.log('[x] if ("injectTo" in col) {');
|
||||
}
|
||||
},
|
||||
{
|
||||
immediate: false,
|
||||
}
|
||||
);
|
||||
this.watchList.push(unwatch);
|
||||
}
|
||||
|
||||
if ("autoUpdateProp" in col) {
|
||||
this.$set(this.savedDatalist, col.prop, res.data.list);
|
||||
}
|
||||
|
||||
// end branch
|
||||
} else if (Array.isArray(res.data)) {
|
||||
// 填充 options
|
||||
this.$set(
|
||||
col,
|
||||
"options",
|
||||
col.customLabel
|
||||
? res.data.map((i) => ({
|
||||
label: col.optionLabel ? i[col.optionLabel] : i.name,
|
||||
value: col.optionValue ? i[col.optionValue] : i.id,
|
||||
[col.customLabel]: i[col.customLabel],
|
||||
}))
|
||||
: res.data.map((i) => ({
|
||||
label: col.optionLabel ? i[col.optionLabel] : i.name,
|
||||
value: col.optionValue ? i[col.optionValue] : i.id,
|
||||
}))
|
||||
);
|
||||
|
||||
// 是否需要缓存数据列表
|
||||
if ("injectTo" in col || col.cached) {
|
||||
this.cachedList[col.prop] = res.data;
|
||||
}
|
||||
|
||||
// 设置监听
|
||||
if ("injectTo" in col && !col.watcher) {
|
||||
console.log("set watcher: ", col.prop);
|
||||
|
||||
const valueProp = "optionValue" in col ? col.optionValue : "id";
|
||||
const unwatch = this.$watch(
|
||||
() => this.dataForm[col.prop],
|
||||
(val) => {
|
||||
if (col.disableWatcherOnEdit && this.editMode) return;
|
||||
console.log("do watcher: ", col.prop);
|
||||
if (!val) {
|
||||
col.injectTo.map((item) => {
|
||||
this.$set(this.dataForm, item[0], null);
|
||||
this.$forceUpdate();
|
||||
});
|
||||
return;
|
||||
}
|
||||
const chosenObject = this.cachedList[col.prop].find((i) => i[valueProp] === val);
|
||||
if (chosenObject) {
|
||||
col.injectTo.map((item) => {
|
||||
this.$set(this.dataForm, item[0], chosenObject[item[1]]);
|
||||
this.$forceUpdate();
|
||||
});
|
||||
} else {
|
||||
console.log('[x] if ("injectTo" in col) {');
|
||||
}
|
||||
},
|
||||
{
|
||||
immediate: false,
|
||||
}
|
||||
);
|
||||
this.$set(col, "watcher", unwatch);
|
||||
this.watchList.push(unwatch);
|
||||
}
|
||||
|
||||
if ("autoUpdateProp" in col) {
|
||||
this.$set(this.savedDatalist, col.prop, res.data);
|
||||
}
|
||||
}
|
||||
// end branch
|
||||
} else {
|
||||
col.options.splice(0);
|
||||
}
|
||||
});
|
||||
|
||||
console.log("after getData: ", promiseHistory);
|
||||
};
|
||||
|
||||
/** 处理函数 */
|
||||
const handleFn = (prevProp, anchorField, anchorValue, targetField, col) => {
|
||||
console.log("[handleFn]: ", prevProp, anchorField, anchorValue, targetField);
|
||||
/** 此时 cachedList 已经确保可用了 */
|
||||
const target = this.cachedList[prevProp].find((i) => i[anchorField] === anchorValue);
|
||||
const param = target ? target[targetField] : "";
|
||||
console.log("((( chosenObject )))", target);
|
||||
|
||||
getData(col, param);
|
||||
};
|
||||
|
||||
this.configs.form.rows.forEach((row) => {
|
||||
row.forEach((col) => {
|
||||
if (col == null) return;
|
||||
if (col.fetchData && typeof col.fetchData === "function" && !col.hasPrev) {
|
||||
getData(col);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/** 必须要遍历两遍 */
|
||||
this.configs.form.rows.forEach((row) => {
|
||||
row.forEach((col) => {
|
||||
if (col == null) return;
|
||||
if (col.fetchData && typeof col.fetchData === "function" && col.hasPrev) {
|
||||
console.log("[hasPrev] set watcher: ", col.hasPrev);
|
||||
|
||||
// 获取数据 - 需要等待前置条件时
|
||||
const unwatch = this.$watch(
|
||||
() => this.dataForm[col.hasPrev],
|
||||
(val) => {
|
||||
console.log("[hasPrev] do watcher: ", col.hasPrev);
|
||||
if (!val) {
|
||||
col.injectTo.map((item) => {
|
||||
this.$set(this.dataForm, item[0], null);
|
||||
this.$forceUpdate();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.editMode) this.$set(this.dataForm, col.prop, null);
|
||||
|
||||
const { search, get } = col.fetchDataParam; // 伴随着 hasPrev 出现的
|
||||
|
||||
if (!this.cachedList[col.hasPrev]) {
|
||||
// 如果 prev 还尚不存在,但此时 promiseHistory 一定存在了
|
||||
promiseHistory[col.hasPrev].then(() => {
|
||||
handleFn(col.hasPrev, search, val, get, col);
|
||||
});
|
||||
} else {
|
||||
handleFn(col.hasPrev, search, val, get, col);
|
||||
}
|
||||
},
|
||||
{
|
||||
immediate: false,
|
||||
}
|
||||
);
|
||||
this.watchList.push(unwatch);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (this.configs.extraFields)
|
||||
this.configs.extraFields.forEach((cnf) => {
|
||||
if (cnf.listenTo) {
|
||||
console.log("set watcher for: ", cnf.prop);
|
||||
const unwatch = this.$watch(
|
||||
() => this.dataForm[cnf.listenTo.prop],
|
||||
(carId) => {
|
||||
console.log("do watcher for: ", cnf.prop);
|
||||
if (!carId) return;
|
||||
if (cnf.disableWatcherOnEdit && this.editMode) return;
|
||||
cnf.listenTo.handler.call(this, this.cachedList[cnf.listenTo.prop], carId);
|
||||
},
|
||||
{
|
||||
immediate: false,
|
||||
}
|
||||
);
|
||||
this.watchList.push(unwatch);
|
||||
}
|
||||
});
|
||||
},
|
||||
computed: {
|
||||
uploadHeaders() {
|
||||
return {
|
||||
token: Cookies.get("token") || "",
|
||||
};
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
IsNotAvaliable(col) {
|
||||
return this.detailMode || (col.disableOnEdit && this.editMode);
|
||||
},
|
||||
|
||||
/** utitilities */
|
||||
showButton(operate) {
|
||||
const notDetailMode = !this.detailMode;
|
||||
const showAlways = operate.showAlways ?? false;
|
||||
const editMode = operate.showOnEdit && this.dataForm.id;
|
||||
const addMode = !operate.showOnEdit && !this.dataForm.id;
|
||||
const permission = operate.permission ? this.$hasPermission(operate.permission) : true;
|
||||
return notDetailMode && (showAlways || ((editMode || addMode) && permission));
|
||||
},
|
||||
|
||||
resetSpecificFields(fields) {
|
||||
Object.keys(this.dataForm).forEach((key) => {
|
||||
// console.log(`${key} ${fields}`, key in fields, fields.indexOf(key))
|
||||
if (fields.indexOf(key) !== -1) {
|
||||
// console.log(`key ${key} in fields`)
|
||||
// this.dataForm[key] = null;
|
||||
this.$set(this.dataForm, key, null);
|
||||
}
|
||||
});
|
||||
console.log("this.dataform", this.dataForm);
|
||||
},
|
||||
|
||||
resetForm(excludeId = false, immediate = false) {
|
||||
setTimeout(
|
||||
() => {
|
||||
Object.keys(this.dataForm).forEach((key) => {
|
||||
if (excludeId && key === "id") return;
|
||||
this.dataForm[key] = null;
|
||||
});
|
||||
Object.keys(this.shadowDataForm).forEach((key) => {
|
||||
this.shadowDataForm[key] = null;
|
||||
});
|
||||
this.$refs.dataForm.clearValidate();
|
||||
this.$emit("dialog-closed"); // 触发父组件销毁自己
|
||||
},
|
||||
immediate ? 0 : 200
|
||||
);
|
||||
},
|
||||
|
||||
/** init **/
|
||||
init(id, detailMode, tagInfo, extraParams) {
|
||||
// console.log("[DialogJustForm] init", this.dataForm, id, detailMode);
|
||||
if (this.$refs.dataForm) {
|
||||
// console.log("[DialogJustForm] clearing form validation...");
|
||||
// 当不是首次渲染dialog的时候,一开始就清空验证信息,本组件的循环里只有一个 dataForm 所以只用取 [0] 即可
|
||||
this.$refs.dataForm.clearValidate();
|
||||
}
|
||||
|
||||
this.detailMode = detailMode ?? false;
|
||||
this.editMode = id ? true : false;
|
||||
|
||||
/** 判断 extraParams */
|
||||
if (extraParams && typeof extraParams === "object") {
|
||||
for (const [key, value] of Object.entries(extraParams)) {
|
||||
// console.log("[dialog] dataForm | key | value", this.dataForm, key, value);
|
||||
this.$set(this.dataForm, key, value);
|
||||
}
|
||||
}
|
||||
|
||||
this.$nextTick(() => {
|
||||
this.dataForm.id = id || null;
|
||||
if (this.dataForm.id) {
|
||||
// 如果是编辑
|
||||
this.loadingStatus = true;
|
||||
|
||||
// 获取基本信息
|
||||
this.$http
|
||||
.get(this.urls.base + `/${this.dataForm.id}`)
|
||||
.then(({ data: res }) => {
|
||||
if (res && res.code === 0) {
|
||||
if (res.data) this.dataForm = __pick(res.data, Object.keys(this.dataForm));
|
||||
else {
|
||||
this.$message({
|
||||
message: "后端返回的数据为 null",
|
||||
type: "error",
|
||||
duration: 2000,
|
||||
});
|
||||
}
|
||||
/** 格式化文件上传列表 */
|
||||
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 {
|
||||
this.$message({
|
||||
message: `${res.code}: ${res.msg}`,
|
||||
type: "error",
|
||||
duration: 1500,
|
||||
});
|
||||
}
|
||||
this.loadingStatus = false;
|
||||
})
|
||||
.catch((err) => {
|
||||
this.loadingStatus = false;
|
||||
this.$message({
|
||||
message: `${err}`,
|
||||
type: "error",
|
||||
duration: 1500,
|
||||
});
|
||||
});
|
||||
} else {
|
||||
this.loadingStatus = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
handleButtonClick(col) {
|
||||
if (!("onClick" in col)) {
|
||||
console.log("[handleButtonClick] 配置文件config.js 里没有绑定 onClick");
|
||||
return;
|
||||
}
|
||||
|
||||
col.onClick.call(this, this.dataForm.id);
|
||||
},
|
||||
|
||||
/** handlers */
|
||||
handleSelectChange(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();
|
||||
},
|
||||
|
||||
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", url) {
|
||||
if ("parentId" in this.dataForm) {
|
||||
console.log("[DialogJustForm parentId]", this.dataForm.parentId);
|
||||
// 对特殊的键做特殊处理,如 parentId 是一个 cascader,获取的值是 ["xxx"],后端只需要xxx
|
||||
const lastItem = this.dataForm.parentId.length - 1;
|
||||
this.dataForm.parentId = this.dataForm.parentId[lastItem];
|
||||
}
|
||||
|
||||
this.$refs.dataForm.validate((passed, result) => {
|
||||
if (passed) {
|
||||
this.loadingStatus = true;
|
||||
|
||||
let httpPayload = null;
|
||||
/** 针对有文件上传选项的弹窗提供特殊的 payload */
|
||||
if (this.dataForm.files) {
|
||||
httpPayload = {
|
||||
...this.dataForm,
|
||||
fileIds: this.dataForm.files.map((file) => file.id),
|
||||
};
|
||||
} else {
|
||||
httpPayload = this.dataForm;
|
||||
}
|
||||
|
||||
/** 针对时间段设置 payload */
|
||||
if ("startTime" in this.dataForm && "endTime" in this.dataForm) {
|
||||
const { startTime, endTime } = this.dataForm;
|
||||
httpPayload = {
|
||||
...httpPayload,
|
||||
startTime: startTime
|
||||
? moment(startTime).format("YYYY-MM-DDTHH:mm:ss")
|
||||
: moment().format("YYYY-MM-DDTHH:mm:ss"),
|
||||
endTime: endTime ? moment(endTime).format("YYYY-MM-DDTHH:mm:ss") : null, // moment().format("YYYY-MM-DDTHH:mm:ss"),
|
||||
};
|
||||
}
|
||||
|
||||
/** 针对时间段设置 payload */
|
||||
if ("updateTime" in this.dataForm) {
|
||||
const { updateTime } = this.dataForm;
|
||||
httpPayload = {
|
||||
...httpPayload,
|
||||
updateTime: updateTime
|
||||
? moment(updateTime).format("YYYY-MM-DDTHH:mm:ss")
|
||||
: moment().format("YYYY-MM-DDTHH:mm:ss"),
|
||||
};
|
||||
}
|
||||
|
||||
/** 发送 */
|
||||
return this.$http({
|
||||
// url: this.urls.formUrl ? this.urls.formUrl : this.urls.base,
|
||||
url: url ?? this.urls.base,
|
||||
method,
|
||||
data: httpPayload,
|
||||
})
|
||||
.then(({ data: res }) => {
|
||||
console.log("[add&update] res is: ", res);
|
||||
this.loadingStatus = false;
|
||||
if (res.code === 0) {
|
||||
this.$message.success(method === "POST" ? "添加成功" : "更新成功");
|
||||
this.$emit("refreshDataList");
|
||||
// if (method === "POST") this.handleClose();
|
||||
this.handleClose();
|
||||
} else {
|
||||
this.$message({
|
||||
message: `${res.code}: ${res.msg}`,
|
||||
type: "error",
|
||||
duration: 2000,
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((errMsg) => {
|
||||
this.$message.error("参数错误:" + errMsg);
|
||||
if (this.loadingStatus) this.loadingStatus = false;
|
||||
});
|
||||
} else {
|
||||
this.$message.error("请核查字段信息");
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
handleBtnClick(payload) {
|
||||
console.log("btn click payload: ", payload);
|
||||
|
||||
if ("name" in payload) {
|
||||
switch (payload.name) {
|
||||
case "cancel":
|
||||
this.handleClose();
|
||||
break;
|
||||
case "reset":
|
||||
this.resetForm(true, true); // true means exclude id, immediate execution
|
||||
break;
|
||||
case "resetSpecific":
|
||||
// qualityInspectionRecord config 里引用
|
||||
console.log("resetFields", this.resetFields);
|
||||
this.resetSpecificFields(this.resetFields);
|
||||
break;
|
||||
case "add":
|
||||
case "update":
|
||||
this.addOrUpdate(payload.name === "add" ? "POST" : "PUT");
|
||||
break;
|
||||
case "update-bom":
|
||||
this.addOrUpdate("POST", this.urls.editUrl);
|
||||
break;
|
||||
case "add-pos-manually": {
|
||||
this.addOrUpdate("POST", this.urls.posFormUrl);
|
||||
break;
|
||||
}
|
||||
case "add-car-payload": {
|
||||
console.log("edit-car-payload", payload);
|
||||
this.addOrUpdate("POST", this.urls.payloadFormUrl);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log("[x] 不是这么用的! 缺少name属性");
|
||||
}
|
||||
},
|
||||
|
||||
handleUploadChange(file, fileList) {
|
||||
console.log("[Upload] handleUploadChange...", file, fileList);
|
||||
},
|
||||
|
||||
handleClose() {
|
||||
this.resetForm();
|
||||
this.$emit("update:dialogVisible", false);
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.dialog-just-form >>> .el-dialog__body {
|
||||
/* padding-top: 16px !important;
|
||||
padding-bottom: 16px !important; */
|
||||
padding-top: 0 !important;
|
||||
padding-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.el-select,
|
||||
.el-cascader,
|
||||
.el-date-editor {
|
||||
width: 100% !important;
|
||||
}
|
||||
|
||||
.dialog-just-form >>> .el-dialog__header {
|
||||
padding: 10px 20px 10px;
|
||||
/* background: linear-gradient(to bottom, rgba(0, 0, 0, 0.25), white); */
|
||||
}
|
||||
</style>
|
@ -0,0 +1,426 @@
|
||||
<!-- 表格页加上搜索条件 -->
|
||||
<template>
|
||||
<div class="list-view-with-head" ref="pointer-loading-ref">
|
||||
<!-- <head-form :form-config="headFormConfig" @headBtnClick="btnClick" /> -->
|
||||
<BaseSearchForm :head-config="headConfig" @btn-click="handleBtnClick" />
|
||||
|
||||
<BaseListTable
|
||||
v-loading="tableLoading"
|
||||
:table-config="tableConfig.table"
|
||||
:column-config="tableConfig.column"
|
||||
:table-data="dataList"
|
||||
@operate-event="handleOperate"
|
||||
:current-page="page"
|
||||
:current-size="size"
|
||||
@select="handleTableSelect"
|
||||
:refresh-layout-key="refreshLayoutKey" />
|
||||
|
||||
<el-pagination
|
||||
v-if="navigator"
|
||||
class="mt-5 flex justify-end"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handlePageChange"
|
||||
:current-page.sync="page"
|
||||
:page-size.sync="size"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
:total="totalPage"
|
||||
layout="total, sizes, prev, pager, next, jumper"></el-pagination>
|
||||
|
||||
<DialogJustForm
|
||||
ref="edit-dialog"
|
||||
v-if="!!dialogConfigs"
|
||||
:dialog-visible.sync="dialogVisible"
|
||||
:configs="dialogConfigs"
|
||||
@refreshDataList="getList"
|
||||
@emit-data="handleOperate" />
|
||||
<Overlay v-if="overlayVisible" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import BaseListTable from "@/components/BaseListTable.vue";
|
||||
import BaseSearchForm from "@/components/BaseSearchForm.vue";
|
||||
import DialogJustForm from "./DialogJustForm.vue";
|
||||
import Overlay from "@/components/Overlay.vue";
|
||||
import moment from "moment";
|
||||
|
||||
export default {
|
||||
name: "ListViewWithHead",
|
||||
components: {
|
||||
BaseSearchForm,
|
||||
BaseListTable,
|
||||
DialogJustForm,
|
||||
Overlay,
|
||||
},
|
||||
props: {
|
||||
navigator: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
tableConfig: {
|
||||
type: Object,
|
||||
default: () => ({
|
||||
/** 列配置, 即 props **/ column: [],
|
||||
/** 表格整体配置 */ table: undefined,
|
||||
}),
|
||||
},
|
||||
headConfig: {
|
||||
type: Object,
|
||||
default: () => ({}),
|
||||
},
|
||||
/** 请求page接口的时候有些字段是必填的,没有会报500,把相关字段名传入这个prop: */
|
||||
listQueryExtra: {
|
||||
type: Array,
|
||||
default: () => ["key"],
|
||||
},
|
||||
attachListQueryExtra: {
|
||||
// 新增时,附带 listQueryExtra 里的哪些键和对应值
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
initDataWhenLoad: { type: Boolean, default: true },
|
||||
/** dialog configs 或许可以从 tableConfig 计算出来 computed... */
|
||||
dialogConfigs: {
|
||||
type: Object,
|
||||
default: () => null,
|
||||
},
|
||||
carPayloadDialogConfigs: {
|
||||
type: Object,
|
||||
default: () => null,
|
||||
},
|
||||
triggerUpdate: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
dialogType() {
|
||||
return this.dialogConfigs.menu ? DIALOG_WITH_MENU : DIALOG_JUST_FORM;
|
||||
},
|
||||
},
|
||||
activated() {
|
||||
this.refreshLayoutKey = this.layoutTable();
|
||||
},
|
||||
watch: {
|
||||
page: (val) => {
|
||||
console.log("page changed:", val);
|
||||
},
|
||||
size: (val) => {
|
||||
console.log("size changed:", val);
|
||||
},
|
||||
triggerUpdate(val, oldVal) {
|
||||
if (val && val !== oldVal) {
|
||||
// get list
|
||||
this.page = 1;
|
||||
this.size = "defaultPageSize" in this.tableConfig.column ? this.tableConfig.column.defaultPageSize : 20;
|
||||
this.getList();
|
||||
}
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
dialogVisible: false,
|
||||
topBtnConfig: null,
|
||||
totalPage: 0,
|
||||
page: 1,
|
||||
size: 20, // 默认20
|
||||
dataList: [],
|
||||
tableLoading: false,
|
||||
refreshLayoutKey: null,
|
||||
overlayVisible: false,
|
||||
cachedSearchCondition: {},
|
||||
needAttachmentDialog: false,
|
||||
tableSelectedIds: [],
|
||||
};
|
||||
},
|
||||
inject: ["urls"],
|
||||
mounted() {
|
||||
// 更新页面默认 size
|
||||
const size = "defaultPageSize" in this.tableConfig.column ? this.tableConfig.column.defaultPageSize : 20;
|
||||
this.size = size;
|
||||
|
||||
this.initDataWhenLoad && this.getList();
|
||||
},
|
||||
methods: {
|
||||
/** 获取 列表数据 */
|
||||
getList(queryParams) {
|
||||
this.tableLoading = true;
|
||||
|
||||
const params = queryParams
|
||||
? { ...queryParams, page: this.page, limit: this.size }
|
||||
: {
|
||||
page: this.page,
|
||||
limit: this.size,
|
||||
};
|
||||
|
||||
if (!queryParams && this.listQueryExtra && this.listQueryExtra.length) {
|
||||
this.listQueryExtra.map((nameOrObj) => {
|
||||
if (typeof nameOrObj === "string") params[nameOrObj] = "";
|
||||
else if (typeof nameOrObj === "object") {
|
||||
Object.keys(nameOrObj).forEach((key) => {
|
||||
params[key] = nameOrObj[key];
|
||||
});
|
||||
}
|
||||
});
|
||||
this.cachedSearchCondition = Object.assign({}, params);
|
||||
}
|
||||
|
||||
this.$http[this.urls.pageIsPostApi ? "post" : "get"](
|
||||
this.urls.page,
|
||||
this.urls.pageIsPostApi
|
||||
? {
|
||||
...params,
|
||||
}
|
||||
: {
|
||||
params,
|
||||
}
|
||||
)
|
||||
.then(({ data: res }) => {
|
||||
console.log("[http response] res is: ", res);
|
||||
|
||||
if (res.code === 0) {
|
||||
// page 场景:
|
||||
if ("list" in res.data) {
|
||||
this.dataList = res.data.list;
|
||||
this.totalPage = res.data.total;
|
||||
} else if ("records" in res.data) {
|
||||
this.dataList = res.data.records.map((item) => ({
|
||||
...item,
|
||||
id: item._id ?? item.id,
|
||||
}));
|
||||
this.totalPage = res.data.total;
|
||||
} else if (Array.isArray(res.data)) {
|
||||
this.dataList = res.data;
|
||||
} else {
|
||||
this.dataList.splice(0);
|
||||
this.totalPage = 0;
|
||||
}
|
||||
} else {
|
||||
this.$message({
|
||||
message: `${res.code}: ${res.msg}`,
|
||||
type: "error",
|
||||
duration: 2000,
|
||||
});
|
||||
}
|
||||
this.tableLoading = false;
|
||||
})
|
||||
.catch((err) => {
|
||||
this.$message({
|
||||
message: `${err}`,
|
||||
type: "error",
|
||||
duration: 2000,
|
||||
});
|
||||
this.tableLoading = false;
|
||||
});
|
||||
// }
|
||||
},
|
||||
|
||||
layoutTable() {
|
||||
return Math.random();
|
||||
},
|
||||
|
||||
handleTableSelect(ids) {
|
||||
this.tableSelectedIds = [...ids];
|
||||
},
|
||||
|
||||
/** 处理 表格操作 */
|
||||
handleOperate({ type, data }) {
|
||||
console.log("payload", type, data);
|
||||
// 编辑、删除、跳转路由、打开弹窗(动态component)都可以在配置里加上 url
|
||||
// payload: { type: string, data: string | number | object }
|
||||
switch (type) {
|
||||
case "delete": {
|
||||
// 找到删除的 prompt 字段
|
||||
const deleteConfig = data.head?.options?.find((item) => item.name === "delete");
|
||||
let promptName = data.name ?? data.id;
|
||||
if (deleteConfig && "promptField" in deleteConfig) {
|
||||
promptName = data[deleteConfig.promptField];
|
||||
}
|
||||
|
||||
let hintMsg = `确定要删除记录 "${promptName}" 吗?`;
|
||||
if (promptName == data.id) {
|
||||
// 如果 promptName 计算出来是 data.id 就以'该记录'代称
|
||||
hintMsg = "确定删除该记录?";
|
||||
}
|
||||
|
||||
let currenPageListLength = this.dataList.length;
|
||||
// 确认是否删除
|
||||
return this.$confirm(hintMsg, "提示", {
|
||||
confirmButtonText: "确认",
|
||||
cancelButtonText: "我再想想",
|
||||
type: "warning",
|
||||
})
|
||||
.then(() => {
|
||||
// this.$http.delete(this.urls.base + `/${data}`).then((res) => {
|
||||
this.$http({
|
||||
url: this.urls.base,
|
||||
method: "DELETE",
|
||||
// data: data.id,
|
||||
data: [`${data.id}`],
|
||||
// headers: {
|
||||
// "Content-Type": "application/json"
|
||||
// }
|
||||
}).then(({ data: res }) => {
|
||||
if (res.code === 0) {
|
||||
this.$message.success("删除成功!");
|
||||
// this.page = 1;
|
||||
// this.size =
|
||||
// "defaultPageSize" in this.tableConfig.column ? this.tableConfig.column.defaultPageSize : 20;
|
||||
if (currenPageListLength == 1) this.page = this.page > 1 ? this.page - 1 : 1;
|
||||
|
||||
this.getList();
|
||||
} else {
|
||||
this.$message({
|
||||
message: `${res.code}: ${res.msg}`,
|
||||
type: "error",
|
||||
duration: 1500,
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch((err) => {});
|
||||
}
|
||||
case "edit": {
|
||||
console.log("[edit] ", data);
|
||||
this.openDialog(data); /** data is ==> id */
|
||||
break;
|
||||
}
|
||||
case "view":
|
||||
case "view-detail-action": {
|
||||
this.openDialog(data, true);
|
||||
break;
|
||||
}
|
||||
case "view-blender-batch-details": {
|
||||
this.$router.push({
|
||||
name: "pms-blenderBatchDetails",
|
||||
query: {
|
||||
batchId: data,
|
||||
},
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
handleBtnClick({ btnName, payload }) {
|
||||
console.log("[search] form handleBtnClick", btnName, payload);
|
||||
switch (btnName) {
|
||||
case "批量同步":
|
||||
this.overlayVisible = true;
|
||||
this.$http.post(this.urls.syncUrl, this.tableSelectedIds).then(({ data: res }) => {
|
||||
this.$message({ message: res.msg, type: res.code === 0 ? "success" : "error" });
|
||||
res.code == 0 && this.getList();
|
||||
this.overlayVisible = false;
|
||||
});
|
||||
break;
|
||||
case "新增":
|
||||
this.openDialog();
|
||||
break;
|
||||
case "导入":
|
||||
this.openUploadDialog();
|
||||
break;
|
||||
case "手动添加": {
|
||||
this.openDialog();
|
||||
return;
|
||||
}
|
||||
case "查询": {
|
||||
if (typeof payload === "object") {
|
||||
// BaseSearchForm 给这个组件传递了数据
|
||||
Object.assign(this.cachedSearchCondition, payload);
|
||||
if ("timerange" in payload) {
|
||||
if (!!payload.timerange) {
|
||||
const [startTime, endTime] = payload["timerange"];
|
||||
this.cachedSearchCondition.startTime = moment(startTime).format("YYYY-MM-DDTHH:mm:ss");
|
||||
this.cachedSearchCondition.endTime = moment(endTime).format("YYYY-MM-DDTHH:mm:ss");
|
||||
} else {
|
||||
delete this.cachedSearchCondition.startTime;
|
||||
delete this.cachedSearchCondition.endTime;
|
||||
}
|
||||
delete this.cachedSearchCondition.timerange;
|
||||
}
|
||||
}
|
||||
|
||||
/** 处理 listQueryExtra 里的数据 */
|
||||
this.listQueryExtra?.map((cond) => {
|
||||
if (typeof cond === "string") {
|
||||
if (!!payload[cond]) {
|
||||
this.cachedSearchCondition[cond] = payload[cond];
|
||||
} else {
|
||||
this.cachedSearchCondition[cond] = "";
|
||||
}
|
||||
} else if (typeof cond === "object") {
|
||||
Object.keys(cond).forEach((key) => {
|
||||
this.cachedSearchCondition[key] = cond[key];
|
||||
});
|
||||
}
|
||||
});
|
||||
console.log("查询", this.cachedSearchCondition);
|
||||
this.getList(this.cachedSearchCondition);
|
||||
break;
|
||||
}
|
||||
case "同步":
|
||||
case "全部同步":
|
||||
this.$confirm("是否同步数据?", "提示", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning",
|
||||
}).then(() => {
|
||||
this.overlayVisible = true;
|
||||
this.$http
|
||||
.post(this.urls.syncUrl)
|
||||
.then(({ data: res }) => {
|
||||
console.log("同步", res);
|
||||
this.$message({ message: res.msg, type: res.code === 0 ? "success" : "error" });
|
||||
this.getList();
|
||||
this.overlayVisible = false;
|
||||
})
|
||||
.catch((err) => {
|
||||
this.overlayVisible = false;
|
||||
});
|
||||
});
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
/** 导航器的操作 */
|
||||
handleSizeChange(val) {
|
||||
// val 是新值
|
||||
this.page = 1;
|
||||
this.size = val;
|
||||
this.getList(this.cachedSearchCondition);
|
||||
},
|
||||
|
||||
handlePageChange(val) {
|
||||
// val 是新值
|
||||
this.getList(this.cachedSearchCondition);
|
||||
},
|
||||
|
||||
/** 打开对话框 */
|
||||
openDialog(row_id, detail_mode, tag_info) {
|
||||
this.dialogVisible = true;
|
||||
let extraParams = null;
|
||||
if (this.attachListQueryExtra && this.listQueryExtra.length) {
|
||||
this.listQueryExtra.forEach((item) => {
|
||||
let found = item[this.attachListQueryExtra];
|
||||
if (found !== null && found !== undefined) extraParams = item;
|
||||
});
|
||||
}
|
||||
this.$nextTick(() => {
|
||||
console.log(`[edit-dialog] extraParams: ${extraParams}`);
|
||||
this.$refs["edit-dialog"].init(/** some args... */ row_id, detail_mode, tag_info, extraParams);
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.list-view-with-head {
|
||||
background: white;
|
||||
/* height: 100%; */
|
||||
min-height: inherit;
|
||||
border-radius: 6px;
|
||||
padding: 16px;
|
||||
box-shadow: 0 0 1.125px 0.125px rgba(0, 0, 0, 0.125);
|
||||
}
|
||||
</style>
|
@ -93,6 +93,20 @@ export default function () {
|
||||
rules: { required: true, message: "必填项不能为空", trigger: "blur" },
|
||||
elparams: { placeholder: "请输入批次重量" },
|
||||
},
|
||||
{
|
||||
input: true,
|
||||
label: "牌号",
|
||||
prop: "bomName",
|
||||
rules: { required: true, message: "必填项不能为空", trigger: "blur" },
|
||||
elparams: { placeholder: "请输入批次重量" },
|
||||
},
|
||||
{
|
||||
select: [],
|
||||
label: "版本号",
|
||||
prop: "bomVersion",
|
||||
rules: { required: true, message: "必填项不能为空", trigger: "blur" },
|
||||
elparams: { placeholder: "请输入批次重量" },
|
||||
},
|
||||
],
|
||||
],
|
||||
operations: [
|
||||
|
@ -10,7 +10,8 @@
|
||||
|
||||
<script>
|
||||
import initConfig from "./config";
|
||||
import ListViewWithHead from "@/views/atomViews/ListViewWithHead.vue";
|
||||
// import ListViewWithHead from "@/views/atomViews/ListViewWithHead.vue";
|
||||
import ListViewWithHead from "./components/ListViewWithHead.vue";
|
||||
|
||||
export default {
|
||||
name: "BlenderBatchView",
|
||||
|
Loading…
Reference in New Issue
Block a user