import React, { useEffect, useRef, useState } from 'react';
import { Button, Checkbox, Col, Collapse, DatePicker, Drawer, Form, Input, message, Modal, Popconfirm, Row, Select, Spin, Tabs, Upload } from 'antd'
import ProTable, { ActionType, ProColumns } from '@ant-design/pro-table';
import { getList, saveGroup, delOne, saveMember, changeEx, queryVoList, changeMember, applyFor, roomStatus, juryTem, rePassWord } from './service';
import moment from 'moment';
import { getProId, getProMethod, getDefId, getSessionProjectData, getRoomReturnURL } from '@/utils/session';
import { getURLInformation } from '@/utils/CommonUtils';
import './judgList.less';
import '@/assets/xsy_style.less';
import FileDown from '@/utils/Download';
import { UploadOutlined } from '@ant-design/icons';
import { btnAuthority } from '@/utils/authority';
import RiskPrevention from '@/utils/RiskPrevention';
import { history } from 'umi';
import { downloadFile } from '@/utils/DownloadUtils';
import ExpertPhotoUpload from '@/components/ElecBidEvaluation/ExpertPhotoUpload';
import { getUserPhoto } from '@/pages/Tender/ProjectManager/JudgingPanel/List/service';
import BidEvalAppointment from '@/components/ElecBidEvaluation/BidEvalAppointment';

