|
@@ -0,0 +1,213 @@
|
|
|
+/**
|
|
|
+ * @description 所有周日报通用的方法
|
|
|
+ */
|
|
|
+import moment from 'moment'
|
|
|
+import request from '@/config/axios'
|
|
|
+import { getUserInfo } from '@/utils/tool'
|
|
|
+
|
|
|
+const userInfo = getUserInfo()
|
|
|
+
|
|
|
+// 所有请求
|
|
|
+const api = {
|
|
|
+ workDayList: '/adm/workday/list', // 获取工作日列表
|
|
|
+ logList: '/adm/report/list' // 获取周报日志列表
|
|
|
+}
|
|
|
+export const http = {
|
|
|
+ // 获取工作日列表 YYYY-MM-DD HH:mm:ss
|
|
|
+ getWorkDayList: async (startDate: string, endDate: string) => {
|
|
|
+ // 用一种不太优雅的方式实现请求效果
|
|
|
+ const params = {
|
|
|
+ dateDay: [startDate, endDate]
|
|
|
+ }
|
|
|
+ const result: any = await request.get({ url: api.workDayList, params })
|
|
|
+ return result ?? []
|
|
|
+ },
|
|
|
+
|
|
|
+ // 获取近三个月周日报日志列表
|
|
|
+ getLogList: async (type: 'weekly' | 'daily') => {
|
|
|
+ const nearThreeMonth = getNearThreeMonth()
|
|
|
+ const requests = [
|
|
|
+ request.get({
|
|
|
+ url: api.logList,
|
|
|
+ params: {
|
|
|
+ reportType: type,
|
|
|
+ reportYear: nearThreeMonth[0].reportYear,
|
|
|
+ reportMonth: nearThreeMonth[0].reportMonth,
|
|
|
+ userId: userInfo.id ?? ''
|
|
|
+ }
|
|
|
+ }),
|
|
|
+ request.get({
|
|
|
+ url: api.logList,
|
|
|
+ params: {
|
|
|
+ reportType: type,
|
|
|
+ reportYear: nearThreeMonth[1].reportYear,
|
|
|
+ reportMonth: nearThreeMonth[1].reportMonth,
|
|
|
+ userId: userInfo.id ?? ''
|
|
|
+ }
|
|
|
+ }),
|
|
|
+ request.get({
|
|
|
+ url: 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] ?? []), ...(result?.[1] ?? []), ...(result?.[2] ?? [])]
|
|
|
+ return allLog
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 写一个方法,把人员及部门的列表数据转换为树状数据
|
|
|
+export 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
|
|
|
+}
|
|
|
+// 提交校验
|
|
|
+export const onSubmitCheck = (formData: any) => {
|
|
|
+ if (formData.reportContent == '') {
|
|
|
+ return {
|
|
|
+ msg: '请填写今日工作',
|
|
|
+ success: false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (formData.weeklyWorkloadList.length == 0) {
|
|
|
+ return {
|
|
|
+ msg: '请分配工作量',
|
|
|
+ success: false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (formData.receiveUserIds.length == 0) {
|
|
|
+ return {
|
|
|
+ msg: '请选择接收人',
|
|
|
+ success: false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ msg: '',
|
|
|
+ success: true
|
|
|
+ }
|
|
|
+}
|
|
|
+// 判断是否是本人的评论,由于只能删除自己发出的评论,所以做一个判断
|
|
|
+export const isMyComment = (data: any) => {
|
|
|
+ return data.commentUserId == userInfo.id
|
|
|
+}
|
|
|
+// 返回从当前日期计算起的三个月
|
|
|
+export const getNearThreeMonth = () => {
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ reportYear: moment().format('YYYY'),
|
|
|
+ reportMonth: moment().format('M')
|
|
|
+ },
|
|
|
+ {
|
|
|
+ reportYear: moment().subtract(1, 'month').format('YYYY'),
|
|
|
+ reportMonth: moment().subtract(1, 'month').format('M')
|
|
|
+ },
|
|
|
+ {
|
|
|
+ reportYear: moment().subtract(2, 'month').format('YYYY'),
|
|
|
+ reportMonth: moment().subtract(2, 'month').format('M')
|
|
|
+ }
|
|
|
+ ]
|
|
|
+}
|
|
|
+// 返回当前月尾那周周日 到 上上个月初那周的周一前一天的日期
|
|
|
+export const getMonthRange = () => {
|
|
|
+ const endTime = moment().endOf('month').endOf('week').add(1, 'day').format('YYYY-MM-DD HH:mm:ss')
|
|
|
+ const startTime = moment()
|
|
|
+ .subtract(2, 'month')
|
|
|
+ .startOf('month')
|
|
|
+ .startOf('week')
|
|
|
+ .format('YYYY-MM-DD HH:mm:ss')
|
|
|
+ return [startTime, endTime]
|
|
|
+}
|
|
|
+// 将工作日数据进行整理,转成按日期划分的对象
|
|
|
+export const setWorkDayListToObj = (data: any) => {
|
|
|
+ const obj: any = {}
|
|
|
+ data.forEach((item: any) => {
|
|
|
+ const date = moment(item.dateDay).format('YYYY-MM-DD')
|
|
|
+ obj[date] = item
|
|
|
+ })
|
|
|
+ return obj
|
|
|
+}
|
|
|
+// 将工作日数据进行整理,按周划分(传回来的周的划分是错的,但是时间紧迫,所以先这样)
|
|
|
+export const setWorkDayListToWeek = (data: any) => {
|
|
|
+ const weekObj: any = {}
|
|
|
+ data.forEach((item: any) => {
|
|
|
+ const { dateDay, dayOfWeek, week, month, year } = item
|
|
|
+ const date = moment(dateDay).format('YYYY-MM-DD')
|
|
|
+ const desc = `这天是${year}-${month}的第${week}周的第${dayOfWeek}天`
|
|
|
+ // week 表示第几周, dayOfWeek 表示本周的第几天
|
|
|
+ const title = `${year}-${month}`
|
|
|
+ if (weekObj[title]) {
|
|
|
+ if (weekObj[title][week]) {
|
|
|
+ weekObj[title][week].push({ ...item, date, desc })
|
|
|
+ } else {
|
|
|
+ weekObj[title][week] = [{ ...item, date, desc }]
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ weekObj[title] = {
|
|
|
+ [week]: [{ ...item, date, desc }]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ // console.log("weekObj", weekObj);
|
|
|
+ return weekObj
|
|
|
+}
|
|
|
+// 处理数据,将工作周划分和周日报填报情况进行合并
|
|
|
+export const mergeWorkDayAndLogs = (workObj: any, logList: any) => {
|
|
|
+ const workList: any = []
|
|
|
+ // 把复杂的对象拆为数组
|
|
|
+ for (const key in workObj) {
|
|
|
+ for (const week in workObj[key]) {
|
|
|
+ const data = workObj[key][week]
|
|
|
+ const logs = logList.filter((item: any) => {
|
|
|
+ const { reportStartDate, reportEndDate } = item
|
|
|
+ const checkData = moment(data[data.length - 1].date)
|
|
|
+ return checkData.isBetween(reportStartDate, reportEndDate, null, '[]')
|
|
|
+ })
|
|
|
+ workList.push({
|
|
|
+ month: key,
|
|
|
+ week,
|
|
|
+ data,
|
|
|
+ startDate: data[0].date,
|
|
|
+ endDate: data[data.length - 1].date,
|
|
|
+ isLog: logs
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 再把数组重组为以月划分的对象
|
|
|
+ const monthObj: any = {}
|
|
|
+ workList.map((item: any) => {
|
|
|
+ const { month } = item
|
|
|
+ if (monthObj[month]) {
|
|
|
+ monthObj[month].push(item)
|
|
|
+ } else {
|
|
|
+ monthObj[month] = [item]
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return monthObj
|
|
|
+}
|