import { Button, Card, Form } from "antd"
import { history } from 'umi';
import ProTable from '@ant-design/pro-table';
import React, { useEffect, useState } from "react";
import { getInteriorManagerProjectList } from '../service'
import { auctionFollowUpAProjectManager, getDicData } from '@/utils/session';
import { getUrlParam, getUrlRelativePath, isEmpty, proTableValueEnum } from '@/utils/CommonUtils';
import { btnAuthority } from '@/utils/authority';

const AuctionMyLookingForInnerShot: React.FC<{}> = () => {
  const [form] = Form.useForm();

  //获取字典
  const getDict: any = getDicData();
  const dictData = JSON.parse(getDict);
  //项目列表参数
  const [projectParams, setProjectParams] = useState<string>("");
  //url项目名称
  const projectName = getUrlParam("projectName");
  //url分页信息
  const current = getUrlParam("current");
  const columns: any = [
    {
      title: '序号',
      valueType: 'index',
      width: 80
    },
    {
      title: '处置名称',
      dataIndex: 'projectName',
      initialValue: projectName ? projectName : void 0
    },
    {
      title: '处置编号',
      dataIndex: 'disposalNum',
      search: false,
      key: 'disposalNum',
    },

    {
      title: '处置实施部门',
      dataIndex: 'disposalDepartmentName',
      search: false,
      key: 'disposalDepartmentName',
    },
    {
      title: '处置经理',
      dataIndex: 'disposalManagerName',
      search: false,
    },
    {
      title: '处置类型',
      dataIndex: 'auctionType',
      valueEnum: proTableValueEnum(dictData['dispose_type=ebp_project']),
      search: false,
      key: 'auctionType',
    },

    {
      title: '竞拍开始时间',
      dataIndex: 'auctionStartTime',
      search: false,
      key: 'auctionStartTime',
    },
    {
      title: '状态',
      dataIndex: 'bidOpeningStatus',
      search: false,
      key: 'bidOpeningStatus',
      render: (_: any, record: any) => {
        if (record.bidOpeningStatus == 0) {
          return (<>未开始</>)
        } else if (record.bidOpeningStatus == 1) {
          return (<>正在竞拍</>)
        } else if (record.bidOpeningStatus == 2) {
          return (<>竞拍结束</>)
        } else if (record.bidOpeningStatus == 6) {//（手动结束）竞拍结束无人出价页面操作
          return (<>竞拍结束</>)
        } else if (record.bidOpeningStatus == 7) {
          return (<>竞拍中止</>)
        } else {
          return (<>未开始</>)
        }
      }
    },
    {
      title: '操作',
      valueType: 'option',
      width: 100,
      render: (_: any, record: any) => {
        return <Button hidden={btnAuthority(['ebtp-auction-manager'])} type='link' danger onClick={() => saveProject({
          "id": record?.id,
          "projectName": record?.projectName,
          "bidMethodDict": 'auction',
        })}>项目跟进</Button>
      }
    }
  ];

  const pagination: any= { 
    defaultPageSize: 10, 
    showSizeChanger: false,
    defaultCurrent: current ? Number(current) : 1
  }

  const saveProject = (val: any) => { // 点击项目跟进存储项目信息
    let projectURLParams = JSON.parse(projectParams);
    let params = `${'?current=' + projectURLParams.current}${isEmpty(projectURLParams.projectName) ? '' : '&projectName=' + projectURLParams.projectName}`;
    val.returnURL = getUrlRelativePath() + params;
    auctionFollowUpAProjectManager(val);
    history.push('/ProjectLayout/Auction/AuctionInfoManage')
  }

  /*拉取数据 beg*/
  useEffect(() => {
    form.resetFields();//清除form中数据
  }, []);

  return (
    <>
      <Card title="我发起的内拍项目">
        <ProTable
          className="proSearch"
          columns={columns}
          rowKey="id"
          options={false}
          size="small"
          request={async (params) =>
            await getInteriorManagerProjectList(params).then((res) => {
              setProjectParams(JSON.stringify(params));
              if (res.code == 200) {
                let data = res.data;
                return Promise.resolve({
                  data: data.records,
                  success: res.success,
                  total: res.data.total,
                  current: res.data.current,
                });
              }
              return Promise.resolve({
                data: [],
                success: false,
                total: 0,
                current: 1,
              });
            })
          }
          pagination={pagination}
          toolBarRender={false}
          search={{
            filterType: "query",
            optionRender: (searchConfig: any, { form }) => {
              return [
                <Button
                  key="resetText"
                  onClick={() => {
                    form?.setFieldsValue({
                      projectName: null,
                      bidMethodDict: null,
                      current: 1,
                    })
                    form?.submit();
                  }}
                >
                  {searchConfig?.resetText}
                </Button>,
                <Button
                  key="searchText"
                  type="primary"
                  onClick={() => {
                    form?.submit();
                  }}
                >
                  {searchConfig?.searchText}
                </Button>,
              ];
            },
          }}
        />
      </Card>
    </>
  )
}

export default AuctionMyLookingForInnerShot







