import PageContent from '@/components/PageContent';
import { queryDailyWorkReport } from '@/services/user';
import { LeftOutlined } from '@ant-design/icons';
import { useParams, useRequest } from '@umijs/max';
import { Spin } from 'antd';
import dayjs from 'dayjs';
import styles from './index.less';
const SystemDaily = (props) => {
  const { projectId } = useParams();

  const { data = {}, loading } = useRequest(queryDailyWorkReport, {
    defaultParams: [projectId],
    formatResult: (res) => {
      const data = res.data;
      const result = {
        ...data,
        task_percent:
          data.push_task !== 0 ? data.push_complete_task / data.push_task : 0,
        work_percent:
          data.work_order_task !== 0
            ? data.work_order_complete_task / data.work_order_task
            : 0,
      };
      return result;
    },
  });
  const {
    automatic_task = 0,
    push_optimize_task = 0,
    self_inspection_task = 0,
    self_inspection_normal_task = 0,
    self_inspection_abnormal_task = 0,
    push_task = 0,
    task_percent = 0,
    work_order_task = 0,
    work_percent = 0,
    user_name = '',
    user_name_count = 0,
  } = data;
  const handleOnClick = () => {
    history.back();
  };
  return (
    <PageContent closeable={false}>
      <Spin spinning={loading}>
        <div className={styles.titleContent}>
          <div className={styles.title}>
            <LeftOutlined
              onClick={handleOnClick}
              style={{ fontSize: 36, cursor: 'pointer', marginRight: '20px' }}
            />
            系统工作日报
          </div>
          <div className={styles.time}>{dayjs().format('MM月DD日')}</div>
        </div>
        <div className={styles.content}>
          <div className={styles.text}>
            执行自控指令次数：{automatic_task || 0}次
          </div>
          <div className={styles.text}>
            推送优化建议：{push_optimize_task}条
          </div>
          <div className={styles.text}>
            系统自检次数：{self_inspection_task}条
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;正常次数：
            {self_inspection_normal_task}条
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;异常次数：
            {self_inspection_abnormal_task}条
          </div>
          <div className={styles.text}>
            推送任务：{push_task}条&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            任务完成率：{task_percent}%
          </div>
          <div className={styles.text}>
            工单数量：{work_order_task}条
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;工单完成率：
            {work_percent}%
          </div>
          <div className={styles.text}>
            工单完成人员第一名：
            {user_name ? `${user_name}完成${user_name_count}个工单` : '暂无'}
          </div>
        </div>
      </Spin>
    </PageContent>
  );
};
export default SystemDaily;
