import React, { useEffect, useReducer } from "react"; import { Input, Card, Tooltip, Button, Calendar, DatePicker, Select, Spin, Popconfirm, Switch, } from "antd"; import styles from "./index.less"; import { doFetch } from "@/utils/doFetch"; import getPrem from "@/utils/getPrem"; //权限判断fn import { useRequest } from "umi"; import moment from "moment"; import DrawInitForm from "@/components/DrawInitForm"; const initState = { vs: false, fields: {}, iftype: {}, scheduleData: [], year: moment().year(), month: moment().month() + 1, curitem: {}, loadingData: false, }, monthSelect = [], defaultFields = { isWeekday: { value: null, type: "radio", title: "修改工作日历", name: ["isWeekday"], required: true, options: [ { label: "工作日", value: 1, }, { label: "休息日", value: 0, }, ], }, }; function reducer(state, action) { let { type } = action, newState = {}; switch (type) { case "edit": newState = { ...state, vs: true, iftype: { title: "修改工作日历", val: type, }, fields: { ...action.fields }, curitem: { ...action.curitem }, }; break; case "changeData": newState = { ...state, scheduleData: action.scheduleData, loadingData: false, }; break; case "changeLoading": newState = { ...state, loadingData: action.loadingData, }; break; case "changeYear": newState = { ...state, year: action.year, }; break; case "changeMonth": newState = { ...state, month: action.month, }; break; case "close": newState = { ...state, vs: false, fields: {}, iftype: {}, curitem: {}, }; break; } return newState; } function getMonth() { for (let i = 1; i < 13; i++) { let obj = { value: i, label: i + "月", }; monthSelect.push(obj); } } getMonth(); const Schedule = (props) => { const { checkedNode, reloadTree } = props; const { run, loading } = useRequest(doFetch, { manual: true, formatResult: (res) => res, onSuccess: (result, params) => { if (result.code == "0000") { dispatch({ type: "close" }); reload(); reloadTree && reloadTree(); } }, }), [state, dispatch] = useReducer(reducer, initState), { vs, fields, iftype, scheduleData, year, month, curitem } = state; useEffect(() => { if (checkedNode) { reload(); } else { dispatch({ type: "changeMonth", month: moment().month() + 1 }); dispatch({ type: "changeYear", year: moment().year() }); } }, [checkedNode, year, month]); function reload() { dispatch({ type: "changeLoading", loadingData: true }); doFetch({ url: "/ngic-auth/sysWorkSchedule/queryMonth", params: { relationId: checkedNode.key, yearMonth: `${year}-${month}` }, }).then((res) => { if (res.code == "0000") { let data = res?.data?.dataList ?? []; dispatch({ type: "changeData", scheduleData: data }); } }); } function getListData(value) { for (let i = 0; i < scheduleData.length; i++) { if (value.date() == scheduleData[i].day) { return scheduleData[i].isWeekday == 1 ? "工作日" : "休息日"; } } } function dateCellRender(value) { const listData = getListData(value); let selectDate = value.format("YYYY-MM-DD"), selectDateObj = scheduleData.filter((it) => it.date == selectDate); return (