/***
 * 
 * 信贷-----福费廷
 * 
***/

import React, { Component, Fragment } from 'react'
import {
	Page, Validator, Notification, FormItem, BottomBtn,
	InputItem, Input, Bind, SelectItem, Button, Label, DatePickerItem, Section, ConfirmButton, Steps,CheckboxItem
} from '@/components/Common-Library'
import Api from '@/service/api'
import CodeTableFactory from '@/components/CodeTable'
import "./index.less"
import { inject, observer } from 'mobx-react'
import { action, observable, autorun } from 'mobx'
import { Row, Col, Popconfirm, Modal ,Spin, Radio } from 'antd';
import { Link, withRouter } from 'react-router-dom'
import Business from '@/views/Public/Business'

const { Pre, Next, StepWrapper } = Steps
const CodeTable = CodeTableFactory.getInstance()
const confirm = Modal.confirm
  
@withRouter
@inject('UserContext')
@inject('i18n')
@observer
export default class XdaFPTScreen extends Page {
	@observable
  formBlur = false
  
	@observable
  limmod_dir1 = []  //行业投向一级码表

  @observable
  limmod_dir2 = []  //行业投向二级码表

  @observable
  limmod_dir3 = []  //行业投向三级码表

  @observable
  limmod_dir4 = []  //行业投向四级码表

  @observable
  limmod_inv1 = []  //涉农贷款类型一级码表

  @observable
  limmod_inv2 = []  //涉农贷款类型二级码表

  @observable
  limmod_inv3 = []  //涉农贷款类型三级码表

  @observable
  limmod_inv4 = []  //涉农贷款类型四级码表

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

  async componentWillMount() {
  }
  
	componentWillUnmount() {

	}

	onTabFocus = async () => {
    //进入信贷页签的同时对信贷相关字段赋值，同时获取相关一级码表
    let codetable = await this.com.wrappedInstance.wrappedInstance.onLimmod_astlim();
    this.limmod_dir1 = codetable[0]
    this.limmod_inv1 = codetable[1]
	}

  //根据传递的参数确定请求哪一级的码表
  onXda_mandir= async(val,codtyp)=>{
    let url = this.props.extra.inifrm+'/limmod_get' + codtyp + val
    const rtnmsg = await Api.post(url,{data:this.model})
    if(rtnmsg.retcod == SUCCESS)
    {
        //最终码表赋值
        if(rtnmsg.codetable[`limmod_${codtyp}${val + 1}`]){
          this[`limmod_${codtyp}${val+1}`] = rtnmsg.codetable[`limmod_${codtyp}${val+1}`]
        }
    }
    else
    {
      Notification.error({message:'服务端请求失败!'})
    }
    //余下逻辑处理
  }

  getDir = (val,codtyp)=>{
    //limmod_${codtyp + val} 的值发生变化时，第一时间清空其后的选项
    switch(val){
      case 1:
        this.model[`limmod_${codtyp + 2}`] = ""
        this.model[`limmod_${codtyp + 3}`] = ""
        this.model[`limmod_${codtyp + 4}`] = ""
        break
      case 2:
        this.model[`limmod_${codtyp + 3}`] = ""
        this.model[`limmod_${codtyp + 4}`] = ""
        break
      case 3:
        this.model[`limmod_${codtyp + 4}`] = ""
        break
    }
    //limmod_${codtyp + val} 有值时，请求下级码表
    this.model[`limmod_${codtyp + val}`] && this.onXda_mandir(val,codtyp)
  }

