import React, { Fragment, useState, useEffect, useMemo, useRef } from 'react';
import { useNavigate } from 'umi';
import {
  Card,
  Table,
  Empty,
  Button,
  Modal,
  message,
  Form,
  DatePicker,
  Row,
  Col,
  Select,
} from 'antd';
import { PageContainer } from '@ant-design/pro-components';
const { RangePicker } = DatePicker;
import { useRequest, useModel } from '@umijs/max';
import { queryProfileList, queryApplyList } from '@/services/boom';
import dayjs from 'dayjs';
import { queryApprovedList } from '@/services/contract';
import PageContent from '@/components/PageContent';
const TYPE = {
  Contract: 1,
  OA: 2,
};
function Approved(props) {
  const { user } = useModel('userInfo');
  // const [tabActive, setTabActive] = useState('1');
  // const [detail, setDetail] = useState({});
  const [conVisible, setConVisible] = useState(false);
  const approveFormRef = useRef();
  const applyFormRef = useRef();
  let navigate = useNavigate();
  const contractResult = (res) => {
    let data = res.data?.list?.map((item) => {
      return {
        ...item,
        table_name: `${user.CName}提交的合同审批`,
        table_desc: [
          `合同名称：${item.name}`,
          `合同编号：${item.code}`,
          `合同金额：${item.amount}万元`,
        ],
        CName: user.CName,
        create_time: item.cancel_on || item.created_on,
        type: TYPE.Contract,
        statusText: StatusText[item.status],
        showBtn:
          item.status == Status.Checking || item.status == Status.CalChecking,
        // key: `${TYPE.Contract}_${item.id}`,
      };
    });
    return { data, pagination: res.data?.pagination };
  };
  //OA我审批过的列表
  const {
    data: conAuditedData,
    run: conAuditedRun,
    loading: conAduitedLoading,
  } = useRequest((data) => queryApprovedList(data), {
    defaultParams: [{ currentPage: 1, pageSize: 10 }],
    // formatResult: contractResult,
  });
  // //合同 我审批过的列表
  // const {
  //   data: conAuditData,
  //   run: conAuditRun,
  //   loading: conAduitLoading,
  // } = useRequest((data) => queryGetContractList(data), {
  //   manual: true,
  //   formatResult: contractResult,
  // });0
  // const applyData = useMemo(() => {
  //   let result = [];
  //   if (conAuditedData?.data && conAuditedData?.data.length > 0) result = [...conAuditedData?.data];
  //   return result;
  // }, [conAuditedData]);
  // const onTabChange = (activeKey) => {
  //   if (activeKey == '1') {
  //     conAuditedRun();
  //   } else {

  //   }
  //   setTabActive(activeKey);
  // };
  const handleApplySubmit = (values) => {
    console.log(values);
    OAApplyRun(values);
  };
  const handleApplyPaginationChange = (pagination) => {
    conAuditedRun({
      currentPage: pagination.current,
      pageSize: 10,
    });
  };
  const columns = [
    {
      title: '标题',
      dataIndex: 'name',
      width: '30%',
    },
    // {
    //   title: '摘要',
    //   dataIndex: 'table_desc',
    //   render: (descList) => {
    //     return (
    //       <ul>
    //         {descList?.map((item) => (
    //           <li>{item}</li>
    //         ))}
    //       </ul>
    //     );
    //   },
    // },
    // {
    //   title: '发起人',
    //   dataIndex: 'CName',
    //   width: '20%',
    // },
    {
      title: '发起时间',
      render: (record) => {
        return dayjs(record.create_time).format('YYYY-MM-DD HH:mm:ss');
      },
      width: '20%',
    },
    {
      title: '我审批的时间',
      render: (record) => {
        return dayjs(record.audit_time).format('YYYY-MM-DD HH:mm:ss');
      },
      width: '20%',
    },
    {
      title: '状态',
      // dataIndex: 'status',
      render: (record) => {
        switch (record.audit_status) {
          case 0:
            return '审核中';
          case 1:
            return '通过';
          case 2:
            return '拒绝';
          case 3:
            return '终审通过';
        }
      },
      width: '20%',
    },
  ];

  const renderPage = () => {
    // if (activeKey == '1')
    return (
      <>
        {' '}
        <Form
          name="basic"
          // labelCol={{ span: 0 }}
          // wrapperCol={{ span: 24 }}
          onFinish={handleApplySubmit}
          ref={applyFormRef}
        >
          {/* <div style={{ display: 'flex' }}>
            <Form.Item name="range-picker" label="申请时间：">
              <RangePicker />
            </Form.Item>
            <Form.Item>
              <Button
                type="primary"
                htmlType="submit"
                style={{ marginLeft: 10 }}
              >
                查询
              </Button>
            </Form.Item>
          </div> */}
        </Form>
        <Table
          rowKey="id"
          columns={columns}
          dataSource={conAuditedData?.list}
          loading={conAduitedLoading}
          pagination={conAuditedData?.pagination}
          onChange={handleApplyPaginationChange}
        />
      </>
    );
    // else if (activeKey == '2')
    //   return (
    //     <>
    //       {' '}
    //       <Form
    //         name="basic"
    //         // labelCol={{ span: 0 }}
    //         // wrapperCol={{ span: 24 }}
    //         // onFinish={handleApproveSubmit}
    //         ref={approveFormRef}
    //       >
    //         <div style={{ display: 'flex' }}>
    //           <Form.Item name="range-picker" label="审批时间：">
    //             <RangePicker />
    //           </Form.Item>
    //           <Form.Item name="audit_status" label="状态：" initialValue="">
    //             <Select
    //               style={{ width: 120 }}
    //               options={[
    //                 { value: '', label: '全部' },
    //                 { value: '0', label: '审核中' },
    //                 { value: '1', label: '通过' },
    //                 { value: '2', label: '拒绝' },
    //                 { value: '3', label: '终审通过' },
    //               ]}
    //             />
    //           </Form.Item>
    //           <Form.Item>
    //             <Button
    //               type="primary"
    //               htmlType="submit"
    //               style={{ marginLeft: 10 }}
    //             >
    //               查询
    //             </Button>
    //           </Form.Item>
    //         </div>
    //       </Form>
    //       <Table
    //         columns={agreementColumns}
    //         dataSource={conAuditData?.data}
    //         loading={conAduitLoading}
    //         pagination={conAuditData?.pagination}
    //       // onChange={handleProfilePaginationChange}
    //       />
    //     </>
    //   );
  };
  return (
    <PageContent>
      <div>{renderPage()}</div>
    </PageContent>
  );
}
export default Approved;
