Commit 432e2f71 by chenwq

feat: 优化审批提交页面的表单项处理逻辑,添加通用选择器功能

1 parent f2093d69
......@@ -131,6 +131,41 @@ const REJECT_FORM_CONFIG = [
},
];
const PICKER_FIELD_MAP = {
supervisor: [
["assignedSupervisorPhone", "phone"],
["assignedSupervisorName", "name"],
["assignedSupervisorUuid", "uuid"],
],
scene: [
["teachingSceneCode", "code"],
["teachingSceneName", "name"],
["teachingMethodCode"],
["teachingMethodName"],
],
method: [
["teachingMethodCode", "code"],
["teachingMethodName", "name"],
],
topic: [
["teachingTopicCode", "code"],
["teachingTopicName", "name"],
],
};
const APPROVE_SUBMIT_KEYS = [
"assignedSupervisorPhone",
"assignedSupervisorName",
"assignedSupervisorUuid",
"teachingSceneCode",
"teachingSceneName",
"teachingTime",
"teachingMethodCode",
"teachingMethodName",
"teachingTopicCode",
"teachingTopicName",
];
export default {
name: "MineApprovalSubmit",
data() {
......@@ -156,6 +191,7 @@ export default {
form: {
assignedSupervisorPhone: "",
assignedSupervisorName: "",
assignedSupervisorUuid: "",
teachingSceneCode: "",
teachingSceneName: "",
teachingTime: "",
......@@ -243,8 +279,9 @@ export default {
normalizeSupervisorItem(item) {
return {
...item,
phone: item.assignedSupervisorPhone || item.supervisorPhone || item.phone || item.mobile || "",
name: item.assignedSupervisorName || item.supervisorName || item.name || item.staffName || "",
phone: item.phone || "",
name: item.name || "",
uuid: item.uuid || "",
};
},
handleFormItemClick(item) {
......@@ -268,37 +305,17 @@ export default {
this.picker.show = false;
return;
}
const handlers = {
supervisor: this.applySupervisor,
scene: this.applyScene,
method: this.applyMethod,
topic: this.applyTopic,
};
const handler = handlers[this.picker.key];
if (handler)
handler(item);
this.applyPickerValue(item);
this.picker.show = false;
},
applySupervisor(item) {
this.form.assignedSupervisorPhone = item.phone;
this.form.assignedSupervisorName = item.name;
},
applyScene(item) {
this.form.teachingSceneCode = item.code;
this.form.teachingSceneName = item.name;
this.form.teachingMethodCode = "";
this.form.teachingMethodName = "";
},
applyMethod(item) {
this.form.teachingMethodCode = item.code;
this.form.teachingMethodName = item.name;
},
applyTopic(item) {
this.form.teachingTopicCode = item.code;
this.form.teachingTopicName = item.name;
applyPickerValue(item) {
const fields = PICKER_FIELD_MAP[this.picker.key] || [];
fields.forEach(([formKey, itemKey]) => {
this.form[formKey] = itemKey ? item[itemKey] || "" : "";
});
},
onTimeConfirm(value) {
this.form.teachingTime = dayjs(value).format("YYYY-MM-DD HH:mm:ss");
this.form.teachingTime = dayjs(value).format("YYYY-MM-DD HH:mm");
this.showTimePicker = false;
},
getFormValue(item) {
......@@ -313,6 +330,17 @@ export default {
getFirstEmptyRequired() {
return this.currentFormItems.find(item => item.required && !this.form[item.requiredKey || item.valueKey]);
},
isSubmitSuccess(res) {
console.log("submit res", res);
if (!res)
return false;
if (res.code === undefined)
return true;
return Number(res.code) === 0 || Number(res.code) === 200;
},
getSubmitErrorMessage(res) {
return res?.message || res?.msg || res?.errorMsg || "提交失败";
},
buildParams() {
const params = {
id: this.id,
......@@ -325,17 +353,15 @@ export default {
}
return {
...params,
assignedSupervisorPhone: this.form.assignedSupervisorPhone,
assignedSupervisorName: this.form.assignedSupervisorName,
teachingSceneCode: this.form.teachingSceneCode,
teachingSceneName: this.form.teachingSceneName,
teachingTime: this.form.teachingTime,
teachingMethodCode: this.form.teachingMethodCode,
teachingMethodName: this.form.teachingMethodName,
teachingTopicCode: this.form.teachingTopicCode,
teachingTopicName: this.form.teachingTopicName,
...this.pickFormValues(APPROVE_SUBMIT_KEYS),
};
},
pickFormValues(keys) {
return keys.reduce((values, key) => {
values[key] = this.form[key];
return values;
}, {});
},
async submit() {
if (this.submitting)
return;
......@@ -348,13 +374,16 @@ export default {
Toast(emptyItem.message || `请填写${emptyItem.label}`);
return;
}
console.log("提交参数", this.buildParams());
this.submitting = true;
api.submitApproval(this.buildParams()).then((res) => {
console.log("提交结果", res);
if (!res) {
Toast(this.getSubmitErrorMessage(res));
return;
}
Toast("提交成功");
// this.$router.replace({ name: "mine/tasks" });
this.$router.replace({ name: "mine/tasks" });
}).catch(() => {
// 处理错误
Toast("提交失败");
}).finally(() => {
this.submitting = false;
});
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!