import React, {useEffect, useState} from 'react';
import {Button, Card, Divider, List, message, Modal, Progress} from "antd";
import style from "@/pages/BiddingAnnouncement/components/style.less";
import ProTable from "@ant-design/pro-table";
import {DownloadOutlined, UnorderedListOutlined} from "@ant-design/icons/lib";
import {getBiddingDocumentsDecryptList, DownFile, decryptFile} from "./service"
import './index.less';

interface BiddingDocumentsDecryptProps {
  assessRoomId: "1331563848498413568";
}

const BiddingDocumentsDecrypt: React.FC<BiddingDocumentsDecryptProps> = (props) => {
  // /*投标文件查看*/
  const [pageloading, setPageloading] = useState<boolean>(false);
  const [spin, spinSet] = useState<any>(false);

  const [rateVis, handleRateVis] = useState<boolean>(false); //进度显隐
  const [rateCount, rateCountSet] = useState<number>(0); //查询进度启动器
  const [jmComplete, jmCompleteSet] = useState<number>(0);//已解密成功
  const [jmFail, jmFailSet] = useState<number>(0);//解密失败
  const [jmWait, jmWaitSet] = useState<number>(0);//未解密
  const [jmFileCount, jmFileCountSet] = useState<number>(0);//文件总数




  const [ListData, setListData] = useState<any>();
  useEffect(() => {
    getBiddingDocumentsDecryptList("1331563848498413568").then(res => {
      if (res.message != null && res.message == "success") {
        setListData(res.data)
      }

    })
  }, [props.assessRoomId])

  /*查看*/
  const OpenWindow = (record: any, docid: any) => {
    // window.open(`/room/index?aa=${record.assessRoomId}&bb=${record.turnSort}`)
    window.open("/viewOfTenderDocuments?tdocid=" + docid + "&tendererId=" + record.id);
  }

  /*下载*/
  const download = (record: any, docid: any) => {
    message.warn('暂时下载不了');
   /* DownFile({tdocId: docid, tendererName: record.companyName}).then(res => {

    })*/
  }
  const downloadPak = (docid: any) => {
    message.warn('暂时下载不了');
   /* DownFile({tdocId: docid}).then(res => {

    })*/
  }
  /*解密*/
  const decrypt =(record:any)=>{
    handleRateVis(true);
    decryptFile({turnId:record}).then(res=>{

    })

  }

  /*===========================*/
  /*===========================*/
  return (
    <Card>
      <Divider style={{margin: "8px 0px"}}/>
      <div className={style.label}>
        <UnorderedListOutlined style={{marginRight: "8px"}}/>投标文件查看
      </div>
      <List
        itemLayout="vertical"
        dataSource={ListData}
        renderItem={item => (
          <List.Item>
            <ProTable
              loading={pageloading}
              toolBarRender={() => [
                <Button onClick={() => decrypt(item.id)}> 解密</Button>,,
                <Button onClick={() => downloadPak(item.id)}> 打包下载</Button>,
                // <Button> 下载说明</Button>,
              ]}
              search={false}
              options={false}
              columns={[
                {
                  title: '序号',
                  dataIndex: 'index',
                  valueType: 'index'
                },
                {
                  title: '供应商名称',
                  dataIndex: 'companyName',
                  valueType: 'text'
                },
                {
                  title: '操作',
                  // valueType: 'option',
                  render: (text: any, record: any) => {
                    return (
                      <>
                        <Button type="primary" onClick={() => download(record, item.id)} shape="round"
                                icon={<DownloadOutlined/>}>下载</Button>
                        <Button type="primary" onClick={() => OpenWindow(record, item.id)} shape="round"
                                icon={<DownloadOutlined/>}>查看</Button>
                      </>
                    );
                  }

                }
              ]}
              dataSource={item.registerInfoVOList}
              // request={params => }
              // rowKey={"id"}
            />
          </List.Item>
        )}
      />
      <Modal
        title="解密进度"
        width={'800px'}
        destroyOnClose
        centered
        bodyStyle={{ padding: '32px 40px 48px', overflowY: 'auto' }}
        visible={rateVis}
        footer={false}
        onCancel={()=>handleRateVis(false)}

      >
        <Progress percent={(jmComplete + jmFail) * 100 / jmFileCount} status="active" />

        <div style={{ textAlign: "center" }}>
          文件总数：<span style={{ fontSize: 30, color: 'rgb(0,144,255)' }}>{jmFileCount}</span> 个
        </div>
        <div style={{ textAlign: "center" }}>
          解密成功：<span style={{ fontSize: 30, color: 'rgb(61,169,92)' }}>{jmComplete}</span> 个,
          {/* 排队解密中：<span style={{ fontSize: 30, color: 'red' }}>{100 - rate}</span> 个, */}
          正在解密：<span style={{ fontSize: 30, color: 'rgb(0,144,255)' }}>{jmWait}</span> 个,
          解密失败：<span style={{ fontSize: 30, color: 'red' }}>{jmFail}</span> 个
        </div>
      </Modal>

    </Card>
  )
}
export default BiddingDocumentsDecrypt
