优化后,再次提交
This commit is contained in:
390
unpackage/dist/dev/mp-weixin/pages/hiddendanger/rectification.js
vendored
Normal file
390
unpackage/dist/dev/mp-weixin/pages/hiddendanger/rectification.js
vendored
Normal file
@@ -0,0 +1,390 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../../common/vendor.js");
|
||||
const request_api = require("../../request/api.js");
|
||||
const request_request = require("../../request/request.js");
|
||||
if (!Array) {
|
||||
const _easycom_up_textarea2 = common_vendor.resolveComponent("up-textarea");
|
||||
const _easycom_up_input2 = common_vendor.resolveComponent("up-input");
|
||||
const _easycom_up_datetime_picker2 = common_vendor.resolveComponent("up-datetime-picker");
|
||||
const _easycom_up_checkbox2 = common_vendor.resolveComponent("up-checkbox");
|
||||
const _easycom_up_checkbox_group2 = common_vendor.resolveComponent("up-checkbox-group");
|
||||
const _easycom_u_popup2 = common_vendor.resolveComponent("u-popup");
|
||||
const _easycom_up_upload2 = common_vendor.resolveComponent("up-upload");
|
||||
(_easycom_up_textarea2 + _easycom_up_input2 + _easycom_up_datetime_picker2 + _easycom_up_checkbox2 + _easycom_up_checkbox_group2 + _easycom_u_popup2 + _easycom_up_upload2)();
|
||||
}
|
||||
const _easycom_up_textarea = () => "../../uni_modules/uview-plus/components/u-textarea/u-textarea.js";
|
||||
const _easycom_up_input = () => "../../uni_modules/uview-plus/components/u-input/u-input.js";
|
||||
const _easycom_up_datetime_picker = () => "../../uni_modules/uview-plus/components/u-datetime-picker/u-datetime-picker.js";
|
||||
const _easycom_up_checkbox = () => "../../uni_modules/uview-plus/components/u-checkbox/u-checkbox.js";
|
||||
const _easycom_up_checkbox_group = () => "../../uni_modules/uview-plus/components/u-checkbox-group/u-checkbox-group.js";
|
||||
const _easycom_u_popup = () => "../../uni_modules/uview-plus/components/u-popup/u-popup.js";
|
||||
const _easycom_up_upload = () => "../../uni_modules/uview-plus/components/u-upload/u-upload.js";
|
||||
if (!Math) {
|
||||
(_easycom_up_textarea + _easycom_up_input + _easycom_up_datetime_picker + _easycom_up_checkbox + _easycom_up_checkbox_group + _easycom_u_popup + _easycom_up_upload)();
|
||||
}
|
||||
const _sfc_main = {
|
||||
__name: "rectification",
|
||||
setup(__props) {
|
||||
const hazardId = common_vendor.ref("");
|
||||
const assignId = common_vendor.ref("");
|
||||
const rectifyId = common_vendor.ref("");
|
||||
const isEdit = common_vendor.ref(false);
|
||||
const formData = common_vendor.reactive({
|
||||
rectifyPlan: "",
|
||||
// 整改方案
|
||||
rectifyResult: "",
|
||||
// 整改完成情况
|
||||
planCost: "",
|
||||
// 投资资金(计划)
|
||||
actualCost: ""
|
||||
// 投资资金(实际)
|
||||
});
|
||||
const show = common_vendor.ref(false);
|
||||
const value1 = common_vendor.ref(Date.now());
|
||||
common_vendor.ref("");
|
||||
const cateList = common_vendor.ref([]);
|
||||
const showUserPopup = common_vendor.ref(false);
|
||||
const selectedUserIds = common_vendor.ref([]);
|
||||
const selectedUsers = common_vendor.ref([]);
|
||||
const selectedUsersText = common_vendor.computed(() => {
|
||||
if (selectedUsers.value.length === 0)
|
||||
return "";
|
||||
if (selectedUsers.value.length <= 2) {
|
||||
return selectedUsers.value.map((u) => u.name).join("、");
|
||||
}
|
||||
return `${selectedUsers.value[0].name}等${selectedUsers.value.length}人`;
|
||||
});
|
||||
const onUserChange = (ids) => {
|
||||
common_vendor.index.__f__("log", "at pages/hiddendanger/rectification.vue:125", "选中的ID:", ids);
|
||||
};
|
||||
const confirmUserSelect = () => {
|
||||
selectedUsers.value = cateList.value.filter((item) => selectedUserIds.value.includes(item.id));
|
||||
showUserPopup.value = false;
|
||||
common_vendor.index.__f__("log", "at pages/hiddendanger/rectification.vue:133", "选中的整改人员:", selectedUsers.value);
|
||||
};
|
||||
const fetchDeptUsers = async () => {
|
||||
common_vendor.index.__f__("log", "at pages/hiddendanger/rectification.vue:138", "当前hazardId:", hazardId.value);
|
||||
try {
|
||||
const res = await request_api.getDeptUsersWithSubordinates({ hazardId: hazardId.value });
|
||||
if (res.code === 0 && res.data) {
|
||||
const userList = [];
|
||||
res.data.forEach((dept) => {
|
||||
if (dept.users && dept.users.length > 0) {
|
||||
dept.users.forEach((user) => {
|
||||
userList.push({
|
||||
id: String(user.userId),
|
||||
name: `${user.nickName}(${dept.deptName})`
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
cateList.value = userList;
|
||||
common_vendor.index.__f__("log", "at pages/hiddendanger/rectification.vue:156", "整改人员列表:", cateList.value);
|
||||
}
|
||||
} catch (error) {
|
||||
common_vendor.index.__f__("error", "at pages/hiddendanger/rectification.vue:159", "获取部门人员失败:", error);
|
||||
}
|
||||
};
|
||||
const fileList1 = common_vendor.ref([]);
|
||||
const deletePic = (event) => {
|
||||
fileList1.value.splice(event.index, 1);
|
||||
};
|
||||
const afterRead = async (event) => {
|
||||
let lists = [].concat(event.file);
|
||||
let fileListLen = fileList1.value.length;
|
||||
lists.map((item) => {
|
||||
fileList1.value.push({
|
||||
...item,
|
||||
status: "uploading",
|
||||
message: "上传中"
|
||||
});
|
||||
});
|
||||
for (let i = 0; i < lists.length; i++) {
|
||||
const result = await uploadFilePromise(lists[i].url);
|
||||
let item = fileList1.value[fileListLen];
|
||||
fileList1.value.splice(fileListLen, 1, {
|
||||
...item,
|
||||
status: "success",
|
||||
message: "",
|
||||
url: result
|
||||
});
|
||||
fileListLen++;
|
||||
}
|
||||
};
|
||||
const uploadFilePromise = (filePath) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
common_vendor.index.uploadFile({
|
||||
url: request_request.baseUrl + "/frontend/attachment/upload",
|
||||
filePath,
|
||||
name: "file",
|
||||
header: {
|
||||
"Authorization": request_request.getToken()
|
||||
},
|
||||
success: (res) => {
|
||||
const data = JSON.parse(res.data);
|
||||
if (data.code === 0) {
|
||||
resolve(data.data);
|
||||
} else {
|
||||
reject(data.msg || "上传失败");
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
common_vendor.index.__f__("error", "at pages/hiddendanger/rectification.vue:214", "上传失败:", err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
const handleSubmit = async () => {
|
||||
if (!formData.rectifyPlan) {
|
||||
common_vendor.index.showToast({
|
||||
title: "请输入整改方案",
|
||||
icon: "none"
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!formData.rectifyResult) {
|
||||
common_vendor.index.showToast({
|
||||
title: "请输入整改完成情况",
|
||||
icon: "none"
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (selectedUsers.value.length === 0) {
|
||||
common_vendor.index.showToast({
|
||||
title: "请选择整改人员",
|
||||
icon: "none"
|
||||
});
|
||||
return;
|
||||
}
|
||||
const attachments = fileList1.value.map((file) => {
|
||||
let url = "";
|
||||
if (typeof file.url === "string") {
|
||||
url = file.url;
|
||||
} else if (file.url && typeof file.url === "object") {
|
||||
url = file.url.url || file.url.path || "";
|
||||
}
|
||||
const fileName = typeof url === "string" && url ? url.split("/").pop() : file.name || "";
|
||||
return {
|
||||
fileName: fileName || "",
|
||||
filePath: url || "",
|
||||
fileType: file.type || "image/png",
|
||||
fileSize: file.size || 0
|
||||
};
|
||||
});
|
||||
const params = {
|
||||
hazardId: hazardId.value,
|
||||
assignId: assignId.value,
|
||||
rectifyPlan: formData.rectifyPlan,
|
||||
rectifyResult: formData.rectifyResult,
|
||||
planCost: Number(formData.planCost) || 0,
|
||||
actualCost: Number(formData.actualCost) || 0,
|
||||
attachments,
|
||||
// 整改人员ID数组
|
||||
rectifyUserIds: selectedUserIds.value.map((id) => Number(id))
|
||||
};
|
||||
if (rectifyId.value) {
|
||||
params.rectifyId = rectifyId.value;
|
||||
}
|
||||
try {
|
||||
const res = await request_api.submitRectification(params);
|
||||
if (res.code === 0) {
|
||||
common_vendor.index.showToast({
|
||||
title: isEdit.value ? "保存成功" : "提交成功",
|
||||
icon: "success"
|
||||
});
|
||||
setTimeout(() => {
|
||||
common_vendor.index.navigateBack();
|
||||
}, 1500);
|
||||
} else {
|
||||
common_vendor.index.showToast({
|
||||
title: res.msg || (isEdit.value ? "保存失败" : "提交失败"),
|
||||
icon: "none"
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
common_vendor.index.__f__("error", "at pages/hiddendanger/rectification.vue:296", "提交整改失败:", error);
|
||||
common_vendor.index.showToast({
|
||||
title: "操作失败",
|
||||
icon: "none"
|
||||
});
|
||||
}
|
||||
};
|
||||
const fetchRectifyDetail = async () => {
|
||||
try {
|
||||
common_vendor.index.showLoading({ title: "加载中..." });
|
||||
const res = await request_api.getRectifyDetail({ rectifyId: rectifyId.value });
|
||||
common_vendor.index.hideLoading();
|
||||
if (res.code === 0 && res.data) {
|
||||
const data = res.data;
|
||||
formData.rectifyPlan = data.rectifyPlan || "";
|
||||
formData.rectifyResult = data.rectifyResult || "";
|
||||
formData.planCost = data.planCost ? String(data.planCost) : "";
|
||||
formData.actualCost = data.actualCost ? String(data.actualCost) : "";
|
||||
hazardId.value = data.hazardId || "";
|
||||
assignId.value = data.assignId || "";
|
||||
if (data.attachments && data.attachments.length > 0) {
|
||||
fileList1.value = data.attachments.map((att) => ({
|
||||
url: att.filePath.startsWith("http") ? att.filePath : request_request.baseUrl.replace("/api", "") + att.filePath,
|
||||
status: "success",
|
||||
message: "",
|
||||
name: att.fileName,
|
||||
type: att.fileType,
|
||||
filePath: att.filePath
|
||||
// 保存原始路径用于提交
|
||||
}));
|
||||
}
|
||||
if (data.memberIds) {
|
||||
const memberIdArr = data.memberIds.split(",").map((id) => String(id.trim()));
|
||||
selectedUserIds.value = memberIdArr;
|
||||
setTimeout(() => {
|
||||
selectedUsers.value = cateList.value.filter((item) => memberIdArr.includes(item.id));
|
||||
}, 500);
|
||||
} else if (data.rectifierId) {
|
||||
selectedUserIds.value = [String(data.rectifierId)];
|
||||
setTimeout(() => {
|
||||
selectedUsers.value = cateList.value.filter((item) => item.id === String(data.rectifierId));
|
||||
}, 500);
|
||||
}
|
||||
common_vendor.index.setNavigationBarTitle({ title: "编辑整改信息" });
|
||||
}
|
||||
} catch (error) {
|
||||
common_vendor.index.hideLoading();
|
||||
common_vendor.index.__f__("error", "at pages/hiddendanger/rectification.vue:356", "获取整改详情失败:", error);
|
||||
common_vendor.index.showToast({ title: "获取详情失败", icon: "none" });
|
||||
}
|
||||
};
|
||||
const aiGenerating = common_vendor.ref(false);
|
||||
const handleAiGenerate = async () => {
|
||||
if (!hazardId.value) {
|
||||
common_vendor.index.showToast({ title: "缺少隐患信息", icon: "none" });
|
||||
return;
|
||||
}
|
||||
aiGenerating.value = true;
|
||||
try {
|
||||
const detailRes = await request_api.getHiddenDangerDetail({
|
||||
hazardId: hazardId.value,
|
||||
assignId: assignId.value
|
||||
});
|
||||
if (detailRes.code !== 0 || !detailRes.data) {
|
||||
common_vendor.index.showToast({ title: "获取隐患详情失败", icon: "none" });
|
||||
return;
|
||||
}
|
||||
const { title, description } = detailRes.data;
|
||||
const aiRes = await request_api.generateRectifyPlan({ title, description });
|
||||
if (aiRes.code === 0 && aiRes.data) {
|
||||
if (aiRes.data.rawResponse) {
|
||||
formData.rectifyPlan = aiRes.data.rawResponse;
|
||||
}
|
||||
common_vendor.index.showToast({ title: "AI生成完成", icon: "success", duration: 2e3 });
|
||||
} else {
|
||||
common_vendor.index.showToast({ title: aiRes.msg || "AI生成失败", icon: "none" });
|
||||
}
|
||||
} catch (error) {
|
||||
common_vendor.index.__f__("error", "at pages/hiddendanger/rectification.vue:393", "AI生成整改方案失败:", error);
|
||||
common_vendor.index.showToast({ title: "AI生成失败,请重试", icon: "none" });
|
||||
} finally {
|
||||
aiGenerating.value = false;
|
||||
}
|
||||
};
|
||||
common_vendor.onLoad((options) => {
|
||||
if (options.hazardId) {
|
||||
hazardId.value = options.hazardId;
|
||||
}
|
||||
if (options.assignId) {
|
||||
assignId.value = options.assignId;
|
||||
}
|
||||
fetchDeptUsers();
|
||||
if (options.rectifyId) {
|
||||
rectifyId.value = options.rectifyId;
|
||||
isEdit.value = options.isEdit === "1";
|
||||
fetchRectifyDetail();
|
||||
}
|
||||
});
|
||||
return (_ctx, _cache) => {
|
||||
return common_vendor.e({
|
||||
a: !aiGenerating.value
|
||||
}, !aiGenerating.value ? {} : {}, {
|
||||
b: common_vendor.t(aiGenerating.value ? "AI生成中..." : "AI生成整改方案"),
|
||||
c: aiGenerating.value,
|
||||
d: aiGenerating.value,
|
||||
e: common_vendor.o(handleAiGenerate),
|
||||
f: common_vendor.o(($event) => formData.rectifyPlan = $event),
|
||||
g: common_vendor.p({
|
||||
placeholder: "请输入内容",
|
||||
maxlength: -1,
|
||||
autoHeight: true,
|
||||
modelValue: formData.rectifyPlan
|
||||
}),
|
||||
h: common_vendor.o(($event) => formData.rectifyResult = $event),
|
||||
i: common_vendor.p({
|
||||
placeholder: "请输入内容",
|
||||
modelValue: formData.rectifyResult
|
||||
}),
|
||||
j: common_vendor.o(($event) => formData.planCost = $event),
|
||||
k: common_vendor.p({
|
||||
placeholder: "请输入内容",
|
||||
type: "number",
|
||||
modelValue: formData.planCost
|
||||
}),
|
||||
l: common_vendor.o(($event) => formData.actualCost = $event),
|
||||
m: common_vendor.p({
|
||||
placeholder: "请输入内容",
|
||||
type: "number",
|
||||
modelValue: formData.actualCost
|
||||
}),
|
||||
n: common_vendor.o(($event) => value1.value = $event),
|
||||
o: common_vendor.p({
|
||||
hasInput: true,
|
||||
show: show.value,
|
||||
mode: "date",
|
||||
modelValue: value1.value
|
||||
}),
|
||||
p: common_vendor.t(selectedUsers.value.length > 0 ? selectedUsersText.value : "请选择整改人员(可多选)"),
|
||||
q: selectedUsers.value.length === 0 ? 1 : "",
|
||||
r: common_vendor.o(($event) => showUserPopup.value = true),
|
||||
s: common_vendor.o(($event) => showUserPopup.value = false),
|
||||
t: common_vendor.f(cateList.value, (item, k0, i0) => {
|
||||
return {
|
||||
a: "f18ba0ce-7-" + i0 + ",f18ba0ce-6",
|
||||
b: common_vendor.p({
|
||||
label: item.name,
|
||||
name: item.id,
|
||||
activeColor: "#2667E9",
|
||||
shape: "square"
|
||||
}),
|
||||
c: item.id
|
||||
};
|
||||
}),
|
||||
v: common_vendor.o(onUserChange),
|
||||
w: common_vendor.o(($event) => selectedUserIds.value = $event),
|
||||
x: common_vendor.p({
|
||||
placement: "column",
|
||||
modelValue: selectedUserIds.value
|
||||
}),
|
||||
y: common_vendor.o(($event) => showUserPopup.value = false),
|
||||
z: common_vendor.o(confirmUserSelect),
|
||||
A: common_vendor.o(($event) => showUserPopup.value = false),
|
||||
B: common_vendor.p({
|
||||
show: showUserPopup.value,
|
||||
mode: "bottom",
|
||||
round: "20"
|
||||
}),
|
||||
C: common_vendor.o(afterRead),
|
||||
D: common_vendor.o(deletePic),
|
||||
E: common_vendor.p({
|
||||
fileList: fileList1.value,
|
||||
name: "1",
|
||||
multiple: true,
|
||||
maxCount: 10
|
||||
}),
|
||||
F: common_vendor.t(isEdit.value ? "保存修改" : "提交整改"),
|
||||
G: common_vendor.o(handleSubmit),
|
||||
H: common_vendor.gei(_ctx, "")
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-f18ba0ce"]]);
|
||||
wx.createPage(MiniProgramPage);
|
||||
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/hiddendanger/rectification.js.map
|
||||
Reference in New Issue
Block a user