150 lines
5.8 KiB
JavaScript
150 lines
5.8 KiB
JavaScript
"use strict";
|
||
const common_vendor = require("../../common/vendor.js");
|
||
const request_api = require("../../request/api.js");
|
||
if (!Array) {
|
||
const _easycom_up_picker2 = common_vendor.resolveComponent("up-picker");
|
||
const _easycom_up_datetime_picker2 = common_vendor.resolveComponent("up-datetime-picker");
|
||
(_easycom_up_picker2 + _easycom_up_datetime_picker2)();
|
||
}
|
||
const _easycom_up_picker = () => "../../uni_modules/uview-plus/components/u-picker/u-picker.js";
|
||
const _easycom_up_datetime_picker = () => "../../uni_modules/uview-plus/components/u-datetime-picker/u-datetime-picker.js";
|
||
if (!Math) {
|
||
(_easycom_up_picker + _easycom_up_datetime_picker)();
|
||
}
|
||
const _sfc_main = {
|
||
__name: "assignment",
|
||
setup(__props) {
|
||
const hazardId = common_vendor.ref("");
|
||
const assignId = common_vendor.ref("");
|
||
const showUserPicker = common_vendor.ref(false);
|
||
const selectedUser = common_vendor.ref("");
|
||
const selectedUserId = common_vendor.ref("");
|
||
const userColumns = common_vendor.ref([["暂无数据"]]);
|
||
const userList = common_vendor.ref([]);
|
||
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) {
|
||
const users = [];
|
||
res.data.forEach((dept) => {
|
||
if (dept.users && dept.users.length > 0) {
|
||
dept.users.forEach((user) => {
|
||
users.push({
|
||
id: String(user.userId),
|
||
name: `${user.nickName}(${dept.deptName})`
|
||
});
|
||
});
|
||
}
|
||
});
|
||
userList.value = users;
|
||
userColumns.value = [users.map((u) => u.name)];
|
||
console.log("整改人员列表:", users);
|
||
}
|
||
} catch (error) {
|
||
console.error("获取部门人员失败:", error);
|
||
}
|
||
};
|
||
const onUserConfirm = (e) => {
|
||
console.log("选择的人员:", e);
|
||
if (e.value && e.value.length > 0) {
|
||
selectedUser.value = e.value[0];
|
||
const user = userList.value.find((u) => u.name === e.value[0]);
|
||
if (user) {
|
||
selectedUserId.value = user.id;
|
||
}
|
||
}
|
||
showUserPicker.value = false;
|
||
};
|
||
const onDateConfirm = (e) => {
|
||
console.log("选择的日期时间:", 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: ""
|
||
// 交办备注(可选)
|
||
};
|
||
console.log("提交数据:", params);
|
||
try {
|
||
const res = await request_api.assignHiddenDanger(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) {
|
||
console.error("交办失败:", 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;
|
||
fetchDeptUsers();
|
||
});
|
||
return (_ctx, _cache) => {
|
||
return {
|
||
a: common_vendor.t(selectedUser.value || "请选择整改人员"),
|
||
b: common_vendor.n(selectedUser.value ? "" : "text-gray"),
|
||
c: common_vendor.o(($event) => showUserPicker.value = true),
|
||
d: common_vendor.o(onUserConfirm),
|
||
e: common_vendor.o(($event) => showUserPicker.value = false),
|
||
f: common_vendor.o(($event) => showUserPicker.value = false),
|
||
g: common_vendor.p({
|
||
show: showUserPicker.value,
|
||
columns: userColumns.value
|
||
}),
|
||
h: common_vendor.t(selectedDate.value || "请选择整改期限"),
|
||
i: common_vendor.n(selectedDate.value ? "" : "text-gray"),
|
||
j: common_vendor.o(($event) => showDatePicker.value = true),
|
||
k: common_vendor.o(onDateConfirm),
|
||
l: common_vendor.o(($event) => showDatePicker.value = false),
|
||
m: common_vendor.o(($event) => showDatePicker.value = false),
|
||
n: common_vendor.o(($event) => dateValue.value = $event),
|
||
o: common_vendor.p({
|
||
show: showDatePicker.value,
|
||
mode: "datetime",
|
||
modelValue: dateValue.value
|
||
}),
|
||
p: common_vendor.o(handleCancel),
|
||
q: common_vendor.o(handleSubmit)
|
||
};
|
||
};
|
||
}
|
||
};
|
||
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-6209e844"]]);
|
||
wx.createPage(MiniProgramPage);
|