123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- import request from "@/utils/request";
- import { getUserInfo } from "@/utils/tools";
- import { IReport, IReportList } from "./interface";
- import { getNearThreeMonth } from "./service";
- // 周日报所有的请求接口
- const api = {
- list: "/adm/report/list", // 周日报列表
- submit: "/admin-api/adm/report/add-report-info", // 周日报提交、暂存
- project: "/business/project/page", // 项目列表
- workDayList: "/admin-api/adm/workday/list", // 获取工作日列表
- receiveUser: "/admin-api/adm/report/recent-receive-user", // 获取最近接收人
- logDetail: "/admin-api/adm/report/query-detail", // 获取周日报详情
- reportCommentList: "/admin-api/adm/reportComment/getList", // 获取周日报评论列表
- deleteComment: "/admin-api/adm/reportComment/delete", // 删除周日报评论
- addComment: "/admin-api/adm/reportComment/send", // 添加周日报评论
- logList: "/admin-api/adm/report/list", // 获取周报日志列表
- };
- const userInfo = getUserInfo();
- export const http = {
- // 请求周日报列表
- getReportList: async (params: IReportList) => {
- return await request.get(api.list, { params });
- },
- // 提交、暂存周日报
- submitReport: async (params: IReport) => {
- return await request.post(api.submit, params);
- },
- // 项目列表
- getProjectList: async () => {
- const params = {
- pageSize: -1,
- userId: userInfo.id ?? "",
- xmzList: [1, 4], // 仅可对进行中和已验收的项目进行填报
- };
- const result: any = await request.get(api.project, { params });
- return result.msg == "success" ? result.data.records : [];
- },
- // 获取工作日列表 YYYY-MM-DD HH:mm:ss
- getWorkDayList: async (startDate: string, endDate: string) => {
- // const result: any = await request.get(api.workDayList, {
- // data: { dateDay: [startDate, endDate] },
- // });
- // 用一种不太优雅的方式实现请求效果
- const encodedStartDate = encodeURIComponent(startDate);
- const encodedEndDate = encodeURIComponent(endDate);
- const url = `${api.workDayList}?dateDay%5B0%5D=${encodedStartDate}&dateDay%5B1%5D=${encodedEndDate}`;
- const result: any = await request.get(url);
- return result.msg == "success" ? result.data : [];
- },
- // 获取接收人历史
- getReceiveUser: async () => {
- const params = { userId: userInfo.id };
- const result: any = await request.get(api.receiveUser, { params });
- return result.msg == "success" ? result.data : [];
- },
- // 获取周日报详情
- getLogDetail: async (reportId: string) => {
- const params = { reportId };
- const result: any = await request.get(api.logDetail, { params });
- return result.msg == "success" ? result.data : {};
- },
- // 获取周日报评论列表
- getReportCommentList: async (reportId: string) => {
- const uId = userInfo.id ?? "";
- const params = { reportId, uId };
- const result: any = await request.get(api.reportCommentList, { params });
- return result.msg == "success" ? result.data : [];
- },
- // 删除周日报评论
- deleteReportComment: async (reportCommentId: string) => {
- return await request.delete(`${api.deleteComment}`, {
- data: [reportCommentId],
- });
- },
- // 添加周日报评论
- addReportComment: async (params: any) => {
- const commentUserId = userInfo.id ?? "";
- return await request.post(api.addComment, { ...params, commentUserId });
- },
- // 获取近三个月周日报日志列表
- getLogList: async (type: "weekly" | "daily") => {
- const nearThreeMonth = getNearThreeMonth();
- const requests = [
- request.get(api.logList, {
- params: {
- reportType: type,
- reportYear: nearThreeMonth[0].reportYear,
- reportMonth: nearThreeMonth[0].reportMonth,
- userId: userInfo.id ?? "",
- },
- }),
- request.get(api.logList, {
- params: {
- reportType: type,
- reportYear: nearThreeMonth[1].reportYear,
- reportMonth: nearThreeMonth[1].reportMonth,
- userId: userInfo.id ?? "",
- },
- }),
- request.get(api.logList, {
- params: {
- reportType: type,
- reportYear: nearThreeMonth[2].reportYear,
- reportMonth: nearThreeMonth[2].reportMonth,
- userId: userInfo.id ?? "",
- },
- }),
- ];
- const result: any = await Promise.all(requests);
- const allLog = [
- ...(result?.[0].data ?? []),
- ...(result?.[1].data ?? []),
- ...(result?.[2].data ?? []),
- ];
- return allLog;
- },
- // 获取当月日志列表
- getMonthLogList: async (
- type: "weekly" | "daily",
- year: string,
- month: string
- ) => {
- const params = {
- reportType: type,
- reportYear: year,
- reportMonth: month,
- userId: userInfo.id ?? "",
- };
- const result: any = await request.get(api.logList, {
- params,
- });
- 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 : [];
- },
- };
|