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 {
	Page, Validator, Notification, FormItem,
	InputItem, Input, Bind, SelectItem,  Label,  Section, DatePickerItem,ConfirmButton,TextAreaItem
} from '@/components/Common-Library'
import CodeTableFactory from '@/components/CodeTable'
const CodeTable = CodeTableFactory.getInstance()
@observer
export default class Ptypicker 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 = {}
      let rmbrpt = this.props.model.rmbrpt;
      console.log(rmbrpt)
      if(rmbrpt)
      {
        const rtnmsg = await Api.post("bhgadd/recp_ptysel", {data:{rmbrpt:this.props.model.rmbrpt} })
       // console.log(data);
        if (rtnmsg.retcod == SUCCESS) {
            // 给table的dataSource赋值，重新渲染table
            this.dataSource = rtnmsg.data["recp_ptylst"];
            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
    }
    else{
        Notification.error({ message: '请输入支付行号!' })

    }
    }







    handleCancel() {
        this.visible = false;
    }
    async onSelect(row) {

       // let url=this.state.url.substr(0,14);
        const rtnmsg = await Api.post("bhgadd/recp_sure", { params: { ptyinr: row.inr }, data: {} })   
        rtnmsg.data && Object.assign(this.props.model,rtnmsg.data);
        this.visible = false

    }
    render() {
        const columns = [
          
            {
                title:<Label itext="联行行号" />, 
                dataIndex:"bnkcod",
                key:"bnkcod",
                width:100,
                sorter: (r1,r2)=>ColSorter(r1.bnkcod,r2.bnkcod),
            },
            {
                title:<Label itext="中文名称" />, 
                dataIndex:"namcn",
                key:"namcn",
                width:100,
                sorter: (r1,r2)=>ColSorter(r1.namcn,r2.namcn),
            },
            {
                title:<Label itext="地址" />, 
                dataIndex:"adrcn",
                key:"adrcn",
                width:100,
                sorter: (r1,r2)=>ColSorter(r1.adrcn,r2.adrcn),
            },
            ]
        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>);
    }
}