update order--edit

This commit is contained in:
lb 2023-07-28 17:05:28 +08:00
parent 7f7e9d3b85
commit 3291c1a971

View File

@ -433,8 +433,8 @@
<!-- footer --> <!-- footer -->
<div slot="footer"> <div slot="footer">
<!-- TODO: permission 相关内容 未添加 --> <!-- TODO: permission 相关内容 未添加 -->
<el-button v-if="mode.includes('create')" type="primary" @click="handleSave">保存</el-button> <el-button v-if="mode.includes('create')" type="primary" @click="handleSave('POST')">保存</el-button>
<el-button v-if="mode.includes('edit')" type="primary" @click="handleUpdate">更新</el-button> <el-button v-if="mode.includes('edit')" type="primary" @click="handleSave('PUT')">更新</el-button>
<el-button v-if="mode.includes('reset')" type="warning" @click="handleReset">重置</el-button> <el-button v-if="mode.includes('reset')" type="warning" @click="handleReset">重置</el-button>
<el-button @click="handleClose">取消</el-button> <el-button @click="handleClose">取消</el-button>
</div> </div>
@ -694,6 +694,7 @@ export default {
const targetBom = this.versionList.find((item) => item.value === v); const targetBom = this.versionList.find((item) => item.value === v);
// this.bomId this.dataForm.bomId // this.bomId this.dataForm.bomId
this.bomId = targetBom.id; this.bomId = targetBom.id;
console.log("[handleVersionChange] new bomID", this.bomId);
}, },
async init(id) { async init(id) {
@ -749,101 +750,36 @@ export default {
this.$forceUpdate(); this.$forceUpdate();
}, },
addOrUpdate(method = "POST") { async handleSave(method = "POST") {
if ("parentId" in this.dataForm) { this.$refs.dataForm.validate((valid) => {
// console.log("[DialogJustForm parentId]", this.dataForm.parentId); if (valid) {
// parentId cascader ["xxx"]xxx this.btnLoading = true;
const lastItem = this.dataForm.parentId.length - 1; try {
this.dataForm.parentId = this.dataForm.parentId[lastItem]; const { data: res } = this.$http({
} url: this.urls.base,
method,
this.$refs.dataForm.validate((passed, result) => { data: {
if (passed) { ...this.dataForm,
this.formLoading = true; bomId: this.bomId != null ? this.bomId : this.dataForm.bomId,
},
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("请核查字段信息"); if (res && res.code == 0) {
this.$message.success("添加成功");
this.$emit("refreshDataList");
this.handleClose();
this.btnLoading = false;
} else {
throw new Error("请求出错");
}
} catch (err) {
this.$message.error("参数错误:" + "msg" in err ? err.msg : err);
this.btnLoading = false;
}
} }
}); });
}, },
handleSave() {},
handleUpdate() {},
handleReset() {}, handleReset() {},
handleClose() { handleClose() {