const JudgingPanel: React.FC<{}> = () => {
  const modalHeight = window.innerHeight * 96 / 100;
  const proId = getProId();
  const roomType = getURLInformation('roomType');
  const roomId = getURLInformation('roomId');
  const sectionId = getURLInformation('secId');
  const formLayout = { labelCol: { span: 8 }, wrapperCol: { span: 16 }, };
  const FormItem = Form.Item;
  const [form] = Form.useForm();
  const { Option } = Select;
  const { Panel } = Collapse;
  const { TextArea } = Input;
  const { TabPane } = Tabs;
  const actionRef = useRef<ActionType>();
  const [spin, spinSet] = useState<any>(false);
  const [loading, loadingSet] = useState<any>(false);
  const [modalVis, setModalVis] = useState<boolean>(false);//新增评委会
  const [updateData, updateDataSet] = useState<any>();//评委会modal数据
  const [memberVis, setMemberVis] = useState<boolean>(false);
  const [open, openSet] = useState<boolean>(false);//评委会里是否有开启评审的评审室 true有开启的 false无
  const [allEnd, allEndSet] = useState<boolean>(true);//评委会关联标段的评审室是否都关闭了   
  // const [yushen, yushenSet] = useState<boolean>(false);//是否预审
  const [readOnly, readOnlySet] = useState<boolean>(true);//只读
  const [disabled, disabledSet] = useState<boolean>(true);//禁用
  const [manNum, manNumSet] = useState<number>(5);//人数
  const [riskVisible, setRiskVisible] = useState<boolean>(false);//风控弹窗 2021.9.7 zhoujianlong
  const [riskData, setRiskData] = useState<any[]>([]);//风控数据 2021.9.7 zhoujianlong
  const [selectEvalVisible, setSelectEvalVisible] = useState<boolean>(false);//电子评标室-评标室预约选择 2022.8.26 zhoujianlong
  const [selectEvalDisabled, setSelectEvalDisabled] = useState<boolean>(true);//电子评标室-评标室预约选择不可选状态控制 true-不可填写 false-可填写 2022.8.26 zhoujianlong
  const [selectEvalData, setSelectEvalData] = useState<any>();//电子评标室-评标室预约选择-数据 2022.8.26 zhoujianlong
  // const [userPhotoId, setUserPhotoId] = useState<string>("");//电子评标室-录入外部专家-相片id 2022.8.29 zhoujianlong
  const [appoType, setAppoType] = useState<string>("0");//电子评标室-预约框状态 2022.8.29 zhoujianlong
  function getShouName() {
    const method = getDefId();
    let num = 3;
    if (method === 'procurement_mode_1' || method === 'procurement_mode_2' || method === 'procurement_mode_3') {//招标
      num = 5;
    }
    manNumSet(num);
  }
  //创建控制
  const [activeKey, activeKeySet] = useState('1');

  //创建评委会小组
  const saveG = async (fields: any) => {
    const hide = message.loading('正在配置');
    try {
      const success = await saveGroup({ ...fields }).then((res) => {
        if (res?.code == 4004 && res?.success == false) { //2021.9.7 zhoujianlong 新增评委会保存增加风控
          const data = res?.data?.result == undefined ? [] : res?.data?.result
          setRiskData(data)
          setRiskVisible(true)
        }
        return res.success
      });
      hide();
      if (success) {
        message.success('配置成功');
      }
      return true;
    } catch (error) {
      hide();
      message.error('配置失败请重试！');
      return false;
    }
  };

  //主页表格
  const [dataSource, dataSourceSet] = useState<any>();//主列表数据
  const [btnDis, btnDisSet] = useState<boolean>(true);//创建评审室按钮
  const columns: ProColumns<any>[] = [
    { title: '序号', valueType: 'index', width: 50, },
    // {
    //   title: '评审小组分类', dataIndex: 'juryType', width: '10%',
    //   valueEnum: {
    //     '1': { text: '资格预审评审', },
    //     '2': { text: '招标项目评审', },
    //   }
    // },
    { title: '专家数量', dataIndex: 'expertNumber', width: '8%', },
    { title: '采购人代表数量', dataIndex: 'representativeNumber', width: '12%', },
    { title: '包件名称', dataIndex: 'sectionName', },
    { title: '预计开始时间', dataIndex: 'startTime', valueType: 'dateTime', width: '10%', },
    { title: '预计结束时间', dataIndex: 'endTime', valueType: 'dateTime', width: '10%', },
    {
      title: '操作', dataIndex: 'option', width: '16%',
      valueType: 'option',
      render: (_, record) => {
        if (record.status == 0 || record.status == 2) {
          return (
            <>
              {returnCheck(record, false)}
              <Popconfirm
                placement="topRight"
                title={"确定删除么？"}
                onConfirm={async () => {
                  spinSet(true)
                  await del({ id: record.id });
                  getPage();
                  spinSet(false)
                }}
                okText="确定"
                cancelText="取消"
              >
                <Button hidden={btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} type='text'>删除</Button>
              </Popconfirm>
              <Button hidden={btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} type='text' onClick={async () => {
                spinSet(true)
                await apply({ id: record.id });
                getPage();
                spinSet(false)
              }}>提交申请</Button>
            </>
          )
        } else if (record.status == 1) {//已提交申请
          return (
            <>{returnCheck(record, true)}</>
          )
        } else if (record.status == 3) {
          return (
            <>
              {returnCheck(record, true)}
              <Button type='text' onClick={async () => {
                await queryOpenStatus(record.id);
                categorySet(record.juryCategoryVOList);
                juryIdSet(record.id);
                memberCountSet(memberCount + 1);
                setMemberVis(true);
              }}>成员管理</Button>
              {record.elecEvalRoomReserve && (record.elecEvalRoomReserve.status == -1 || record.elecEvalRoomReserve.status == 0) && <Button type='text' onClick={() => {
                setSelectEvalData(record.elecEvalRoomReserve)
                setAppoType("1");
                setSelectEvalVisible(true);
              }}>修改预约</Button>}
            </>
          );
        } else {
          return (<></>)
        }
      }
    },
  ];
  useEffect(() => {
    getPage();
    getShouName();//人数判断
  }, [])
  async function getPage() {
    spinSet(true);
    getList(roomId).then(res => {
      if (res?.data != undefined) {
        dataSourceSet([res.data]);
      } else {
        dataSourceSet([]);
      }
      btnDisSet(res.data != undefined);
    })
    spinSet(false);
  }
  function returnCheck(record: any, check: any) {//返回操作列查看、修改按钮
    return (
      <Button
        hidden={!check && btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])}
        type='text'
        onClick={() => {
          updateDataSet(record);
          //剔除代表
          let list = [...record.juryCategoryVOList];
          list.map((item: any, index: any) => {
            if (item.category == 1) {
              list.splice(index, 1);
            }
          });
          cqDataSet(list);
          setModalVis(true);
          disabledSet(check);
          readOnlySet(check);
        }}>{check ? '查看' : '修改'}</Button>
    )
  }

  //删除
  const del = async (fields: any) => {
    const hide = message.loading('正在删除');
    try {
      const success = await delOne({ ...fields }).then((res) => {
        return res.success
      });
      hide();
      if (success) {
        message.success('删除成功');
        return true;
      } else {
        message.error('删除失败');
        return false;
      }
    } catch (error) {
      hide();
      message.error('删除失败请重试！');
      getPage();
      return false;
    }
  };
  //提交申请
  const apply = async (fields: any) => {
    const hide = message.loading('正在提交');
    try {
      const success = await await applyFor({ ...fields }).then((res) => {
        return res.success
      });
      hide();
      if (success) {
        message.success('提交成功');
        return true;
      } else {
        message.error('提交失败');
        return false;
      }
    } catch (error) {
      hide();
      message.error('提交失败请重试！');
      getPage();
      return false;
    }
  };

  function disabledDate(current: any) {//日期选择
    // Can not select days before today and today
    return current && current < moment().startOf('day');
  }


  const rule = (mes: any) => {//创建修改 规则
    return [
      {
        required: true,
        message: `请录入${mes}`,
      },
    ]
  }

  useEffect(() => {//给表单赋值
    if (updateData?.reserveStatus == 1) {
      setSelectEvalDisabled(false);
    }
    form.setFieldsValue({
      juryType: updateData != undefined ? updateData.juryType : null,
      representativeNumber: updateData != undefined ? updateData.representativeNumber : null,
      expertNumber: updateData != undefined ? updateData.expertNumber : null,
      startTime: updateData != undefined ? updateData.reserveStatus == 1 ? moment(updateData.elecEvalRoomReserve.reserveStartDate, 'yyyy-MM-DD HH:mm:ss') : moment(updateData.startTime, 'yyyy-MM-DD HH:mm:ss') : null,
      endTime: updateData != undefined ? updateData.reserveStatus == 1 ? moment(updateData.elecEvalRoomReserve.reserveEndDate, 'yyyy-MM-DD HH:mm:ss') : moment(updateData.endTime, 'yyyy-MM-DD HH:mm:ss') : null,
      evalLocation: updateData != undefined ? updateData.evalLocation : null,
      description: updateData != undefined ? updateData.description : null,
      reserveBy: updateData?.reserveStatus == 1 ? updateData.elecEvalRoomReserve.reserveBy : null,
      reserveContactNumber: updateData?.reserveStatus == 1 ? updateData.elecEvalRoomReserve.reserveContactNumber : null,
    })
  }, [updateData]);

  const group = () => {//评审小组modal
    return (
      <>
        <Modal
          visible={modalVis}
          style={{ overflowX: 'hidden', position: 'relative', }}
          bodyStyle={{ maxHeight: "500px", overflowY: 'auto', overflowX: 'hidden', minHeight: '420px', width: '1000px', }}
          width={'1000px'}
          centered
          maskClosable={false}
          title="创建评审小组"
          footer={renderFooter()}
          onCancel={() => {
            setModalVis(false);
            updateDataSet({});
            cqDataSet([]);
            updateKeySet(-1);
            activeKeySet('1');
          }}
        >
          <Tabs size="large" style={{ backgroundColor: '#fff' }} activeKey={activeKey} onChange={changeTabs}>
            <TabPane tab="评委会基本信息" key="1">
              {tab1()}
            </TabPane>
            <TabPane tab="抽取条件设置" key="2">
              {tab2()}
            </TabPane>
          </Tabs>
          {cqDrawer()}
        </Modal>
      </>
    )
  }
  function changeTabs(key: any) {
    if (key == 1) {
      activeKeySet(key);
    } else {
      nextStep()
    }
  }
  //人数校验
  function checkMan(count: number, expCon: any) {
    let res = true;
    const defId = getDefId();//16
    const method = getProMethod();//9
    const yushenType = getSessionProjectData().openTenderForm;
    let manNumT = 5;

    if (method === 'procurement_mode_1' || method === 'procurement_mode_2') {
      if (roomType == '1' && yushenType == 'open_tender_form_2') {//资格预审   自愿招标为3
        manNumT = 3;
      }
      if (expCon < count * 2 / 3) {
        res = false;
        message.error("专家人数不少于评委会总人数2/3")
      }
    } else if (method === 'procurement_mode_3') {//比选
      if (expCon < count * 2 / 5) {
        res = false;
        message.error("专家人数不少于评委会总人数2/5")
      }
    } else if (method === 'procurement_mode_4') {//招募
      manNumT = 1;
      if (count < manNumT) {
        res = false;
        message.error(`评委会总人数需大于1`)
      } else {
        return true;
      }
    } else if (method === 'procurement_mode_5') {//竞谈
      if (manNumT = 5) {//最低价
        manNumT = 3;
      }
      if (expCon < count * 1 / 3) {
        res = false;
        message.error("专家人数不少于评委会总人数1/3")
      }
    } else if (method === 'procurement_mode_6') {//单一
      manNumT = 3;
    } else if (method === 'procurement_mode_9') {//单一
      manNumT = 3;
    } else if (defId == 'inquiry') {//询价
      manNumT = 3;
    }
    if (count < manNumT || count % 2 == 0) {//校验总人数
      res = false;
      message.error(`评委会总人数需大于等于${manNumT}人且为单数`)
    }
    return res
  }
  async function nextStep() {//下一步
    const formVals = form.getFieldsValue();
    let verify = false;
    await form.validateFields().then(() => {
      let juryRoomListTem: any = [];
      juryRoomListTem.push({ roomId: roomId, sectionId: sectionId, roomType: roomType });
      verify = true;
      juryRoomListSet(juryRoomListTem);
      //采购人数需要大于5 需要取项目类型
      const count = parseInt(formVals.representativeNumber) + parseInt(formVals.expertNumber);

      if (verify) {
        verify = checkMan(count, parseInt(formVals.expertNumber));
      }
      const st = moment(formVals.startTime).format('yyyy-MM-DD HH:mm:ss');
      const et = moment(formVals.endTime).format('yyyy-MM-DD HH:mm:ss');
      if (st > et || st == et) {//校验时间
        verify = false;
        message.error("预计开始时间应早于预计结束时间")
      }
      if (selectEvalData?.reserveStatus == "1") {//预约了评标室
        const selectStartTime = moment(selectEvalData.reserveStartDate).format('yyyy-MM-DD HH:mm:ss');
        const selectEndTime = moment(selectEvalData.reserveEndDate).format('yyyy-MM-DD HH:mm:ss');
        if (selectStartTime != st || selectEndTime != et) {
          verify = false;
          message.error("预约时间需与选择评标室中的预约时间相等");
        }
      }
      if (verify) {
        activeKeySet('2');
      }
    })
  }
  //添加抽取drawer
  const formLayoutDrawer = { labelCol: { span: 8 }, wrapperCol: { span: 16 }, };
  const tailLayoutDrawer = { wrapperCol: { offset: 8, span: 20 }, };
  const [juryRoomList, juryRoomListSet] = useState<any>([]);
  const [cqData, cqDataSet] = useState<any>([]);//抽取表格，提交时需要
  const [addCq, addCqSet] = useState<any>(false);//添加抽取抽屉显示控制
  const [updateKey, updateKeySet] = useState<any>(-1);//触发修改存key
  const [formCq] = Form.useForm();
  const [display, displaySet] = useState<any>(true);
  const columnsCq: ProColumns<any>[] = [//抽取表格
    { title: '序号', valueType: 'index', width: 50, },
    {
      title: '专家分类', dataIndex: 'subCategory',
      valueEnum: {
        '1': { text: '技术', },
        '2': { text: '商务', },
        '3': { text: '法律', },
        '4': { text: '其它', },
      }
    },
    { title: '需抽数量', dataIndex: 'extractNumber', },
    {
      title: '抽取方式', dataIndex: 'extractMethod',
      valueEnum: {
        '1': { text: '外部录入', },
        '2': { text: '随机抽取', },
      }
    },
    { title: '抽取规则要求', dataIndex: 'cqRude', },
    {
      title: '操作', dataIndex: 'option', width: 100,
      valueType: 'option',
      render: (_, record) => {
        return (
          <>
            {
              !disabled ?
                <>
                  <Button hidden={btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} type='text' onClick={() => {
                    addCqSet(true);
                    updateKeySet(record.key);
                    formCq.setFieldsValue({ ...record });
                  }}>修改</Button>
                  <Popconfirm
                    placement="topRight"
                    title={"确定删除么？"}
                    onConfirm={async () => {
                      let dataTem = [...cqData];
                      dataTem.map((item: any, index: any) => {
                        if (item.key == record.key) {
                          dataTem.splice(index, 1)
                        }
                      });
                      cqDataSet(dataTem);
                    }}
                    okText="确定"
                    cancelText="取消"
                  >
                    <Button hidden={btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} type='text' >删除</Button>
                  </Popconfirm>
                </>
                : <></>
            }

          </>
        );
      }
    },
  ];
  const cqDrawer = () => {//添加抽取条件、修改
    return (
      <>
        <Drawer
          title="抽取条件"
          placement="right"
          width={'40%'}
          onClose={() => { addCqSet(false); updateKeySet(-1); formCq.resetFields(); }}
          visible={addCq}
          getContainer={false}
          style={{ position: 'absolute' }}
        >
          <Form {...formLayoutDrawer} form={formCq}>
            <Row>
              <Col span={24}>
                <FormItem name="subCategory" label="专家分类" rules={rule('专家分类')}>
                  <Select style={{ width: "50%" }} >
                    <Option value="1" title='技术'>技术</Option>
                    <Option value="2" title='商务'>商务</Option>
                    <Option value="3" title='法律'>法律</Option>
                    <Option value="4" title='其它'>其它</Option>
                  </Select>
                </FormItem>
              </Col>
            </Row>
            <Row>
              <Col span={24}>
                <FormItem name="extractNumber" label="需求数量" rules={[
                  ...rule('需求数量'),
                  {
                    pattern: /^[0-9]+$/,
                    message: '需求数量应为正整数',
                  }
                ]}>
                  <Input type='number' style={{ width: "50%" }} />
                </FormItem>
              </Col>
            </Row>
            <Row>
              <Col span={24}>
                <FormItem name="extractMethod" label="抽取方式" rules={rule('抽取方式')} initialValue='1'>
                  <Select style={{ width: "50%" }}>
                    <Option value="1" title='外部录入'>外部录入</Option>
                    {/* <Option value="2" title='随机抽取'>随机抽取</Option> */}
                  </Select>
                </FormItem>
              </Col>
            </Row>
            <div>
              {/* <Row>
              <Col span={24}>
                <FormItem name="cqbs" label="抽取倍数">
                  <Select style={{ width: "40%" }} >
                    <Option value="1倍">1倍</Option>
                  </Select>
                </FormItem>
              </Col>
            </Row>
            <Row>
              <Col span={24}>
                <FormItem name="lxcq" label="是否轮询抽取">
                  <Radio.Group>
                    <Radio value={0}>否</Radio>
                    <Radio value={1}>是</Radio>
                  </Radio.Group>
                </FormItem>
              </Col>
            </Row>
            <Row>
              <Col span={24}>
                <FormItem name="zjly" label="专家来院">
                  <Checkbox >中国联通</Checkbox>
                </FormItem>
              </Col>
            </Row>
            <Row>
              <Col span={24}>
                <FormItem name="area" label="所属地区">
                  <Checkbox >中国联通</Checkbox>
                </FormItem>
              </Col>
            </Row>
            <Row>
              <Col span={24}>
                <FormItem name="zhuanye" label="评审专业">
                  <Checkbox >中国联通</Checkbox>
                </FormItem>
              </Col>
            </Row> */}
            </div>
            <Row><Col span={24}><FormItem {...tailLayoutDrawer}>
              <Button hidden={btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} type="primary" loading={loading} onClick={async () => {
                let formValsCq = formCq.getFieldsValue();
                let dataTem = [...cqData];
                let verify = false;
                loadingSet(true);
                await formCq.validateFields().then(() => {
                  verify = true;
                  let index = -1;
                  index = cqData.findIndex((item: any) => item.key == updateKey);//技术的key对不上  查询cqData里对应的index
                  for (const item of cqData) {
                    if (cqData[index] != undefined) {//修改
                      if (cqData[index].subCategory != formValsCq.subCategory && formValsCq.subCategory == item.subCategory) {
                        verify = false; message.error('该类别已存在')
                      }
                    } else {
                      if (formValsCq.subCategory == item.subCategory) {
                        verify = false; message.error('该类别已存在')
                      }
                    }
                  }
                }).catch((errorInfo) => {
                  // message.error(errorInfo);
                  loadingSet(false);
                });
                //如果 updateKey有值，走修改
                if (verify) {
                  if (updateKey != -1) {
                    dataTem.map((item: any, index: any) => {
                      if (item.key == updateKey) {
                        dataTem[index] = { ...formValsCq, key: updateKey, category: 2 };
                      }
                    });
                    cqDataSet(dataTem);
                    addCqSet(false); updateKeySet(-1); formCq.resetFields();//清空
                  } else {
                    let num = 0;
                    if (dataTem.length != 0) {
                      num = dataTem[dataTem.length - 1].key + 1;
                    }
                    dataTem.push({ ...formValsCq, key: num, category: 2 });
                    cqDataSet(dataTem);
                    addCqSet(false); updateKeySet(-1); formCq.resetFields();
                  }
                }
                loadingSet(false);
              }}>保存</Button>
            </FormItem></Col></Row>
          </Form>
        </Drawer>
      </>
    )
  }
  const tab1 = () => {//cqtab1
    return (
      <>
        <h3 className="first-title">专家申请基本信息</h3>
        <Form {...formLayout} form={form}>
          {/* {
            display ?
              <Row style={{ marginTop: '20px', }}>
                <Col span={12}>
                  <FormItem
                    name="juryType"
                    label="专家申请分类"
                    rules={rule('专家申请分类')} >
                    <Select style={{ width: "60%" }} disabled={disabled}>
                      <Option value="1" title='资格预审评审'>资格预审评审</Option>
                      <Option value="2" title='招标项目评审'>招标项目评审</Option>
                    </Select>
                  </FormItem>
                </Col>
                <Button hidden={btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} disabled={disabled} style={{ marginLeft: '-120px' }} type='primary' onClick={() => {
                  form.setFieldsValue({ juryType: '' }); displaySet(!display)
                }}>{display ? '自行输入' : '选择分类'}</Button>
              </Row>
              : <Row style={{ marginTop: '20px', }}>
                <Col span={12}>
                  <FormItem
                    name="juryType"
                    label="专家申请分类"
                    rules={rule('专家申请分类')} >
                    <Input style={{ width: "60%" }} disabled={disabled} />
                  </FormItem>
                </Col>
                <Button hidden={btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} disabled={disabled} style={{ marginLeft: '-120px' }} type='primary' onClick={() => {
                  form.setFieldsValue({ juryType: '' }); displaySet(!display)
                }}>{display ? '自行输入' : '选择分类'}</Button>
              </Row>
          } */}
          <Row>
            <Col span={12}><FormItem
              name="representativeNumber"
              label="采购人代表数量"
              rules={[...rule('采购人代表数量'), { pattern: /^([1-9]?\d|100)$/, message: '请输入正确数值' }]}
            >
              <Input style={{ width: "90%" }} disabled={disabled} />
            </FormItem></Col>
            <Col span={12}><FormItem
              name="expertNumber"
              label="专家数量(不含代表)"
              rules={[...rule('专家数量'), { pattern: /^([1-9]?\d|100)$/, message: '请输入正确数值' }]}
            >
              <Input style={{ width: "90%" }} disabled={disabled} />
            </FormItem></Col>
            <Col span={12}>
              <Form.Item label="评审地点" style={{ marginBottom: 0 }} required>
                <FormItem
                  name="evalLocation"
                  rules={[...rule('评审地点'), { type: 'string', message: '请输入正确内容' }, { max: 100, message: '内容超长' }]}
                  style={{ display: 'inline-block', width: 'calc(60% - 8px)' }}
                >
                  <Input style={{ width: "100%" }} disabled={disabled || !selectEvalDisabled} />
                </FormItem>
                <Form.Item
                  style={{ display: 'inline-block', width: 'calc(40% - 8px)', margin: '0 8px' }}
                >
                  <Button type='primary' onClick={() => selectEvalClick()} disabled={disabled}>选择评标室</Button>
                </Form.Item>
              </Form.Item>
            </Col>
            <Col span={12}><FormItem
              name="description"
              label="申请要求"
              rules={[{ type: 'string', message: '请输入正确内容' }, { max: 100, message: '内容超长' }]}
            >
              <Input style={{ width: "90%" }} disabled={disabled} />
            </FormItem></Col>
            <Col span={12}><FormItem
              name="startTime"
              label="预计评审开始时间"
              rules={rule('开始时间')}
            >
              <DatePicker
                format="YYYY-MM-DD HH:mm:ss"
                disabledDate={disabledDate}
                showTime={{ defaultValue: moment('00:00:00', 'HH:mm:ss') }}
                disabled={disabled}
                showNow={false}
                style={{ width: "90%" }}
              />
            </FormItem></Col>
            <Col span={12}><FormItem
              name="endTime"
              label="预计评审结束时间"
              rules={rule('结束时间')}
            >
              <DatePicker
                format="YYYY-MM-DD HH:mm:ss"
                disabledDate={disabledDate}
                showTime={{ defaultValue: moment('00:00:00', 'HH:mm:ss') }}
                disabled={disabled}
                showNow={false}
                style={{ width: "90%" }}
              />
            </FormItem></Col>
            <Col span={12}><FormItem
              name="reserveBy"
              label="预约人"
              rules={[{ required: !selectEvalDisabled, message: `请录入预约人` }, { max: 100, message: '内容超长' }]}
            >
              <Input style={{ width: "90%" }} disabled={disabled || selectEvalDisabled} />
            </FormItem></Col>
            <Col span={12}><FormItem
              name="reserveContactNumber"
              label="预约人联系方式"
              rules={[{ required: !selectEvalDisabled, message: `请录入预约人联系方式` }, { max: 100, message: '内容超长' }]}
            >
              <Input type="number" style={{ width: "90%" }} disabled={disabled || selectEvalDisabled} />
            </FormItem></Col>
          </Row>
        </Form>
      </>
    )
  }
  const tab2 = () => {//cqtab2
    return (
      <>
        <div className='headerDiv'>
          <h3 className="first-title floatLeft">抽取条件</h3>
          <div className='rightDiv'>
            <Button hidden={btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} disabled={disabled} type='primary' onClick={() => { addCqSet(true) }}>添加抽取条件</Button>
          </div>
        </div>
        <ProTable
          columns={columnsCq}
          dataSource={cqData}
          search={false}
          pagination={false}
          options={false}
          bordered
        />
        <div className='headerDiv mt15'>
          <h3 className="first-title floatLeft">回避单位信息</h3>
          <div className='rightDiv'>
            <Button hidden={btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} type='primary'>添加回避单位</Button>
          </div>
        </div>
        <div className='headerDiv mt15'>
          <h3 className="first-title floatLeft">回避专家信息</h3>
          <div className='rightDiv'>
            <Button hidden={btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} type='primary'>添加回避专家</Button>
          </div>
        </div>
      </>
    )
  }
  const renderFooter = () => {//评审小组footer
    if (activeKey === '1') {
      return (
        <>
          <Button onClick={() => {
            setModalVis(false);
            updateDataSet({});
            cqDataSet([]);
            updateKeySet(-1);
            activeKeySet('1');
          }}>取消</Button>
          <Button type="primary" onClick={async () => {
            nextStep();
          }}>
            下一步
          </Button>
        </>
      );
    }
    if (activeKey === '2') {
      return (
        <>
          <Button style={{ float: 'left' }} onClick={() => { activeKeySet('1') }}>
            上一步
          </Button>
          <Button onClick={() => {
            setModalVis(false);
            updateDataSet({});
            cqDataSet([]);
            updateKeySet(-1);
            activeKeySet('1');
          }}>{disabled ? '关闭' : '取消'}</Button>
          <Button hidden={disabled || btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} type="primary" loading={loading} onClick={async () => {
            loadingSet(true);
            let pass = true;
            const formVals = form.getFieldsValue();
            const count = parseInt(formVals.expertNumber);
            // const formValsCq = formCq.getFieldsValue();
            formVals.startTime != undefined ? formVals.startTime = formVals.startTime.format('yyyy-MM-DD HH:mm:ss') : null;
            formVals.endTime != undefined ? formVals.endTime = formVals.endTime.format('yyyy-MM-DD HH:mm:ss') : null;
            let params = { ...formVals, projectId: proId, juryCategoryVOList: cqData, roomId: roomId, juryRoomList: juryRoomList, reserveStatus: 0 };
            if (updateData != undefined) {
              params['id'] = updateData.id;
            }
            let countCq = 0;
            cqData.map((item: any) => {
              countCq = countCq + parseInt(item.extractNumber);
            });
            if (count != countCq) {
              pass = false;
              message.error(`抽取数量不等于设置的专家数量(${count})`);
            }
            if (selectEvalData?.reserveStatus == "1") {//预约了评标室
              params.reserveStatus = 1;
              const evalRoomReserveVO = {
                ...selectEvalData,
                reserveStartDate: params.startTime,
                reserveEndDate: params.endTime,
                reserveSectionList: juryRoomList.map((item: any) => ({ sectionId: item.sectionId, assessRoomId: item.roomId })),
              }
              params["evalRoomReserveVO"] = evalRoomReserveVO;
            }
            if (pass) {
              const success = await saveG(params);
              if (success) {
                getPage();
                cqDataSet([]);
                updateKeySet(-1);
              }
              setModalVis(false);
              updateDataSet({});
              activeKeySet('1');
            }
            loadingSet(false);
          }}>
            完成
          </Button>
        </>
      );
    } else {
      return (<></>)
    }
  };

  //成员管理
  const [add, setAdd] = useState<boolean>(false);//录入外部专家Drawer显隐
  const [changeMan, changeManSet] = useState<boolean>(false);//更换Drawer显隐
  const [juryId, juryIdSet] = useState<any>('');//更换专家所需评委会id
  const [reason, reasonSet] = useState<any>('');//更换专家原因
  const [category, categorySet] = useState<any>([]);//类别  juryCategoryVOList
  const [daibiao, daibiaoSet] = useState<any>({});//代表
  const [jishu, jishuSet] = useState<any>({});//技术
  const [shangwu, shangwuSet] = useState<any>({});//商务
  const [falv, falvSet] = useState<any>({});//法律
  const [qita, qitaSet] = useState<any>({});//其它
  const [luru, luruSet] = useState<number>(0);//录入外部传类别
  const [updateKeyMem, updateKeyMemSet] = useState<any>(-1);//触发修改存key
  const [memberCount, memberCountSet] = useState<number>(0);//刷新成员管理页面
  const [checkBoxs, checkBoxsSet] = useState<any>([]);//更换专家按钮组
  const [checkBoxsStatus, checkBoxsStatusSet] = useState<any>({});//更换专家按钮组
  const [changeMemberId, changeMemberIdSet] = useState<any>('');//更换专家id
  const [changeBtn, changeBtnSet] = useState<any>(true);//更换按钮显隐
  const [formMem] = Form.useForm();
  function reset() {//重置
    categorySet([]);
    // daibiaoSet({});
    // shangwuSet({});
    // falvSet({});
    // qitaSet({});
    luruSet(0);
    updateKeyMemSet(-1);
    checkBoxsSet([]);
    changeMemberIdSet('');
    form.resetFields();
  }
  const columnsMember: ProColumns<any>[] = [//成员管理页面表格
    { title: '序号', valueType: 'index', width: 50, },
    { title: '专家姓名', dataIndex: 'name', },
    { title: '手机号码', dataIndex: 'mobile', },
    { title: '证件号码', dataIndex: 'certificate', },
    { title: '工作单位', dataIndex: 'workunit', },
    { title: '通知状态', dataIndex: 'status', },
    { title: '通知结果备注', dataIndex: 'remark', },
    {
      title: '照片',
      dataIndex: 'faceId',
      render: (_, record) => {
        if (record.faceId) {
          return <a onClick={() => downloadFile({ uid: record.faceId })}>{record.name}</a>
        };
        return '-';
      }
    },
    {
      title: '操作', dataIndex: 'option', width: 180,
      valueType: 'option',
      render: (_, record) => {
        return (
          <>
            <Button type='text' hidden={open || btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} onClick={() => {//修改
              returnType(record.categoryId);
              setAdd(true);
              updateKeyMemSet(record.key);
              changeBtnSet(true);
              formMem.setFieldsValue({ ...record });
            }}>修改</Button>
            <Popconfirm
              placement="topRight"
              title={"确定删除么？"}
              onConfirm={() => { confirmMem(record); }}
              okText="确定"
              cancelText="取消"
            >
              <Button type='text' hidden={open || btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])}>删除</Button>
            </Popconfirm>
            <Button type='text' hidden={btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase']) || record.changeStatus == 0 || record.changeStatus == undefined} onClick={() => {//更换
              returnType(record.categoryId);
              setAdd(true);
              updateKeyMemSet(record.key);
              changeMemberIdSet(record.id);
              changeBtnSet(false);
              formMem.setFieldsValue({ ...record });
            }}>更换</Button>
            <Button type='text' hidden={!open || allEnd || btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} onClick={async () => {
              await rePassWord(record.id);
            }}>重置密码</Button>
          </>
        );
      }
    },
  ];
  function returnType(inId: any) {//修改时根据record.categoryId判断类别
    category != undefined ? category.map((item: any,) => {
      if (item.id == inId) {
        if (item.category == 1) {
          luruSet(1);
        } else if (item.category == 2 && item.subCategory == 1) {
          luruSet(2);
        } else if (item.category == 2 && item.subCategory == 2) {
          luruSet(3);
        } else if (item.category == 2 && item.subCategory == 3) {
          luruSet(4);
        } else if (item.category == 2 && item.subCategory == 4) {
          luruSet(5);
        }
      }
    }) : null;
  }
  function returnCate(luru: any) {//取data
    switch (luru) {
      case 1: return daibiao;
      case 2: return jishu;
      case 3: return shangwu;
      case 4: return falv;
      case 5: return qita;
      default: break;
    }
  }
  function dataSet(data: any, luru: any) {//塞data
    let dataT = [];
    switch (luru) {
      case 1: dataT = daibiao; dataT.juryMemberList = data; daibiaoSet(dataT); break;
      case 2: dataT = jishu; dataT.juryMemberList = data; jishuSet(dataT); break;
      case 3: dataT = shangwu; dataT.juryMemberList = data; shangwuSet(dataT); break;
      case 4: dataT = falv; dataT.juryMemberList = data; falvSet(dataT); break;
      case 5: dataT = qita; dataT.juryMemberList = data; qitaSet(dataT); break;
      default: break;
    }
  }
  function returnHeader(name: any) {
    return (
      <h3 className="first-title">{name}</h3>
    )
  }
  function returnCheckBox(type: any) {//更改选人
    return (
      <>
        {type != undefined ?
          type.map((item: any) => {
            return (
              <Checkbox checked={checkBoxsStatus[item.id]} name='checkBoxsChange' value={item.id} onChange={(e) => {
                let data = [...checkBoxs];
                let status = { ...checkBoxsStatus };
                if (e.target.checked) {
                  data.push({ memberId: item.id });
                  status[item.id] = true;
                } else {
                  data.map((item: any, index: any) => {
                    item.memberId == e.target.value ? data.splice(index, 1) : null;
                  })
                  status[item.id] = false;
                }
                checkBoxsStatusSet(status);
                checkBoxsSet(data);
              }}>{item.name}</Checkbox>
            )
          }) : null
        }
      </>
    )
  }
  useEffect(() => {//拆类别
    daibiaoSet({});
    jishuSet({});
    shangwuSet({});
    falvSet({});
    qitaSet({});
    category.map((item: any) => {
      if (item.category == 1) {
        daibiaoSet(item);
      } else {
        if (item.subCategory == 1) {
          jishuSet(item);
        } else if (item.subCategory == 2) {
          shangwuSet(item);
        } else if (item.subCategory == 3) {
          falvSet(item);
        } else if (item.subCategory == 4) {
          qitaSet(item);
        }
      }
    });
  }, [memberCount]);
  async function queryOpenStatus(id: any) {//查是否开启评审  id:评委会id
    await roomStatus(id).then((res) => {
      if (res.data) {
        openSet(res.data.anyOpenRoom);
        allEndSet(res.data.allEndRoom);
      }
    })
  }
  const returnPanel = () => {//返回手风琴
    return (
      <>
        {daibiao.juryMemberList != undefined ?
          <Panel header={`采购人代表(最大人数：${daibiao.extractNumber})`} key="1">
            <ProTable
              key='proTable1'
              columns={columnsMember}
              dataSource={daibiao.juryMemberList}
              bordered
              style={{ padding: '16px' }}
              options={false}
              search={false}
              pagination={false}
              toolBarRender={() => [
                <Button key="button" hidden={open || btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} disabled={daibiao.extractNumber == daibiao.length} type="primary"
                  onClick={() => {
                    if (returnCate(1).juryMemberList.length != returnCate(1).extractNumber) {
                      setAdd(true); luruSet(1); formMem.resetFields();
                    } else {
                      message.error('录入人数已满')
                    }
                  }}
                > 录入外部专家</Button>
              ]}
            />
          </Panel>
          : null}
        {jishu.juryMemberList != undefined ?
          <Panel header={`技术(最大人数：${jishu.extractNumber})`} key="2">
            <ProTable
              key='proTable2'
              columns={columnsMember}
              dataSource={jishu.juryMemberList}
              bordered
              style={{ padding: '16px' }}
              options={false}
              search={false}
              pagination={false}
              toolBarRender={() => [
                <Button key="button" hidden={open || btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} disabled={jishu.extractNumber == jishu.length}
                  type="primary" onClick={() => {
                    if (returnCate(2).juryMemberList.length != returnCate(2).extractNumber) {
                      setAdd(true); luruSet(2); formMem.resetFields();
                    } else {
                      message.error('录入人数已满')
                    }
                  }}> 录入外部专家</Button>
              ]}
            />
          </Panel>
          : null}
        {shangwu.juryMemberList != undefined ?
          <Panel header={`商务(最大人数：${shangwu.extractNumber})`} key="3">
            <ProTable
              key='proTable3'
              columns={columnsMember}
              dataSource={shangwu.juryMemberList}
              bordered
              style={{ padding: '16px' }}
              options={false}
              search={false}
              pagination={false}
              toolBarRender={() => [
                <Button key="button" hidden={open || btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} disabled={shangwu.extractNumber == shangwu.length}
                  type="primary" onClick={() => {
                    if (returnCate(3).juryMemberList.length != returnCate(3).extractNumber) {
                      setAdd(true); luruSet(3); formMem.resetFields();
                    } else {
                      message.error('录入人数已满')
                    }
                  }}> 录入外部专家</Button>
              ]}
            />
          </Panel>
          : null}
        {falv.juryMemberList != undefined ?
          <Panel header={`法律(最大人数：${falv.extractNumber})`} key="4">
            <ProTable
              key='proTable4'
              columns={columnsMember}
              dataSource={falv.juryMemberList}
              bordered
              style={{ padding: '16px' }}
              options={false}
              search={false}
              pagination={false}
              toolBarRender={() => [
                <Button key="button" hidden={open || btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} disabled={falv.extractNumber == falv.length}
                  type="primary" onClick={() => {
                    if (returnCate(4).juryMemberList.length != returnCate(4).extractNumber) {
                      setAdd(true); luruSet(4); formMem.resetFields();
                    } else {
                      message.error('录入人数已满')
                    }
                  }}> 录入外部专家</Button>
              ]}
            />
          </Panel>
          : null}
        {qita.juryMemberList != undefined ?
          <Panel header={`其它(最大人数：${qita.extractNumber})`} key="5">
            <ProTable
              key='proTable5'
              columns={columnsMember}
              dataSource={qita.juryMemberList}
              bordered
              style={{ padding: '16px' }}
              options={false}
              search={false}
              pagination={false}
              toolBarRender={() => [
                <Button key="button" hidden={open || btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} disabled={qita.extractNumber == qita.length}
                  type="primary" onClick={() => {
                    if (returnCate(5).juryMemberList.length != returnCate(5).extractNumber) {
                      setAdd(true); luruSet(5); formMem.resetFields();
                    } else {
                      message.error('录入人数已满')
                    }
                  }}> 录入外部专家</Button>
              ]}
            />
          </Panel>
          : null}
      </>
    )
  }
  function checkRe(data: any) {//查重
    let pass = true;
    !checkReRoot(daibiao, data, 1) ? pass = false : null;
    !checkReRoot(jishu, data, 2) ? pass = false : null;
    !checkReRoot(shangwu, data, 3) ? pass = false : null;
    !checkReRoot(falv, data, 4) ? pass = false : null;
    !checkReRoot(qita, data, 5) ? pass = false : null;
    return pass;
  }
  function checkReRoot(type: any, data: any, updateType: any) {//查重
    const { certificate, mobile, name } = data;
    let pass = true;
    if (certificate == '' || mobile == '' || name == '' || certificate == undefined || mobile == undefined || name == undefined) {
      pass = false;
    } else {
      if (type.juryMemberList != undefined && updateType != luru) {
        for (const item of type.juryMemberList) {
          if (item.certificate == certificate) {//身份证号重复
            pass = false;
            message.error('身份证号重复');
            break;
          }
          if (item.mobile == mobile) {//手机号重复
            pass = false;
            message.error('手机号重复');
            break;
          }
        }
      } else if (type.juryMemberList != undefined && updateType == luru) {
        for (const item of type.juryMemberList) {
          if (item.certificate == certificate && item.key != updateKeyMem) {//身份证号重复
            pass = false;
            message.error('身份证号重复');
            break;
          }
          if (item.mobile == mobile && item.key != updateKeyMem) {//手机号重复
            pass = false;
            message.error('手机号重复');
            break;
          }
        }
      }
    }

    return pass;
  }
  const returnDrawerMem = () => {//成员管理抽屉（专家信息）添加、修改
    return (
      <>
        <Drawer
          title="录入外部专家"
          placement="right"
          width={'50%'}
          onClose={() => {
            setAdd(false);
            changeBtnSet(true);
            // formMem.resetFields();
          }}
          visible={add}
          getContainer={false}
          style={{ position: 'absolute' }}
        >
          <Form {...formLayoutDrawer} form={formMem}>
            <Row><Col span={24}><FormItem
              name="mobile"
              label="手机号"
              rules={[
                ...rule('手机号'),
                {
                  pattern: /(^[1][3,4,5,6,7,8,9][0-9]{9}$)|(^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$)/,
                  message: '输入的电话号码不正确',
                },
              ]}
            >
              <Input style={{ width: "60%" }} />
            </FormItem></Col></Row>
            <Row><Col span={24}><FormItem
              name="name"
              label="姓名"
              rules={rule('姓名')}
            >
              <Input style={{ width: "60%" }} />
            </FormItem></Col></Row>
            <Row><Col span={24}><FormItem
              name="workunit"
              label="工作单位"
            >
              <Input style={{ width: "60%" }} />
            </FormItem></Col></Row>
            <Row><Col span={24}><FormItem
              name="phone"
              label="办公电话"
              rules={[
                {
                  pattern: /^\d+$|^\d+[.]?\d+$/,
                  message: '输入的电话号码不正确',
                },
              ]}
            >
              <Input style={{ width: "60%" }} />
            </FormItem></Col></Row>
            <Row><Col span={24}><FormItem
              name="certificateType"
              label="证件类别"
              initialValue={'1'}
            >
              <Select style={{ width: "60%" }} >
                <Option value={'1'} title="居民身份证">居民身份证</Option>
              </Select>
            </FormItem></Col></Row>
            <Row><Col span={24}><FormItem
              name="certificate"
              label="证件号码"
              rules={[
                ...rule('证件号码'),
                {
                  pattern: /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
                  message: '输入的身份证号不正确',
                },
              ]}
            >
              <Input style={{ width: "60%" }} />
            </FormItem></Col></Row>
            <Form.Item label="照片" style={{ marginBottom: 0 }}>
              <Form.Item
                name="faceId"
                style={{ display: 'inline-block', width: '60%' }}
              >
                <ExpertPhotoUpload maxSize={60} />
              </Form.Item>
              <Form.Item
                style={{ display: 'inline-block', width: '40%', position: "relative", right: '24%' }}
              >
                <Button type='primary' onClick={() => getExpertPhoto()}>获取照片</Button>
              </Form.Item>
            </Form.Item>
            {/* <Row><Col span={24}><FormItem
                name="type"
                label="通知方式"
              >
                <Select style={{ width: "60%" }}>
                  <Option key="1" value="人工通知">人工通知</Option>
                </Select>
              </FormItem></Col></Row> */}
            <Row><Col span={24}><FormItem {...tailLayoutDrawer}>
              <Button type="primary" loading={loading} hidden={!changeBtn || btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} onClick={async () => {
                loadingSet(true);
                let pass = true;
                let formValsMem = formMem.getFieldsValue();
                const dataTem = [...returnCate(luru).juryMemberList];
                await formMem.validateFields().then(() => {
                  pass = checkRe(formValsMem);
                }).catch(() => {
                  pass = false;
                });
                if (pass) {
                  //如果 updateKey有值，走修改
                  if (updateKeyMem != undefined && updateKeyMem != -1) {
                    dataTem.map((item: any, index: any) => {
                      if (item.key == updateKeyMem) {
                        dataTem[index] = { ...formValsMem, key: updateKeyMem, categoryId: returnCate(luru).id };
                      }
                    });
                    dataSet(dataTem, luru);
                  } else {
                    if (returnCate(luru).juryMemberList.length != returnCate(luru).extractNumber) {
                      let num = 0;
                      if (dataTem.length != 0) {
                        num = dataTem[dataTem.length - 1].key + 1;
                      }
                      dataTem.push({ ...formValsMem, key: num, categoryId: returnCate(luru).id });
                      dataSet(dataTem, luru);
                    } else {
                      message.error('录入人数已满！');
                    }
                  }
                  updateKeyMemSet(-1);
                  memberCountSet(memberCount + 1);
                  changeBtnSet(true);
                  setAdd(false);
                }
                loadingSet(false);
              }}>暂存</Button>
              <Button type="primary" loading={loading} hidden={changeBtn || btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} onClick={async () => {
                loadingSet(true);
                let formValsMem = formMem.getFieldsValue();
                const success = await changeMember({ ...formValsMem, oldId: changeMemberId }).then((res) => {
                  return res.success
                });
                if (success) { message.success('更改成功！') } else { message.error('更改失败！'); }
                await queryVoList({ id: juryId }).then((res) => {
                  if (res.code == 200) {
                    categorySet(res.data.juryCategoryVOList);
                    memberCountSet(memberCount + 1);
                  }
                });
                getPage();
                loadingSet(false);
                changeBtnSet(true);
                setAdd(false);
              }}>更换</Button>
            </FormItem></Col></Row>
          </Form>
        </Drawer>
      </>
    )
  }
  const returnDrawerChange = () => {//更换专家抽屉
    return (
      <>
        <Drawer
          title="更换专家"
          placement="left"
          width={'50%'}
          onClose={() => changeManSet(false)}
          visible={changeMan}
          getContainer={false}
          style={{ position: 'absolute' }}
          footer={<div>
            <Button hidden={btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} type='primary' style={{ float: 'right' }} loading={loading} onClick={async () => {
              loadingSet(true);
              const success = await changeEx({ changeMemberList: checkBoxs, juryId: juryId, reason: reason }).then((res) => {
                return res.success
              })
              if (success) {
                message.success('申请成功！');
                changeManSet(false);
              } else {
                message.error('申请失败！');
              }
              await queryVoList({ id: juryId }).then((res) => {
                if (res.code == 200) {
                  categorySet(res.data.juryCategoryVOList);
                  memberCountSet(memberCount + 1);
                }
              });
              checkBoxsSet([]);
              loadingSet(false);

            }}>确定</Button>&nbsp;&nbsp;
            <Button style={{ float: 'right', marginRight: '10px' }} onClick={async () => { changeManSet(false); }}>取消</Button>
          </div>}
        >
          {daibiao.juryMemberList != undefined ? <>
            {returnHeader('采购人代表')}
            {returnCheckBox(daibiao.juryMemberList)}
          </> : null}
          {jishu.juryMemberList != undefined ? <>
            {returnHeader('技术类专家')}
            {returnCheckBox(jishu.juryMemberList)}
          </> : null}
          {shangwu.juryMemberList != undefined ? <>
            {returnHeader('商务类专家')}
            {returnCheckBox(shangwu.juryMemberList)}
          </> : null}
          {falv.juryMemberList != undefined ? <>
            {returnHeader('法律类专家')}
            {returnCheckBox(falv.juryMemberList)}
          </> : null}
          {qita.juryMemberList != undefined ? <>
            {returnHeader('其它类专家')}
            {returnCheckBox(qita.juryMemberList)}
          </> : null}
          <br /><br />取消原因：
          <TextArea onBlur={(e) => { reasonSet(e.target.value) }} />
        </Drawer>
      </>
    )
  }
  const returnFooterMem = () => {//返回成员modal foot
    return (
      <>
        <Button onClick={() => {
          setMemberVis(false);
          categorySet([]);
        }}>取消</Button>
        <Button hidden={btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} type="primary" disabled={open} loading={loading || spin} onClick={async () => {
          loadingSet(true);
          const params = [];
          let chackNum: any = true;
          if (daibiao.juryMemberList != undefined) {
            if (daibiao.extractNumber == daibiao.juryMemberList.length) {
              params.push(...daibiao.juryMemberList)
            } else {
              chackNum = false;
              message.error('代表人数不符合规定!');
            }
          }
          if (jishu.juryMemberList != undefined) {
            if (jishu.extractNumber == jishu.juryMemberList.length) {
              params.push(...jishu.juryMemberList)
            } else {
              chackNum = false;
              message.error('技术类人数不符合规定!');
            }
          }
          if (shangwu.juryMemberList != undefined) {
            if (shangwu.extractNumber == shangwu.juryMemberList.length) {
              params.push(...shangwu.juryMemberList)
            } else {
              chackNum = false;
              message.error('商务类人数不符合规定!');
            }
          }
          if (falv.juryMemberList != undefined) {
            if (falv.extractNumber == falv.juryMemberList.length) {
              params.push(...falv.juryMemberList)
            } else {
              chackNum = false;
              message.error('法律类人数不符合规定!');
            }
          }
          if (qita.juryMemberList != undefined) {
            if (qita.extractNumber == qita.juryMemberList.length) {
              params.push(...qita.juryMemberList)
            } else {
              chackNum = false;
              message.error('其它类人数不符合规定!');
            }
          }
          // jishu != undefined && jishu.extractNumber==jishu.juryMemberList.length ? params.push(...jishu.juryMemberList) : null;
          // shangwu != undefined && shangwu.extractNumber==shangwu.juryMemberList.length ? params.push(...shangwu.juryMemberList) : null;
          // falv != undefined && falv.extractNumber==falv.juryMemberList.length ? params.push(...falv.juryMemberList) : null;
          // qita != undefined && qita.extractNumber==qita.juryMemberList.length ? params.push(...qita.juryMemberList) : null;

          if (chackNum) {
            const success = await saveMember({ juryMemberDTOList: params, roomId: roomId }).then((res) => {
              return res.success
            });
            if (success) {
              message.success('保存成功！');
              categorySet([]);
              setMemberVis(false);
              getPage();
            } else {
              message.error('保存失败');
            }
          }
          loadingSet(false);
        }}>保存</Button>
      </>
    )
  }
  //上传文件
  const props = {
    name: 'file',
    action: '/api/biz-service-ebtp-rsms/v1/jury/template/import',
    // headers: {
    //   authorization: 'authorization-text',
    // },
    data: {
      juryId: juryId
    },
    accept: ".xls,.xlsx",
    itemRender: () => { return null },
    onChange(info: any) {
      spinSet(true);
      if (info.file.status === 'done') {
        if (info.file?.response?.code == 200) {
          if (info.file?.response?.data[0].juryMemberList != null) {
            message.success(`${info.file.name} 导入成功`);
            categorySet(info.file?.response?.data);
            memberCountSet(memberCount + 1);
            spinSet(false);
          } else {
            message.error('导入数据为空,请确认');
            spinSet(false);
          }
        } else {
          message.error(info.file?.response?.message);
          spinSet(false);
        }
      } else if (info.file.status === 'error') {
        message.error(`${info.file.name} 导入失败`);
        spinSet(false);
      }
    },
  };
  const [oid, oidSet] = useState<any>('');
  useEffect(() => {
    juryTem().then(res => {
      res?.code == 200 && oidSet(res.data?.documentCenterId);
    })
  }, [])
  const member = () => {//返回成员管理Modal
    return (
      <>
        <Modal
          visible={memberVis}
          maskClosable={false}
          style={{ overflowX: 'hidden', maxHeight: modalHeight }}
          width={"60%"}
          centered
          destroyOnClose
          title="评审小组成员管理"
          bodyStyle={{ maxHeight: modalHeight - 140, overflow: 'auto', minHeight: '300px', padding: '16px 0px 0px 0px' }}
          footer={returnFooterMem()}
          onCancel={() => {
            setMemberVis(false);
            reset();
          }}
        >
          <Spin spinning={spin}>
            <div className='headerDiv pl24 pr16'>
              <h3 className="first-title floatLeft">评审小组成员管理</h3>
              <div className='rightDiv'>
                {/* <Button key="1" className='mR8' onClick={() => { }}>通知专家</Button> */}
                <Button key="2" type='primary' className='mR8' hidden={!open || allEnd || btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} onClick={() => {
                  checkBoxsSet([]);
                  checkBoxsStatusSet({});
                  changeManSet(true)
                }}>更换专家</Button>
                <FileDown fileId={oid} btnName={'下载EXCEL模板'} style={{ margin: '2px 5px' }} />
                <Upload {...props}>
                  <Button icon={<UploadOutlined />} hidden={open || btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} disabled={spin} type="primary" key="4" style={{ margin: '2px 5px' }}>导入EXCEL模板</Button>
                </Upload>
              </div>
            </div>

            <Collapse className='xsy-collapse' style={{ marginTop: '16px' }} defaultActiveKey={['1', '2', '3', '4', '5',]}>
              {returnPanel()}
            </Collapse>
          </Spin>
          {returnDrawerMem()}
          {returnDrawerChange()}
        </Modal>
      </>
    )
  }

  const confirmMem = async (record: any) => {
    let type: number = 0;
    category != undefined ? category.map((item: any,) => {//判断类别
      if (item.id == record.categoryId) {
        if (item.category == 1) {
          type = 1;
        } else if (item.category == 2 && item.subCategory == 1) {
          type = 2;
        } else if (item.category == 2 && item.subCategory == 2) {
          type = 3;
        } else if (item.category == 2 && item.subCategory == 3) {
          type = 4;
        } else if (item.category == 2 && item.subCategory == 4) {
          type = 5;
        }
      }
    }) : null;
    const dataTem = [...returnCate(type).juryMemberList];
    dataTem.map((item: any, index: any) => {
      if (item.key == record.key) {
        dataTem.splice(index, 1);
      }
    });
    dataSet(dataTem, type);
    memberCountSet(memberCount + 1);
  }

  //评标室预约回调
  const returnEvalData = (value: any) => {
    setSelectEvalVisible(false);
    setSelectEvalDisabled(false);
    setSelectEvalData(value);
    form.setFieldsValue({
      startTime: value.reserveStartDate,
      endTime: value.reserveEndDate,
      evalLocation: value.areaAddress,
      reserveBy: value.reserveBy,
      reserveContactNumber: value.reserveContactNumber,
    })
  }
  //评标室预约-选择评标室
  const selectEvalClick = () => {
    setAppoType("0");
    setSelectEvalVisible(true);
  }
  //录入外部专家-获取照片
  const getExpertPhoto = () => {
    formMem.validateFields(["certificate"]).then(value => {
      getUserPhoto(value.certificate).then(res => {//获取照片
        if (res?.code == 200) {
          const data = res?.data;
          if (data) {
            formMem.setFieldsValue({ faceId: data });
            message.info("获取专家照片成功");
          } else {
            message.info("当前专家无照片，请上传");
          }
        }
      })
    })
  }

  return (
    <div className='bgCWhite' style={{ padding: '24px' }}>
      <Spin spinning={spin}>
        <div className='xsy-headerDiv'>
          <h3 className="first-title floatLeft">评审小组管理</h3>
          <div className='xsy-rightDiv'>
            <Button key="button" hidden={btnDis || btnAuthority(['ebtp-agency-project-manager', 'ebtp-purchase'])} type="primary" onClick={() => {
              setModalVis(true);
              // form.resetFields();
              reset();
              setSelectEvalData(null);
              disabledSet(false); readOnlySet(false);
            }}>创建评审小组</Button>
            <Button style={{ marginLeft: '10px' }} onClick={() => { history.push(getRoomReturnURL()) }}>返回</Button>
          </div>
        </div>
        <ProTable
          key='proTable6'
          // title={() => }
          // headerTitle={<h3 className="first-title floatLeft">评审小组管理</h3>}
          actionRef={actionRef}//action触发后更新表格
          columns={columns}//表格
          dataSource={dataSource}
          size='small'
          options={false}
          search={false}
          tableAlertRender={false}
          pagination={{
            defaultPageSize: 10,
            showSizeChanger: false,
          }}//默认显示条数
        // toolBarRender={() => [
        //   <Button key="button" hidden={btnDis} type="primary" onClick={() => {
        //     setModalVis(true);
        //     // form.resetFields();
        //     reset();
        //     disabledSet(false); readOnlySet(false);
        //   }}>
        //     创建评审小组
        //   </Button>,
        //   <Button style={{ marginLeft: '10px' }} onClick={() => { history.back() }}>返回</Button>
        // ]}
        // request={() => getList(roomId).then((res) => {
        //   let dataT: any = [];
        //   if (res.data != undefined) {
        //     btnDis = true;
        //     dataT.push(res.data);
        //   } else {
        //     btnDis = false;
        //   }
        //   const result = {
        //     data: dataT,
        //     total: res.data.total,
        //     success: res.data.success,
        //     pageSize: res.data.pageSize,
        //     current: res.data.current
        //   };
        //   return result;
        // })}
        />
      </Spin>
      {group()}
      {member()}
      {/**风控组件 */}
      {riskVisible && <RiskPrevention
        modalVisible={riskVisible}
        onCancel={() => {
          setRiskVisible(false)
          setRiskData([])
        }}
        data={riskData}
      />}
      {/**电子评标室-评标室预约选择 */}
      <BidEvalAppointment modalVisible={selectEvalVisible} onCancel={() => setSelectEvalVisible(false)} onSubmit={(value: any) => returnEvalData(value)} values={selectEvalData} type={appoType} reload={() => actionRef.current?.reload()} />
    </div>
  )
}
export default JudgingPanel;