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

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

type widowRush = {

}& ProductProps;
// 票据表
const DiscountTable : 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: 'sDate',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '截止数据日期',
          dataIndex: 'eDate',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '年月',
          dataIndex: 'yearMonth',
          search: false,
          hideInTable: true,
          width:150,
          ellipsis:true
          },
        {
          title: '数据日期',
          dataIndex: 'dataDate',
          valueType: 'date',
          hideInTable: false,
          width:150,
          ellipsis:true,
          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: 'ccy',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '币种',
          dataIndex: 'ccyDesc',
          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: 'effectDate',
          valueType:'date',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '到期日',
          dataIndex: 'expiryDate',
          valueType:'date',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '贴现类型代码',
          dataIndex: 'discountingType',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true
        },
        {
          title: '贴现类型',
          dataIndex: 'discountingTypes',
          valueType:'treeSelect',
          request:()=>fetchDict('discountingType'),
          fieldProps: {
            treeDefaultExpandAll: true,
            treeCheckable:true,
         },
          hideInTable: true,
          width:150,
          ellipsis:true,
          order:-6
        },
        {
          title: '贴现类型',
          dataIndex: 'discountingTypeDesc',
          search: false,
          hideInTable: false,
          width:150,
          ellipsis:true,
        },
        {
          title: '票据类型代码',
          dataIndex: 'billType',
          search: false,
          hideInTable: false,
          width:150,
        },
        {
          title: '票据类型',
          dataIndex: 'billType',
          search: false,
          hideInTable: false,
          valueType: 'treeSelect',
          request: () => fetchDict('BILL_TYPE'),
          fieldProps: {
           treeDefaultExpandAll: true,
        },
        width:150,
        },
        {
          title: '票号',
          dataIndex: 'billNo',
          search: false,
          hideInTable: false,
          width:150,
        },
        {
          title: '产品编号',
          dataIndex: 'productNo',
          search: false,
          hideInTable: false,
          width:150,
        },
        {
          title: '产品名称',
          dataIndex: 'productName',
          hideInTable: false,
          width:150,
          order:-8
        },
        {
          title: '表内外标识代码',
          dataIndex: 'onbalshOffbalshFlag',
          search: false,
          hideInTable: false,
          width:150,
        },
        {
          title: '表内外标识',
          dataIndex: 'onbalshOffbalshFlag',
          search: false,
          hideInTable: false,
          valueType: 'treeSelect',
          request: () => fetchDict('ONOROFF'),
          fieldProps: {
           treeDefaultExpandAll: true,
        },
        width:150,
        },
        {
          title: '账簿类型代码',
          dataIndex: 'accountBookType',
          search: false,
          hideInTable: false,
          width:150,
        },
        {
          title: '账簿类型',
          dataIndex: 'accountBookType',
          search: false,
          hideInTable: false,
          valueType: 'treeSelect',
          request: () => fetchDict('ACCOUNT_TYPE'),
          fieldProps: {
           treeDefaultExpandAll: true,
        },
        width:150,
        },
        {
          title: '是否我行承兑代码',
          dataIndex: 'ifSelfbankAcceptance',
          search: false,
          hideInTable: false,
          width:150,
        },
        {
          title: '是否我行承兑',
          dataIndex: 'ifSelfbankAcceptance',
          search: false,
          hideInTable: false,
          valueType: 'treeSelect',
          request: () => fetchDict(''),
          fieldProps: {
           treeDefaultExpandAll: true,
        },
        width:150,
        },
        {
          title: '承兑人客户编号',
          dataIndex: 'acceptorClientNo',
          search: false,
          hideInTable: false,
          width:150,
        },
        {
          title: '承兑人客户名',
          dataIndex: 'acceptorClientName',
          search: false,
          hideInTable: false,
          width:150,
        },
        {
          title: '账务机构编号', 
          dataIndex: 'accountOrgnNo',
          search: false,
          hideInTable: false,
          width:150,
        },
        {
          title: '账务机构名称', 
          dataIndex: 'accountOrgnName',
          search: false,
          hideInTable: false,
          width:150,
        },
        {
          title: '经营机构编号',
          dataIndex: 'manageOrgnNo',
          search: false,
          hideInTable: false,
          width:150,
        },
        {
          title: '经营机构',
          dataIndex: 'manageOrgnNos',
          valueType:'treeSelect',
          request:()=>fetchDict('org'),
          fieldProps: {
            treeDefaultExpandAll: true,
            treeCheckable:true,
            popupMatchSelectWidth:300
         },
          order:-7,
          hideInTable: true,
        },
        {
          title: '经营机构编名称',
          dataIndex: 'manageOrgnName',
          search: false,
          hideInTable: false,
          width:150,
        },
        {
          title: '核心客户号',
          dataIndex: 'coreClientNo',
          hideInTable: false,
          width:150,
          order:-3
        },
        {
          title: '客户编号',
          dataIndex: 'clientNo',
          hideInTable: false,
          width:150,
          order:-4
        },
        {
          title: '客户名称',
          dataIndex: 'clientName',
          hideInTable: false,
          order:-5,
          width:150,
        },
      ];
    

    return (
        <SDPage>
        <SDTable
         title="查询表格"
         rowKey="customerName"
         request={async (formdata:SysListModel) =>{
          const data = await getDataList(formdata)
           return {data: data}
         }  }
         columns={columns}
         toolBarRender={(_, { selectedRows }) => [
          <SDButton
            key="export"
            successMessage=''
            onClick={() => {
              baseFun.confirm('确认导出数据？',async() => {  exportExcelModel(formDataList,"DiscountTable")});
            }}
          >
            全部导出
          </SDButton>,
        ]}
         actionRef={actionRef}
         formRef={formRef}
         setDetailVisible={() => {setDetailVisible(true)}}
         setEditType={setEditType}
         setCurrentRow={setCurrentRow}
         />
        </SDPage>
        
    );
}
export default DiscountTable;