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 mBhgdel 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'
import Ptspta1 from '@/views/Public/Ptspta1'
const CodeTable = CodeTableFactory.getInstance()

@inject('UserContext')
@inject('i18n')
@observer
export default class BhgdelScreen extends Page {
	@observable
  formBlur = false
  
  @observable
  extra = { inifrm: 'bhgdel', bchtmpinr: ''}
  
  //提交按钮的禁用
  @observable
  isDisabled=false;

	constructor(props) {
		super(props)
		this.model = new mBhgdel()
    this.bind = Bind.bind(this)
	this.onSav=this.onSav.bind(this);
  }
  
  //初始化代码
  async componentWillMount() {
      let bchtmpinr='';
    if(this.props.location.state){
      let selflg = this.props.location.state.selflg
			if (selflg)
				this.onSel()
    }else{
        this.extra.bchtmpinr=this.props.location.query.bchtmpinr;
      const rtnmsg = await Api.post(this.extra.inifrm + '/init', {params: { bchtmpinr:this.extra.bchtmpinr }})
      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('bhgdel/sav', {params: { bchtmpinr:this.extra.bchtmpinr }, data: this.model })
				if (rtnmsg.retcod == SUCCESS) {
			console.log(rtnmsg.retcod)
					Notification.success({ message: '注销成功!' })
					this.props.history.push({ pathname: 'bchreg', state: { 'selflg': true } });
				}
				else {
			Notification.error({ message: '服务端请求失败!' })
			this.isDisabled=false;
				}
				//余下逻辑处理
			})
	  }
  
	onRtn = () => {
		this.props.history.push("bchreg");
	}

	//交易内实现
	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("rmbrpt")} disabled={true} maxLength={12}  desp="人行支付行号" path="/bhggrp/rec/rmbrpt" />
                </Col>
              </Row>
            </Col>
            <Col span={12}>
              <Row className="row">
                <Col span={5} offset={2}>
                <Label itext="机构编码" />
                </Col>
                <Col span={14}>
                <InputItem InputProps={bind("branch")}   disabled={true} maxLength={8}  desp="机构编码" path="/bhggrp/rec/branch" />
                </Col>
              </Row>
            </Col>
          </Row>
          <Row>
            <Col span={12}>
              <Row className="row">
                <Col span={5} offset={2}>
                <Label itext="中文名称" />
                </Col>
                <Col span={14}>
                <InputItem InputProps={bind("namcn")}   disabled={true}   maxLength={40}  desp="中文名称" path="/bhggrp/rec/namcn" />
                </Col>
              </Row>
            </Col>
            <Col span={12}>
              <Row className="row">
                <Col span={5} offset={2}>
                <Label itext="机构级别" />
                </Col>
                <Col span={14}>
                <SelectItem InputProps={bind("lev")}  disabled={true} code={CodeTable.bchlev}  desp="机构级别" path="/bhggrp/rec/lev"/>
                </Col>
              </Row>
            </Col>
          </Row>

        	<Row>
					<Col span={12}>
						<Row className="row">
							<Col span={5} offset={2}>
						
								<Label itext="中文地址" />
								</Col>
								<Col span={14}>
									<TextAreaItem style={{ resize: "none" }} disabled={true} InputProps={bind("adrcn")} desp="中文地址" path="/bhggrp/rec/adrcn" />
								</Col>

						</Row>
					</Col>

				</Row>
		
				{/* <Row>
					<Col span={24}>
						<Row className="row">

							<Col span={16} offset={1}>
							<TextAreaItem   style={{ resize: "none" }}  InputProps={bind("adrcn")} desp="中文地址" path="/bhggrp/rec/adrcn"/>
							</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>
		)
	}
}
