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 mDblfee 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'
const CodeTable = CodeTableFactory.getInstance()
import {Card} from 'antd'


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

    constructor(props) {
        super(props)
        this.model = new mDblfee()
        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()
		 }	
	}
	
    feelstHeader = [
        {
            title: <Label i18nId="FEEP_TH000043" />,
            dataIndex: "feecod",
            key: "feecod",
            width: 100,
        },
        {
            title: <Label i18nId="FEEP_TH000033" />,
            dataIndex: "feenam",
            key: "feenam",
            width: 100,
        },
        {
            title: <Label i18nId="FEEP_TH000034" />,
            dataIndex: "acc",
            key: "acc",
            width: 100,
        },
        {
            title: <Label i18nId="FEEP_TH000035" />,
            dataIndex: "begdat",
            key: "begdat",
            width: 100,
            render: (val, row, index) => {
                if (val) {
                    let dat = Moment(val).format('YYYY-MM-DD')
                    return dat;
                }
                return val
            }
        },
        {
            title: <Label i18nId="FEEP_TH000036" />,
            dataIndex: "enddat",
            key: "enddat",
            width: 100,
            render: (val, row, index) => {
                if (val) {
                    let dat = Moment(val).format('YYYY-MM-DD')
                    return dat;
                }
                return val
            }
        },
        {
            title: <Label i18nId="FEEP_TH000037" />,
            dataIndex: "bchinr",
            key: "bchinr",
            width: 100,
        },
        {
            title: <Label i18nId="FEEP_TH000038" />,
            dataIndex: "calrul",
            key: "calrul",
            width: 100,
            render: (val, row, index) => {
                let text = val
                let em = CodeTable.calrul.find(item => item.value == val)
                if (em)
                    text = em.label
                return text
            }
        },
        {
            title: <Label i18nId="FEEP_TH000039" />,
            dataIndex: "ratcal",
            key: "ratcal",
            width: 100,
        },
        {
            title: '操作',
            dataIndex: "op",
            key: "op",
            width: 120,
            render: (val, row, index) => {
                return (
                    <div>
                        <Link to={{ pathname: 'dbefee', query: { inr: row.inr } }}>修改</Link>
                        <Divider type="vertical" />
                        <Link to={{ pathname: 'dbifee', query: { inr: row.inr } }}>明细</Link>
                        <Divider type="vertical" />
                        <Link to={{ pathname: 'dbdfee', query: { inr: row.inr } }}>删除</Link>
                    </div>
                )
            }
        },
    ]
    edit = inr => {
        console.log(inr)
        this.props.history.push('dbefee')
    }
    detail = inr => {
        this.props.history.push('dbifee')
    }

    //按钮事件
    onAdd = () => {
        this.props.history.push('dbafee')
    }

    onSel = () => {
        this.formBlur = true  //已触发表单提交处理
        Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
            if (errors)
                return
            const rtnmsg = await Api.post('dblfee/sel', { data: this.model })
            if (rtnmsg.retcod == SUCCESS) {
                //  Notification.success({ message: '数据提交成功!' })
                this.model.feep_feelst = rtnmsg.data.feep_feelst;
            }
            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={"FEEP_LT000008"} />
                                    </Col>
                                    <Col span={14}>
                                        <InputItem InputProps={bind("feep_feecod")} />
                                    </Col>
                                </Row>
                            </Col>
                            <Col span={12}>
                                <Row className='row'>
                                    <Col span={5} offset={2}>
                                        <Label i18nId={"FEEP_LT000009"} />
                                    </Col>
                                    <Col span={14}>
                                        <InputItem InputProps={bind("feep_feenam")} />
                                    </Col>
                                </Row>
                            </Col>
                        </Row>

                        <Row>
                            <Col span={12}>
                                <Row className='row'>
                                    <Col span={5} offset={2}>
                                        <Label i18nId={"FEEP_LT000010"} />
                                    </Col>
                                    <Col span={6}>
                                        <DatePickerItem InputProps={bind("feep_begdat")} />
                                    </Col>
                                    <Col span={1} offset={1} >
                                        <Label value="至"/>
                                    </Col>
                                    <Col span={6} >
                                        <DatePickerItem InputProps={bind("feep_enddat")} />
                                    </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 }} columns={this.feelstHeader} dataSource={this.model.feep_feelst} />
                    </Col>
                </Row>
                
            </div>
			</Card>
        )
    }
}
