import React, { Component, Fragment } from 'react'
import {
    Page, Validator, Notification, FormItem, DatePickerItem,
    InputItem, Input, Bind, SelectItem, Button, Label, Image, Table
} from '@/components/Common-Library'
import Api from '@/service/api'
import mDbaaut from '../model'
import CodeTableFactory from '@/components/CodeTable'
import "./index.less"
import { inject, observer } from 'mobx-react'
import { action, observable } from 'mobx'
import { Col, Row, Card, Divider } from 'antd'


import { TableExpansion } from '@/components/Business-Library'

const CodeTable = CodeTableFactory.getInstance()


@inject('UserContext')
@inject('i18n')
@observer
export default class Dblbcl2Screen extends Page {
    @observable
    formBlur = false

    @observable
    bchlevelLst: []

    constructor(props) {
        super(props)
        this.model = new mDbaaut()
        this.model.openValidate() //开启校验
        this.bind = Bind.bind(this)
    }

    componentWillUnmount() {
        this.model.closeValidate()//关闭校验
    }

    async componentWillMount() {
        if (this.props.location.query) {
            console.log(this.props.location.query)
			let selinr = this.props.location.query.inr
			const rtnmsg = await Api.post('dbebcl/init', { params: { selinr } })
			if (rtnmsg.retcod == SUCCESS) {
				Object.assign(this.model, rtnmsg.data)
                this.bchlevelLst = rtnmsg.codetable['bchkey'];
                
                this.bclp_bcllstHeader[3].type.add.code = rtnmsg.codetable['bchkey']
                this.bclp_bcllstHeader[3].type.edit.code = rtnmsg.codetable['bchkey']
                this.setState({})
			}
			else {
				Notification.error({ message: '服务端请求失败!' })
			}
		}
    }

    bclp_bcllstHeader = [
        // {
        //     title: <Label value="机构" />,
        //     dataIndex: "bchkey",
        //     key: "bchkey",
        //     width: 100,
        // },
        {
            title: <Label value="业务品种" />,
            dataIndex: "busrou",
            key: "busrou",
            width: 100,
            type: {
                add: { type: 'select', code: CodeTable.busrou },
                edit: { type: 'select', code: CodeTable.busrou },
            }
        },
        {
            title: <Label value="经办方式" />,
            dataIndex: "exeflg",
            key: "exeflg",
            width: 100,
            type: {
                add: { type: 'select', code: CodeTable.exetyp },
                edit: { type: 'select', code: CodeTable.exetyp },
            }
        },
        {
            title: <Label value="登记方式" />,
            dataIndex: "regflg",
            key: "regflg",
            width: 100,
            type: {
                add: { type: 'select', code: CodeTable.regflg },
                edit: { type: 'select', code: CodeTable.regflg },
            }
        },
        {
            title: <Label value="上收单证中心" />,
            dataIndex: "upbchkey",
            key: "upbchkey",
            width: 100,
            type: {
                add: { type: 'select', code: [] },
                edit: { type: 'select', code: [] },
            }
        },
    ]

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

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

        })
    }
    onSav = () => {
        this.formBlur = true  //已触发表单提交处理
        Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
            if (errors)
                return
            const rtnmsg = await Api.post('dbebcl/sav', { data: this.model })
            if (rtnmsg.retcod == SUCCESS) {
                Notification.success({ message: '提交成功!' })
                this.props.history.push({ pathname: 'dblbcl', state: { 'selflg': true } });
            }
            else {
                Notification.error({ message: '服务端请求失败!' })
            }
            //余下逻辑处理

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

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

        })
    }
    onRtn = () => {
        this.props.history.push("dblbcl");
    }
    onChk = () => {
        this.formBlur = true  //已触发表单提交处理
        Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
            if (errors)
                return
            const rtnmsg = await Api.post('dbebcl/chk', { data: this.model })
            if (rtnmsg.retcod == SUCCESS) {
                Notification.success({ message: '数据提交成功!' })

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

        })
    }

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

        return (
            <Card title="自动化交易配置" size="small" className="transTitle">
                <div style={{ position: 'relative' }}>

                    <Row gutter={16}>
                        <Col span={9} offset={3} className='item' >
                            <Col span={7} >
                                <Label value={"归属机构"} />
                            </Col>
                            <Col span={17}>
                                <SelectItem InputProps={bind("bchkey")} code={this.bchlevelLst} desp="归属机构" path="/autgrp/rec/bchkey" />
                            </Col>
                        </Col>
                    </Row>
                    {/* <Row gutter={16}>
                        <Col span={9} offset={3} className='item' >
                            <Col span={7} >
                                <Label value={"业务品种"} />
                            </Col>
                            <Col span={17}>
                                <InputItem InputProps={bind("frm")} maxLength={6} desp="交易码" path="/autgrp/rec/frm" />
                            </Col>
                        </Col>
                        <Col span={9} className='item' >
                            <Col span={7} >
                                <Label value={"经办方式"} />
                            </Col>
                            <Col span={17}>
                                <InputItem InputProps={bind("frmnam")} maxLength={40} desp="交易名" path="/autgrp/rec/frmnam" />
                            </Col>
                        </Col>
                    </Row>
                    <Row gutter={16}>
                        <Col span={9} offset={3} className='item' >
                            <Col span={7} >
                                <Label value={"登记方式"} />
                            </Col>
                            <Col span={17}>
                                <SelectItem InputProps={bind("autspt")} code={CodeTable.autflg} desp="自动经办" path="/autgrp/rec/autspt" />
                            </Col>
                        </Col>
                        <Col span={9} className='item' >
                            <Col span={7} >
                                <Label value={"业务上收机构"} />
                            </Col>
                            <Col span={17}>
                                <SelectItem InputProps={bind("auttrn")} code={CodeTable.autflg} desp="自动复核" path="/autgrp/rec/auttrn" />
                            </Col>
                        </Col>
                    </Row> */}
                    <TableExpansion
                        delete={true}
                        pagination={{ pageSize: 10, hideOnSinglePage: true }}
                        rowKey="inr"
                        columns={this.bclp_bcllstHeader}
                        model={this.model}
                        dataSource={this.model.bclp_bcllst}
                        onChange={(value) => { this.model.bclp_bcllst = value }}
                        path="/autgrp/audlst"
                    />


                    <div style={{ textAlign: "center" }}>
                        <Button style={{ marginLeft: 10, marginRight: 10 }} type="primary" icon="save" onClick={this.onSav}>
                            <Label value="提交" />
                        </Button>
                        <Button style={{ marginLeft: 10, marginRight: 10 }} type="primary" icon="save" onClick={this.onChk}>
                            <Label value="检查" />
                        </Button>
                        <Button style={{ marginLeft: 10, marginRight: 10 }} type="primary" onClick={this.onRtn}>
                            <Label value="返回" />
                        </Button>
                    </div>
                    {/* <Row gutter={16} style={{ marginTop: 12 }}>
                        <Col span={4} offset={10}>
                            <div className='bchbutton'>
                                <Button type="primary" icon="save" onClick={this.onSav}>
                                    <Label value="提交" />
                                </Button>
                            </div>
                            <div className='bchbutton'>
                                <Button type="primary" icon="save" onClick={this.onChk}>
                                    <Label value="检查" />
                                </Button>
                            </div>
                            <div className='bchbutton'>
                                <Button type="primary" onClick={this.onRtn}>
                                    <Label value="返回" />
                                </Button>
                            </div>
                        </Col>
                    </Row> */}
                </div>
            </Card>
        )
    }
}
