299 lines
12 KiB
JavaScript
299 lines
12 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const request_api = require("../../request/api.js");
|
|
const utils_draftCache = require("../../utils/draftCache.js");
|
|
const utils_useDraftCache = require("../../utils/useDraftCache.js");
|
|
const components_hazard_hazardForm = require("../../components/hazard/hazardForm.js");
|
|
if (!Array) {
|
|
const _easycom_u_radio2 = common_vendor.resolveComponent("u-radio");
|
|
const _easycom_u_radio_group2 = common_vendor.resolveComponent("u-radio-group");
|
|
const _easycom_up_textarea2 = common_vendor.resolveComponent("up-textarea");
|
|
(_easycom_u_radio2 + _easycom_u_radio_group2 + _easycom_up_textarea2)();
|
|
}
|
|
const _easycom_u_radio = () => "../../uni_modules/uview-plus/components/u-radio/u-radio.js";
|
|
const _easycom_u_radio_group = () => "../../uni_modules/uview-plus/components/u-radio-group/u-radio-group.js";
|
|
const _easycom_up_textarea = () => "../../uni_modules/uview-plus/components/u-textarea/u-textarea.js";
|
|
if (!Math) {
|
|
(_easycom_u_radio + _easycom_u_radio_group + _easycom_up_textarea + HazardFormPopup)();
|
|
}
|
|
const HazardFormPopup = () => "../../components/hazard/HazardFormPopup.js";
|
|
const _sfc_main = {
|
|
__name: "Inspectionresult",
|
|
setup(__props) {
|
|
const oneTableId = common_vendor.ref("");
|
|
const checkData = common_vendor.ref(null);
|
|
const hazardFormRef = common_vendor.ref(null);
|
|
const showHazardPopup = common_vendor.ref(false);
|
|
const hazardPayload = common_vendor.ref(components_hazard_hazardForm.createEmptyHazardPayload());
|
|
const radiolist1 = common_vendor.reactive([
|
|
{ name: "正常", value: 1, disabled: false },
|
|
{ name: "异常", value: 2, disabled: false },
|
|
{ name: "不涉及", value: 3, disabled: false }
|
|
]);
|
|
const radiovalue1 = common_vendor.ref("");
|
|
const value1 = common_vendor.ref("");
|
|
const normalizeInspectionDraft = (data) => {
|
|
if (!data)
|
|
return { radiovalue1: "", value1: "", hazardPayload: components_hazard_hazardForm.createEmptyHazardPayload() };
|
|
if (!data.hazardPayload && data.hazardFormData) {
|
|
data.hazardPayload = {
|
|
formData: data.hazardFormData,
|
|
address: data.hazardAddress || "",
|
|
lng: data.hazardLng || 0,
|
|
lat: data.hazardLat || 0,
|
|
areaId: "",
|
|
areaName: "",
|
|
fileList: data.hazardFileList || []
|
|
};
|
|
}
|
|
return {
|
|
radiovalue1: data.radiovalue1 || "",
|
|
value1: data.value1 || "",
|
|
hazardPayload: data.hazardPayload || components_hazard_hazardForm.createEmptyHazardPayload()
|
|
};
|
|
};
|
|
const inspectionDraftHasContent = (data) => {
|
|
var _a, _b;
|
|
const normalized = normalizeInspectionDraft(data);
|
|
const payload = normalized.hazardPayload;
|
|
return !!(normalized.radiovalue1 || normalized.value1 || ((_a = payload.formData) == null ? void 0 : _a.title) || ((_b = payload.formData) == null ? void 0 : _b.description) || payload.fileList && payload.fileList.length > 0);
|
|
};
|
|
const {
|
|
showRestoreBanner,
|
|
clear: clearDraft,
|
|
restore: restoreDraft,
|
|
bindAutoSave
|
|
} = utils_useDraftCache.useDraftCache({
|
|
getKey: () => {
|
|
var _a;
|
|
return utils_draftCache.buildDraftKey(
|
|
utils_draftCache.DRAFT_NS.INSPECTION_RESULT,
|
|
oneTableId.value,
|
|
(_a = checkData.value) == null ? void 0 : _a.currentIndex
|
|
);
|
|
},
|
|
getPayload: () => ({
|
|
radiovalue1: radiovalue1.value,
|
|
value1: value1.value,
|
|
hazardPayload: JSON.parse(JSON.stringify(hazardPayload.value))
|
|
}),
|
|
hasContent: inspectionDraftHasContent,
|
|
applyPayload: (data) => {
|
|
const normalized = normalizeInspectionDraft(data);
|
|
radiovalue1.value = normalized.radiovalue1;
|
|
value1.value = normalized.value1;
|
|
hazardPayload.value = normalized.hazardPayload;
|
|
common_vendor.nextTick$1(() => {
|
|
var _a;
|
|
(_a = hazardFormRef.value) == null ? void 0 : _a.applyPayload(normalized.hazardPayload);
|
|
});
|
|
},
|
|
clearForm: () => {
|
|
radiovalue1.value = "";
|
|
value1.value = "";
|
|
clearHazard();
|
|
},
|
|
canSave: () => !!oneTableId.value,
|
|
requireInitialized: true
|
|
});
|
|
bindAutoSave(() => [radiovalue1.value, value1.value, hazardPayload.value]);
|
|
const groupChange = (n) => {
|
|
if (n !== "异常") {
|
|
clearHazard();
|
|
}
|
|
};
|
|
const radioChange = (n) => {
|
|
common_vendor.index.__f__("log", "at pages/Inspectionresult/Inspectionresult.vue:207", "radioChange", n);
|
|
};
|
|
const hasHazardData = common_vendor.computed(() => components_hazard_hazardForm.hasValidHazardPayload(hazardPayload.value));
|
|
const progressPercent = common_vendor.computed(() => {
|
|
if (!checkData.value)
|
|
return 0;
|
|
const current = checkData.value.currentIndex || 1;
|
|
const total = checkData.value.totalCount || 1;
|
|
return Math.round(current / total * 100);
|
|
});
|
|
const openHazardPopup = () => {
|
|
showHazardPopup.value = true;
|
|
};
|
|
const editHazard = () => {
|
|
showHazardPopup.value = true;
|
|
};
|
|
const onHazardConfirm = (payload) => {
|
|
if (payload) {
|
|
hazardPayload.value = JSON.parse(JSON.stringify(payload));
|
|
}
|
|
};
|
|
const clearHazard = () => {
|
|
var _a;
|
|
hazardPayload.value = components_hazard_hazardForm.createEmptyHazardPayload();
|
|
(_a = hazardFormRef.value) == null ? void 0 : _a.resetForm();
|
|
};
|
|
const handleSubmit = async () => {
|
|
var _a, _b, _c, _d;
|
|
if (!radiovalue1.value) {
|
|
common_vendor.index.showToast({ title: "请选择检查结果", icon: "none" });
|
|
return;
|
|
}
|
|
const selectedItem = radiolist1.find((item) => item.name === radiovalue1.value);
|
|
const resultValue = selectedItem ? selectedItem.value : null;
|
|
if (!resultValue) {
|
|
common_vendor.index.showToast({ title: "请选择检查结果", icon: "none" });
|
|
return;
|
|
}
|
|
if (radiovalue1.value === "异常" && !hasHazardData.value) {
|
|
common_vendor.index.showToast({ title: "请填写隐患信息", icon: "none" });
|
|
return;
|
|
}
|
|
try {
|
|
common_vendor.index.showLoading({ title: "提交中..." });
|
|
if (radiovalue1.value === "异常" && hasHazardData.value) {
|
|
const payload = ((_a = hazardFormRef.value) == null ? void 0 : _a.getPayload()) || hazardPayload.value;
|
|
const hazardParams = components_hazard_hazardForm.buildHiddenDangerParams(payload, {
|
|
taskId: (_b = checkData.value) == null ? void 0 : _b.taskId,
|
|
checkPointId: (_c = checkData.value) == null ? void 0 : _c.checkPointId
|
|
});
|
|
const hazardRes = await request_api.addHiddenDanger(hazardParams);
|
|
if (hazardRes.code !== 0) {
|
|
common_vendor.index.hideLoading();
|
|
common_vendor.index.showToast({ title: hazardRes.msg || "新增隐患失败", icon: "none" });
|
|
return;
|
|
}
|
|
}
|
|
const submitParams = {
|
|
taskId: (_d = checkData.value) == null ? void 0 : _d.taskId,
|
|
result: resultValue,
|
|
remark: value1.value
|
|
};
|
|
const res = await request_api.submitCheckResult(submitParams);
|
|
common_vendor.index.hideLoading();
|
|
if (res.code === 0) {
|
|
clearDraft(false);
|
|
if (res.data && res.data.allFinished === true) {
|
|
common_vendor.index.showToast({ title: "全部检查已完成", icon: "success" });
|
|
setTimeout(() => {
|
|
common_vendor.index.navigateBack();
|
|
}, 1500);
|
|
} else if (res.data && res.data.nextTask) {
|
|
common_vendor.index.showToast({ title: "提交成功,进入下一题", icon: "success" });
|
|
resetFormState();
|
|
checkData.value = res.data.nextTask;
|
|
} else {
|
|
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.hideLoading();
|
|
common_vendor.index.__f__("error", "at pages/Inspectionresult/Inspectionresult.vue:306", "提交失败:", error);
|
|
common_vendor.index.showToast({ title: "提交失败", icon: "none" });
|
|
}
|
|
};
|
|
const resetFormState = () => {
|
|
radiovalue1.value = "";
|
|
value1.value = "";
|
|
clearHazard();
|
|
};
|
|
const getCheckData = async () => {
|
|
try {
|
|
const res = await request_api.enterCheckPlan(oneTableId.value);
|
|
if (res.code === 0) {
|
|
checkData.value = res.data;
|
|
restoreDraft();
|
|
}
|
|
} catch (error) {
|
|
common_vendor.index.__f__("error", "at pages/Inspectionresult/Inspectionresult.vue:325", error);
|
|
}
|
|
};
|
|
common_vendor.onLoad((options) => {
|
|
if (options.id) {
|
|
oneTableId.value = options.id;
|
|
getCheckData();
|
|
}
|
|
});
|
|
return (_ctx, _cache) => {
|
|
var _a, _b, _c, _d;
|
|
return common_vendor.e({
|
|
a: checkData.value
|
|
}, checkData.value ? {
|
|
b: common_vendor.t(checkData.value.currentIndex || 1),
|
|
c: common_vendor.t(checkData.value.totalCount || 1),
|
|
d: progressPercent.value + "%"
|
|
} : {}, {
|
|
e: common_vendor.t(((_a = checkData.value) == null ? void 0 : _a.name) || "加载中..."),
|
|
f: ((_b = checkData.value) == null ? void 0 : _b.point) || "",
|
|
g: common_vendor.f(radiolist1, (item, index, i0) => {
|
|
return {
|
|
a: index,
|
|
b: common_vendor.o(radioChange, index),
|
|
c: "643afff0-1-" + i0 + ",643afff0-0",
|
|
d: common_vendor.p({
|
|
customStyle: {
|
|
marginBottom: "8px"
|
|
},
|
|
label: item.name,
|
|
name: item.name
|
|
})
|
|
};
|
|
}),
|
|
h: common_vendor.o(groupChange),
|
|
i: common_vendor.o(($event) => radiovalue1.value = $event),
|
|
j: common_vendor.p({
|
|
placement: "row",
|
|
modelValue: radiovalue1.value
|
|
}),
|
|
k: radiovalue1.value === "异常"
|
|
}, radiovalue1.value === "异常" ? common_vendor.e({
|
|
l: !hasHazardData.value
|
|
}, !hasHazardData.value ? {
|
|
m: common_vendor.o(openHazardPopup)
|
|
} : common_vendor.e({
|
|
n: common_vendor.t(hazardPayload.value.formData.title),
|
|
o: common_vendor.t((_c = common_vendor.unref(components_hazard_hazardForm.LEVEL_OPTIONS)[hazardPayload.value.formData.level]) == null ? void 0 : _c.title),
|
|
p: hazardPayload.value.formData.level === 0 ? 1 : "",
|
|
q: hazardPayload.value.formData.level === 1 ? 1 : "",
|
|
r: hazardPayload.value.formData.level === 2 ? 1 : "",
|
|
s: common_vendor.t(((_d = common_vendor.unref(components_hazard_hazardForm.SOURCE_OPTIONS)[hazardPayload.value.formData.source]) == null ? void 0 : _d.title) || "-"),
|
|
t: common_vendor.t(hazardPayload.value.address || "-"),
|
|
v: common_vendor.t(hazardPayload.value.formData.description || "-"),
|
|
w: hazardPayload.value.fileList.length > 0
|
|
}, hazardPayload.value.fileList.length > 0 ? {
|
|
x: common_vendor.t(hazardPayload.value.fileList.length)
|
|
} : {}, {
|
|
y: common_vendor.o(editHazard),
|
|
z: common_vendor.o(clearHazard)
|
|
})) : {}, {
|
|
A: common_vendor.o(($event) => value1.value = $event),
|
|
B: common_vendor.p({
|
|
placeholder: "请输入备注信息",
|
|
modelValue: value1.value
|
|
}),
|
|
C: common_vendor.o(handleSubmit),
|
|
D: common_vendor.sr(hazardFormRef, "643afff0-3", {
|
|
"k": "hazardFormRef"
|
|
}),
|
|
E: common_vendor.o(onHazardConfirm),
|
|
F: common_vendor.o(($event) => common_vendor.unref(clearDraft)(true)),
|
|
G: common_vendor.o(($event) => showHazardPopup.value = $event),
|
|
H: common_vendor.o(($event) => hazardPayload.value = $event),
|
|
I: common_vendor.p({
|
|
title: "填写隐患信息",
|
|
mode: "collect",
|
|
["body-height"]: "60vh",
|
|
["show-draft-banner"]: common_vendor.unref(showRestoreBanner),
|
|
show: showHazardPopup.value,
|
|
modelValue: hazardPayload.value
|
|
}),
|
|
J: common_vendor.gei(_ctx, "")
|
|
});
|
|
};
|
|
}
|
|
};
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-643afff0"]]);
|
|
wx.createPage(MiniProgramPage);
|
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/Inspectionresult/Inspectionresult.js.map
|