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 Bchpicker 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 usrinr='';
        const rtnmsg = await Api.post("dbiusr/usrp_bchsel", {params:{rmbrpt:this.props.model.rmbrpt,usg:this.props.model.usg}})
       // console.log(data);
        if (rtnmsg.retcod == SUCCESS) {
            // 给table的dataSource赋值，重新渲染table
            this.dataSource = rtnmsg.data["usrp_bchlst"];
            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("dbiusr/usrp_sure", { params: { inr: row.inr } })   
      //  rtnmsg.data && Object.assign(this.props.model,rtnmsg.data);
      if(rtnmsg.data!==null)
      {
        this.props.model.bchkey=rtnmsg.data.bchkey;
        this.props.model.rmbrpt=rtnmsg.data.rmbrpt;
        this.props.model.bchnam=rtnmsg.data.bchnam;   
        this.props.model.etyextkey=rtnmsg.data.etyextkey;   
      }
        this.visible = false

    }
    render() {
        const columns = [
          
            {
                title:<Label itext="机构编号" />, 
                dataIndex:"branch",
                key:"branch",
                width:100,
                sorter: (r1,r2)=>ColSorter(r1.branch,r2.branch),
            },
            {
                title:<Label itext="联行行号" />, 
                dataIndex:"rmbrpt",
                key:"rmbrpt",
                width:100,
                sorter: (r1,r2)=>ColSorter(r1.rmbrpt,r2.rmbrpt),
            },
            {
                title:<Label itext="机构名称" />, 
                dataIndex:"namcn",
                key:"namcn",
                width:100,
                sorter: (r1,r2)=>ColSorter(r1.namcn,r2.namcn),
            },
            {
                title:<Label itext="机构层级" />, 
                dataIndex:"lev",
                key:"lev",
                width:100,
                sorter: (r1,r2)=>ColSorter(r1.lev,r2.lev),
                render:(val, row, index)=>{
                    let text = val
                    let em = CodeTable.bchlev.find(item=>item.value==val)
                    if(em)
                        text= em.label
                    return text
                }
            },
            ]
        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>);
    }
}