add order--edit
This commit is contained in:
parent
f0c1691775
commit
5961000f53
@ -32,7 +32,7 @@
|
||||
:total="totalPage"
|
||||
layout="total, sizes, prev, pager, next, jumper"></el-pagination>
|
||||
|
||||
<DialogJustForm
|
||||
<OrderEditDialog
|
||||
modal-append-to-body
|
||||
ref="order-dialog"
|
||||
v-if="renderDialog"
|
||||
@ -73,11 +73,12 @@ import DialogWithMenu from "./DialogWithMenu.vue";
|
||||
import DialogUpload from "@/components/DialogUpload.vue";
|
||||
import moment from "moment";
|
||||
import Overlay from "@/components/Overlay.vue";
|
||||
import OrderEditDialog from './order--edit.vue'
|
||||
|
||||
// const dictList = JSON.parse(localStorage.getItem("dictList"));
|
||||
export default {
|
||||
name: "ListSectionWithHead",
|
||||
components: { BaseSearchForm, BaseListTable, DialogWithMenu, DialogJustForm, DialogUpload, Overlay },
|
||||
components: { OrderEditDialog, BaseSearchForm, BaseListTable, DialogWithMenu, DialogJustForm, DialogUpload, Overlay },
|
||||
props: {
|
||||
headConfig: {
|
||||
type: Object,
|
||||
|
806
src/views/modules/pms/order/components/order--edit.vue
Normal file
806
src/views/modules/pms/order/components/order--edit.vue
Normal file
@ -0,0 +1,806 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
class="order--edit_dialog"
|
||||
:fullscreen="fullscreen"
|
||||
:visible="visible"
|
||||
@close="handleClose"
|
||||
:destroy-on-close="false"
|
||||
:close-on-click-modal="false">
|
||||
<!-- title -->
|
||||
<div slot="title" class="dialog-title">
|
||||
<h2 class="">
|
||||
{{ detailMode ? "查看详情" : dataForm.id ? "修改订单" : "新增订单" }}
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<!-- form -->
|
||||
|
||||
<el-form ref="dataForm" :model="dataForm" v-loading="formLoading" size="small">
|
||||
<InputsArea title="生产订单">
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="6">
|
||||
<el-form-item label="订单状态" prop="statusDictValue" :rules="null">
|
||||
<span style="display: block; margin-top: 0">{{ dataForm.statusDictValue }}</span>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item
|
||||
label="订单号"
|
||||
prop="code"
|
||||
:rules="{ required: true, message: '必填项不能为空', trigger: 'blur' }">
|
||||
<el-input v-model="dataForm.code" v-bind="{ placeholder: '输入订单号' }"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item
|
||||
label="订单子号"
|
||||
prop="cate"
|
||||
:rules="[
|
||||
{ required: true, message: '必填项不能为空', trigger: 'blur' },
|
||||
{
|
||||
type: 'number',
|
||||
message: '输入正确的数字类型',
|
||||
trigger: 'blur',
|
||||
transform: '<<(val) => Number(val)>>',
|
||||
},
|
||||
]">
|
||||
<el-input v-model="dataForm.cate" v-bind="{ placeholder: '输入订单子号' }"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item
|
||||
label="计划开始时间"
|
||||
prop="planStartTime"
|
||||
:rules="{ required: true, message: '必填项不能为空', trigger: 'blur' }">
|
||||
<el-date-picker
|
||||
v-model="dataForm.planStartTime"
|
||||
v-bind="{
|
||||
placeholder: '选择计划开始时间',
|
||||
type: 'datetime',
|
||||
'value-format': 'yyyy-MM-ddTHH:mm:ss',
|
||||
}"></el-date-picker>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</InputsArea>
|
||||
|
||||
<InputsArea title="设备与参数">
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="6">
|
||||
<el-form-item
|
||||
label="压机"
|
||||
prop="press"
|
||||
:rules="{ required: true, message: '必填项不能为空', trigger: 'blur' }">
|
||||
<el-select
|
||||
v-model="dataForm.press"
|
||||
filterable
|
||||
clearable
|
||||
v-bind="{ placeholder: '选择压机', filterable: true }">
|
||||
<el-option v-for="opt in options" :key="opt.label" :label="opt.label" :value="opt.value">
|
||||
<span>{{ opt.label }}</span>
|
||||
<span v-if="col.extraLabel" style="display: inline-block; margin-left: 12px; font-size: 0.9em">
|
||||
{{ opt.code }}
|
||||
</span>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item
|
||||
label="混料机号"
|
||||
prop="blender"
|
||||
:rules="{ required: true, message: '必填项不能为空', trigger: 'blur' }">
|
||||
<el-select
|
||||
v-model="dataForm.blender"
|
||||
filterable
|
||||
clearable
|
||||
v-bind="{ placeholder: '选择混料机', filterable: true }">
|
||||
<el-option v-for="opt in options" :key="opt.label" :label="opt.label" :value="opt.value">
|
||||
<span>{{ opt.label }}</span>
|
||||
<span v-if="col.extraLabel" style="display: inline-block; margin-left: 12px; font-size: 0.9em">
|
||||
{{ opt.code }}
|
||||
</span>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="隧道窑号" prop="kiln" :rules="null">
|
||||
<el-select
|
||||
v-model="dataForm.kiln"
|
||||
filterable
|
||||
clearable
|
||||
v-bind="{ placeholder: '选择隧道窑', filterable: true }">
|
||||
<el-option v-for="opt in options" :key="opt.label" :label="opt.label" :value="opt.value">
|
||||
<span>{{ opt.label }}</span>
|
||||
<span v-if="col.extraLabel" style="display: inline-block; margin-left: 12px; font-size: 0.9em">
|
||||
{{ opt.code }}
|
||||
</span>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="Add on" prop="sapParam1" :rules="null">
|
||||
<el-input v-model="dataForm.sapParam1" v-bind="{ placeholder: '输入addon' }"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="6">
|
||||
<el-form-item label="牌号" prop="bomId" :rules="null">
|
||||
<el-select
|
||||
v-model="dataForm.bomId"
|
||||
filterable
|
||||
clearable
|
||||
v-bind="{ placeholder: '选择牌号', filterable: true }">
|
||||
<el-option v-for="opt in options" :key="opt.label" :label="opt.label" :value="opt.value">
|
||||
<span>{{ opt.label }}</span>
|
||||
<span v-if="col.extraLabel" style="display: inline-block; margin-left: 12px; font-size: 0.9em">
|
||||
{{ opt.undefined }}
|
||||
</span>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="配方号" prop="bomCode" :rules="null">
|
||||
<span style="display: block; margin-top: 0">{{ dataForm.bomCode }}</span>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="版本号" prop="ai" :rules="null">
|
||||
<span style="display: block; margin-top: 0">{{ dataForm.ai }}</span>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="包装代码" prop="packTech" :rules="null">
|
||||
<el-select
|
||||
v-model="dataForm.packTech"
|
||||
filterable
|
||||
clearable
|
||||
v-bind="{ placeholder: '选择包装代码', filterable: true }">
|
||||
<el-option v-for="opt in options" :key="opt.label" :label="opt.label" :value="opt.value">
|
||||
<span>{{ opt.label }}</span>
|
||||
<span v-if="col.extraLabel" style="display: inline-block; margin-left: 12px; font-size: 0.9em">
|
||||
{{ opt.code }}
|
||||
</span>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="6">
|
||||
<el-form-item label="物料" prop="productId" :rules="null">
|
||||
<el-select
|
||||
v-model="dataForm.productId"
|
||||
filterable
|
||||
clearable
|
||||
v-bind="{ placeholder: '选择物料', filterable: true }">
|
||||
<el-option v-for="opt in options" :key="opt.label" :label="opt.label" :value="opt.value">
|
||||
<span>{{ opt.label }}</span>
|
||||
<span v-if="col.extraLabel" style="display: inline-block; margin-left: 12px; font-size: 0.9em">
|
||||
{{ opt.code }}
|
||||
</span>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="砖型" prop="shape" :rules="null">
|
||||
<el-select
|
||||
v-model="dataForm.shape"
|
||||
filterable
|
||||
clearable
|
||||
v-bind="{ placeholder: '选择砖型', filterable: true }">
|
||||
<el-option v-for="opt in options" :key="opt.label" :label="opt.label" :value="opt.value">
|
||||
<span>{{ opt.label }}</span>
|
||||
<span v-if="col.extraLabel" style="display: inline-block; margin-left: 12px; font-size: 0.9em">
|
||||
{{ opt.code }}
|
||||
</span>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item
|
||||
label="烧成温度"
|
||||
prop="sapParam6"
|
||||
:rules="[
|
||||
{ required: true, message: '必填项不能为空', trigger: 'blur' },
|
||||
{
|
||||
type: 'number',
|
||||
message: '输入正确的数字类型',
|
||||
trigger: 'blur',
|
||||
transform: '<<(val) => Number(val)>>',
|
||||
},
|
||||
]">
|
||||
<el-input v-model="dataForm.sapParam6" v-bind="{ placeholder: '输入烧成温度' }"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item
|
||||
label="烧成时间 H"
|
||||
prop="sapParam7"
|
||||
:rules="[
|
||||
{ required: true, message: '必填项不能为空', trigger: 'blur' },
|
||||
{
|
||||
type: 'number',
|
||||
message: '输入正确的数字类型',
|
||||
trigger: 'blur',
|
||||
transform: '<<(val) => Number(val)>>',
|
||||
},
|
||||
]">
|
||||
<el-input v-model="dataForm.sapParam7" v-bind="{ placeholder: '输入烧成时间' }"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</InputsArea>
|
||||
|
||||
<InputsArea title="其他">
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="6">
|
||||
<el-form-item label="生产订单类型" prop="specifications" :rules="null">
|
||||
<el-input v-model="dataForm.specifications" v-bind="{ placeholder: '输入生产订单类型' }"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item
|
||||
label="生产订单砖数"
|
||||
prop="prodqty"
|
||||
:rules="[
|
||||
{ required: true, message: '必填项不能为空', trigger: 'blur' },
|
||||
{
|
||||
type: 'number',
|
||||
message: '输入正确的数字类型',
|
||||
trigger: 'blur',
|
||||
transform: '<<(val) => Number(val)>>',
|
||||
},
|
||||
]">
|
||||
<el-input v-model="dataForm.prodqty" v-bind="{ placeholder: '输入要求生产的数量' }"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item
|
||||
label="已生产数"
|
||||
prop="yieldqty"
|
||||
:rules="[
|
||||
{
|
||||
type: 'number',
|
||||
message: '输入正确的数字类型',
|
||||
trigger: 'blur',
|
||||
transform: '<<(val) => Number(val)>>',
|
||||
},
|
||||
]">
|
||||
<el-input v-model="dataForm.yieldqty" v-bind="{ placeholder: '输入已经生产的数量' }"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item
|
||||
label="托盘码放砖数"
|
||||
prop="pcsKilnCar"
|
||||
:rules="[
|
||||
{ required: true, message: '必填项不能为空', trigger: 'blur' },
|
||||
{
|
||||
type: 'number',
|
||||
message: '输入正确的数字类型',
|
||||
trigger: 'blur',
|
||||
transform: '<<(val) => Number(val)>>',
|
||||
},
|
||||
]">
|
||||
<el-input v-model="dataForm.pcsKilnCar" v-bind="{ placeholder: '输入托盘码放砖数' }"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="6">
|
||||
<el-form-item
|
||||
label="销售订单号"
|
||||
prop="saleNo"
|
||||
:rules="{ required: true, message: '必填项不能为空', trigger: 'blur' }">
|
||||
<el-input v-model="dataForm.saleNo" v-bind="{ placeholder: '输入销售订单号' }"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="销售订单item号" prop="saleOrderItem" :rules="null">
|
||||
<el-input v-model="dataForm.saleOrderItem" v-bind="{ placeholder: '输入销售订单item号' }"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item
|
||||
label="销售订单砖数"
|
||||
prop="soqty"
|
||||
:rules="[
|
||||
{ required: true, message: '必填项不能为空', trigger: 'blur' },
|
||||
{
|
||||
type: 'number',
|
||||
message: '输入正确的数字类型',
|
||||
trigger: 'blur',
|
||||
transform: '<<(val) => Number(val)>>',
|
||||
},
|
||||
]">
|
||||
<el-input v-model="dataForm.soqty" v-bind="{ placeholder: '输入销售订单砖数' }"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item
|
||||
label="销售时间"
|
||||
prop="deliveryTime"
|
||||
:rules="{ required: true, message: '必填项不能为空', trigger: 'blur' }">
|
||||
<el-date-picker v-model="dataForm.deliveryTime" v-bind="{ placeholder: '选择销售时间' }"></el-date-picker>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="6">
|
||||
<el-form-item
|
||||
label="客户"
|
||||
prop="customerId"
|
||||
:rules="{ required: true, message: '必填项不能为空', trigger: 'blur' }">
|
||||
<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">
|
||||
<span>{{ opt.label }}</span>
|
||||
<span v-if="col.extraLabel" style="display: inline-block; margin-left: 12px; font-size: 0.9em">
|
||||
{{ opt.name }}
|
||||
</span>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="物料号销售文本" prop="shortDesc" :rules="null">
|
||||
<span style="display: block; margin-top: 0">{{ dataForm.shortDesc }}</span>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6"></el-col>
|
||||
<el-col :span="6"></el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="6">
|
||||
<el-form-item label="备注" prop="remark" :rules="null">
|
||||
<el-input v-model="dataForm.remark" v-bind="{ placeholder: '备注' }"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</InputsArea>
|
||||
</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";
|
||||
import InputsArea from "./InputsArea.vue";
|
||||
|
||||
export default {
|
||||
name: "DialogJustForm",
|
||||
components: { InputsArea },
|
||||
props: {
|
||||
configs: {
|
||||
type: Object,
|
||||
default: () => ({
|
||||
clickModalToClose: false,
|
||||
forms: null,
|
||||
}),
|
||||
},
|
||||
fullscreen: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
inject: ["urls"],
|
||||
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 {
|
||||
formLoading: false,
|
||||
dataForm,
|
||||
watchList,
|
||||
cachedList,
|
||||
detailMode: false,
|
||||
baseDialogConfig: null,
|
||||
visible: false,
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
/** 处理 injectTo 选项 */
|
||||
this.configs.form.field.forEach((field) => {
|
||||
field.rows.forEach((row) => {
|
||||
row.forEach((col) => {
|
||||
if (!col.prop) return;
|
||||
if ("injectTo" in col && Array.isArray(col.injectTo)) {
|
||||
// console.log("watching options ..... ", col);
|
||||
col.injectTo.map((item) => {
|
||||
const unwatch = this.$watch(
|
||||
() => 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,
|
||||
}
|
||||
);
|
||||
this.watchList.push(unwatch);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
computed: {
|
||||
uploadHeaders() {
|
||||
return {
|
||||
token: Cookies.get("token") || "",
|
||||
};
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
handleFilelistUpdate(newFilelist) {
|
||||
// TODO: 直接访问 .files 可能不太合适
|
||||
this.dataForm.files = newFilelist.map((file) => ({
|
||||
id: file.id,
|
||||
name: file.name,
|
||||
url: file.url,
|
||||
typeCode: file.typeCode,
|
||||
}));
|
||||
// 更新请求
|
||||
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 */
|
||||
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));
|
||||
},
|
||||
|
||||
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
|
||||
);
|
||||
},
|
||||
|
||||
/** init **/
|
||||
init(id, detailMode) {
|
||||
this.visible = true;
|
||||
return;
|
||||
// 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.$nextTick(() => {
|
||||
this.dataForm.id = id || null;
|
||||
if (this.dataForm.id) {
|
||||
// 如果是编辑
|
||||
this.formLoading = true;
|
||||
|
||||
// 获取基本信息
|
||||
this.$http
|
||||
.get(this.urls.base + `/${this.dataForm.id}`)
|
||||
.then(({ data: res }) => {
|
||||
if (res && res.code === 0) {
|
||||
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 {
|
||||
this.$message({
|
||||
message: `${res.code}: ${res.msg}`,
|
||||
type: "error",
|
||||
duration: 1500,
|
||||
});
|
||||
}
|
||||
this.formLoading = false;
|
||||
})
|
||||
.catch((err) => {
|
||||
this.formLoading = false;
|
||||
this.$message({
|
||||
message: `${err}`,
|
||||
type: "error",
|
||||
duration: 1500,
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// 如果不是编辑
|
||||
this.formLoading = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/** handlers */
|
||||
handleSelectChange(col, eventValue) {
|
||||
// console.log("[dialog] select change: ", col, eventValue);
|
||||
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") {
|
||||
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.formLoading = 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") : 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"),
|
||||
// };
|
||||
// }
|
||||
/** 针对时间段设置 payload */
|
||||
if ("deliveryTime" in this.dataForm) {
|
||||
const { deliveryTime } = this.dataForm;
|
||||
httpPayload = {
|
||||
...httpPayload,
|
||||
deliveryTime: deliveryTime ? moment(deliveryTime).format("YYYY-MM-DDTHH:mm:ss") : null,
|
||||
};
|
||||
}
|
||||
|
||||
// Object.getOwnPropertyNames(this.dataForm).forEach((prop) => {
|
||||
// if (/.*?Time/.test(prop)) {
|
||||
// console.log("HTTP prop", prop, this.dataForm[prop]);
|
||||
// }
|
||||
// });
|
||||
|
||||
// return;
|
||||
|
||||
/** 发送 */
|
||||
return this.$http({
|
||||
url: this.urls.base,
|
||||
method,
|
||||
data: httpPayload,
|
||||
})
|
||||
.then(({ data: res }) => {
|
||||
// console.log("[add&update] res is: ", res);
|
||||
this.formLoading = false;
|
||||
if (res.code === 0) {
|
||||
this.$message.success(method === "POST" ? "添加成功" : "更新成功");
|
||||
this.$emit("refreshDataList");
|
||||
this.handleClose();
|
||||
} else {
|
||||
this.$message({
|
||||
message: `${res.code}: ${res.msg}`,
|
||||
type: "error",
|
||||
duration: 2000,
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((errMsg) => {
|
||||
this.$message.error("参数错误:" + errMsg);
|
||||
if (this.formLoading) this.formLoading = 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 "add":
|
||||
case "update":
|
||||
this.addOrUpdate(payload.name === "add" ? "POST" : "PUT");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
console.log("[x] 不是这么用的! 缺少name属性");
|
||||
}
|
||||
},
|
||||
|
||||
handleUploadChange(file, fileList) {
|
||||
// console.log("[Upload] handleUploadChange...", file, fileList);
|
||||
},
|
||||
|
||||
handleClose() {
|
||||
this.visible = false;
|
||||
|
||||
setTimeout(() => {
|
||||
this.$emit("destroy-dialog");
|
||||
// this.resetForm();
|
||||
// this.$emit("update:dialogVisible", false);
|
||||
}, 200);
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.order--edit_dialog >>> .el-dialog {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.order--edit_dialog >>> .el-dialog__header {
|
||||
padding: 0 20px 0;
|
||||
/* background: linear-gradient(to bottom, #eee, #ccc, #eee); */
|
||||
background: #eeec;
|
||||
border-bottom: 1px solid #dddc;
|
||||
}
|
||||
|
||||
.order--edit_dialog >>> .el-dialog__body {
|
||||
/* padding-top: 16px !important;
|
||||
padding-bottom: 16px !important; */
|
||||
/* transform: scale(0.95); */
|
||||
padding-top: 24px !important;
|
||||
padding-bottom: 0 !important;
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.order--edit_dialog >>> .el-dialog__footer {
|
||||
border-top: 1px solid #dddc;
|
||||
background-color: #eeec;
|
||||
padding: 10px 20px;
|
||||
}
|
||||
|
||||
.el-select,
|
||||
.el-cascader,
|
||||
.el-date-editor {
|
||||
width: 100% !important;
|
||||
}
|
||||
|
||||
.h0 {
|
||||
height: 0;
|
||||
width: 0;
|
||||
}
|
||||
</style>
|
Loading…
Reference in New Issue
Block a user