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 { Link, withRouter } from 'react-router-dom'
import Ptspta1 from '@/views/Public/Ptspta1'
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 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.nam1 = `${this.model.max1_cur}   ${this.model.max1_amt}   ${this.model.pts2_namcn}`
      this.model.difrat =    this.model.basrat1 -this.model.basrat
		})
	}

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

	//按钮事件 获取业务编号
	async onGetref(){
    this.formBlur=true  //已触发表单提交处理
    Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
      if(errors)
          return 
      const rtnmsg = await Api.post('fstopn/getref',{data:this.model})
      if(rtnmsg.retcod == SUCCESS)
      {
        this.model.ownref1=rtnmsg.data.ownref1
        // Notification.success({message:'数据提交成功!'})
          
      }
      else
      {
        Notification.error({message:'服务端请求失败!'})
      }
      //余下逻辑处理
                
    })
  }
	
	//交易内实现
	renderPage() {
		const bind = this.bind
		const { i18n } = this.props
    const { ownbch } = 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="bptopn" />	
              </Col>
              <Col span={14}>
                <InputItem InputProps={bind("pntref")}  maxLength={16} disabled={true} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="单据描述" trn="bptopn" />
              </Col>
              <Col span={14}>
                <InputItem InputProps={bind("pntnam")}  maxLength={100} disabled={true} />
              </Col>
            </Row>
          </Col>
        </Row>

				<Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="福费廷编号" trn="fstopn" />	
              </Col>
              <Col span={14}>
                <InputItem InputProps={bind("ownref")}  maxLength={16} disabled={true} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="概要描述" trn="bptopn" />
              </Col>
              <Col span={14}>
                <InputItem InputProps={bind("nam")}  maxLength={100} disabled={true} />
              </Col>
            </Row>
          </Col>
        </Row>

				<Row>
          <Col span={12}>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}>
                  <Label itext="福费廷类型" trn="fstopn" />
                </Col>
                <Col span={14}>
                  <SelectItem InputProps={bind("ffttyp")} code={CodeTable.ffttyp} disabled={true} />
                </Col>
              </Row>
            </Col>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}>
                  <Label itext="福费廷金额" trn="fstopn" />	
                </Col>
                <Col span={6}>
                  <SelectItem InputProps={bind("max_cur")} 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="福费廷余额" trn="fstopn" />
                </Col>
                <Col span={6}>
                  <SelectItem InputProps={bind("opn1_cur")} code={CodeTable.curtxt} disabled={true} />
                </Col>
                <Col span={7} offset={1}>
                  <InputItem InputProps={ {...bind("opn1_amt"), type:"amount",cur:this.model.opn1_cur}} disabled={true} />
                </Col>
              </Row>
            </Col>
          </Col>
          <Col span={12}>
            <Ptspta1 model={this.model} argArr={{ desc: "出让方", prefix: 'pts1', url: 'fstopn/selp_sel', flg: 'B', datakey: '\\fptp\\selp\\ptslst' }} isDisabled={true} />
          </Col>
        </Row>
				
				<Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="单据金额" trn="bptopn" />
              </Col>
              <Col span={6}>
                <SelectItem InputProps={bind("doccur")} code={CodeTable.curtxt} disabled={true} />
              </Col>
              <Col span={7} offset={1}>
                <InputItem InputProps={ {...bind("docamt"), type:"amount",cur:this.model.doccur}} disabled={true} />
              </Col>
            </Row>
          </Col>
        </Row>
				
				<Row>
          <Col span={12}>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}>
                  <Label itext="融资利率" trn="fstopn" />	
                </Col>
                <Col span={6}>
                  <InputItem InputProps={bind("basrat")} disabled={true} />
                </Col>
                <Col span={1} offset={1}>
                  <Label itext="%" trn="bptopn" />
                </Col>
              </Row>
            </Col>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}>
                  <Label itext="归属机构" trn="fstopn" />	
                </Col>
                <Col span={14}>
                  <SelectItem InputProps={bind("ownbch")} code={ownbch} disabled={true} />
                </Col>
              </Row>
            </Col>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}>
                  <Label itext="起息日" trn="fstopn" />
                </Col>
                <Col span={6}>
                  <DatePickerItem InputProps={bind("opndat")} disabled={true} />
                </Col>
              </Row>
            </Col>
          </Col>
          <Col span={12}>
            <Ptspta1 model={this.model} argArr={{ desc: "开证行", prefix: 'pts', url: 'fstopn/invp_sel', flg: 'B', datakey: '\\fptp\\invp\\ptslst' }} isDisabled={true} />
          </Col>
        </Row>
				
				<Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="到期日" trn="fstopn" />	
              </Col>
              <Col span={6}>
                <DatePickerItem InputProps={bind("expdat")} disabled={true} />
              </Col>
            </Row>
          </Col>
        </Row>
				
				<Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="收息方式" trn="fstopn" />
              </Col>
              <Col span={14}>
                <SelectItem InputProps={bind("iratyp")} code={CodeTable.iratyp} disabled={true} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="待摊销利息" trn="fstopn" />
              </Col>
              <Col span={14}>
                <InputItem InputProps={bind("fstmod_trnopnamt")} />
              </Col>
            </Row>
          </Col>
        </Row>

				<Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="卖出业务编号" trn="fstopn" />
              </Col>
              <Col span={11}>
                <InputItem InputProps={bind("ownref1")}  maxLength={16} disabled={true} />
              </Col>
              <Col span={2} offset={1}>
                <Button  type="primary"  onClick={()=>{this.onGetref()}}>
                  <Label itext="获取"/>
                </Button>
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="描述" trn="fstopn" />
              </Col>
              <Col span={14}>
                <InputItem InputProps={bind("nam1")}  maxLength={100} disabled={true}/>
              </Col>
            </Row>
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}>
                  <Label itext="卖出价" trn="fstopn" />	
                </Col>
                <Col span={6}>
                  <InputItem InputProps={bind("basrat1")} />
                </Col>
                <Col span={1} offset={1}>
                  <Label itext="%" trn="fstopn" />	
                </Col>
              </Row>
            </Col>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}>
                  <Label itext="福费廷卖出类型" trn="fstopn" />
                </Col>
                <Col span={14}>
                  <SelectItem InputProps={bind("fsttyp")} code={CodeTable.fsttyp} />
                </Col>
              </Row>
            </Col>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}>
                  <Label itext="转卖金额" trn="fstopn" />
                </Col>
                <Col span={6}>
                  <SelectItem InputProps={bind("max1_cur")} code={CodeTable.curtxt} />
                </Col>
                <Col span={7} offset={1}>
                  <InputItem InputProps={ {...bind("max1_amt"), type:"amount",cur:this.model.max1_cur}} />
                </Col>
              </Row>
            </Col>
          </Col>
          <Col span={12}>
            <Ptspta1 model={this.model} argArr={{ desc: "包买行", prefix: 'pts2', url: 'fstopn/buyp_sel', flg: 'B', datakey: '\\fstp\\buyp\\ptslst' }} formBlur={this.formBlur}  />
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="卖出日期" trn="fstopn" />
              </Col>
              <Col span={6}>
                <DatePickerItem InputProps={bind("opndat1")} />
              </Col>
            </Row>
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="利差" trn="fstopn" />
              </Col>
              <Col span={6}>
                <InputItem disabled={true} InputProps={bind("difrat")} />
              </Col>
              <Col span={1} offset={1}>
                <Label itext="%" trn="fstopn" />	
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="收汇金额" trn="fstopn" />
              </Col>
              <Col span={6}>
                <SelectItem InputProps={bind("fincur")} code={CodeTable.curtxt} />
              </Col>
              <Col span={7} offset={1}>
                <InputItem InputProps={ {...bind("finamt"), type:"amount",cur:this.model.fincur}} />
              </Col>
            </Row>
          </Col>
        </Row>
				
				{/* 底部按钮 */}
        <BottomBtn _this={this} />
			</div >
		)
	}
}
