import React, { Component, Fragment } from 'react'
import PropTypes from 'prop-types'
import {
    Page, Validator, Notification, FormItem, DatePickerItem, TextAreaItem, CheckboxItem, Checkbox,
    InputItem, Input, Bind, SelectItem, Button, Label, Image, Table
} from '@/components/Common-Library'
import Api from '@/service/api'
import mGetsel from '../model'
import CodeTableFactory from '@/components/CodeTable'
import { Row, Col, Popconfirm, Modal, Spin, Tooltip } from 'antd';
import "./index.less"
import { inject, observer } from 'mobx-react'
import { action, observable, runInAction } from 'mobx'


const CodeTable = CodeTableFactory.getInstance()


@inject('UserContext')
@inject('i18n')
@observer
export default class GetselScreen extends Page {
    static childContextTypes = {
        trn: PropTypes.string,
    }
    getChildContext() {
        return { trn: 'getsel' }
    }


    @observable
    formBlur = false

    constructor(props) {
        super(props)
        this.model = new mGetsel()
        this.bind = Bind.bind(this)
    }

    async componentWillMount() {
		/*
		*添加初始化代码
		*/
        const rtnmsg = await Api.post('getsel/init', { data: this.model })
        if (rtnmsg.retcod == SUCCESS) {
            const { data } = rtnmsg
            runInAction(() => {
                Object.assign(this.model, data)
            })
        }
        //快照模式下，不必开启校验，否则，静默校验，和记录变动
        !this.loadDisplay() && this.model.openMonitor && this.model.openMonitor() //开启校验	
    }
    componentWillUnmount() {
        this.model.stopMonitor && this.model.stopMonitor()//关闭校验
    }

    getmod_gidlstHeader = [
        {
            title: <Label itext="保函编号" />,
            dataIndex: "ownref",
            key: "ownref",
            width: 100,
            sorter: (r1, r2) => ColSorter(r1.ownref, r2.ownref),
        },
        {
            title: <Label itext="交易名称" />,
            dataIndex: "nam",
            key: "nam",
            width: 100,
            sorter: (r1, r2) => ColSorter(r1.nam, r2.nam),
        },
        {
            title: <Label itext="创建日期" />,
            dataIndex: "credat",
            key: "credat",
            width: 100,
            sorter: (r1, r2) => ColSorter(r1.credat, r2.credat),
        },
        {
            title: <Label itext="结束日期" />,
            dataIndex: "clsdat",
            key: "clsdat",
            width: 100,
            sorter: (r1, r2) => ColSorter(r1.clsdat, r2.clsdat),
        },
        {
            title: <Label itext="保函类型" />,
            dataIndex: "hndtyp",
            key: "hndtyp",
            width: 100,
            sorter: (r1, r2) => ColSorter(r1.hndtyp, r2.hndtyp),
            render: (val, row, index) => {
                let text = val
                let em = CodeTable.hndtyp.find(item => item.value == val)
                if (em)
                    text = em.label
                return text
            }
        },
    ]


    //按钮事件
    onGetmod_choose = () => {
        this.formBlur = true  //已触发表单提交处理
        Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
            if (errors)
                return
            const rtnmsg = await Api.post('getsel/getmod_choose', { data: this.model })
            if (rtnmsg.retcod == SUCCESS) {
                Notification.success({ message: '数据提交成功!' })

            }
            else {
                Notification.error({ message: '服务端请求失败!' })
            }
            //余下逻辑处理

        })
    }
    onOpnbut = () => {
        this.formBlur = true  //已触发表单提交处理
        Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
            if (errors)
                return
            const rtnmsg = await Api.post('getsel/opnbut', { data: this.model })
            if (rtnmsg.retcod == SUCCESS) {
                Notification.success({ message: '数据提交成功!' })

            }
            else {
                Notification.error({ message: '服务端请求失败!' })
            }
            //余下逻辑处理

        })
    }
    onGetmod_sel = () => {
        this.formBlur = true  //已触发表单提交处理
        Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
            if (errors)
                return
            const rtnmsg = await Api.post('getsel/getmod_sel', { data: this.model })
            if (rtnmsg.retcod == SUCCESS) {
                Notification.success({ message: '数据提交成功!' })

            }
            else {
                Notification.error({ message: '服务端请求失败!' })
            }
            //余下逻辑处理

        })
    }


    //交易内实现
    renderPage() {
        const bind = this.bind
        const { i18n } = this.props

        return (
            <div className="transPage">
                <Row>
                    <Col span={24}>
                        <Row className="row">
                            <Col span={2} >
                                <Label itext="保函编号" trn="ditsel" />
                            </Col>
                            <Col span={3} >
                                <InputItem InputProps={bind("getmod_ownref")} maxLength={20} desp="业务编号" path="/getmod/ownref" />
                            </Col>

                        </Row>
                    </Col>

                </Row>
                {/* <Button  type="primary"  onClick={this.onOpnbut} desp="出口保函通知" path="/opnbut">
		<Label   itext="出口保函通知"/>
	</Button> */}


                {/* <Label itext="保函编号" trn="getsel" />	
	<InputItem InputProps={bind("getmod_ownref")}  maxLength={20}  desp="业务编号" path="/getmod/ownref" />
	<Button  type="primary" icon="search" onClick={this.onGetmod_sel} desp="查询" path="/getmod/sel">
		<Label   itext="查询"/>
	</Button>
	<Button  type="primary"  onClick={this.onGetmod_choose} desp="选中" path="/getmod/choose">
		<Label   itext="选中"/>
	</Button>

	
	<Label itext="出口保函查询标准" trn="getsel" />	
	<SelectItem InputProps={bind("getmod_selflg")} code={CodeTable.getselflg}  desp="出口保函查询标准" path="/getmod/selflg"/> */}
                <Table rowKey="inr" columns={this.getmod_gidlstHeader} dataSource={this.model.getmod_gidlst} path="/getmod/gidlst" />
            </div>
        )
    }
}
