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

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

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

	//交易码表
	@observable
	spt_frm=[]

	@observable
	checkData=""

	constructor(props) {
		super(props)
		this.model = props.model
		this.bind = Bind.bind(this)
		this.state={
			conget_sector:""
		}
	}

	//根据选择业务不同请求不同交易码表
	async Selchange(val){
		if(val){
			//只要选项发生变化，立即清空页面数据只保存当前操作的数据
			this.model.clear()
			this.model.conget_sector=val

			const rtnmsg=await Api.post('sptrim/conget_sector',{ params:{sector:val} })
			if(rtnmsg.retcod == SUCCESS){
				this.spt_frm=rtnmsg.codetable.spt_frm
			}else{
				Notification.error({message:'服务端请求失败!'})
			}
		}else{
			this.model.clear()
			this.spt_frm=[]
		}
	}

	frmChange= val =>{
		if(!val){
			//如果此选项没有值，立即清空页面数据，只保存上一级选项的数据
			this.setState({conget_sector:this.model.conget_sector},()=>{
				this.model.clear();
				this.model.conget_sector=this.state.conget_sector;
			});
		}else{
      let option=this.spt_frm.find(item=>item.value==val)
      //如果对象中的 description 项有值，则直接跳转至指定页面
      option.description && this.props.history.push({pathname:option.description});
			//如果此选项的值更换了，立即清空页面数据，只保存上一级选项和当前选项的数据
			this.setState({conget_sector:this.model.conget_sector},()=>{
				this.model.clear();
				this.model.conget_sector=this.state.conget_sector;
				this.model.spt_frm=val;
			});
		}
	}

	childEvevnt = childData => {
		this.child = childData;
		this.checkData=childData.checkData
	}

	handleClick=()=>{
		if(this.model.spt_frm && this.model.conget_selref){
			this.child.onConget_search();
		}
	}

	inputBlur= () =>{
		if(!this.checkData){
			return
		}else if(this.model.conget_selref!==this.checkData){
			let conget_selref=this.model.conget_selref
			let conget_sector=this.model.conget_sector
			let spt_frm=this.model.spt_frm
			this.model.clear()
			this.model.conget_selref=conget_selref
			this.model.conget_sector=conget_sector
			this.model.spt_frm=spt_frm
		}
	}

	//交易内实现
	renderPage() {
		const bind = this.bind
		const { i18n } = this.props
		const { bchlevelLst } = this.props.extra
		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 itext="业务" trn="sptrim" />
							</Col>
							<Col span={14}>
								<SelectItem InputProps={{...bind("conget_sector"),onAfterChange:(val)=>{this.Selchange(val)}}} code={CodeTable.busrou}  desp="Business Sector" path="/conget/sector" />
							</Col>
						</Row>
					</Col>
					<Col span={12}></Col>
				</Row>

				<Row>
					<Col span={12}>
						<Row className="row">
							<Col span={5} offset={2}>
								<Label itext="交易" trn="sptrim" />	
							</Col>
							<Col span={14}>
								<SelectItem  InputProps={{...bind("spt_frm"),onAfterChange:(val)=>{this.frmChange(val)}}} 
									code={this.spt_frm}  desp="交易名称" path="/spt/frm"/>
							</Col>
						</Row>
					</Col>
					<Col span={12}></Col>
				</Row>

				<Row>
					<Col span={12}>
						<Row className="row">
							<Col span={5} offset={2}>
								<Label itext="业务参考号" trn="sptrim" />
							</Col>
							<Col span={12}>
								<InputItem InputProps={{...bind("conget_selref"),onPressEnter:this.handleClick,onBlur:this.inputBlur}}  maxLength={40}  desp="Refecence of selected contract" path="/conget/selref" />
							</Col>
							<Col span={1} offset={1}>
								<Cankaohao model={this.model} 
									disabled={!this.model.spt_frm || !this.model.conget_selref}
									childEvevnt={this.childEvevnt}
								/>
							</Col>
						</Row>
					</Col>
					<Col span={12}></Col>
				</Row>

				<Row>
					<Col span={12}>
						<Row className="row">
							<Col span={5} offset={2}>
								<Label itext="业务信息" trn="sptrim" />
							</Col>
							<Col span={14}>
								<InputItem InputProps={bind("conget_selnam")}  maxLength={40}  desp="name of selected contract" path="/conget/selnam" disabled={true} />
							</Col>
						</Row>
					</Col>
					<Col span={12}></Col>
				</Row>

				<Row>
					<Col span={12}>
						<Row className="row">
							<Col span={5} offset={2}>
								<Label itext="柜员" trn="sptrim" />
							</Col>
							<Col span={14}>
								<InputItem InputProps={bind("spt_ownusr")}  maxLength={40}  desp="指定用户组" path="/spt/ownusr" disabled={true} />
							</Col>
						</Row>
					</Col>
					<Col span={12}></Col>
				</Row>

				<Row>
					<Col span={12}>
						<Ptspta1 model={this.model} argArr={{ desc: "客户", prefix: 'pts', url: 'sptrim/adrp_ptysel', flg: 'C', datakey: '\\detp\\adrp\\ptslst' }} isDisabled={true}  />
					</Col>
					<Col span={12}></Col>
				</Row>

				<Row>
					<Col span={12}>
						<Row className="row">
							<Col span={5} offset={2}>
								<Label itext="金额" trn="sptrim" />
							</Col>
							<Col span={6}>
								<SelectItem InputProps={bind("rim_cur")}	code={CodeTable.curtxt}   desp="Currency" path="/trnmod/rimmod/rim/cur" disabled={true}/>
							</Col>
							<Col span={7} offset={1}>
								<InputItem   InputProps={ {...bind("rim_amt"), type:"amount", cur:this.model.rim_cur} } disabled={true} />
							</Col>
						</Row>
					</Col>
					<Col span={12}></Col>
				</Row>

				<Row>
					<Col span={12}>
						<Row className="row">
							<Col span={5} offset={2}>
								<Label itext="登记指示" trn="sptrim" />	
							</Col>
							<Col span={14}>
								<TextAreaItem InputProps={bind("conget_inftxt")} rows={5} style={{ resize: "none" }} desp="inftxt" path="/conget/inftxt"/>
							</Col>
						</Row>
					</Col>
					<Col span={12}></Col>
				</Row>
				
				{/* 底部按钮 */}
        <BottomBtn _this={this} />
			</div >
		)
	}
}
