import React,{Component,Fragment} from 'react'
import {Page,Validator,Notification,FormItem,
    InputItem,Input,Bind,SelectItem,Button,Label,Table,Section,DatePickerItem,ConfirmButton} from '@/components/Common-Library'
import {Divider} from 'antd'
import Api from '@/service/api'
import mDbefee 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 } from 'antd'
import {Link} from 'react-router-dom'
import Moment from 'moment'
const CodeTable = CodeTableFactory.getInstance()




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

    @observable
    isDisabled=false

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

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

	async componentWillMount() {
		if(this.props.location.query){
			let selinr = this.props.location.query.inr
			const rtnmsg = await Api.post('dbefee/init', { params: {selinr} })
			if (rtnmsg.retcod == SUCCESS) {
				//Notification.success({ message: '数据提交成功!' })
				Object.assign(this.model,rtnmsg.data)
			}
			else {
				Notification.error({ message: '服务端请求失败!' })
			}	
    }
    //快照模式下，不必开启校验，否则，静默校验，和记录变动
    !this.loadDisplay() && this.model.openMonitor() //开启校验	
	}

    //按钮事件
     onRtn= ()=>{
		this.props.history.push("dblfee");
    }
	onSav= ()=>{
        this.formBlur=true  //已触发表单提交处理
        this.isDisabled=true //禁用提交按钮

        Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
                if(errors){
                  this.isDisabled=false
                  return 
                }
				let params = {}
				if(this.props.location.query)
				{
					let selinr = this.props.location.query.inr
					params = {selinr}		
				}
                const rtnmsg = await Api.post('dbefee/sav',{params,data:this.model})
                if(rtnmsg.retcod == SUCCESS)
                {
                    Notification.success({message:'提交成功!'});
					this.props.history.push({pathname: 'dblfee', state: {'selflg':true}});
                }
                else
                {
                  Notification.error({message:'服务端请求失败!'})
                  this.isDisabled=false
                }
                //余下逻辑处理     
        })
    }


    //交易内实现
    renderPage(){
    	const bind = this.bind
        const {i18n} = this.props
        const CodeTable = CodeTableFactory.getInstance()
     
        return (
		<Card title="费用维护" size="small" className="transTitle">
      <div style={{position:'relative'}}>
        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label i18nId={"FEEP_LT000014"}/>
              </Col>
              <Col span={14}>
                <InputItem InputProps={bind("feecod")} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label i18nId={"FEEP_LT000015"}/>	
              </Col>
              <Col span={14}>
                <SelectItem InputProps={bind("reltir")} code={CodeTable.feecbs}  />
              </Col>
            </Row>
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label i18nId={"FEEP_LT000042"}/>	
              </Col>
              <Col span={14}>
                <InputItem InputProps={bind("feenam")} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label i18nId={"FEEP_LT000017"}/>	
              </Col>
              <Col span={14}>
                <SelectItem InputProps={bind("rol")} code={CodeTable.feerol}  />
              </Col>
            </Row>
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label i18nId={"FEEP_LT000018"}/>	
              </Col>
              <Col span={14}>
                <InputItem InputProps={bind("acc")} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label i18nId={"FEEP_LT000016"}/>	
              </Col>
              <Col span={14}>
                <SelectItem InputProps={bind("staflg")} code={CodeTable.feesta}  />
              </Col>
            </Row>
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label i18nId={"FEEP_LT000020"}/>	
              </Col>
              <Col span={14}>
                <InputItem InputProps={bind("accacr")} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label i18nId={"FEEP_LT000021"}/>	
              </Col>
              <Col span={14}>
                <InputItem InputProps={bind("accacr2")} />
              </Col>
            </Row>
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label i18nId={"FEEP_LT000022"}/>	
              </Col>
              <Col span={6}>
                <DatePickerItem InputProps={bind("begdat")}/>
              </Col>
              <Col span={7} offset={1}>
                <DatePickerItem InputProps={bind("enddat")}/>
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label i18nId={"FEEP_LT000019"}/>	
              </Col>
              <Col span={14}>
                <InputItem InputProps={bind("reltrn")} />
              </Col>
            </Row>
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label i18nId={"FEEP_LT000028"}/>	
              </Col>
              <Col span={6}>
                <SelectItem InputProps={bind("maxcur")} code={CodeTable.curtxt} />
              </Col>
              <Col span={7} offset={1}>
                <InputItem InputProps={bind("maxamt")} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label i18nId={"FEEP_LT000024"}/>	
              </Col>
              <Col span={14}>
                <SelectItem InputProps={bind("calrul")} code={CodeTable.calrul}  />
              </Col>
            </Row>
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label i18nId={"FEEP_LT000026"}/>	
              </Col>
              <Col span={6}>
                <SelectItem InputProps={bind("mincur")} code={CodeTable.curtxt} />
              </Col>
              <Col span={7} offset={1}>
                <InputItem InputProps={bind("minamt")} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label i18nId={"FEEP_LT000025"}/>	
              </Col>
              <Col span={14}>
                <InputItem InputProps={bind("ratcal")} />
              </Col>
            </Row>
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label i18nId={"FEEP_LT000030"}/>	
              </Col>
              <Col span={14}>
                <SelectItem InputProps={bind("pertyp")} code={CodeTable.feeper}  />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label i18nId={"FEEP_LT000032"}/>	
              </Col>
              <Col span={14}>
                <InputItem InputProps={bind("permin")} />
              </Col>
            </Row>
          </Col>
        </Row>

				<Row type="flex" justify="center">
          <Col>
            <div className="button0">
              <div className='button2'>
                {/* 退出按钮 */}
                <Button type="primary" onClick={this.onRtn} >
                  <Label i18nId="MTABUT_BT000464" />
                </Button>
              </div>
              <div className='button2'>
                <ConfirmButton
                  type="primary"
                  icon="save"
                  message="确定提交？"
                  onOK={this.onSav}
                  disabled={this.isDisabled}
                >
                  <Label i18nId="MTABUT_BT000473" />
                </ConfirmButton>
              </div>
            </div>
          </Col>
        </Row>
		  </div>
		</Card>
		)
	}
}
