457 lines
18 KiB
JavaScript
457 lines
18 KiB
JavaScript
"use strict";
|
||
const common_vendor = require("../../common/vendor.js");
|
||
const request_api = require("../../request/api.js");
|
||
const utils_hazardNav = require("../../utils/hazardNav.js");
|
||
if (!Array) {
|
||
const _easycom_up_textarea2 = common_vendor.resolveComponent("up-textarea");
|
||
const _easycom_up_radio2 = common_vendor.resolveComponent("up-radio");
|
||
const _easycom_up_radio_group2 = common_vendor.resolveComponent("up-radio-group");
|
||
const _easycom_up_picker2 = common_vendor.resolveComponent("up-picker");
|
||
(_easycom_up_textarea2 + _easycom_up_radio2 + _easycom_up_radio_group2 + _easycom_up_picker2)();
|
||
}
|
||
const _easycom_up_textarea = () => "../../uni_modules/uview-plus/components/u-textarea/u-textarea.js";
|
||
const _easycom_up_radio = () => "../../uni_modules/uview-plus/components/u-radio/u-radio.js";
|
||
const _easycom_up_radio_group = () => "../../uni_modules/uview-plus/components/u-radio-group/u-radio-group.js";
|
||
const _easycom_up_picker = () => "../../uni_modules/uview-plus/components/u-picker/u-picker.js";
|
||
if (!Math) {
|
||
(_easycom_up_textarea + _easycom_up_radio + _easycom_up_radio_group + _easycom_up_picker)();
|
||
}
|
||
const _sfc_main = {
|
||
__name: "apply",
|
||
setup(__props) {
|
||
const showHazardPicker = common_vendor.ref(false);
|
||
const hazardLocked = common_vendor.ref(false);
|
||
const selectedHazard = common_vendor.ref("");
|
||
const selectedHazardId = common_vendor.ref("");
|
||
const assignId = common_vendor.ref("");
|
||
const taskId = common_vendor.ref("");
|
||
const hazardColumns = common_vendor.ref([["暂无数据"]]);
|
||
const selectableHazardList = common_vendor.ref([]);
|
||
const selectedDeptName = common_vendor.ref("");
|
||
const aiGenerating = common_vendor.ref(false);
|
||
const hazardEndRadio = common_vendor.ref("no");
|
||
const hazardEnd = common_vendor.computed(() => hazardEndRadio.value === "yes");
|
||
const normalizeHazardEndRadio = (value) => value === "yes" ? "yes" : "no";
|
||
const sendMsgFlagRadio = common_vendor.ref("yes");
|
||
const sendMsgFlag = common_vendor.computed(() => sendMsgFlagRadio.value === "yes");
|
||
const nextStepName = common_vendor.ref("");
|
||
const nextStepLoading = common_vendor.ref(false);
|
||
const nextStepDisplay = common_vendor.computed(() => {
|
||
if (nextStepLoading.value)
|
||
return "加载中...";
|
||
return nextStepName.value || "暂无下一步流程";
|
||
});
|
||
const selectedAssigneeIdentityId = common_vendor.ref("");
|
||
const selectedAssigneeName = common_vendor.ref("");
|
||
common_vendor.ref("");
|
||
common_vendor.ref("");
|
||
common_vendor.ref(false);
|
||
common_vendor.ref([]);
|
||
common_vendor.ref(false);
|
||
const formData = common_vendor.reactive({
|
||
rectifyDeadline: "",
|
||
responsibleDeptId: "",
|
||
responsiblePerson: "",
|
||
mainTreatmentContent: "",
|
||
treatmentResult: "",
|
||
selfVerifyContent: ""
|
||
});
|
||
const fillHazardRelatedFields = (hazard) => {
|
||
formData.rectifyDeadline = hazard.deadline || "";
|
||
selectedDeptName.value = hazard.deptName || "";
|
||
formData.responsiblePerson = hazard.rectifierName || "";
|
||
formData.responsibleDeptId = hazard.deptId || "";
|
||
};
|
||
const resolveTaskIdFromHazard = (hazard) => {
|
||
var _a, _b;
|
||
if (!hazard)
|
||
return "";
|
||
const candidates = [
|
||
hazard.taskId,
|
||
hazard.flowTaskId,
|
||
hazard.currentTaskId,
|
||
(_a = hazard.flowTask) == null ? void 0 : _a.taskId,
|
||
(_b = hazard.currentTask) == null ? void 0 : _b.taskId
|
||
];
|
||
for (const id of candidates) {
|
||
if (id != null && id !== "")
|
||
return String(id);
|
||
}
|
||
return "";
|
||
};
|
||
const resolveTaskIdFromAssign = (assign) => {
|
||
var _a, _b, _c, _d, _e;
|
||
if (!assign)
|
||
return "";
|
||
const candidates = [
|
||
assign.taskId,
|
||
assign.flowTaskId,
|
||
assign.currentTaskId,
|
||
(_a = assign.rectify) == null ? void 0 : _a.taskId,
|
||
(_b = assign.rectify) == null ? void 0 : _b.flowTaskId,
|
||
(_c = assign.rectify) == null ? void 0 : _c.currentTaskId,
|
||
(_d = assign.flow) == null ? void 0 : _d.taskId,
|
||
(_e = assign.currentTask) == null ? void 0 : _e.taskId
|
||
];
|
||
for (const id of candidates) {
|
||
if (id != null && id !== "")
|
||
return String(id);
|
||
}
|
||
return "";
|
||
};
|
||
const resolveAssignWithRectify = (assigns, currentAssignId) => {
|
||
if (!(assigns == null ? void 0 : assigns.length))
|
||
return null;
|
||
if (currentAssignId) {
|
||
const byAssignId = assigns.find(
|
||
(item) => String(item.assignId) === String(currentAssignId) && item.rectify
|
||
);
|
||
if (byAssignId)
|
||
return byAssignId;
|
||
}
|
||
return assigns.find((item) => item.rectify) || assigns[0] || null;
|
||
};
|
||
const resolveTaskIdFromDetail = (data) => {
|
||
if (!data)
|
||
return "";
|
||
if (data.taskId)
|
||
return String(data.taskId);
|
||
if (data.flowTaskId)
|
||
return String(data.flowTaskId);
|
||
if (data.currentTaskId)
|
||
return String(data.currentTaskId);
|
||
const assigns = data.assigns || [];
|
||
const matchedAssign = resolveAssignWithRectify(assigns, assignId.value);
|
||
const fromMatched = resolveTaskIdFromAssign(matchedAssign);
|
||
if (fromMatched)
|
||
return fromMatched;
|
||
for (const assign of assigns) {
|
||
const id = resolveTaskIdFromAssign(assign);
|
||
if (id)
|
||
return id;
|
||
}
|
||
return "";
|
||
};
|
||
const resolveNextTaskName = (data) => {
|
||
var _a;
|
||
if (!data)
|
||
return "";
|
||
const branches = data.branches || [];
|
||
const matchedBranch = branches.find((item) => item.matched) || branches[0];
|
||
return ((_a = matchedBranch == null ? void 0 : matchedBranch.nextNode) == null ? void 0 : _a.taskName) || "";
|
||
};
|
||
const buildPreviewVariables = () => ({
|
||
quickApprove: true
|
||
});
|
||
const fetchNextStep = async () => {
|
||
nextStepLoading.value = true;
|
||
try {
|
||
const currentTaskId = taskId.value;
|
||
if (!currentTaskId) {
|
||
nextStepName.value = "";
|
||
return;
|
||
}
|
||
const res = await request_api.getFlowNextNodes({
|
||
taskId: currentTaskId,
|
||
previewVariables: buildPreviewVariables(),
|
||
includeSubProcess: true
|
||
});
|
||
if (res.code === 0) {
|
||
const payload = res.data && typeof res.data === "object" ? res.data : res;
|
||
nextStepName.value = resolveNextTaskName(payload);
|
||
} else {
|
||
nextStepName.value = "";
|
||
}
|
||
} catch (error) {
|
||
common_vendor.index.__f__("error", "at pages/closeout/apply.vue:384", "获取下一步流程失败:", error);
|
||
nextStepName.value = "";
|
||
} finally {
|
||
nextStepLoading.value = false;
|
||
}
|
||
};
|
||
const resolveTaskIdForHazard = async (hazard) => {
|
||
const presetTaskId = taskId.value;
|
||
const fromHazard = resolveTaskIdFromHazard(hazard);
|
||
if (fromHazard) {
|
||
taskId.value = fromHazard;
|
||
}
|
||
if (!(hazard == null ? void 0 : hazard.hazardId)) {
|
||
return;
|
||
}
|
||
if (!assignId.value && hazard.assignId) {
|
||
assignId.value = String(hazard.assignId);
|
||
}
|
||
if (taskId.value) {
|
||
return;
|
||
}
|
||
try {
|
||
const params = { hazardId: hazard.hazardId };
|
||
if (assignId.value) {
|
||
params.assignId = assignId.value;
|
||
}
|
||
const res = await request_api.getHiddenDangerDetail(params);
|
||
if (res.code === 0 && res.data) {
|
||
taskId.value = resolveTaskIdFromDetail(res.data) || presetTaskId;
|
||
}
|
||
} catch (error) {
|
||
common_vendor.index.__f__("error", "at pages/closeout/apply.vue:420", "获取隐患任务信息失败:", error);
|
||
}
|
||
if (!taskId.value && presetTaskId) {
|
||
taskId.value = presetTaskId;
|
||
}
|
||
};
|
||
const resetFlowSelection = () => {
|
||
selectedAssigneeIdentityId.value = "";
|
||
selectedAssigneeName.value = "";
|
||
nextStepName.value = "";
|
||
};
|
||
const applySelectedHazard = async (hazard) => {
|
||
if (!hazard)
|
||
return;
|
||
selectedHazard.value = hazard.title || hazard.hazardTitle || `隐患${hazard.hazardId}`;
|
||
selectedHazardId.value = hazard.hazardId;
|
||
assignId.value = hazard.assignId ? String(hazard.assignId) : "";
|
||
if (hazard.taskId) {
|
||
taskId.value = String(hazard.taskId);
|
||
}
|
||
fillHazardRelatedFields(hazard);
|
||
resetFlowSelection();
|
||
await resolveTaskIdForHazard(hazard);
|
||
await fetchNextStep();
|
||
};
|
||
const resolveSelectableRecords = (data) => {
|
||
if (!data)
|
||
return [];
|
||
if (Array.isArray(data))
|
||
return data;
|
||
if (Array.isArray(data.records))
|
||
return data.records;
|
||
return [];
|
||
};
|
||
const canApplyWriteoff = (item) => (item == null ? void 0 : item.statusName) === "待销号" && ((item == null ? void 0 : item.applyFlag) === true || (item == null ? void 0 : item.applyFlag) === 1 || (item == null ? void 0 : item.applyFlag) === "1");
|
||
const fetchSelectableHazardList = async () => {
|
||
try {
|
||
const res = await request_api.getHiddenDangerList({ pageNum: 1, pageSize: 100, status: 4 });
|
||
if (res.code === 0 && res.data) {
|
||
const list = resolveSelectableRecords(res.data).filter(canApplyWriteoff);
|
||
selectableHazardList.value = list;
|
||
if (list.length > 0) {
|
||
hazardColumns.value = [list.map((item) => item.title || item.hazardTitle || `隐患${item.hazardId}`)];
|
||
} else {
|
||
hazardColumns.value = [["暂无可申请销号的隐患"]];
|
||
}
|
||
}
|
||
} catch (error) {
|
||
common_vendor.index.__f__("error", "at pages/closeout/apply.vue:473", "获取可申请销号隐患列表失败:", error);
|
||
}
|
||
};
|
||
const onHazardConfirm = async (e) => {
|
||
if (e.value && e.value.length > 0) {
|
||
const index = e.indexs[0];
|
||
const hazard = selectableHazardList.value[index];
|
||
if (hazard) {
|
||
await applySelectedHazard(hazard);
|
||
}
|
||
}
|
||
showHazardPicker.value = false;
|
||
};
|
||
const handleAiGenerate = async () => {
|
||
if (!selectedHazardId.value) {
|
||
common_vendor.index.showToast({ title: "请先选择隐患", icon: "none" });
|
||
return;
|
||
}
|
||
aiGenerating.value = true;
|
||
try {
|
||
const hazardRes = await request_api.getHiddenDangerDetail({ hazardId: selectedHazardId.value });
|
||
if (hazardRes.code !== 0 || !hazardRes.data) {
|
||
common_vendor.index.showToast({ title: "获取隐患详情失败", icon: "none" });
|
||
return;
|
||
}
|
||
const assigns = hazardRes.data.assigns;
|
||
if (!assigns || assigns.length === 0 || !assigns[0].rectify) {
|
||
common_vendor.index.showToast({ title: "该隐患暂无整改记录", icon: "none" });
|
||
return;
|
||
}
|
||
const rectifyId = assigns[0].rectify.rectifyId;
|
||
const rectifyRes = await request_api.getRectifyDetail({ rectifyId });
|
||
if (rectifyRes.code !== 0 || !rectifyRes.data) {
|
||
common_vendor.index.showToast({ title: "获取整改详情失败", icon: "none" });
|
||
return;
|
||
}
|
||
const rectifyPlan = rectifyRes.data.rectifyPlan;
|
||
if (!rectifyPlan) {
|
||
common_vendor.index.showToast({ title: "整改方案内容为空", icon: "none" });
|
||
return;
|
||
}
|
||
const aiRes = await request_api.generateWriteoffContent({ rectifyContent: rectifyPlan });
|
||
if (aiRes.code === 0 && aiRes.data) {
|
||
formData.mainTreatmentContent = aiRes.data.mainContent || "";
|
||
formData.treatmentResult = aiRes.data.completionContent || "";
|
||
formData.selfVerifyContent = aiRes.data.selfInspection || "";
|
||
common_vendor.index.showToast({ title: "AI生成成功", icon: "success" });
|
||
} else {
|
||
common_vendor.index.showToast({ title: aiRes.msg || "AI生成失败", icon: "none" });
|
||
}
|
||
} catch (error) {
|
||
common_vendor.index.__f__("error", "at pages/closeout/apply.vue:538", "AI生成销号方案失败:", error);
|
||
common_vendor.index.showToast({ title: "AI生成失败,请重试", icon: "none" });
|
||
} finally {
|
||
aiGenerating.value = false;
|
||
}
|
||
};
|
||
const handleCancel = () => {
|
||
common_vendor.index.navigateBack();
|
||
};
|
||
const handleSubmit = async () => {
|
||
if (!selectedHazardId.value) {
|
||
common_vendor.index.showToast({ title: "请选择隐患", icon: "none" });
|
||
return;
|
||
}
|
||
const params = {
|
||
hazardId: Number(selectedHazardId.value),
|
||
rectifyDeadline: formData.rectifyDeadline || "",
|
||
responsibleDeptId: Number(formData.responsibleDeptId) || 0,
|
||
responsiblePerson: formData.responsiblePerson || "",
|
||
mainTreatmentContent: formData.mainTreatmentContent || "",
|
||
treatmentResult: formData.treatmentResult || "",
|
||
selfVerifyContent: formData.selfVerifyContent || "",
|
||
hazardEnd: hazardEnd.value,
|
||
quickApprove: hazardEnd.value ? null : true,
|
||
sendMsgFlag: hazardEnd.value ? null : sendMsgFlag.value
|
||
};
|
||
try {
|
||
const res = await request_api.applyDelete(params);
|
||
if (res.code === 0) {
|
||
common_vendor.index.showToast({ title: "申请成功", icon: "success" });
|
||
setTimeout(() => {
|
||
common_vendor.index.navigateBack();
|
||
}, 1500);
|
||
} else {
|
||
common_vendor.index.showToast({ title: res.msg || "申请失败", icon: "none" });
|
||
}
|
||
} catch (error) {
|
||
common_vendor.index.__f__("error", "at pages/closeout/apply.vue:588", "申请失败:", error);
|
||
common_vendor.index.showToast({ title: "请求失败", icon: "none" });
|
||
}
|
||
};
|
||
common_vendor.onLoad(async (options) => {
|
||
hazardLocked.value = (options == null ? void 0 : options.locked) === "1";
|
||
if (options == null ? void 0 : options.assignId) {
|
||
assignId.value = String(options.assignId);
|
||
}
|
||
if (options == null ? void 0 : options.taskId) {
|
||
taskId.value = String(options.taskId);
|
||
}
|
||
const hazardFromOptions = utils_hazardNav.buildWriteoffHazardFromOptions(options);
|
||
if (hazardFromOptions == null ? void 0 : hazardFromOptions.hazardId) {
|
||
await applySelectedHazard(hazardFromOptions);
|
||
} else {
|
||
if (!hazardLocked.value) {
|
||
await fetchSelectableHazardList();
|
||
}
|
||
if (taskId.value) {
|
||
await fetchNextStep();
|
||
}
|
||
}
|
||
common_vendor.nextTick$1(() => {
|
||
hazardEndRadio.value = normalizeHazardEndRadio(hazardEndRadio.value);
|
||
});
|
||
});
|
||
return (_ctx, _cache) => {
|
||
return common_vendor.e({
|
||
a: hazardLocked.value
|
||
}, hazardLocked.value ? {
|
||
b: common_vendor.t(selectedHazard.value || "加载中..."),
|
||
c: common_vendor.n(selectedHazard.value ? "" : "text-gray")
|
||
} : {
|
||
d: common_vendor.t(selectedHazard.value || "请选择隐患"),
|
||
e: common_vendor.n(selectedHazard.value ? "" : "text-gray"),
|
||
f: common_vendor.o(($event) => showHazardPicker.value = true)
|
||
}, {
|
||
g: common_vendor.t(formData.rectifyDeadline || "请先选择隐患"),
|
||
h: common_vendor.n(formData.rectifyDeadline ? "" : "text-gray"),
|
||
i: common_vendor.t(selectedDeptName.value || "请先选择隐患"),
|
||
j: common_vendor.n(selectedDeptName.value ? "" : "text-gray"),
|
||
k: common_vendor.t(formData.responsiblePerson || "请先选择隐患"),
|
||
l: common_vendor.n(formData.responsiblePerson ? "" : "text-gray"),
|
||
m: !aiGenerating.value
|
||
}, !aiGenerating.value ? {} : {}, {
|
||
n: common_vendor.t(aiGenerating.value ? "AI生成中..." : "AI 生成销号方案"),
|
||
o: aiGenerating.value,
|
||
p: aiGenerating.value,
|
||
q: common_vendor.o(handleAiGenerate),
|
||
r: common_vendor.o(($event) => formData.mainTreatmentContent = $event),
|
||
s: common_vendor.p({
|
||
placeholder: "请输入主要治理内容",
|
||
modelValue: formData.mainTreatmentContent
|
||
}),
|
||
t: common_vendor.o(($event) => formData.treatmentResult = $event),
|
||
v: common_vendor.p({
|
||
placeholder: "请输入隐患治理完成情况",
|
||
modelValue: formData.treatmentResult
|
||
}),
|
||
w: common_vendor.o(($event) => formData.selfVerifyContent = $event),
|
||
x: common_vendor.p({
|
||
placeholder: "请输入隐患治理责任单位自行验收的情况",
|
||
modelValue: formData.selfVerifyContent
|
||
}),
|
||
y: common_vendor.p({
|
||
label: "否",
|
||
name: "no",
|
||
customStyle: {
|
||
marginRight: "48rpx"
|
||
}
|
||
}),
|
||
z: common_vendor.p({
|
||
label: "是",
|
||
name: "yes"
|
||
}),
|
||
A: "hazard-end-" + hazardEndRadio.value,
|
||
B: common_vendor.o(($event) => hazardEndRadio.value = $event),
|
||
C: common_vendor.p({
|
||
placement: "row",
|
||
activeColor: "#2667e9",
|
||
modelValue: hazardEndRadio.value
|
||
}),
|
||
D: !hazardEnd.value
|
||
}, !hazardEnd.value ? {
|
||
E: common_vendor.t(nextStepDisplay.value),
|
||
F: common_vendor.p({
|
||
label: "是",
|
||
name: "yes",
|
||
customStyle: {
|
||
marginRight: "48rpx"
|
||
}
|
||
}),
|
||
G: common_vendor.p({
|
||
label: "否",
|
||
name: "no"
|
||
}),
|
||
H: common_vendor.o(($event) => sendMsgFlagRadio.value = $event),
|
||
I: common_vendor.p({
|
||
placement: "row",
|
||
activeColor: "#2667e9",
|
||
modelValue: sendMsgFlagRadio.value
|
||
})
|
||
} : {}, {
|
||
J: common_vendor.o(handleCancel),
|
||
K: common_vendor.o(handleSubmit),
|
||
L: !hazardLocked.value
|
||
}, !hazardLocked.value ? {
|
||
M: common_vendor.o(onHazardConfirm),
|
||
N: common_vendor.o(($event) => showHazardPicker.value = false),
|
||
O: common_vendor.o(($event) => showHazardPicker.value = false),
|
||
P: common_vendor.p({
|
||
show: showHazardPicker.value,
|
||
columns: hazardColumns.value
|
||
})
|
||
} : {}, {
|
||
Q: common_vendor.gei(_ctx, "")
|
||
});
|
||
};
|
||
}
|
||
};
|
||
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-15674ee6"]]);
|
||
wx.createPage(MiniProgramPage);
|
||
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/closeout/apply.js.map
|