Files
threeonecheck_web/unpackage/dist/dev/mp-weixin/pages/hiddendanger/assignment.js

290 lines
11 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const request_api = require("../../request/api.js");
if (!Array) {
const _easycom_u_popup2 = common_vendor.resolveComponent("u-popup");
const _easycom_up_datetime_picker2 = common_vendor.resolveComponent("up-datetime-picker");
(_easycom_u_popup2 + _easycom_up_datetime_picker2)();
}
const _easycom_u_popup = () => "../../uni_modules/uview-plus/components/u-popup/u-popup.js";
const _easycom_up_datetime_picker = () => "../../uni_modules/uview-plus/components/u-datetime-picker/u-datetime-picker.js";
if (!Math) {
(_easycom_u_popup + _easycom_up_datetime_picker)();
}
const _sfc_main = {
__name: "assignment",
setup(__props) {
const hazardId = common_vendor.ref("");
const assignId = common_vendor.ref("");
const showUserPopup = common_vendor.ref(false);
const selectedUser = common_vendor.ref("");
const selectedUserId = common_vendor.ref("");
const deptList = common_vendor.ref([]);
const activeDeptIndex = common_vendor.ref(0);
const userPickerSelectedId = common_vendor.ref("");
const formatUserDisplayName = (user) => {
if (user.postName) {
return `${user.nickName}_${user.postName}`;
}
return user.nickName || "";
};
const currentDeptUsers = common_vendor.computed(() => {
const dept = deptList.value[activeDeptIndex.value];
return (dept == null ? void 0 : dept.users) || [];
});
const userPickerSelectedText = common_vendor.computed(() => {
if (!userPickerSelectedId.value)
return "";
for (const dept of deptList.value) {
const user = (dept.users || []).find((u) => String(u.userId) === String(userPickerSelectedId.value));
if (user)
return formatUserDisplayName(user);
}
return "";
});
const deptHasSelectedUser = (dept) => {
var _a;
if (!userPickerSelectedId.value || !((_a = dept.users) == null ? void 0 : _a.length))
return false;
return dept.users.some((user) => String(user.userId) === String(userPickerSelectedId.value));
};
const onUserItemClick = (userId) => {
userPickerSelectedId.value = String(userId);
};
const openUserPopup = () => {
userPickerSelectedId.value = selectedUserId.value;
const firstDeptWithUsers = deptList.value.findIndex((dept) => {
var _a;
return ((_a = dept.users) == null ? void 0 : _a.length) > 0;
});
activeDeptIndex.value = firstDeptWithUsers >= 0 ? firstDeptWithUsers : 0;
showUserPopup.value = true;
};
const cancelUserSelect = () => {
showUserPopup.value = false;
};
const confirmUserSelect = () => {
if (!userPickerSelectedId.value) {
common_vendor.index.showToast({ title: "请选择整改责任人", icon: "none" });
return;
}
selectedUserId.value = String(userPickerSelectedId.value);
selectedUser.value = userPickerSelectedText.value;
showUserPopup.value = false;
};
const showDatePicker = common_vendor.ref(false);
const dateValue = common_vendor.ref(Date.now());
const selectedDate = common_vendor.ref("");
const fetchDeptUsers = async () => {
try {
const res = await request_api.getDepartmentPersonUsers();
if (res.code === 0 && res.data) {
deptList.value = res.data;
common_vendor.index.__f__("log", "at pages/hiddendanger/assignment.vue:172", "部门人员树:", deptList.value);
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/hiddendanger/assignment.vue:175", "获取部门人员失败:", error);
}
};
const onDateConfirm = (e) => {
common_vendor.index.__f__("log", "at pages/hiddendanger/assignment.vue:181", "选择的日期时间:", e);
const date = new Date(e.value);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, "0");
const hours = String(date.getHours()).padStart(2, "0");
const minutes = String(date.getMinutes()).padStart(2, "0");
const seconds = String(date.getSeconds()).padStart(2, "0");
selectedDate.value = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
showDatePicker.value = false;
};
const handleCancel = () => {
common_vendor.index.navigateBack();
};
const handleSubmit = async () => {
if (!selectedUserId.value) {
common_vendor.index.showToast({ title: "请选择整改人员", icon: "none" });
return;
}
if (!selectedDate.value) {
common_vendor.index.showToast({ title: "请选择整改期限", icon: "none" });
return;
}
const params = {
hazardId: Number(hazardId.value),
// 隐患ID
assigneeId: Number(selectedUserId.value),
// 被指派人ID
deadline: selectedDate.value,
// 处理期限
assignRemark: ""
// 交办备注(可选)
};
common_vendor.index.__f__("log", "at pages/hiddendanger/assignment.vue:217", "提交数据:", params);
try {
const res = await request_api.assignHiddenDanger(params);
if (res.code === 0) {
clearDraft(false);
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/hiddendanger/assignment.vue:231", "交办失败:", error);
common_vendor.index.showToast({ title: "请求失败", icon: "none" });
}
};
const hasDraft = common_vendor.ref(false);
const showRestoreBanner = common_vendor.ref(false);
const isRestoring = common_vendor.ref(false);
const getDraftKey = () => `draft_assign_${hazardId.value || ""}`;
const saveDraft = () => {
if (isRestoring.value)
return;
const key = getDraftKey();
const hasContent = selectedDate.value;
if (!hasContent) {
common_vendor.index.removeStorageSync(key);
hasDraft.value = false;
return;
}
const data = {
selectedDate: selectedDate.value,
dateValue: dateValue.value
};
common_vendor.index.setStorageSync(key, JSON.stringify(data));
hasDraft.value = true;
};
const clearDraft = (showToast = true) => {
const key = getDraftKey();
common_vendor.index.removeStorageSync(key);
hasDraft.value = false;
showRestoreBanner.value = false;
isRestoring.value = true;
selectedDate.value = "";
dateValue.value = Date.now();
common_vendor.nextTick$1(() => {
isRestoring.value = false;
});
if (showToast) {
common_vendor.index.showToast({ title: "草稿已清空", icon: "none" });
}
};
const restoreDraft = () => {
const key = getDraftKey();
const cached = common_vendor.index.getStorageSync(key);
if (cached) {
try {
const data = JSON.parse(cached);
const hasContent = data.selectedDate;
if (!hasContent)
return;
isRestoring.value = true;
selectedDate.value = data.selectedDate || "";
dateValue.value = data.dateValue || Date.now();
hasDraft.value = true;
showRestoreBanner.value = true;
common_vendor.nextTick$1(() => {
isRestoring.value = false;
});
common_vendor.index.showToast({
title: "已自动恢复您上次未提交的内容",
icon: "none",
duration: 2500
});
} catch (e) {
common_vendor.index.__f__("error", "at pages/hiddendanger/assignment.vue:306", "解析草稿失败:", e);
isRestoring.value = false;
}
}
};
common_vendor.watch(
() => [selectedDate.value],
() => {
if (hazardId.value) {
saveDraft();
}
}
);
common_vendor.onLoad((options) => {
if (options.hazardId)
hazardId.value = options.hazardId;
if (options.assignId)
assignId.value = options.assignId;
fetchDeptUsers();
restoreDraft();
});
return (_ctx, _cache) => {
return common_vendor.e({
a: showRestoreBanner.value
}, showRestoreBanner.value ? {
b: common_vendor.o(($event) => clearDraft(true))
} : {}, {
c: common_vendor.t(selectedUser.value || "请选择整改责任人"),
d: !selectedUser.value ? 1 : "",
e: common_vendor.o(openUserPopup),
f: common_vendor.o(cancelUserSelect),
g: userPickerSelectedId.value
}, userPickerSelectedId.value ? {
h: common_vendor.t(userPickerSelectedText.value)
} : {}, {
i: common_vendor.f(deptList.value, (dept, index, i0) => {
return common_vendor.e({
a: common_vendor.t(dept.deptName),
b: deptHasSelectedUser(dept)
}, deptHasSelectedUser(dept) ? {} : {}, {
c: dept.deptId,
d: common_vendor.n({
active: activeDeptIndex.value === index
}),
e: common_vendor.o(($event) => activeDeptIndex.value = index, dept.deptId)
});
}),
j: currentDeptUsers.value.length === 0
}, currentDeptUsers.value.length === 0 ? {} : {
k: common_vendor.f(currentDeptUsers.value, (user, k0, i0) => {
return common_vendor.e({
a: common_vendor.t(formatUserDisplayName(user)),
b: String(userPickerSelectedId.value) === String(user.userId)
}, String(userPickerSelectedId.value) === String(user.userId) ? {} : {}, {
c: "user-" + user.userId,
d: String(userPickerSelectedId.value) === String(user.userId) ? 1 : "",
e: common_vendor.o(($event) => onUserItemClick(user.userId), "user-" + user.userId)
});
})
}, {
l: "dept-users-" + activeDeptIndex.value,
m: common_vendor.o(cancelUserSelect),
n: common_vendor.o(confirmUserSelect),
o: common_vendor.o(cancelUserSelect),
p: common_vendor.p({
show: showUserPopup.value,
mode: "bottom",
round: "20"
}),
q: common_vendor.t(selectedDate.value || "请选择整改期限"),
r: common_vendor.n(selectedDate.value ? "" : "text-gray"),
s: common_vendor.o(($event) => showDatePicker.value = true),
t: common_vendor.o(onDateConfirm),
v: common_vendor.o(($event) => showDatePicker.value = false),
w: common_vendor.o(($event) => showDatePicker.value = false),
x: common_vendor.o(($event) => dateValue.value = $event),
y: common_vendor.p({
show: showDatePicker.value,
mode: "datetime",
modelValue: dateValue.value
}),
z: common_vendor.o(handleCancel),
A: common_vendor.o(handleSubmit),
B: common_vendor.gei(_ctx, "")
});
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-6209e844"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/hiddendanger/assignment.js.map