import React, { Component, Fragment } from 'react'
import {
    Page, Validator, Notification, FormItem,
    InputItem, Input, Bind, SelectItem, Button, Label, Table, Section, DatePickerItem
} from '@/components/Common-Library'
import { Divider } from 'antd'
import Api from '@/service/api'
import mDbltrm from '../model'
import CodeTableFactory from '@/components/CodeTable'
import "./index.less"
import { inject, observer } from 'mobx-react'
import { action, observable } from 'mobx'
import { Col, Row } from 'antd'
import { Link } from 'react-router-dom'
import Moment from 'moment'
import {Card} from 'antd'
const CodeTable = CodeTableFactory.getInstance()

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

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

    componentWillUnmount() {
        this.model.closeValidate()//关闭校验
    }
	
	componentWillMount() {
		 if (this.props.location.state) {
             let selflg = this.props.location.state.selflg
		     if (selflg)
				this.onSel()
		 }	
	}
    trmlstHeader = [
        {
            title: <Label i18nId="TRMP_TH000003" />,
            dataIndex: "trmtyp",
            key: "trmtyp",
            width: 100,
        },
        {
            title: <Label i18nId="TRMP_TH000004" />,
            dataIndex: "nam",
            key: "nam",
            width: 100,
        },
        {
            title: <Label i18nId="TRMP_TH000005" />,
            dataIndex: "trmcod",
            key: "trmcod",
            width: 100,
        },
        {
            title: <Label i18nId="TRMP_TH000006" />,
            dataIndex: "trnseq",
            key: "trnseq",
            width: 100,
        },
        {
            title: <Label i18nId="TRMP_TH000002" />,
            dataIndex: "trmflg",
            key: "trmflg",
            width: 100,
            render: (val, row, index) => {
                let text = val
                let em = CodeTable.trmflg.find(item => item.value == val)
                if (em)
                    text = em.label
                return text
            }
        },
        {
            title: '操作',
            dataIndex: "op",
            key: "op",
            width: 120,
            render: (val, row, index) => {
                return (
                    <div>
                        <Link to={{ pathname: 'dbetrm', query: { inr: row.inr } }}>修改</Link>
                        <Divider type="vertical" />
                        <Link to={{ pathname: 'dbitrm', query: { inr: row.inr } }}>明细</Link>
                        <Divider type="vertical" />
                        <Link to={{ pathname: 'dbdtrm', query: { inr: row.inr } }}>删除</Link>
                    </div>
                )
            }
        },
    ]


    //按钮事件
    onAdd = () => {
        this.props.history.push('dbatrm')
    }
    onSel = () => {
        this.formBlur = true  //已触发表单提交处理
        Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
            if (errors)
                return
            const rtnmsg = await Api.post('dbltrm/sel', { data: this.model })
            if (rtnmsg.retcod == SUCCESS) {
                //Notification.success({message:'数据提交成功!'})
                this.model.trmp_trmlst = rtnmsg.data.trmp_trmlst;
            }
            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>
                    <Col span={20}>

                        <Row>
                            <Col span={12}>
                                <Row className='row'>
                                    <Col span={5} offset={2}>
                                        <Label i18nId={"DBLTRM_LT000002"} />
                                    </Col>
                                    <Col span={14}>
                                        <InputItem InputProps={bind("trmp_trmtyp")} />
                                    </Col>
                                </Row>
                            </Col>
                            <Col span={12}>
                                <Row className='row'>
                                    <Col span={5} offset={2}>
                                        <Label i18nId={"DBLTRM_LT000003"} />
                                    </Col>
                                    <Col span={14}>
                                        <InputItem InputProps={bind("trmp_trmcod")} />
                                    </Col>
                                </Row>
                            </Col>
                        </Row>


                    </Col>
                </Row>
                <div className='button0'>
                    <div className='button2'>
                        <Button type="primary" icon="search" onClick={this.onSel}>
                            <Label i18nId="MTABUT_BT000022" />
                        </Button>
                    </div>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				 <div className='button2'>
                        <Button type="primary" onClick={this.onAdd}>
                            <Label i18nId="MTABUT_BT000182" />
                        </Button>
                    </div>
                </div>
                <Row >
                    <Col span={23} style={{ marginLeft: 40 }}>
                <Table pagination={{ pageSize: 10, hideOnSinglePage: true }} rowKey="inr" columns={this.trmlstHeader} dataSource={this.model.trmp_trmlst} />
                    </Col>
                </Row>
            </div>
			</Card>
        )
    }
}
