import React, { Component, Fragment } from 'react'
import {
    Page, Validator, Notification, FormItem, DatePickerItem,
    InputItem, Bind, SelectItem, Button, Label, Image, Select, 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, Form, Icon,Input } from 'antd'


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

const CodeTable = CodeTableFactory.getInstance()


@inject('UserContext')
@inject('i18n')
@observer
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()//关闭校验
        this.model.stopMonitor()//关闭校验
    }

    async componentWillMount() {
        const rtnmsg = await Api.post('dbabcl/init', {})
        if (rtnmsg.retcod == SUCCESS) {
            Object.assign(this.model, rtnmsg.data)
            this.bchlevelLst = rtnmsg.codetable['bchkey'];

            // this.autgrp_audlstHeader[0].type.add.code = rtnmsg.codetable['bchkey']
            // this.autgrp_audlstHeader[0].type.edit.code = rtnmsg.codetable['bchkey']

            this.autgrp_audlstHeader[3].type.add.code = rtnmsg.codetable['bchkey']
            this.autgrp_audlstHeader[3].type.edit.code = rtnmsg.codetable['bchkey']
            // this.autgrp_audlstHeader[0].type.add.code.splice(3,1)

            this.setState({})
        }
        else {
            Notification.error({ message: '服务端请求失败!' })
        }

        //快照模式下，不必开启校验，否则，静默校验，和记录变动
        !this.loadDisplay() && this.model.openMonitor() //开启校验	
    }

    autgrp_audlstHeader = [
        // {
        //     title: <Label value="机构" />,
        //     dataIndex: "bchkey",
        //     key: "bchkey",
        //     width: 100,
        //     render: () => {
        //         return <Select code={this.bchlevelLst} />
        //     },
        //     type: {
        //         add: { type: 'select', code: [] },
        //         edit: { type: 'select', code: [] },
        //     }
        // },
        {
            title: <Label value="业务品种" />,
            dataIndex: "busrou",
            key: "busrou",
            width: 100,
            render: (text, row, record) => {
                // const { getFieldDecorator } = this.props.form;
                // console.log(text)
                console.log(record)
                return <FormItem>
                    {this.props.form.getFieldDecorator(record+"id", {
                        rules: [{ required: true, message: 'Please input your username!' }],
                    })(
                        <Input
                            placeholder="Username"
                            value={text}
                        />,
                    )}
                </FormItem>
            },
            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('dbabcl/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('dbabcl/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('dbabcl/cusp_sel', { data: this.model })
            if (rtnmsg.retcod == SUCCESS) {
                Notification.success({ message: '数据提交成功!' })

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

        })
    }
    onRtn = () => {
        this.props.history.push("dblbcl");
    }
    onChk = () => {
        console.log(this.model.bclp_bcllst)
        this.props.form.validateFields((err, values) => {
            if (!err) {
                console.log('Received values of form: ', values);
            }
        });
        this.formBlur = true  //已触发表单提交处理
        Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
            if (errors)
                return
            const rtnmsg = await Api.post('dbabcl/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="BRANCH ID" path="/bclgrp/rec/bchkey" />
                            </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("busrou")} code={CodeTable.busrou} desp="业务品种" path="/bclgrp/rec/busrou" />
                            </Col>
                        </Col>
                        <Col span={9} className='item' >
                            <Col span={7} >
                                <Label value={"经办方式"} />
                            </Col>
                            <Col span={17}>
                                <SelectItem InputProps={bind("exeflg")} code={CodeTable.exetyp} desp="经办方式" path="/bclgrp/rec/exeflg" />
                            </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("regflg")} code={CodeTable.regflg} desp="登记方式" path="/bclgrp/rec/regflg" />
                            </Col>
                        </Col>
                        <Col span={9} className='item' >
                            <Col span={7} >
                                <Label value={"业务上收机构"} />
                            </Col>
                            <Col span={17}>
                                <SelectItem InputProps={bind("upbchkey")} code={this.bchlevelLst} desp="业务上收机构" path="/bclgrp/rec/upbchkey" />

                            </Col>
                        </Col>
                    </Row> */}
                    {/* <Table
                        delete={true}
                        pagination={{ pageSize: 10, hideOnSinglePage: true }}
                        rowKey="inr"
                        columns={this.autgrp_audlstHeader}
                        model={this.model}
                        dataSource={this.model.bclp_bcllst}
                        onChange={(value) => { this.model.bclp_bcllst = value }}
                        path="/autgrp/audlst"
                    /> */}
                    <TableExpansion
                        delete={true}
                        pagination={{ pageSize: 10, hideOnSinglePage: true }}
                        rowKey="inr"
                        columns={this.autgrp_audlstHeader}
                        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>
        )
    }
}
const a = Form.create({ name: 'validate_other' })(Dblbcl2Screen);
export default a;