/***
 * 
 * 明细  
 * 
***/

import React, { Component, Fragment } from 'react'
import {
	Page, Validator, Notification, FormItem, BottomBtn,
	InputItem, Input, Bind, SelectItem, Button, Label, DatePickerItem, Section, ConfirmButton, Steps
} 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} from 'antd';
import { PtyPicker } from '@/components/Business-Library'
import { Link, withRouter } from 'react-router-dom'
import Ptspta1 from '@/views/Public/Ptspta1'
import Business from '@/views/Public/Business'

import moment from 'moment';

const { Pre, Next, StepWrapper } = Steps
const CodeTable = CodeTableFactory.getInstance()
const confirm = Modal.confirm
  
@withRouter
@inject('UserContext')
@inject('i18n')
@observer
export default class OvwpScreen extends Page {
	@observable
	formBlur = false

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

	//交易描述赋值
	componentDidMount() {
		super.componentDidMount()
		this.autoDispose = autorun(() => {
			this.model.nam = `${this.model.nom1_cur}   ${this.model.nom1_amt}   ${this.model.pts3_namcn || ""}`
			//最大金额计算
			this.model.max_amt = (this.model.nom1_amt * (1 + this.model.nomtop / 100)).toFixed(2)
			if (this.model.avbby == 'SIGT') {
				this.model.tenmaxday = ''
			}else{
				if(this.model.tenmaxday>366){
					this.model.tenmaxday='366';
				}
			}
		})
	}

	componentWillUnmount() {
		this.autoDispose && this.autoDispose()
	}
 


	//按钮事件 获取业务编号
	async onGetref() {
		const rtnmsg = await Api.post(this.props.extra.inifrm + '/getref', { data: this.model })
		if (rtnmsg.retcod == SUCCESS) {
			// Notification.success({ message: 'cptopn/mtabut/getref数据提交成功!' })
			this.model.ownref = rtnmsg.data.ownref;
		}
		else {
			Notification.error({ message: 'cptopn/mtabut/getref服务端请求失败!' })
		}
		//余下逻辑处理
	}

  dateChange=(date)=>{
    let opndat=new Date(date);
    let expdat=this.model.expdat;
    expdat=new Date(expdat);
    if(!date){
      this.model.expdat=""
    }else if(opndat >= expdat){
      this.model.expdat=""
    }
  }
  
