import React,{Component,Fragment} from 'react'
import {Page,Validator,Notification,FormItem,DatePickerItem,TextAreaItem,ConfirmButton,
    InputItem,Input,Bind,SelectItem,Button,Label,Image,Table} from '@/components/Common-Library'
import Api from '@/service/api'
import mDbefrm from '../model'
import CodeTableFactory from '@/components/CodeTable'
import "./index.less"
import { inject, observer } from 'mobx-react'
import { action, observable,runInAction } from 'mobx'
import { Col, Row ,Card,Divider } from 'antd'
import Moment from 'moment'


const CodeTable = CodeTableFactory.getInstance()


@inject('UserContext')
@inject('i18n')
@observer
export default class DbefrmScreen extends Page
{
    @observable
		formBlur=false
		
		//复核层级码表，通用
		reltyp = [
			{label:"一级复核", value:"OA"},
			{label:"二级复核", value:"OAB"},
			{label:"三级复核", value:"OABC"},
			{label:"无需复核", value:"O"}
		]

		//一级复核组码表
		@observable
		urlrec_fstrol1 = []

		@observable
		urlrec_fstrol2 = []

		@observable
		urlrec_fstrol3 = []

		@observable
		urlrec_fstrol4 = []

		//二级复核组码表
		@observable
		urlrec_secrol1 = []

		@observable
		urlrec_secrol2 = []

		@observable
		urlrec_secrol3 = []

		@observable
		urlrec_secrol4 = []

		//三级复核组码表
		@observable
		urlrec_thirol1 = []

		@observable
		urlrec_thirol2 = []

		@observable
		urlrec_thirol3 = []

		@observable
		urlrec_thirol4 = []

    constructor(props)
    {
        super(props)
        this.model = new mDbefrm()  
        this.bind = Bind.bind(this)
    }
	
	async componentWillMount() 
	{
        
    if(this.props.location.query){
	  let selinr = this.props.location.query.selinr
	  let frm = this.props.location.query.frm
			const rtnmsg = await Api.post('dbefrm/init', { params: {selinr,frm} })
			if (rtnmsg.retcod == SUCCESS) {
				Object.assign(this.model,rtnmsg.data)
				//一级复核组码表赋值
				this.urlrec_fstrol1 = rtnmsg.codetable.urlrec_fstrol1
				this.urlrec_fstrol2 = rtnmsg.codetable.urlrec_fstrol2
				this.urlrec_fstrol3 = rtnmsg.codetable.urlrec_fstrol3
				this.urlrec_fstrol4 = rtnmsg.codetable.urlrec_fstrol4
				//二级复核组码表赋值
				this.urlrec_secrol1 = rtnmsg.codetable.urlrec_secrol1
				this.urlrec_secrol2 = rtnmsg.codetable.urlrec_secrol2
				this.urlrec_secrol3 = rtnmsg.codetable.urlrec_secrol3
				this.urlrec_secrol4 = rtnmsg.codetable.urlrec_secrol4
				//三级复核组码表赋值
				this.urlrec_thirol1 = rtnmsg.codetable.urlrec_thirol1
				this.urlrec_thirol2 = rtnmsg.codetable.urlrec_thirol2
				this.urlrec_thirol3 = rtnmsg.codetable.urlrec_thirol3
				this.urlrec_thirol4 = rtnmsg.codetable.urlrec_thirol4
			}
			else {
				Notification.error({ message: '服务端请求失败!' })
			}	
    }	
    //快照模式下，不必开启校验，否则，静默校验，和记录变动
    !this.loadDisplay() && this.model.openMonitor && this.model.openMonitor() //开启校验	
	}
    componentWillUnmount()
    {
        this.model.stopMonitor&&this.model.stopMonitor()//关闭校验
    }



