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'
@observer
export default class YwbhPicker 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("cptspe/cptp_cpdque", { params: { flg }, data: {} })
        if (rtnmsg.retcod == SUCCESS) {
            // 给table的dataSource赋值，重新渲染table
            this.dataSource = rtnmsg.data["cptp_cpdlst"];
            console.log("this.dataSurce ===============================")
            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("/cptspe/cptp_cpdsel", { params: { cpdinr: row.inr }, data: {} })
        // rtnmsg.data && Object.assign(this.props.model, rtnmsg.data);
        rtnmsg.data && this.props.onChange(rtnmsg.data);
        // const { model, prefix } = this.props;
        // if (model && prefix)   //默认赋值
        // {
        //     model[`${prefix}_extkey`] = row.extkey || ""
        //     let adrblk = ''
        //     let nam1 = row.nam1 || ""
        //     let nam2 = row.nam2 || ""
        //     let str1 = row.str1 || ""
        //     let str2 = row.str2 || ""
        //     if (nam1)
        //         adrblk = nam1
        //     if (nam2)
        //         adrblk = adrblk + "\r\n" + nam2
        //     if (str1)
        //         adrblk = adrblk + "\r\n" + str1
        //     if (str2)
        //         adrblk = adrblk + "\r\n" + str2
        //     model[`${prefix}_adrblk`] = adrblk;
        //     //model[`${prefix}_adrblk`] = (row.nam1 || "") + "\r\n" + (row.nam2 || "")+ "\r\n" + (row.str1 || "")+ "\r\n" + (row.str2 || "");
        // }
        // this.props.onSelect && this.props.onSelect(row)
        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,
            },
            {
                title: '概要信息',
                dataIndex: 'nam',
                key: 'nam',
                width: 100,
            },
            {
                title: '经办柜员',
                dataIndex: 'ownusr',
                key: 'ownusr',
                width: 100,
            },
            {
                title: '所属机构',
                dataIndex: 'branchinr',
                key: 'branchinr',
                width: 100,
            },
            {
                title: '经办机构',
                dataIndex: 'bchkeyinr',
                key: 'bchkeyinr',
                width: 100,
            },
        ]
        const props = this.props;
        return (<div style={{ width: 1000 }}>
            <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}
                >

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