import React from 'react';
import { Button, Modal, Table, Icon, } from 'antd';
import { observer } from 'mobx-react'
import Api from '@/service/api'
import { observable } from 'mobx'
import { Notification } from '@/components/Common-Library'
import CodeTableFactory from '@/components/CodeTable'
const CodeTable = CodeTableFactory.getInstance()
@observer
export default class YwbhPicker2 extends React.Component {
    constructor() {
        super();
    }
    @observable
    visible = false

    @observable
    dataSource = []

    @observable
    loading = false

    @observable
    selectRowKeys = []


    async handleClick() {
        this.visible = true
        this.loading = true
        // 请求后台的信息（利用传入的url地址请求）
        let url = this.props.url;
        let flg = this.props.flg;
        // "/cptspe/cptp_cpdque"
        const rtnmsg = await Api.post("ditsel/bdtmod_sel", { params: { flg }, data: {} })
        if (rtnmsg.retcod == SUCCESS) {
            // 给table的dataSource赋值，重新渲染table
            this.dataSource = rtnmsg.data["bdtmod_bddlst"];
            console.log("this.dataSurce =======111========================")
            console.log(this.dataSource);
        } else {
            Notification.error({ message: url + '服务端请求失败!' })
        }
        this.loading = false
    }
    handleCancel() {
        this.visible = false;
    }
    async onSelect(row) {
        console.log("row||||||||||||||||||||||||||||||||||||")
        console.log(row);
        const rtnmsg = await Api.post("ditsel/bdtmod_choose", { params: { bddinr: row.inr }, data: {} })  
        rtnmsg.data && this.props.onChange(rtnmsg.data);  
        this.visible = false

    }
    render() {
        const columns = [
            {
                title: '选择',

                key: 'select',
                width: 100,
                render: (val, row) => {
                    return <Icon type="search" onClick={() => this.onSelect(row)} />
                }
            },
            {
                title: "业务编号" , 
                dataIndex:"ownref",
                key:"ownref",
                width:100,
                sorter: (r1,r2)=>ColSorter(r1.ownref,r2.ownref),
            },
            {
                title: "概要描述" , 
                dataIndex:"nam",
                key:"nam",
                width:100,
                sorter: (r1,r2)=>ColSorter(r1.nam,r2.nam),
            },
            {
                title: "到单日期" , 
                dataIndex:"opndat",
                key:"opndat",
                width:100,
                sorter: (r1,r2)=>ColSorter(r1.opndat,r2.opndat),
            },
            {
                title: "期限" , 
                dataIndex:"tenmaxday",
                key:"tenmaxday",
                width:100,
                sorter: (r1,r2)=>ColSorter(r1.tenmaxday,r2.tenmaxday),
            },
            {
                title: "到期日" , 
                dataIndex:"matdat",
                key:"matdat",
                width:100,
                sorter: (r1,r2)=>ColSorter(r1.matdat,r2.matdat),
            },
            {
                title: "承兑日期" , 
                dataIndex:"accdat",
                key:"accdat",
                width:100,
                sorter: (r1,r2)=>ColSorter(r1.accdat,r2.accdat),
            },
            {
                title: "闭卷日期" , 
                dataIndex:"clsdat",
                key:"clsdat",
                width:100,
                sorter: (r1,r2)=>ColSorter(r1.clsdat,r2.clsdat),
            },
            {
                title: "远期付款指示" , 
                dataIndex:"payinf",
                key:"payinf",
                width:100,
                sorter: (r1,r2)=>ColSorter(r1.payinf,r2.payinf),
            },
            ]
        const props = this.props;
        return (<div style={{ width: 5000 }}>
            <Button type="primary" icon="search" {...this.props} onClick={() => this.handleClick()} />
            <Modal
                visible={this.visible}
                onCancel={() => this.handleCancel()}
                footer={<Button onClick={() => this.handleCancel()}>取消</Button>}
                width={600}
            >
                <Table
                    columns={columns}
                    dataSource={this.dataSource}
                    scroll={{x:1600}}
                >

                </Table>
            </Modal>
        </div>);
    }
}