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,SDTable,SDButton,EditType, baseFun, } from "@sundata/ui-frame";

import {getDataList,exportExcelModel, SysListModel} from '@/services/rwa/dataquality/InterbankDepositOrLendingTable';
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 InterbankDepositOrLendingTable : 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 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,
          width:150,
          ellipsis:true,
          valueType:'date',
          order:-1
        },
        {
          title: '债项编号',
          dataIndex: 'debtitemNo',
          hideInTable: false,
          width:150,
          ellipsis:true,
          order:-2
        },
        {
          title: '合同编号',
          dataIndex: 'contractNo',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },

        {
          title: '资产余额',
          dataIndex: 'assetBal',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '应收利息',
          dataIndex: 'receivableInt',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '应计利息',
          dataIndex: 'accrInt',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '利息调整',
          dataIndex: 'intAdj',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '公允价值变动',
          dataIndex: 'fairValueChange',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '计提准备金',
          dataIndex: 'provisionReserve',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '本金科目号',
          dataIndex: 'prinAccountNo',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '应收利息科目号',
          dataIndex: 'receivableIntAccountNo',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '应计利息科目号',
          dataIndex: 'accrIntAccountNo',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '利息调整科目号',
          dataIndex: 'intAdjAccountNo',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '公允价值变动科目号',
          dataIndex: 'fairValueChangeAccountNo',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '准备金科目号',
          dataIndex: 'reserveAccountNo',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '产品编号',
          dataIndex: 'productNo',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '产品名称',
          dataIndex: 'productName',
          hideInTable: false,
          width:150,
          ellipsis:true,
          order:-6
        },
        {
          title: '产品细类代码',
          dataIndex: 'productSubclass',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '产品细类',
          dataIndex: 'productSubclass',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true,
          valueType: 'treeSelect',
          request: () => fetchDict(''),
          fieldProps: {
           treeDefaultExpandAll: true,
          },
        },
        {
          title: '生效日',
          dataIndex: 'effectDate',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '到期日',
          dataIndex: 'expiryDate',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '拆借存放标识代码',
          dataIndex: 'lendingStoreFlag',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '拆借存放标识',
          dataIndex: 'lendingStoreFlag',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true,
          valueType: 'treeSelect',
          request: () => fetchDict(''),
          fieldProps: {
           treeDefaultExpandAll: true,
          },
        },
        {
          title: '表内外标识代码',
          dataIndex: 'onbalshOffbalshFlag',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true,
        },
        {
          title: '表内外标识',
          dataIndex: 'onbalshOffbalshFlag',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true,
          valueType: 'treeSelect',
          request: () => fetchDict('ONOROFF'),
          fieldProps: {
           treeDefaultExpandAll: true,
          },
        },
        {
          title: '账簿类型代码',
          dataIndex: 'accountBookType',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true,
        },
        {
          title: '账簿类型',
          dataIndex: 'accountBookType',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true,
          valueType: 'treeSelect',
          request: () => fetchDict('ACCOUNT_TYPE'),
          fieldProps: {
           treeDefaultExpandAll: true,
          },
        },
        {
          title: '账务机构编号', 
          dataIndex: 'finBranchNo',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true,
        },
        {
          title: '账务机构名称', 
          dataIndex: 'finBranchName',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true,
        },
        {
          title: '经营机构编号',
          dataIndex: 'manageOrgnNo',
          hideInTable: false,
          search:false,
          width:150,
          ellipsis:true,
          order:-5
        },
        {
          title: '经营机构编号',
          dataIndex: 'manageOrgnNos',
          hideInTable: false,
          width:150,
          ellipsis:true,
          order:-5,
          valueType: 'treeSelect',
          request: () => fetchDict('org'),
          fieldProps: {
           treeDefaultExpandAll: true,
           treeCheckable:true,
          },
        },
        {
          title: '经营机构编名称',
          dataIndex: 'manageOrgnName',
          search: false,
          hideInTable: false,
        },
        {
          title: '客户编号',
          dataIndex: 'clientNo',
          hideInTable: false,
          width:150,
          ellipsis:true,
          order:-3
        },
        {
          title: '客户名称',
          dataIndex: 'clientName',
          hideInTable: false,
          width:150,
          ellipsis:true,
          order:-4
        },

      ];
    

    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={() => {
              // if (selectedRows === undefined || selectedRows.length < 1) {
              //   baseFun.warning('请先选择要倒出的模板');
              //   return;
              // }
              baseFun.confirm('确认导出数据？',async() => {  exportExcelModel(formDataList,"InterbankDepositOrLendingTable")});;
              //baseFun.info('处理完成');
            }}
          >
            全部导出
          </SDButton>,
        ]}
         singleSelect={false}
         actionRef={actionRef}
         formRef={formRef}
         setDetailVisible={() => {setDetailVisible(true)}}
         setEditType={setEditType}
         setCurrentRow={setCurrentRow}
         />

        </SDPage>
        
    );
}
export default InterbankDepositOrLendingTable;