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 Xyzpicker extends React.Component {
    constructor(props) {
        super(props);

       
    }
    @observable
    visible = false

    @observable
    dataSource = []

    @observable
    loading = false

    @observable
    selectRowKeys = []

   
    componentDidMount() {
        this.props.childEvevnt && this.props.childEvevnt(this);
    }


    async handleClick() {
      
        let params = {}

        const rtnmsg = await Api.post("ditsel/ditmod_sel", {data:{ownref1:this.props.model.ownref1,ditmod_clsflg:this.props.model.ditmod_clsflg?'X':''} })
       // console.log(data);
        if (rtnmsg.retcod == SUCCESS) {
            // 给table的dataSource赋值，重新渲染table
            this.dataSource = rtnmsg.data["ditmod_didlst"];
            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/ditmod_choose", { params: { didinr: row.inr }, data: {} })   
        rtnmsg.data && Object.assign(this.props.model,rtnmsg.data);
        this.visible = false

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

            //     key: 'select',
            //     width: 70,
            //     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:"isstyp",
                    key:"isstyp",
                    width:100,
                    sorter: (r1,r2)=>ColSorter(r1.isstyp,r2.isstyp),
                    render:(val, row, index)=>{
                        let text = val
                        let em = CodeTable.isstyp.find(item=>item.value==val)
                        if(em)
                            text= em.label
                        return text
                    }
                },
                {
                    title:"贸易方式", 
                    dataIndex:"trdtyp",
                    key:"trdtyp",
                    width:100,
                    sorter: (r1,r2)=>ColSorter(r1.trdtyp,r2.trdtyp),
                    render:(val, row, index)=>{
                        let text = val
                        let em = CodeTable.trdtyp.find(item=>item.value==val)
                        if(em)
                            text= em.label
                        return text
                    }
                },
                {
                    title:"失效日期", 
                    dataIndex:"expdat",
                    key:"expdat",
                    width:100,
                    sorter: (r1,r2)=>ColSorter(r1.expdat,r2.expdat),
                },
                {
                    title:"兑付方式", 
                    dataIndex:"avbby",
                    key:"avbby",
                    width:100,
                    sorter: (r1,r2)=>ColSorter(r1.avbby,r2.avbby),
                    render:(val, row, index)=>{
                        let text = val
                        let em = CodeTable.avbby.find(item=>item.value==val)
                        if(em)
                            text= em.label
                        return text
                    }
                },
                {
                    title:"效期", 
                    dataIndex:"tenmaxday",
                    key:"tenmaxday",
                    width:100,
                    sorter: (r1,r2)=>ColSorter(r1.tenmaxday,r2.tenmaxday),
                },
                {
                    title:"闭卷日期", 
                    dataIndex:"clsdat",
                    key:"clsdat",
                    width:100,
                    sorter: (r1,r2)=>ColSorter(r1.clsdat,r2.clsdat),
                },
                {
                    title:"经办柜员", 
                    dataIndex:"ownusr",
                    key:"ownusr",
                    width:100,
                    sorter: (r1,r2)=>ColSorter(r1.ownusr,r2.ownusr),
                },
            ]
        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={1200}
            >
                <Table
                    onRow={ row=>({onDoubleClick:()=>this.onSelect(row)}) }
                    columns={columns}
                    dataSource={this.dataSource}
                    pagination={ {pageSize:5} }
                >

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