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 mDbdact 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 DbdactScreen extends Page
{
    @observable
    formBlur=false
    
    @observable
    isDisabled=false

    constructor(props)
    {
        super(props)
        this.model = new mDbdact()
        this.model.openValidate() //开启校验
        this.bind = Bind.bind(this)
    }

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

	async componentWillMount() {
		if(this.props.location.query){
			let selinr = this.props.location.query.inr
			const rtnmsg = await Api.post('dbdact/init', { params: {selinr} })
			if (rtnmsg.retcod == SUCCESS) {
				//Notification.success({ message: '数据提交成功!' })
				Object.assign(this.model,rtnmsg.data)
			}
			else {
				Notification.error({ message: '服务端请求失败!' })
			}	
		}	
	}

    //按钮事件
    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('dbdact/sav',{params,data:this.model})
                if(rtnmsg.retcod == SUCCESS)
                {
                    Notification.success({message:'数据提交成功!'})
					 this.props.history.push({pathname: 'dblact', state: {'selflg':true}});
                }
                else
                {
                  Notification.error({message:'服务端请求失败!'})
                  this.isDisabled=false
                }
                //余下逻辑处理
                    
        })
    }
	onRtn = ()=>{
		 this.props.history.push("dblact");
	}
    

    //交易内实现
    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 class="row">
                  <Col span={5} offset={2}>
                    <Label i18nId={"ACTP_LT000017"} />
                  </Col>
                  <Col span={14}>
                    <InputItem InputProps={bind("ptyextkey")} disabled={true} />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row class="row">
                  <Col span={5} offset={2}>
                    <Label i18nId={"ACTP_LT000018"} />
                  </Col>
                  <Col span={14}>
                    <InputItem InputProps={bind("nam")} disabled={true} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Row class="row">
                  <Col span={5} offset={2}>
                    <Label i18nId={"ACTP_LT000019"} />
                  </Col>
                  <Col span={14}>
                    <SelectItem InputProps={bind("cur")} code={CodeTable.curtxt} disabled={true} />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row class="row">
                  <Col span={5} offset={2}>
                    <Label i18nId={"ACTP_LT000020"} />
                  </Col>
                  <Col span={14}>
                    <InputItem InputProps={bind("extkey")} disabled={true} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Row class="row">
                  <Col span={5} offset={2}>
                    <Label i18nId={"ACTP_LT000021"} />
                  </Col>
                  <Col span={14}>
                    <InputItem InputProps={bind("bchkey")} disabled={true} />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row class="row">
                  <Col span={5} offset={2}>
                    <Label i18nId={"ACTP_LT000022"} />
                  </Col>
                  <Col span={14}>
                    <SelectItem InputProps={bind("cshflg")} code={CodeTable.cshflg} disabled={true} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Row class="row">
                  <Col span={5} offset={2}>
                    <Label i18nId={"ACTP_LT000023"} />
                  </Col>
                  <Col span={14}>
                    <InputItem InputProps={bind("dsp")} disabled={true} />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row class="row">
                  <Col span={5} offset={2}>
                    <Label i18nId={"ACTP_LT000024"} />
                  </Col>
                  <Col span={14}>
                    <InputItem InputProps={bind("trmcod")} disabled={true} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Row class="row">
                  <Col span={5} offset={2}>
                    <Label i18nId={"ACTP_LT000025"} />
                  </Col>
                  <Col span={14}>
                    <SelectItem InputProps={bind("acctyp")} code={CodeTable.acctyp} disabled={true} />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row class="row">
                  <Col span={5} offset={2}>
                    <Label i18nId={"ACTP_LT000026"} />
                  </Col>
                  <Col span={14}>
                    <SelectItem InputProps={bind("sta")} code={CodeTable.actsta} disabled={true} />
                  </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>
		  )
	}
}
