Browse Source

fix: 修改移动端周报填报逻辑

qiny 1 year ago
parent
commit
0c43d7147d

+ 86 - 29
client_h5/src/pages/myLogs/Weekly/index.vue

@@ -47,7 +47,7 @@ import ProjectList from "../components/ProjectList.vue";
 import { getUserInfo } from "@/utils/tools";
 import { http } from "../http";
 import { IReport } from "../interface";
-import { onSubmitCheck } from "../service";
+import { onSubmitCheck, setWorkDayListToWeek } from "../service";
 
 interface FormData {
   reportContent: string; // 内容
@@ -98,44 +98,49 @@ onMounted(async () => {
     thisWeek.value = `${moment(query.startDate).format(
       "YYYY/MM/DD"
     )} ~ ${moment(query.endDate).format("YYYY/MM/DD")}`;
+    // 获取当日详情
+    await getIsWorkDays();
+  } else {
+    // 校对一下周报时间范围
+    await getWeekRange();
+    // 检查一下本周是否已经填了
+    await thisWeekLog();
   }
 
   // 检查一下今天是否已经填了
-  await isFillLog();
+  // await isFillLog();
 
   // 回填历史接收人
   const receiveUser = await http.getReceiveUser();
   formData.receiveUserIds = receiveUser;
-  // 获取当日详情
-  await getIsWorkDays();
 });
 
 // 判断一下本周是否已经填了,如果是填了的就跳转到详情页
-const isFillLog = async () => {
-  const date = thisWeek.value.split(" ~ ");
-  let searchList = await http.getMonthLogList(
-    "weekly",
-    moment(date[1]).format("YYYY"),
-    moment(date[1]).format("M")
-  );
-  // 以防万一
-  if (searchList.length == 0) {
-    searchList = await http.getMonthLogList(
-      "weekly",
-      moment(date[0]).format("YYYY"),
-      moment(date[0]).format("M")
-    );
-  }
-  const searchLog = searchList.find(
-    (item: any) =>
-      moment(item.reportEndDate).format("YYYY-MM-DD") ==
-      moment(date[1]).format("YYYY-MM-DD")
-  );
+// const isFillLog = async () => {
+//   const date = thisWeek.value.split(" ~ ");
+//   let searchList = await http.getMonthLogList(
+//     "weekly",
+//     moment(date[1]).format("YYYY"),
+//     moment(date[1]).format("M")
+//   );
+//   // 以防万一
+//   if (searchList.length == 0) {
+//     searchList = await http.getMonthLogList(
+//       "weekly",
+//       moment(date[0]).format("YYYY"),
+//       moment(date[0]).format("M")
+//     );
+//   }
+//   const searchLog = searchList.find(
+//     (item: any) =>
+//       moment(item.reportEndDate).format("YYYY-MM-DD") ==
+//       moment(date[1]).format("YYYY-MM-DD")
+//   );
 
-  if (searchLog) {
-    push(`/logsDetail?id=${searchLog.id}`);
-  }
-};
+//   if (searchLog) {
+//     push(`/logsDetail?id=${searchLog.id}`);
+//   }
+// };
 
 // 日历
 const calendarShow = ref(false);
@@ -160,7 +165,7 @@ const projectChange = (data: any) => {
 };
 
 // 提交
-const { push } = useRouter();
+const { push, replace } = useRouter();
 const onSubmit = async () => {
   const date = thisWeek.value.split(" ~ ");
   const userInfo = getUserInfo();
@@ -187,6 +192,7 @@ const onSubmit = async () => {
     push(`/logsDetail?id=${result.data}`);
   }
 };
+
 // 获取是否工作日
 const getIsWorkDays = async (date?: string) => {
   const searchDate = date?.split(" ~ ") ?? thisWeek.value.split(" ~ ");
@@ -208,6 +214,57 @@ const getTotalTime = () => {
   });
   totalTime.value = total;
 };
+
+// 获取本周的起始和结束时间
+const getWeekRange = async () => {
+  const startDate = moment().subtract(7, "day").format("YYYY-MM-DD HH:mm:ss");
+  const endDate = moment().add(7, "day").format("YYYY-MM-DD HH:mm:ss");
+  const workDays = await http.getWorkDayList(startDate, endDate);
+  if (workDays?.length == 0) return;
+  const today = workDays.find(
+    (item: any) =>
+      moment(item.dateDay).format("YYYY-MM-DD") == moment().format("YYYY-MM-DD")
+  );
+  const weekGroup = setWorkDayListToWeek(workDays);
+  const todayMonth = `${today.year}-${today.month}`;
+  const todayWeek = today.week.toString();
+  const thisWeek = weekGroup[todayMonth][todayWeek];
+  if (thisWeek.length > 0) {
+    thisWeek.value = `${moment(thisWeek[0].dateDay).format(
+      "YYYY/MM/DD"
+    )} ~ ${moment(thisWeek[thisWeek.length - 1].dateDay).format("YYYY/MM/DD")}`;
+    formData.reportYear = thisWeek[0].year;
+    formData.reportMonth = thisWeek[0].month;
+    formData.reportWeek = thisWeek[0].week;
+  }
+};
+// 判断本周周报是否已经填过
+const thisWeekLog = async () => {
+  const logList = await http.getWeeklyLogList(
+    "weekly",
+    formData.reportYear,
+    formData.reportMonth,
+    formData.reportWeek
+  );
+  const thisWeekLogs = logList.filter(
+    (log: any) =>
+      log.reportWeek == formData.reportWeek &&
+      log.reportMonth == formData.reportMonth
+  );
+  if (thisWeekLogs.length > 0) {
+    // push(`/logsDetail?id=${thisWeekLogs[0].id}`);
+    replace({
+      path: "/logsDetail",
+      query: {
+        id: thisWeekLogs[0].id,
+        detail: JSON.stringify({
+          ...thisWeekLogs[0],
+          comments: [], // 就不传那么多东西过去了,反正详情页面也会查询评论
+        }),
+      },
+    });
+  }
+};
 </script>
 <style lang="scss" scoped>
 @import "../page.scss";

+ 4 - 1
client_h5/src/pages/myLogs/components/LogDetail.vue

@@ -135,7 +135,10 @@ const formData = reactive<FormData>({
 // 初始化日志数据
 const initData = async () => {
   const reportId: any = route.query?.id ?? "";
-  const result = await http.getLogDetail(reportId);
+  const reportDetail = route.query?.detail
+    ? JSON.parse(route.query.detail as string)
+    : null;
+  const result = reportDetail ?? (await http.getLogDetail(reportId));
 
   formData.reportContent = result.reportContent ?? "";
   formData.workloadList = result.workload ?? [];

+ 19 - 0
client_h5/src/pages/myLogs/http.ts

@@ -131,4 +131,23 @@ export const http = {
     });
     return result.msg == "success" ? result.data : [];
   },
+  // 获取本周日志列表
+  getWeeklyLogList: async (
+    type: "weekly" | "daily",
+    reportYear: string | number,
+    reportMonth: string | number,
+    reportWeek: string | number
+  ) => {
+    const params = {
+      reportType: type,
+      reportYear,
+      reportMonth,
+      reportWeek,
+      userId: userInfo.id ?? "",
+    };
+    const result: any = await request.get(api.logList, {
+      params,
+    });
+    return result.msg == "success" ? result.data : [];
+  },
 };