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

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

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

	//交易内实现
	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="用户ID" />
                </Col>
                <Col span={14}>
				<InputItem InputProps={bind("nam")}  maxLength={8}  disabled={true} desp="用户ID" path="/urggrp/rec/nam" />
                </Col>
              </Row>
            </Col>
            <Col span={12}>
              <Row className="row">
                <Col span={5} offset={2}>
                <Label itext="用户名称" />
                </Col>
                <Col span={14}>
				<InputItem InputProps={bind("dspnam")}   disabled={this.model.othame==true?false:true}  maxLength={40}  desp="用户名称" path="/urggrp/rec/dspnam" />
                </Col>
              </Row>
            </Col>
          </Row>

		  <Row>
            <Col span={12}>
              <Row className="row">
                <Col span={5} offset={2}>
                <Label itext="密码" />
                </Col>
                <Col span={14}>
				<InputItem InputProps={{type:"password",...bind("pwd")}} maxLength={100} disabled={true} desp="密码" path="/urggrp/rec/pwd"/>
                </Col>
              </Row>
            </Col>
            <Col span={12}>
              <Row className="row">
                <Col span={5} offset={2}>
                <Label itext="用户组" />
                </Col>
                <Col span={14}>
				<SelectItem InputProps={bind("usg")} code={CodeTable.usgflg}  disabled={this.model.othame==true?false:true}   desp="用户组" path="/urggrp/rec/usg"/>
                </Col>
              </Row>
            </Col>
          </Row>
          <Row>
          <Col span={12}>
              <Row className="row">
                <Col span={5} offset={2}>
                <Label itext="归属机构支付行号" />
                </Col>
                <Col span={6}>
                <InputItem InputProps={bind("rmbrpt")}  disabled={this.model.othame==true?false:true}  maxLength={12}  desp="人行支付行号" path="/urggrp/rec/rmbrpt"  />
                </Col>
                <Col span={4} offset={1}>
                <Bchpicker size='small' type="primary"  disabled={this.model.othame==true?false:true} model={this.model} bchinr={this.extra.usrinr} childEvevnt={this.childEvevnt}  />
                </Col>
              </Row>
            </Col>
            <Col span={12}>
              <Row className="row">
                <Col span={5} offset={2}>
                <Label itext="归属机构" />
                </Col>
                <Col span={14}>
                <InputItem InputProps={bind("bchnam")} disabled={true}   maxLength={8}  desp="归属机构" path="/urggrp/rec/bchnam"  />
                </Col>
				{/* <Col span={4} offset={1}>
                <Bchpicker size='small' type="primary" model={this.model}  childEvevnt={this.childEvevnt}  />
                </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("tel")}  maxLength={30}   disabled={this.model.othame==true?false:true}  desp="电话" path="/urggrp/rec/tel" />
                </Col>
              </Row>
            </Col>
            <Col span={12}>
              <Row className="row">
                <Col span={5} offset={2}>
                <Label itext="电子邮件" />
                </Col>
                <Col span={14}>
				<InputItem InputProps={bind("eml")}  maxLength={80}   disabled={this.model.othame==true?false:true}  desp="电子邮件" path="/urggrp/rec/eml" />
                </Col>
              </Row>
            </Col>
          </Row>

          <Row>
            <Col span={12}>
              <Row className="row">
                <Col span={5} offset={2}>
                <Label itext="DC码值" />
                </Col>
                <Col span={14}>
                <InputItem InputProps={bind("ukey")} disabled={this.model.othame==true?false:true} maxLength={32}  desp="ukey的dc码" path="/urggrp/rec/ukey" />
                </Col>
              </Row>
            </Col>
    
          </Row>


          <Row>
            <Col span={12}>
              <Row className="row">
                <Col span={5} offset={2}>
                <Label itext="用户解锁" />
                </Col>
                <Col span={5}>
				<CheckboxItem InputProps={{...bind("usrrst"),onAfterChange:(val)=>{
											if(val==true){
												this.model.sta="0";
											}
										}}}  desp="用户解锁" path="/usrrst" />
                </Col>
                <Col span={5} offset={2}>
                <Label itext="其他信息修改" />
                </Col>
                <Col span={5}>
                <CheckboxItem InputProps={bind("othame")}  desp="其他信息修改" path="/othame" />
                </Col>

              </Row>
            </Col>
          </Row>

          <Row>
            <Col span={12}>
              <Row className="row">
                <Col span={5} offset={2}>
                <Label itext="重置密码" />
                </Col>
                <Col span={1}>
                <CheckboxItem InputProps={bind("pwdrst")}  desp="重置密码" path="/pwdrst" />
                </Col>
                <Col span={4} offset={2}>
                <Label itext="新密码" />
                </Col>
                <Col span={9}>
                <InputItem InputProps={bind("newpwd")}  disabled={this.model.pwdrst==true?false:true} maxLength={18}  desp="新密码" path="/newpwd" />
                </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>
		)
	}
}