	//交易内实现
	renderPage() {
		const bind = this.bind
		const { i18n } = this.props
		const { bchlevelLst } = this.props.extra
    const {next,pre} = this.props.steps
		if(this.props.flag==true){
			return <Spin style={{width:"100%", justifyContent:"center"}} spinning={this.props.flag} />
		}
		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 i18nId={"CPTP_LT000022"} />
							</Col>
							<Col span={10}>
								<InputItem InputProps={bind("ownref")} disabled={true} />
							</Col>
							<Col span={4} offset={1}>
                <Button type="primary" onClick={() => this.onGetref()} 
                disabled={this.model.ownref}>
									<Label i18nId="CPTP_BT000084" />
								</Button>
							</Col>
						</Row>
					</Col>
					<Col span={12}>
						<Row className="row">
							<Col span={5} offset={2}>
								{/* 概要描述 */}
								<Label itext="概要描述"  />	
							</Col>
							<Col span={14}>
							  <InputItem InputProps={bind("nam")}  maxLength={40}  desp="概要描述" path="/dedgrp/rec/nam" 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("ownbch")} code={bchlevelLst} desp="归属机构" path="/dedgrp/rec/ownbch"  />
							</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}>
									<InputItem InputProps={bind("accusr")}  maxLength={8}  desp="客户经理" path="/dedgrp/rec/accusr" />
								</Col>
							</Row>
						</Col>
						<Col span={24}>
							<Row className="row">
								<Col span={5} offset={2}>
									<Label itext="开立日期"  />
								</Col>
								<Col span={14}>
                  <DatePickerItem InputProps={{...bind("opndat"),onAfterChange:this.dateChange}}desp="开立日期" path="/dedgrp/rec/opndat"  dateDisabled={(time)=>time && time > moment()} />
								</Col>
							</Row>
						</Col>
						<Col span={24}>
							<Row className="row">
								<Col span={5} offset={2}>
									<Label itext="有效日期" />
								</Col>
								<Col span={14}>
									<DatePickerItem InputProps={bind("expdat")}  desp="有效日期" path="/dedgrp/rec/expdat" disabled={!this.model.opndat} />
								</Col>
							</Row>
						</Col>
					</Col>
					<Col span={12}>
						<Ptspta1 model={this.model} argArr={{ desc: "受益人", prefix: 'pts3', url: 'detreg/benp_ptysel', flg: 'C', datakey: '\\detp\\benp\\ptslst' }}  />
					</Col>
				</Row>

				{/* 第四行 */}
				<Row>
					<Col span={12}>
						<Row className="row">
							<Col span={5} offset={2}>
								<Label itext="信用证金额" />
							</Col>
							<Col span={6}>
								<SelectItem InputProps={{
									...bind("nom1_cur"), onChange: val => {
										this.model.nom1_cur = val
										this.model.liqtyp = ""
										this.model.swftyp = ""
									}
								}}
									code={CodeTable.curtxt} disabled={true} />
							</Col>
							<Col span={7} offset={1}>
								<InputItem   InputProps={ {...bind("nom1_amt"), type:"amount",cur:this.model.nom1_cur} } />
							</Col>
						</Row>
					</Col>
					<Col span={12}>
						<Row className="row">
							<Col span={5} offset={2}>
								<Label itext="受益人账号" trn="detreg" />	
							</Col>
							<Col span={14}>
								<InputItem InputProps={bind("pts3_extact")}  maxLength={32}  desp="结算账号" path="/dedgrp/ben/pts/extact" />
							</Col>
						</Row>
					</Col>
				</Row>


				{/* 第五行 */}
				<Row>
					<Col span={12}>
						<Col span={24}>
							<Row className="row">
								<Col span={5} offset={2}>
									<Label itext="上下浮动比例+/-% "  />
								</Col>
								<Col span={6}>
									<InputItem InputProps={bind("nomtop")}  maxLength={8}  desp="上浮" path="\dedgrp\rec\nomtop" />
								</Col>
								<Col span={1} offset={1}>
									<Label itext="/"  />
								</Col>
								<Col span={6}>
									<InputItem InputProps={bind("nomton")}  maxLength={8}  desp="下浮" path="\dedgrp\rec\nomton" />
								</Col>
							</Row>
						</Col>
						<Col span={24}>
							<Row className="row">
								<Col span={5} offset={2}>
									<Label itext="信用证最大金额" />
								</Col>
								<Col span={6}>
									<SelectItem InputProps={{
										...bind("max_cur"), onChange: val => {
											this.model.max_cur = val
											this.model.liqtyp = ""
											this.model.swftyp = ""
										}
									}}
										code={CodeTable.curtxt} disabled={true} />
								</Col>
								<Col span={7} offset={1}>
									<InputItem   InputProps={ {...bind("max_amt"), type:"amount", cur:this.model.max_cur} }  disabled={true}/>
								</Col>
							</Row>
						</Col>
						<Col span={24}>
							<Row className="row">
								<Col span={5} offset={2}>
									<Label itext="开证类型"  />
								</Col>
								<Col span={14}>
                  <SelectItem InputProps={{...bind("isstyp"),
                    onAfterChange:(val)=>{
                      if(val=='OWIS' || !val){
												this.model.pts1_extkey="";
												this.model.pts1_namcn="";
												this.model.pts1_adrcn="";
											}
                    }}} 
                    code={CodeTable.isstyp} desp="开证类型" path="\dedgrp\rec\isstyp"
                  />
								</Col>
							</Row>
						</Col>
					</Col>
					
					<Col span={12}>
						<Ptspta1 model={this.model} argArr={{ desc: "开证行", prefix: 'pts5', url: 'detreg/issp_ptysel', flg: 'B', datakey: '\\detp\\issp\\ptslst' }}  />
					</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("trdtyp")} code={CodeTable.mytype}  desp="贸易方式" path="/dedgrp/rec/trdtyp"/>
								</Col>
							</Row> 
						</Col>
						<Col span={24}>
							<Row className="row">
								<Col span={13} offset={2}>
									{/* 最迟货物装运 */}
									<Label itext="最迟货物装运/服务提供日期 "  />
								</Col>
								<Col span={6}>
									<DatePickerItem InputProps={bind("shpdat")}  desp="最迟货物装运/服务提供日期 " path="/dedgrp/rec/shpdat" />
								</Col>
							</Row>
						</Col>
						<Col span={24}>
							<Row className="row">
								<Col span={5} offset={2}>
									<Label itext="信用证兑付方式"  />
								</Col>
								<Col span={6}>
									<SelectItem InputProps={bind("avbby")} 
										code={CodeTable.avbby}  desp="信用证兑付方式" path="/dedgrp/rec/avbby" />
								</Col>
								<Col span={5} offset={1}>
									<InputItem InputProps={bind("tenmaxday")} desp="期限" 
										path="/didgrp/rec/tenmaxday" disabled={this.model.avbby=='SIGT'}  />
								</Col>
								<Col span={4} offset={1}>
									<Label itext="天" />
								</Col>
							</Row>
						</Col>
					</Col>
					<Col span={12}>
						<Ptspta1 model={this.model} argArr={{ desc: "申请人", prefix: 'pts2', url: 'detreg/aplp_ptysel', flg: 'C', datakey: '\\detp\\aplp\\ptslst' }}  />
					</Col>
				</Row>

				{/* 第七行 */}
				<Row>
					<Col span={12}>
						<Row className="row">
							<Col span={5} offset={2}>
								<Label itext="远期付款指示"  />
							</Col>
							<Col span={14}>
								<InputItem InputProps={bind("defdet")}  maxLength={60}  desp="远期付款指示" path="/dedgrp/rec/defdet" />
							</Col>
						</Row>
					</Col>
					<Col span={12}>
						<Row className="row">
							<Col span={5} offset={2}>
								<Label itext="申请人账号" trn="detreg" />
							</Col>
							<Col span={14}>
								<InputItem InputProps={bind("pts2_extact")}  maxLength={32}  desp="结算账号" path="/dedgrp/apl/pts/extact" />
							</Col>
						</Row>
					</Col>
				</Row>
				
				{/* 底部按钮 */}
        <BottomBtn _this={this} />
			</div >
		)
	}
}
