update 订单详情

This commit is contained in:
lb
2023-03-28 16:19:25 +08:00
parent b62db4d40c
commit 422560c6ef
4 changed files with 596 additions and 292 deletions

View File

@@ -19,17 +19,13 @@
<TrayDetail />
</el-tab-pane>
<el-tab-pane name="order" label="订单详情">
<OrderDetail />
<OrderDetail :configs="configs" />
</el-tab-pane>
</el-tabs>
</el-dialog>
</template>
<script>
import { pick as __pick } from "@/utils/filters";
import Cookies from "js-cookie";
import moment from "moment";
import CarDetail from "./tabs/carDetail.vue";
import OrderDetail from "./tabs/orderDetail.vue";
import SubOrderDetail from "./tabs/subOrderDetail.vue";
@@ -50,309 +46,40 @@ export default {
},
inject: ["urls"],
data() {
const dataForm = {};
const watchList = [];
const cachedList = {};
this.configs.form.rows.forEach((row) => {
row.forEach((col) => {
dataForm[col.prop] = col.default ?? null;
if (col.fetchData)
col.fetchData().then(({ data: res }) => {
// console.log("[DialogJustForm fetchData -->]", res.data.list);
if (res.code === 0 && res.data.list) {
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,
}))
);
// col.options = res.data.list;
} else {
col.options.splice(0);
}
// dataForm[col.prop] = col.default ?? null; // not perfect!
});
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 {
loadingStatus: false,
dataForm,
watchList,
cachedList,
detailMode: false,
baseDialogConfig: null,
visible: false,
activeTab: "sub",
orderId: null,
orderSubId: null,
carLayoutKey: 0
carLayoutKey: 0,
};
},
mounted() {
/** 处理 injectTo 选项 */
// this.configs.form.rows.forEach((row) => {
// row.forEach((col) => {
// 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);
// });
// }
// });
// });
},
methods: {
handleTabClick(tab, event) {
console.log('handle tab click', tab, event)
console.log("handle tab click", tab, event);
// tab.getAList(this.orderId)
switch (tab.label) {
case "子订单进度": break;
case "窑车详情": this.carLayoutKey = Math.random(); break;
case "托盘详情": break;
case "订单详情": break;
case "子订单进度":
break;
case "窑车详情":
this.carLayoutKey = Math.random();
break;
case "托盘详情":
break;
case "订单详情":
break;
}
},
/** 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(order, detailMode) {
this.orderId = order.id;
console.log("init menu dialog,", order);
this.visible = true;
// if (this.$refs.dataForm) {
// this.$refs.dataForm.clearValidate();
// }
this.detailMode = detailMode ?? false;
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) {
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.loadingStatus = false;
})
.catch((err) => {
this.loadingStatus = false;
this.$message({
message: `${err}`,
type: "error",
duration: 1500,
});
});
} else {
// 如果不是编辑
this.loadingStatus = 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.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") : 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,
};
}
/** 发送 */
return this.$http({
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();
} 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 "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() {