307 lines
12 KiB
JavaScript
307 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");
|
||
if (!Array) {
|
||
const _easycom_u_popup2 = common_vendor.resolveComponent("u-popup");
|
||
const _easycom_up_datetime_picker2 = common_vendor.resolveComponent("up-datetime-picker");
|
||
const _easycom_up_radio2 = common_vendor.resolveComponent("up-radio");
|
||
const _easycom_up_radio_group2 = common_vendor.resolveComponent("up-radio-group");
|
||
(_easycom_u_popup2 + _easycom_up_datetime_picker2 + _easycom_up_radio2 + _easycom_up_radio_group2)();
|
||
}
|
||
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";
|
||
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";
|
||
if (!Math) {
|
||
(_easycom_u_popup + _easycom_up_datetime_picker + _easycom_up_radio + _easycom_up_radio_group)();
|
||
}
|
||
const nextStepDisplay = "隐患整改";
|
||
const _sfc_main = {
|
||
__name: "assignment",
|
||
setup(__props) {
|
||
const hazardId = common_vendor.ref("");
|
||
const assignId = common_vendor.ref("");
|
||
const taskId = common_vendor.ref("");
|
||
const showUserPopup = common_vendor.ref(false);
|
||
const selectedUser = common_vendor.ref("");
|
||
const selectedIdentityId = common_vendor.ref("");
|
||
const selectedUserId = common_vendor.ref("");
|
||
const deptList = common_vendor.ref([]);
|
||
const activeDeptIndex = common_vendor.ref(0);
|
||
const userPickerSelectedIdentityId = common_vendor.ref("");
|
||
const findUserByIdentityId = (identityId) => {
|
||
if (!identityId)
|
||
return null;
|
||
for (const dept of deptList.value) {
|
||
const user = (dept.users || []).find((u) => String(u.identityId) === String(identityId));
|
||
if (user)
|
||
return user;
|
||
}
|
||
return null;
|
||
};
|
||
const formatUserDisplayName = (user) => {
|
||
if (user.identityName) {
|
||
return `${user.nickName}_${user.identityName}`;
|
||
}
|
||
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(() => {
|
||
const user = findUserByIdentityId(userPickerSelectedIdentityId.value);
|
||
return user ? formatUserDisplayName(user) : "";
|
||
});
|
||
const deptHasSelectedUser = (dept) => {
|
||
var _a;
|
||
if (!userPickerSelectedIdentityId.value || !((_a = dept.users) == null ? void 0 : _a.length))
|
||
return false;
|
||
return dept.users.some((user) => String(user.identityId) === String(userPickerSelectedIdentityId.value));
|
||
};
|
||
const onUserItemClick = (identityId) => {
|
||
userPickerSelectedIdentityId.value = String(identityId);
|
||
};
|
||
const openUserPopup = () => {
|
||
userPickerSelectedIdentityId.value = selectedIdentityId.value;
|
||
let targetDeptIndex = 0;
|
||
if (selectedIdentityId.value) {
|
||
const deptIndex = deptList.value.findIndex(
|
||
(dept) => (dept.users || []).some((user) => String(user.identityId) === String(selectedIdentityId.value))
|
||
);
|
||
if (deptIndex >= 0)
|
||
targetDeptIndex = deptIndex;
|
||
} else {
|
||
const firstDeptWithUsers = deptList.value.findIndex((dept) => {
|
||
var _a;
|
||
return ((_a = dept.users) == null ? void 0 : _a.length) > 0;
|
||
});
|
||
if (firstDeptWithUsers >= 0)
|
||
targetDeptIndex = firstDeptWithUsers;
|
||
}
|
||
activeDeptIndex.value = targetDeptIndex;
|
||
showUserPopup.value = true;
|
||
};
|
||
const cancelUserSelect = () => {
|
||
showUserPopup.value = false;
|
||
};
|
||
const confirmUserSelect = () => {
|
||
if (!userPickerSelectedIdentityId.value) {
|
||
common_vendor.index.showToast({ title: "请选择整改责任人", icon: "none" });
|
||
return;
|
||
}
|
||
const user = findUserByIdentityId(userPickerSelectedIdentityId.value);
|
||
if (!user) {
|
||
common_vendor.index.showToast({ title: "所选身份无效,请重新选择", icon: "none" });
|
||
return;
|
||
}
|
||
selectedIdentityId.value = String(user.identityId);
|
||
selectedUserId.value = String(user.userId);
|
||
selectedUser.value = formatUserDisplayName(user);
|
||
showUserPopup.value = false;
|
||
};
|
||
const showDatePicker = common_vendor.ref(false);
|
||
const dateValue = common_vendor.ref(Date.now());
|
||
const selectedDate = common_vendor.ref("");
|
||
const sendMsgFlagRadio = common_vendor.ref("yes");
|
||
const sendMsgFlag = common_vendor.computed(() => sendMsgFlagRadio.value === "yes");
|
||
const {
|
||
showRestoreBanner,
|
||
clear: clearDraft,
|
||
restore: restoreDraft,
|
||
bindAutoSave
|
||
} = utils_useDraftCache.useDraftCache({
|
||
getKey: () => utils_draftCache.buildDraftKey(utils_draftCache.DRAFT_NS.ASSIGN, hazardId.value),
|
||
getPayload: () => ({
|
||
selectedDate: selectedDate.value,
|
||
dateValue: dateValue.value,
|
||
sendMsgFlagRadio: sendMsgFlagRadio.value
|
||
}),
|
||
hasContent: (payload) => !!(payload.selectedDate || payload.sendMsgFlagRadio === "no"),
|
||
applyPayload: (payload) => {
|
||
selectedDate.value = payload.selectedDate || "";
|
||
dateValue.value = payload.dateValue || Date.now();
|
||
sendMsgFlagRadio.value = payload.sendMsgFlagRadio === "no" ? "no" : "yes";
|
||
},
|
||
clearForm: () => {
|
||
selectedDate.value = "";
|
||
dateValue.value = Date.now();
|
||
sendMsgFlagRadio.value = "yes";
|
||
},
|
||
canSave: () => !!hazardId.value
|
||
});
|
||
bindAutoSave(() => [selectedDate.value, sendMsgFlagRadio.value]);
|
||
const fetchDeptUsers = async () => {
|
||
try {
|
||
const res = await request_api.getRelatedDeptUsers({
|
||
type: 1
|
||
});
|
||
if (res.code === 0 && res.data) {
|
||
deptList.value = res.data;
|
||
common_vendor.index.__f__("log", "at pages/hiddendanger/assignment.vue:257", "部门人员树:", deptList.value);
|
||
}
|
||
} catch (error) {
|
||
common_vendor.index.__f__("error", "at pages/hiddendanger/assignment.vue:260", "获取部门人员失败:", error);
|
||
}
|
||
};
|
||
const onDateConfirm = (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");
|
||
selectedDate.value = `${year}-${month}-${day}`;
|
||
showDatePicker.value = false;
|
||
};
|
||
const handleCancel = () => {
|
||
common_vendor.index.navigateBack();
|
||
};
|
||
const handleSubmit = async () => {
|
||
if (!selectedIdentityId.value) {
|
||
common_vendor.index.showToast({ title: "请选择整改人员", icon: "none" });
|
||
return;
|
||
}
|
||
if (!selectedDate.value) {
|
||
common_vendor.index.showToast({ title: "请选择整改期限", icon: "none" });
|
||
return;
|
||
}
|
||
if (!taskId.value) {
|
||
common_vendor.index.showToast({ title: "缺少任务ID", icon: "none" });
|
||
return;
|
||
}
|
||
const params = {
|
||
hazardId: Number(hazardId.value),
|
||
// 隐患ID
|
||
taskId: taskId.value,
|
||
// 流程任务ID(列表传入)
|
||
assigneeId: Number(selectedUserId.value),
|
||
// 被指派人用户ID
|
||
assigneeIdentityId: Number(selectedIdentityId.value),
|
||
// 被指派人身份ID
|
||
deadline: selectedDate.value,
|
||
// 处理期限
|
||
assignRemark: "",
|
||
// 交办备注(可选)
|
||
sendMsgFlag: sendMsgFlag.value
|
||
// 是否短信提醒
|
||
};
|
||
common_vendor.index.__f__("log", "at pages/hiddendanger/assignment.vue:305", "提交数据:", 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:319", "交办失败:", error);
|
||
common_vendor.index.showToast({ title: "请求失败", icon: "none" });
|
||
}
|
||
};
|
||
common_vendor.onLoad((options) => {
|
||
if (options.hazardId)
|
||
hazardId.value = options.hazardId;
|
||
if (options.assignId)
|
||
assignId.value = options.assignId;
|
||
if (options.taskId)
|
||
taskId.value = options.taskId;
|
||
fetchDeptUsers();
|
||
restoreDraft();
|
||
});
|
||
return (_ctx, _cache) => {
|
||
return common_vendor.e({
|
||
a: common_vendor.unref(showRestoreBanner)
|
||
}, common_vendor.unref(showRestoreBanner) ? {
|
||
b: common_vendor.o(($event) => common_vendor.unref(clearDraft)(true))
|
||
} : {}, {
|
||
c: common_vendor.t(nextStepDisplay),
|
||
d: common_vendor.t(selectedUser.value || "请选择整改责任人"),
|
||
e: !selectedUser.value ? 1 : "",
|
||
f: common_vendor.o(openUserPopup),
|
||
g: common_vendor.o(cancelUserSelect),
|
||
h: userPickerSelectedIdentityId.value
|
||
}, userPickerSelectedIdentityId.value ? {
|
||
i: common_vendor.t(userPickerSelectedText.value)
|
||
} : {}, {
|
||
j: 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)
|
||
});
|
||
}),
|
||
k: currentDeptUsers.value.length === 0
|
||
}, currentDeptUsers.value.length === 0 ? {} : {
|
||
l: common_vendor.f(currentDeptUsers.value, (user, k0, i0) => {
|
||
return common_vendor.e({
|
||
a: common_vendor.t(formatUserDisplayName(user)),
|
||
b: String(userPickerSelectedIdentityId.value) === String(user.identityId)
|
||
}, String(userPickerSelectedIdentityId.value) === String(user.identityId) ? {} : {}, {
|
||
c: "identity-" + user.identityId,
|
||
d: String(userPickerSelectedIdentityId.value) === String(user.identityId) ? 1 : "",
|
||
e: common_vendor.o(($event) => onUserItemClick(user.identityId), "identity-" + user.identityId)
|
||
});
|
||
})
|
||
}, {
|
||
m: "dept-users-" + activeDeptIndex.value,
|
||
n: common_vendor.o(cancelUserSelect),
|
||
o: common_vendor.o(confirmUserSelect),
|
||
p: common_vendor.o(cancelUserSelect),
|
||
q: common_vendor.p({
|
||
show: showUserPopup.value,
|
||
mode: "bottom",
|
||
round: "20"
|
||
}),
|
||
r: common_vendor.t(selectedDate.value || "请选择整改期限"),
|
||
s: common_vendor.n(selectedDate.value ? "" : "text-gray"),
|
||
t: common_vendor.o(($event) => showDatePicker.value = true),
|
||
v: common_vendor.o(onDateConfirm),
|
||
w: common_vendor.o(($event) => showDatePicker.value = false),
|
||
x: common_vendor.o(($event) => showDatePicker.value = false),
|
||
y: common_vendor.o(($event) => dateValue.value = $event),
|
||
z: common_vendor.p({
|
||
show: showDatePicker.value,
|
||
mode: "date",
|
||
modelValue: dateValue.value
|
||
}),
|
||
A: common_vendor.p({
|
||
label: "是",
|
||
name: "yes",
|
||
customStyle: {
|
||
marginRight: "48rpx"
|
||
}
|
||
}),
|
||
B: common_vendor.p({
|
||
label: "否",
|
||
name: "no"
|
||
}),
|
||
C: common_vendor.o(($event) => sendMsgFlagRadio.value = $event),
|
||
D: common_vendor.p({
|
||
placement: "row",
|
||
activeColor: "#2667e9",
|
||
modelValue: sendMsgFlagRadio.value
|
||
}),
|
||
E: common_vendor.o(handleCancel),
|
||
F: common_vendor.o(handleSubmit),
|
||
G: 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
|