	//交易内实现
	renderPage() {
		const bind = this.bind
		const { ownbch } = this.props.extra

		return (
			<div style={{ position: 'relative' }}>

        <Business  wrappedComponentRef={ref => (this.com = ref)} page={this} steps={this.props.steps} extra={this.props.extra}  model={this.model} />
				
        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="业务品种" />
              </Col>
              <Col span={14}>
                <SelectItem InputProps={bind("xda_bustyp")} code={CodeTable.xdabustyp} disabled={true} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="发生日期" />
              </Col>
              <Col span={14}>
                <DatePickerItem InputProps={bind("xda_occdat")} disabled={true} />
              </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("xda_cusid")} 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("xda_cusnam")} disabled={true} />
              </Col>
            </Row>
          </Col>
        </Row>
				
        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="机构责任类型" />
              </Col>
              <Col span={14}>
                <SelectItem InputProps={bind("xda_liatyp")} code={CodeTable.xdaliatyp} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="是否共占在途额度" />
              </Col>
              <Col span={14}>
                <SelectItem InputProps={bind("xda_zyedflag")} code={CodeTable.freetax} />
              </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("xda_invno")} 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("xda_thiparacc")} disabled={true} />
              </Col>
            </Row>
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="包买金额" />
              </Col>
              <Col span={6}>
                <SelectItem InputProps={bind("xda_buscur")} code={CodeTable.curtxt} disabled={true} />
              </Col>
              <Col span={7} offset={1}>
                <InputItem InputProps={{ ...bind("xda_busamt"), type: "amount", cur: this.model.xda_buscur }} disabled={true} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="单据金额" />
              </Col>
              <Col span={6}>
                <SelectItem InputProps={bind("xda_paycur")} code={CodeTable.curtxt} disabled={true} />
              </Col>
              <Col span={7} offset={1}>
                <InputItem InputProps={{ ...bind("xda_fzanamt"), type: "amount", cur: this.model.xda_paycur }} disabled={true} />
              </Col>
            </Row>
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="投向领域" />
              </Col>
              <Col span={14}>
                <SelectItem InputProps={bind("xda_strnewind")} code={CodeTable.strnewind} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="发票金额" />
              </Col>
              <Col span={6}>
                <SelectItem InputProps={bind("xda_paycur")} code={CodeTable.curtxt} disabled={true} />
              </Col>
              <Col span={7} offset={1}>
                <InputItem InputProps={{ ...bind("xda_traamt"), type: "amount", cur: this.model.xda_paycur }} />
              </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("xda_termon")} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="承兑日期" />
              </Col>
              <Col span={14}>
                <DatePickerItem InputProps={bind("xda_buycordat")} disabled={true} />
              </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("xda_terday")} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="承兑到期日" />
              </Col>
              <Col span={14}>
                <DatePickerItem InputProps={bind("xda_paydat")} disabled={true} />
              </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("xda_exryearat")} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="承兑行名称" />
              </Col>
              <Col span={14}>
                <InputItem InputProps={bind("xda_accbnknam")} disabled={true} />
              </Col>
            </Row>
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="还款方式" />
              </Col>
              <Col span={14}>
                <SelectItem InputProps={bind("xda_rpmd")} code={CodeTable.rpmd} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="承兑金额" />
              </Col>
              <Col span={6}>
                <SelectItem InputProps={bind("xda_paycur")} code={CodeTable.curtxt} disabled={true} />
              </Col>
              <Col span={7} offset={1}>
                <InputItem InputProps={{ ...bind("xda_buyconamt"), type: "amount", cur: this.model.xda_paycur }} disabled={true} />
              </Col>
            </Row>
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="还息方式" />
              </Col>
              <Col span={14}>
                <SelectItem InputProps={bind("xda_ictyp")} code={CodeTable.ictyp} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="账务机构" />
              </Col>
              <Col span={14}>
                <InputItem InputProps={bind("xda_accorgid")} disabled={true} />
              </Col>
            </Row>
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="主要还款来源" />
              </Col>
              <Col span={14}>
                <SelectItem InputProps={bind("xda_paysoun")} code={CodeTable.paysoun} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="管理责任人" />
              </Col>
              <Col span={14}>
                <InputItem InputProps={bind("xda_liapeoid")} />
              </Col>
            </Row>
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="主要担保方式" />
              </Col>
              <Col span={14}>
                <SelectItem InputProps={bind("xda_voutyp")} code={CodeTable.voutyp} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="其他责任人" />
              </Col>
              <Col span={14}>
                <InputItem InputProps={bind("xda_othliapeoid")} />
              </Col>
            </Row>
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="免税标志" />
              </Col>
              <Col span={14}>
                <SelectItem InputProps={bind("xda_freetax")} code={CodeTable.freetax} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}>
                  <Label itext="涉农贷款类型" />
                </Col>
                <Col span={14}>
                  <SelectItem InputProps={{...bind("limmod_inv1"), onAfterChange:()=>{this.getDir(1,'inv')}}} code={this.limmod_inv1} />
                </Col>
              </Row>
            </Col>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}></Col>
                <Col span={14}>
                  <SelectItem InputProps={{...bind("limmod_inv2"), onAfterChange:()=>{this.getDir(2,'inv')}}} code={this.limmod_inv2} disabled={!this.model.limmod_inv1 || this.limmod_inv2.length == 0} />
                </Col>
              </Row>
            </Col>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}></Col>
                <Col span={14}>
                  <SelectItem InputProps={{...bind("limmod_inv3"), onAfterChange:()=>{this.getDir(3,'inv')}}} code={this.limmod_inv3} disabled={!this.model.limmod_inv2 || this.limmod_inv3.length == 0} />
                </Col>
              </Row>
            </Col>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}></Col>
                <Col span={14}>
                  <SelectItem InputProps={bind("limmod_inv4")} code={this.limmod_inv4} disabled={!this.model.limmod_inv3 || this.limmod_inv4.length == 0} />
                </Col>
              </Row>
            </Col>
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}>
                  <Label itext="行业投向" />
                </Col>
                <Col span={14}>
                  <SelectItem InputProps={{...bind("limmod_dir1"),onAfterChange:()=>{this.getDir(1,'dir')}}} code={this.limmod_dir1} />
                </Col>
              </Row>
            </Col>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}></Col>
                <Col span={14}>
                  <SelectItem InputProps={{...bind("limmod_dir2"),onAfterChange:()=>{this.getDir(2,'dir')}}} code={this.limmod_dir2} disabled={!this.model.limmod_dir1 || this.limmod_dir2.length == 0} />
                </Col>
              </Row>
            </Col>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}></Col>
                <Col span={14}>
                  <SelectItem InputProps={{...bind("limmod_dir3"),onAfterChange:()=>{this.getDir(3,'dir')}}} code={this.limmod_dir3} disabled={!this.model.limmod_dir2 || this.limmod_dir3.length == 0} />
                </Col>
              </Row>
            </Col>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}></Col>
                <Col span={14}>
                  <SelectItem InputProps={bind("limmod_dir4")} code={this.limmod_dir4} disabled={!this.model.limmod_dir3 || this.limmod_dir4.length == 0} />
                </Col>
              </Row>
            </Col>
          </Col>
          <Col span={12}>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}>
                  <Label itext="贷款用途" />
                </Col>
                <Col span={14}>
                  <InputItem InputProps={bind("xda_purpose")} />
                </Col>
              </Row>
            </Col>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}>
                  <Label itext="是否绿色信贷" />
                </Col>
                <Col span={14}>
                  <SelectItem InputProps={bind("xda_grncdt")} code={CodeTable.yesnoflg} />
                </Col>
              </Row>
            </Col>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}>
                  <Label itext="科技型企业类型" />
                </Col>
                <Col span={14}>
                  <SelectItem InputProps={bind("xda_scityp")} code={CodeTable.scityp} />
                </Col>
              </Row>
            </Col>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}>
                  <Label itext="保障性安居工程贷款类型" />
                </Col>
                <Col span={14}>
                  <SelectItem InputProps={bind("xda_enstyp")} code={CodeTable.enstyp} />
                </Col>
              </Row>
            </Col>
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="产业结构调整类型" />
              </Col>
              <Col span={14}>
                <SelectItem InputProps={bind("xda_idytyp")} code={CodeTable.idytyp} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="工业转型升级标识" />
              </Col>
              <Col span={14}>
                <SelectItem InputProps={bind("xda_inyid")} code={CodeTable.yesnoflg} />
              </Col>
            </Row>
          </Col>
        </Row>

        {/* 底部按钮 */}
        <BottomBtn _this={this} />

      </div >
		)
	}
}
