/***
 * 
 * 信贷-----信用证
 * 
***/

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

  @observable
  limmod_dir1 = []  //行业投向一级码表

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

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

  @observable
  limmod_dir4 = []  //行业投向四级码表
  
  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]
	}

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

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

	//交易内实现
	renderPage() {
		const bind = this.bind
    const Contry = [
      {label:`中国`,value:`CN` },
    ]

		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}>
                <InputItem InputProps={bind("xda_accorgid")} 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_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>
        </Row>

        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="溢装比例（%）" />
              </Col>
              <Col span={14}>
                <InputItem InputProps={bind("xda_ratio")} 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_defrat")} disabled={true} />
              </Col>
            </Row>
          </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)}}} 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)}}} 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)}}} 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}>
                  <SelectItem InputProps={bind("xda_lctertyp")} code={CodeTable.lctertyp} />
                </Col>
              </Row>
            </Col>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}>
                  <Label itext="远期天数" />
                </Col>
                <Col span={14}>
                  <InputItem InputProps={bind("xda_lgter")} disabled={true} />
                </Col>
              </Row>
            </Col>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}>
                  <Label itext="信用证有效期" />
                </Col>
                <Col span={14}>
                  <DatePickerItem InputProps={bind("xda_oldlcvdat")} disabled={true} />
                </Col>
              </Row>
            </Col>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}>
                  <Label itext="最晚装期" />
                </Col>
                <Col span={14}>
                  <DatePickerItem InputProps={bind("xda_paydat")} disabled={true} />
                </Col>
              </Row>
            </Col>
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="信用证手续费率（‰）" />
              </Col>
              <Col span={14}>
                <InputItem InputProps={bind("xda_pdgrat")} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="最低保证金比例（%）" />
              </Col>
              <Col span={14}>
                <InputItem InputProps={bind("xda_baitrat")} />
              </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}>
                <SelectItem InputProps={bind("xda_apdtyp")} code={CodeTable.apdtyp} />
              </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_prepayacc")} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="贸易凭证类型" />
              </Col>
              <Col span={14}>
                <SelectItem InputProps={bind("xda_couerpar")} code={CodeTable.couerpar} />
              </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_traconno")} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="贸易单据种类" />
              </Col>
              <Col span={14}>
                <SelectItem InputProps={bind("xda_surtyp")} code={CodeTable.surtyp} />
              </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_thipar2")} disabled={true} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="受益人所在国家/地区" />
              </Col>
              <Col span={14}>
                <SelectItem InputProps={bind("xda_thiparid2")} code={Contry} 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_carinfo")} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="是否他行代开" />
              </Col>
              <Col span={14}>
                <SelectItem InputProps={bind("xda_isothbnkage")} code={CodeTable.freetax} 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_agebnknam")} 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_flag2")} code={CodeTable.freetax} 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_conbnknam")} 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_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_idyid")} code={CodeTable.yesnoflg} />
              </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_strnewind")} code={CodeTable.strnewind} />
              </Col>
            </Row>
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                {
                  this.model.xda_liatyp == '0010' ? <Label itext="清收责任人" /> : <Label itext="管理责任人" />
                }
              </Col>
              <Col span={14}>
                <InputItem InputProps={bind("xda_liapeoid")} />
              </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}>
                <InputItem InputProps={bind("xda_ownusr")} 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_ownbch")} disabled={true} />
              </Col>
            </Row>
          </Col>
        </Row>

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

			</div >
		)
	}
}
