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 mDbapty from '../model'
import CodeTableFactory from '@/components/CodeTable'
import "./index.less"
import { inject, observer } from 'mobx-react'
import { action, observable } from 'mobx'
import {Col,Row} from 'antd'
import {Link} from 'react-router-dom'
import Moment from 'moment'
const CodeTable = CodeTableFactory.getInstance()
import {Card} from 'antd'


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

    @observable
    isDisabled=false

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

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

    componentWillMount(){
      //快照模式下，不必开启校验，否则，静默校验，和记录变动
			!this.loadDisplay() && this.model.openMonitor() //开启校验	
    }

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

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

    //交易内实现
    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={"PTYP_LT000181"}/>
                  </Col>
                  <Col span={14}>
                  <InputItem InputProps={bind("extkey")} />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                  <Label i18nId={"PTYP_LT000043"}/>
                  </Col>
                  <Col span={14}>
                  <InputItem InputProps={bind("namcn")} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                  <Label i18nId={"PTYP_LT000037"}/>
                  </Col>
                  <Col span={14}>
                  <InputItem InputProps={bind("nam1")} />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                  <Label i18nId={"PTYP_LT000037"}/>
                  </Col>
                  <Col span={14}>
                  <InputItem InputProps={bind("nam2")} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                  <Label i18nId={"PTYP_LT000046"}/>
                  </Col>
                  <Col span={14}>
                  <InputItem InputProps={bind("str1")} />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                  <Label i18nId={"PTYP_LT000046"}/>
                  </Col>
                  <Col span={14}>
                  <InputItem InputProps={bind("str2")} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                  <Label i18nId={"PTYP_LT000036"}/>
                  </Col>
                  <Col span={14}>
                  <SelectItem InputProps={bind("ptytyp")} code={CodeTable.ptytyp}  />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                  <Label i18nId={"PTYP_LT000038"}/>
                  </Col>
                  <Col span={14}>
                  <SelectItem InputProps={bind("idtyp")} code={CodeTable.idtyp}  />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                  <Label i18nId={"PTYP_LT000040"}/>
                  </Col>
                  <Col span={14}>
                  <InputItem InputProps={bind("juscod")} />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                  <Label i18nId={"PTYP_LT000039"}/>
                  </Col>
                  <Col span={14}>
                  <InputItem InputProps={bind("idcod")} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                  <Label i18nId={"PTYP_LT000041"}/>
                  </Col>
                  <Col span={14}>
                  <SelectItem InputProps={bind("sta")} code={CodeTable.sta}  />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                  <Label i18nId={"PTYP_LT000042"}/>	
                  </Col>
                  <Col span={14}>
                  <InputItem InputProps={bind("ownusr")} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                  <Label i18nId={"PTYP_LT000048"}/>
                  </Col>
                  <Col span={14}>
                  <InputItem InputProps={bind("adrcn")}/>
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                  <Label i18nId={"PTYP_LT000049"}/>	
                  </Col>
                  <Col span={14}>
                  <InputItem InputProps={bind("loccty")} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                  <Label i18nId={"PTYP_LT000050"}/>
                  </Col>
                  <Col span={14}>
                  <InputItem InputProps={bind("loczip")} />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                  <Label i18nId={"PTYP_LT000051"}/>	
                  </Col>
                  <Col span={14}>
                  <InputItem InputProps={bind("loctxt")} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                  <Label i18nId={"PTYP_LT000052"}/>
                  </Col>
                  <Col span={14}>
                  <InputItem InputProps={bind("swfno")} />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                  <Label i18nId={"PTYP_LT000053"}/>	
                  </Col>
                  <Col span={14}>
                  <InputItem InputProps={bind("email")} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="电话" trn="dbapty" />
                  </Col>
                  <Col span={14}>
                    <InputItem InputProps={bind("tel")}  maxLength={30} />
                  </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
                      onOK={this.onSav}
                      icon="save"
                      type="primary"
                      message="确定提交？"
                      disabled={this.isDisabled}
                    >
                      <Label i18nId="MTABUT_BT000473" />
                    </ConfirmButton>
                  </div>
                </div>
              </Col>
            </Row>
		</div>
		</Card>
		)
	}
}