    //按钮事件
    onSav= ()=>{
        this.formBlur=true  //已触发表单提交处理
        Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
              if(errors)
                  return 
              const rtnmsg = await Api.post('dbefrm/sav',{data:this.model})
              if(rtnmsg.retcod == SUCCESS)
              {
                  Notification.success({message:'提交成功!'})
									this.props.history.push("dblfrm");
              }
              else
              {
              	Notification.error({message:'服务端请求失败!'})
              }
                //余下逻辑处理
                    
        })
    }
    onRtn= ()=>{
        this.props.history.push("dblfrm");
    }
    

    //交易内实现
    renderPage(){
    	const bind = this.bind
      const {i18n} = this.props
             
      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("frm")}   disabled={true} />
									</Col>
								</Row>
							</Col>
							<Col span={12}>
								<Row className="row">
									<Col span={5} offset={2}>
										<Label itext="交易中文名" />
									</Col>
									<Col span={14}>
										<InputItem InputProps={bind("namcn")} disabled={true} />
									</Col>
								</Row>
							</Col>
						</Row>

						<Row className="row">
							<Col>
								<Label itext="总行经办复核流程" trn="dbefrm" />
							</Col>
						</Row>

						<Row>
							<Col span={12}>
								<Row className="row">
									<Col span={5} offset={2}>
										<Label itext="复核层级" trn="dbefrm" />
									</Col>
									<Col span={14}>
										<SelectItem InputProps={bind("urlrec_reltyp1")} code={this.reltyp} />
									</Col>
								</Row>
							</Col>
							<Col span={12}>
								<Row className="row">
									<Col span={5} offset={2}>
										<Label itext="一级复核组" trn="dbefrm" />
									</Col>
									<Col span={14}>
										<SelectItem InputProps={bind("urlrec_fstrol1")} code={this.urlrec_fstrol1} disabled={this.urlrec_fstrol1.length == 0} />
									</Col>
								</Row>
							</Col>
						</Row>
						<Row>
							<Col span={12}>
								<Row className="row">
									<Col span={5} offset={2}>
										<Label itext="二级复核组" trn="dbefrm" />
									</Col>
									<Col span={14}>
										<SelectItem InputProps={bind("urlrec_secrol1")} code={this.urlrec_secrol1} disabled={this.urlrec_secrol1.length == 0} />
									</Col>
								</Row>
							</Col>
							<Col span={12}>
								<Row className="row">
									<Col span={5} offset={2}>
										<Label itext="三级复核组" trn="dbefrm" />
									</Col>
									<Col span={14}>
										<SelectItem InputProps={bind("urlrec_thirol1")} code={this.urlrec_thirol1} disabled={this.urlrec_thirol1.length == 0} />
									</Col>
								</Row>
							</Col>
						</Row>

						<Row className="row">
							<Col>
								<Label itext="一级分行经办复核流程" trn="dbefrm" />
							</Col>
						</Row>

						<Row>
							<Col span={12}>
								<Row className="row">
									<Col span={5} offset={2}>
										<Label itext="复核层级" trn="dbefrm" />
									</Col>
									<Col span={14}>
										<SelectItem InputProps={bind("urlrec_reltyp2")} code={this.reltyp} />
									</Col>
								</Row>
							</Col>
							<Col span={12}>
								<Row className="row">
									<Col span={5} offset={2}>
										<Label itext="一级复核组" trn="dbefrm" />
									</Col>
									<Col span={14}>
										<SelectItem InputProps={bind("urlrec_fstrol2")} code={this.urlrec_fstrol2} disabled={this.urlrec_fstrol2.length == 0} />
									</Col>
								</Row>
							</Col>
						</Row>

						<Row>
							<Col span={12}>
								<Row className="row">
									<Col span={5} offset={2}>
										<Label itext="二级复核组" trn="dbefrm" />
									</Col>
									<Col span={14}>
										<SelectItem InputProps={bind("urlrec_secrol2")} code={this.urlrec_secrol2} disabled={this.urlrec_secrol2.length == 0} />
									</Col>
								</Row>
							</Col>
							<Col span={12}>
								<Row className="row">
									<Col span={5} offset={2}>
										<Label itext="三级复核组" trn="dbefrm" />
									</Col>
									<Col span={14}>
										<SelectItem InputProps={bind("urlrec_thirol2")} code={this.urlrec_thirol2} disabled={this.urlrec_thirol2.length == 0} />
									</Col>
								</Row>
							</Col>
						</Row>

						<Row className="row">
							<Col>
								<Label itext="二级分行经办复核流程" trn="dbefrm" />
							</Col>
						</Row>

						<Row>
							<Col span={12}>
								<Row className="row">
									<Col span={5} offset={2}>
										<Label itext="复核层级" trn="dbefrm" />
									</Col>
									<Col span={14}>
										<SelectItem InputProps={bind("urlrec_reltyp3")} code={this.reltyp} />
									</Col>
								</Row>
							</Col>
							<Col span={12}>
								<Row className="row">
									<Col span={5} offset={2}>
										<Label itext="一级复核组" trn="dbefrm" />
									</Col>
									<Col span={14}>
										<SelectItem InputProps={bind("urlrec_fstrol3")} code={this.urlrec_fstrol3} disabled={this.urlrec_fstrol3.length == 0} />
									</Col>
								</Row>
							</Col>
						</Row>

						<Row>
							<Col span={12}>
								<Row className="row">
									<Col span={5} offset={2}>
										<Label itext="二级复核组" trn="dbefrm" />
									</Col>
									<Col span={14}>
										<SelectItem InputProps={bind("urlrec_secrol3")} code={this.urlrec_secrol3} disabled={this.urlrec_secrol3.length == 0} />
									</Col>
								</Row>
							</Col>
							<Col span={12}>
								<Row className="row">
									<Col span={5} offset={2}>
										<Label itext="三级复核组" trn="dbefrm" />
									</Col>
									<Col span={14}>
										<SelectItem InputProps={bind("urlrec_thirol3")} code={this.urlrec_thirol3} disabled={this.urlrec_thirol3.length == 0} />
									</Col>
								</Row>
							</Col>
						</Row>

						<Row className="row">
							<Col>
								<Label itext="支行复核层级" trn="dbefrm" />
							</Col>
						</Row>

						<Row>
							<Col span={12}>
								<Row className="row">
									<Col span={5} offset={2}>
										<Label itext="复核层级" trn="dbefrm" />
									</Col>
									<Col span={14}>
										<SelectItem InputProps={bind("urlrec_reltyp4")} code={this.reltyp} />
									</Col>
								</Row>
							</Col>
							<Col span={12}>
								<Row className="row">
									<Col span={5} offset={2}>
										<Label itext="一级复核组" trn="dbefrm" />
									</Col>
									<Col span={14}>
										<SelectItem InputProps={bind("urlrec_fstrol4")} code={this.urlrec_fstrol4} disabled={this.urlrec_fstrol4.length == 0} />
									</Col>
								</Row>
							</Col>
						</Row>

						<Row>
							<Col span={12}>
								<Row className="row">
									<Col span={5} offset={2}>
										<Label itext="二级复核组" trn="dbefrm" />
									</Col>
									<Col span={14}>
										<SelectItem InputProps={bind("urlrec_secrol4")} code={this.urlrec_secrol4} disabled={this.urlrec_secrol4.length == 0} />
									</Col>
								</Row>
							</Col>
							<Col span={12}>
								<Row className="row">
									<Col span={5} offset={2}>
										<Label itext="三级复核组" trn="dbefrm" />
									</Col>
									<Col span={14}>
										<SelectItem InputProps={bind("urlrec_thirol4")} code={this.urlrec_thirol4} disabled={this.urlrec_thirol4.length == 0} />
									</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="确定提交？"
                    >
                      <Label i18nId="MTABUT_BT000473" />
                    </ConfirmButton>
                  </div>
                </div>
              </Col>
            </Row>

					</div>
      	</Card>
		)
	}
}
