import React, { Component, Fragment } from 'react'
import {
	Page, Validator, Notification, FormItem,
	InputItem, Input, Bind, SelectItem, Button, Label, Table, Section, DatePickerItem,ConfirmButton,TextAreaItem
} from '@/components/Common-Library'
import { Divider } from 'antd'
import Api from '@/service/api'
import mDbebch 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 DbebchScreen extends Page {
	@observable
  formBlur = false
  
  @observable
  extra = { inifrm: 'dbebch', bchinr: ''}

    @observable
    upbranch: []

    @observable
    accbch: []
  
  //提交按钮的禁用
  @observable
  isDisabled=false;

	constructor(props) {
		super(props)
		this.model = new mDbebch()
    this.bind = Bind.bind(this)
    this.onSav=this.onSav.bind(this);
  }
  
  //初始化代码
  async componentWillMount() {
      let bchinr='';
    if(this.props.location.state){
      let selflg = this.props.location.state.selflg
			if (selflg)
				this.onSel()
    }else{

         this.extra.bchinr=this.props.location.query.bchinr;
         this.accbch=this.props.location.query.accbch;
         this.upbranch=this.props.location.query.upbranch;
      const rtnmsg = await Api.post(this.extra.inifrm + '/init', {params:{ bchinr:this.extra.bchinr}})
      if (rtnmsg.retcod == SUCCESS) {
        Object.assign(this.model, rtnmsg.data)
     
      }
      else {
        Notification.error({ message: '服务端请求失败!' })
      }
    }
    //快照模式下，不必开启校验，否则，静默校验，和记录变动
    !this.loadDisplay() && this.model.openMonitor() //开启校验	
  }

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

	//按钮事件
	async onSav(){
    this.formBlur = true  //已触发表单提交处理
    this.isDisabled=true  //禁用提交按钮

    // childEvevnt = childDate => {
    //   this.abc = childDate;
    // };

		Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
			// if (errors){
      //   this.isDisabled=false;
			// 	return
      // }
			const rtnmsg = await Api.post('dbebch/sav', { data: this.model})
			if (rtnmsg.retcod == SUCCESS&&rtnmsg.retmsg=='success') {
        console.log(rtnmsg.retcod)
				Notification.success({ message: '提交成功!' })
				this.props.history.push({ pathname: 'dblbch', state: { 'selflg': true } });
			}
			else {
        Notification.error({ message: rtnmsg.retmsg })
        this.isDisabled=false;
			}
			//余下逻辑处理
		})
  }
  
	onRtn = () => {
		this.props.history.push("dblbch");
	}

	//交易内实现
	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 itext="机构编码" />
                </Col>
                <Col span={14}>
				<InputItem InputProps={bind("branch")}  maxLength={8}  desp="机构编码" path="/bchgrp/rec/branch" />
                </Col>
              </Row>
            </Col>
            <Col span={12}>
              <Row className="row">
                <Col span={5} offset={2}>
                <Label itext="中文名称" trn="dbebch" />	
                </Col>
                <Col span={14}>
				<InputItem InputProps={bind("namcn")}  maxLength={40}  desp="中文名称" path="/bchgrp/rec/namcn" />
                </Col>
              </Row>
            </Col>
          </Row>

          <Row>
            <Col span={12}>
              <Row className="row">
                <Col span={5} offset={2}>
                <Label itext="机构级别" />
                </Col>
                <Col span={14}>
                <SelectItem InputProps={bind("lev")} code={CodeTable.bchlev}  desp="机构级别" path="/bchgrp/rec/lev"/>
                </Col>
              </Row>
            </Col>
            <Col span={12}>
              <Row className="row">
                <Col span={5} offset={2}>
                <Label itext="中文地址" trn="dbebch" />	
                </Col>
                <Col span={14}>
				<TextAreaItem  style={{ resize: "none" }}  InputProps={bind("adrcn")} desp="中文地址" path="/bchgrp/rec/adrcn"/>
                </Col>
              </Row>
            </Col>
          </Row>

          <Row>
            <Col span={12}>
              <Row className="row">
                <Col span={5} offset={2}>
                <Label itext="上级机构" />
                </Col>
                <Col span={14}>
                <SelectItem InputProps={bind("upbranch")}  code={this.upbranch} desp="上级机构编码" path="/bchgrp/rec/upbranch"/>
                </Col>
              </Row>
            </Col>
            <Col span={12}>
              <Row className="row">
                <Col span={5} offset={2}>
                <Label itext="人行支付行号" trn="dbebch" />	
                </Col>
                <Col span={14}>
                <InputItem InputProps={bind("rmbrpt")}  maxLength={12}  desp="人行支付行号" path="/bchgrp/rec/rmbrpt" />
                </Col>
              </Row>
            </Col>
          </Row>
	
          {/* <Row>
            <Col span={12}>
              <Row className="row">
                <Col span={5} offset={2}>
                <Label itext="机构状态" />
                </Col>
                <Col span={14}>
                <SelectItem InputProps={bind("sta")} code={CodeTable.bchrelsta}  desp="机构状态" path="/bchgrp/rec/sta"/>
                </Col>
              </Row>
            </Col>
            <Col span={12}>
              <Row className="row">
                <Col span={5} offset={2}>
                <Label itext="金融机构标识码" trn="dbebch" />	
                </Col>
                <Col span={14}>
                <InputItem InputProps={bind("decnum")}  maxLength={12}  desp="金融机构标识码" path="/bchgrp/rec/decnum" />
                </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_BT000020" />      
                    </Button>
                  </div>
                  <div className='button2'>
                    <ConfirmButton
                      type="primary"
                      onOK={this.onSav}
                      icon="save"
                      message="确定提交？"
                      disabled={this.isDisabled}
                    >
                      <Label i18nId="MTABUT_BT000473" />
                    </ConfirmButton>
                  </div>
                </div>
              </Col>
            </Row>
				</div>
			</Card>
		)
	}
}
