|
@@ -3,16 +3,16 @@
|
|
|
<div class="timer">
|
|
|
<van-cell
|
|
|
title="周报时间"
|
|
|
- :value="formData.date"
|
|
|
+ :value="thisWeek"
|
|
|
@click="calendarShow = true"
|
|
|
/>
|
|
|
- <van-calendar
|
|
|
+ <!-- <van-calendar
|
|
|
v-model:show="calendarShow"
|
|
|
@confirm="onConfirm"
|
|
|
type="range"
|
|
|
:min-date="minDate"
|
|
|
:max-date="maxDate"
|
|
|
- />
|
|
|
+ /> -->
|
|
|
</div>
|
|
|
|
|
|
<div class="title">本周工作</div>
|
|
@@ -22,17 +22,11 @@
|
|
|
autosize
|
|
|
type="textarea"
|
|
|
placeholder=""
|
|
|
- show-word-limit
|
|
|
/>
|
|
|
<div class="title">工作量分配</div>
|
|
|
<ProjectList type="weekly" :onChange="projectChange" />
|
|
|
<div class="title">接收人</div>
|
|
|
- <UserTree
|
|
|
- ref="treeSelectRef"
|
|
|
- v-model="formData.receiveUserIds"
|
|
|
- :listData="transformUserListToTree(userList)"
|
|
|
- placeholder="请选择接收人"
|
|
|
- />
|
|
|
+ <SelectUser v-model="formData.receiveUserIds" />
|
|
|
<van-button round type="primary" block class="send-btn" @click="onSubmit"
|
|
|
>发送</van-button
|
|
|
>
|
|
@@ -44,85 +38,88 @@
|
|
|
*/
|
|
|
import moment from "moment";
|
|
|
import { reactive } from "vue";
|
|
|
-import { userList } from "../mock";
|
|
|
-import UserTree from "@/components/UserSelect/index.vue";
|
|
|
+import { showSuccessToast, showToast } from "vant";
|
|
|
+import SelectUser from "@/components/UserSelect.vue";
|
|
|
import ProjectList from "../components/ProjectList.vue";
|
|
|
import { getUserInfo } from "@/utils/tools";
|
|
|
-const treeSelectRef = ref(null);
|
|
|
-
|
|
|
-// 写一个方法,把人员及部门的列表数据转换为树状数据
|
|
|
-const transformUserListToTree = (arr: any) => {
|
|
|
- const map: any = {};
|
|
|
- const roots: any = [];
|
|
|
- // 将数组转换为以id为key的对象
|
|
|
- arr.forEach((item: any) => {
|
|
|
- map[item.id] = { ...item, label: item.name, children: [] };
|
|
|
- });
|
|
|
- // 将子节点挂载到父节点的children字段下
|
|
|
- arr.forEach((item: any) => {
|
|
|
- const node = {
|
|
|
- id: map[item.id].id,
|
|
|
- name: map[item.id].name,
|
|
|
- value: map[item.id].id,
|
|
|
- children: map[item.id].children ?? [],
|
|
|
- };
|
|
|
- if (item.pid && map[item.pid]) {
|
|
|
- map[item.pid].children.push(node);
|
|
|
- } else if (item.pid) {
|
|
|
- // console.log(`找不到对应id的父节点,删除数据: ${item.name}`)
|
|
|
- // delete map[item.id]
|
|
|
- } else {
|
|
|
- roots.push(node);
|
|
|
- }
|
|
|
- });
|
|
|
- return roots;
|
|
|
-};
|
|
|
+import { http } from "../http";
|
|
|
+import { IReport } from "../interface";
|
|
|
+import { onSubmitCheck } from "../service";
|
|
|
|
|
|
interface FormData {
|
|
|
- date: string; // 日期
|
|
|
reportContent: string; // 内容
|
|
|
weeklyWorkloadList: {
|
|
|
projectId: string;
|
|
|
workTime: number;
|
|
|
}[]; // 工作量分配
|
|
|
receiveUserIds: string[]; // 接收人
|
|
|
+ reportYear: string | number; // 年
|
|
|
+ reportMonth: string | number; // 月
|
|
|
+ reportWeek: string | number; // 周
|
|
|
}
|
|
|
|
|
|
-const currentDate = `${moment().format("YYYY/MM/DD")} ~ ${moment().format(
|
|
|
- "YYYY/MM/DD"
|
|
|
-)}`;
|
|
|
+// 页面数据
|
|
|
+const thisWeek = ref(
|
|
|
+ `${moment()
|
|
|
+ .startOf("week")
|
|
|
+ .subtract(1, "day")
|
|
|
+ .format("YYYY/MM/DD")} ~ ${moment()
|
|
|
+ .endOf("week")
|
|
|
+ .add(1, "day")
|
|
|
+ .format("YYYY/MM/DD")}`
|
|
|
+);
|
|
|
const formData = reactive<FormData>({
|
|
|
- date: currentDate,
|
|
|
reportContent: "",
|
|
|
weeklyWorkloadList: [],
|
|
|
receiveUserIds: [],
|
|
|
+ reportYear: moment().format("YYYY"),
|
|
|
+ reportMonth: moment().format("MM"),
|
|
|
+ reportWeek: 0,
|
|
|
+});
|
|
|
+
|
|
|
+const route = useRoute();
|
|
|
+onMounted(async () => {
|
|
|
+ // 查看有没有传日期进来
|
|
|
+ const query: any = route.query;
|
|
|
+ if (query.startDate && query.endDate) {
|
|
|
+ thisWeek.value = `${moment(query.startDate).format(
|
|
|
+ "YYYY/MM/DD"
|
|
|
+ )} ~ ${moment(query.endDate).format("YYYY/MM/DD")}`;
|
|
|
+ }
|
|
|
+ const receiveUser = await http.getReceiveUser();
|
|
|
+ formData.receiveUserIds = receiveUser;
|
|
|
+ // 获取当日详情
|
|
|
+ await getIsWorkDays();
|
|
|
});
|
|
|
|
|
|
// 日历
|
|
|
const calendarShow = ref(false);
|
|
|
-const onConfirm = (values: any) => {
|
|
|
- const [start, end] = values;
|
|
|
- formData.date = `${moment(start).format("YYYY/MM/DD")} ~ ${moment(end).format(
|
|
|
- "YYYY/MM/DD"
|
|
|
- )}`;
|
|
|
- calendarShow.value = false;
|
|
|
-};
|
|
|
+// const onConfirm = async (values: any) => {
|
|
|
+// const [start, end] = values;
|
|
|
+// thisWeek.value = `${moment(start).format("YYYY/MM/DD")} ~ ${moment(
|
|
|
+// end
|
|
|
+// ).format("YYYY/MM/DD")}`;
|
|
|
+// calendarShow.value = false;
|
|
|
+// // 获取当日详情
|
|
|
+// await getIsWorkDays();
|
|
|
+// };
|
|
|
|
|
|
// 可选择的最小日期,一个月之前,最大日期:今天
|
|
|
-const minDate = moment().subtract(2, "months").toDate();
|
|
|
-const maxDate = moment().toDate();
|
|
|
+// const minDate = moment().subtract(2, "months").toDate();
|
|
|
+// const maxDate = moment().toDate();
|
|
|
|
|
|
// 工作量改变
|
|
|
const projectChange = (data: any) => {
|
|
|
formData.weeklyWorkloadList = data;
|
|
|
};
|
|
|
+
|
|
|
// 提交
|
|
|
-const onSubmit = () => {
|
|
|
- const date = formData.date.split(" ~ ");
|
|
|
+const { push } = useRouter();
|
|
|
+const onSubmit = async () => {
|
|
|
+ const date = thisWeek.value.split(" ~ ");
|
|
|
const userInfo = getUserInfo();
|
|
|
- const params = {
|
|
|
+ const params: IReport = {
|
|
|
...formData,
|
|
|
- // date,
|
|
|
reportType: "weekly",
|
|
|
userId: userInfo.id ?? "",
|
|
|
deptId: userInfo.deptId ?? "",
|
|
@@ -130,7 +127,29 @@ const onSubmit = () => {
|
|
|
reportEndDate: moment(date[1]).valueOf(),
|
|
|
isTemp: false,
|
|
|
};
|
|
|
- console.log("submit-params", params);
|
|
|
+ const submitCheck = onSubmitCheck(params);
|
|
|
+ if (!submitCheck.success) {
|
|
|
+ showToast({
|
|
|
+ message: submitCheck.msg,
|
|
|
+ position: "top",
|
|
|
+ });
|
|
|
+ }
|
|
|
+ const result: any = await http.submitReport(params);
|
|
|
+ if (result.msg == "success") {
|
|
|
+ showSuccessToast("发送成功");
|
|
|
+ push(`/logsDetail?id=${result.data}`);
|
|
|
+ }
|
|
|
+};
|
|
|
+// 获取是否工作日
|
|
|
+const getIsWorkDays = async (date?: string) => {
|
|
|
+ const searchDate = date?.split(" ~ ") ?? thisWeek.value.split(" ~ ");
|
|
|
+ const startDate = moment(searchDate[1]).format("YYYY-MM-DD HH:mm:ss");
|
|
|
+ const endDate = moment(searchDate[1]).format("YYYY-MM-DD HH:mm:ss");
|
|
|
+ const workDays = await http.getWorkDayList(startDate, endDate);
|
|
|
+ formData.reportYear = workDays[0].year;
|
|
|
+ formData.reportMonth = workDays[0].month;
|
|
|
+ formData.reportWeek = workDays[0].week;
|
|
|
+ // return workDays[0];
|
|
|
};
|
|
|
</script>
|
|
|
<style lang="scss" scoped>
|