import React, { useEffect, useRef, useState } from "react";
import type { ProColumns, ActionType, ProFormInstance } from '@ant-design/pro-components';
import type {FormInstance} from 'antd'
import  {Upload} from 'antd'
import { SDPage,SDFormText,SDModalForm,SDTable,SDFormItem,SDButton,SDForm,SDSubmitButton,EditType, SDAreaTtile, SDLayout, SDOperate, baseFun, } from "@sundata/ui-frame";

import {getDataList,selectDetailData,exportExcelModel, SysListModel,} from '@/services/rwa/dataquality/RepoRelatedTable';
import { ProductProps } from "@/sundataImport";
import { useModel } from '@umijs/max';

type widowRush = {
  onCancel:  () => void;
  onChangeVisible(visible: boolean, type: string): unknown;
  onChangeVisdible:(visible:boolean,type ?: 'none' | 'raload' )=>void;
}& ProductProps;
// 回购关联信息表
const RepoRelatedTable : React.FC<widowRush> = (prop:widowRush) => {

    /** 编辑方式，查看、修改、新增按钮时设置，详细信息表单中使用 */
    const [editType, setEditType] = useState<EditType>(prop.editType || 'display');
    /** 是否显示详细信息窗口 */
    const [detailVisible, setDetailVisible] = useState<boolean>(false);
    const [currentRow, setCurrentRow] = useState<SysListModel>();
    /** 表格引用对象，刷新表格使用   */
    const actionRef = useRef<ActionType>();
    const formRef = useRef<FormInstance<any>>();
    const { fetchDict } = useModel('dict');

    // 页面数据
    var formDataList = new Array<SysListModel>;
    /**上传文件 */
    const [fileData, setFileData] = useState<File>();
    // 导入窗口显示
    const [importVisible, setImportVisible] = useState<boolean>(false);

    useEffect(() => {
      }, []);
    
    const selectData = async (formdata : SysListModel) => {
      const data = await selectDetailData(formdata);
      formRef.current?.setFieldsValue(data);
     }


    //关闭窗口刷新父页面
    const closeAndRefresh = ()=>{
    actionRef.current?.reloadAndRest?.();
    }

     
    // 页面展示元素
    const columns: ProColumns<SysListModel>[] = [
        {
          title: '计算实例号',
          dataIndex: 'calcindex',
          search: false,
          hideInTable: true,
          width:150,
          ellipsis:true
        },
        {
          title: '起始数据日期',
          dataIndex: 'startDate',
          search: false,
          hideInTable: true,
          width:150,
          ellipsis:true
        },
        {
          title: '截止数据日期',
          dataIndex: 'endDate',
          search: false,
          hideInTable: true,
          width:150,
          ellipsis:true
        },
        {
          title: '年月',
          dataIndex: 'yearMonth',
          search: false,
          hideInTable: true,
          width:150,
          ellipsis:true
          },
        {
          title: '数据日期',
          dataIndex: 'dataDate',
          hideInTable: false,
          order:-1,
          valueType:'date',
          width:150,
          ellipsis:true
        },
        {
          title: '缓释品编号', 
          dataIndex: 'mitigationProdNo',
          hideInTable: false,
          order:-2,
          width:150,
          ellipsis:true
        },
        {
          title: '缓释品名称',
          dataIndex: 'mitigationProdName',
          hideInTable: false,
          order:-3,
          width:150,
          ellipsis:true
        },
        {
          title: '质押券证券代码', 
          dataIndex: 'pledgeBondsSecurityCode',
          hideInTable: false,
          order:-4,
          width:150,
          ellipsis:true
        },
        {
          title: '证券名称',
          dataIndex: 'securityName',
          hideInTable: false,
          order:-5,
          width:150,
          ellipsis:true
        },
        {
          title: '证券种类代码',
          dataIndex: 'securityClass',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '证券种类',
          dataIndex: 'securityClass',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true,
          valueType: 'treeSelect',
          request: () => fetchDict(''),
          fieldProps: {
           treeDefaultExpandAll: true,
          },
        },
        {
          title: '一般专项标签代码',
          dataIndex: 'generalSpecialLabel',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '一般专项标签',
          dataIndex: 'generalSpecialLabel',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true,
          valueType: 'treeSelect',
          request: () => fetchDict('DEBT_TYPE'),
          fieldProps: {
           treeDefaultExpandAll: true,
          },
        },
        {
          title: '押品价值币种代码',
          dataIndex: 'collateralValueCcyCode',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '币种',
          dataIndex: 'collateralValueCcyCode',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true,
          valueType: 'treeSelect',
          request: () => fetchDict(''),
          fieldProps: {
           treeDefaultExpandAll: true,
          },
        },
        {
          title: '质押券票面金额',
          dataIndex: 'pledgeBondsBillValueAmt',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '缓释起始日',
          dataIndex: 'mitigantOrginDate',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '缓释到期日',
          dataIndex: 'mitigantExpiryDate',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '债项编号', 
          dataIndex: 'debtitemNo',
          hideInTable: false,
          order:-6,
          width:150,
          ellipsis:true
        },
        {
          title: '发行（承兑）人名称',
          dataIndex: 'issuerName',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },

      ];
    

    return (
        <SDPage>
        <SDTable
         title="查询表格"
         rowKey="customerName"
         request={async (formdata:SysListModel) =>{
          const formDatas = await getDataList(formdata);
          // 解构数组（导出用）
          formDataList=[...formDatas];
           return {data: formDatas}
         }  }
         columns={columns}
         toolBarRender={(_, { selectedRows }) => [
          <SDButton
            key="export"
            successMessage=''
            onClick={() => {

              baseFun.confirm('确认导出数据？',async() => {  exportExcelModel(formDataList,"RepoRelatedTable")});;
              //baseFun.info('处理完成');
            }}
          >
            全部导出
          </SDButton>,
        ]}
         actionRef={actionRef}
         formRef={formRef}
         initLoad={false}
         setDetailVisible={() => {setDetailVisible(true)}}
         setEditType={setEditType}
         setCurrentRow={setCurrentRow}
         />

        </SDPage>
        
    );
}
export default RepoRelatedTable;