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'
import mDitsel from '../model'
const CodeTable = CodeTableFactory.getInstance()
@observer
export default class Djpicker extends React.Component {
    constructor(props) {
        super(props);

       
    }
    @observable
    visible = false

    @observable
    dataSource = []

    @observable
    loading = false

    @observable
    selectRowKeys = []


    async handleClick() {
      
        let params = {}

        const rtnmsg = await Api.post("ditsel/bdtmod_sel", {data:{ownref:this.props.model.ownref,bdtmod_clsflg:this.props.model.bdtmod_clsflg?'X':''} })
       // console.log(data);
        if (rtnmsg.retcod == SUCCESS) {
            // 给table的dataSource赋值，重新渲染table
            this.dataSource = rtnmsg.data["bdtmod_bddlst"];
            if(this.dataSource && this.dataSource.length)
            {
                this.setState({data:this.dataSource});
                this.visible = true
                this.loading = true 
            }
            else{
                Notification.message({ message: '未查到数据' })
            }
           
        } else {
            Notification.error({ message: '服务端请求失败!' })
        }
        this.loading = false
    }
    handleCancel() {
        this.visible = false;
    }
    async onSelect(row) {

       // let url=this.state.url.substr(0,14);
        const rtnmsg = await Api.post("ditsel/bdtmod_choose", { params: { bddinr: row.inr }, data: {} })   
        rtnmsg.data && Object.assign(this.props.model,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: 1200 }}>
            <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:1250}}
                >

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