import React, { Component, Fragment } from 'react'
import {
	Page, Validator, Notification, FormItem, InputItem, Input, Bind, SelectItem, Button, Label, BottomBtn, DatePickerItem, Section, ConfirmButton, Steps, Datecompare } 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

import moment from 'moment';
  
@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.doccur}  ${this.model.docamt}  ${this.model.pts_namcn || ""}`
      
      //计算融资比例
      if(this.model.max_amt){
        this.model.pctfin=(this.model.max_amt * 100 / this.model.docamt).toFixed(2)
      }else{
        this.model.pctfin="0"
      }
      
      //计算计息天数
      if(this.model.opndat && this.model.expdat){
        let expdat = moment( this.model.expdat, 'YYYY-MM-DD' )
        let opndat = moment( this.model.opndat, 'YYYY-MM-DD' )
        if(expdat > opndat){
          this.model.intday=expdat.diff( opndat, "day" ).toString()
        }
      }else{
        this.model.intday="0"
      }
		})
	}

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

	//按钮事件 获取业务编号
	async onGetref(){
		const rtnmsg = await Api.post('bptopn/getref',{data:this.model})
		if(rtnmsg.retcod == SUCCESS)
		{
				// Notification.success({message:'数据提交成功!'})
				this.model.ownref = rtnmsg.data.ownref;
		}
		else
		{
			Notification.error({message:'getref服务端请求失败!'})
		}
	}
	
   //控制起息日期选择范围----只能选择今天及今天之后的日期
   dateDisabled=(time)=>{
    return time && time < moment().subtract(1,'day');
  }

	//交易内实现
	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="bptopn" />
              </Col>
              <Col span={11}>
                <InputItem InputProps={bind("ownref")}  maxLength={16} disabled={true} />
              </Col>
              <Col span={2} offset={1}>
                <Button  type="primary"  onClick={()=>{this.onGetref()}} disabled={this.model.ownref} >
                  <Label   itext="获取"/>
                </Button>
              </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="bptopn" />
                </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="bptopn" />	
                </Col>
                <Col span={14}>
                  <InputItem InputProps={bind("accusr")}  maxLength={8}  desp="客户经理" />
                </Col>
              </Row>
            </Col>
            <Col span={24}>
              <Row className="row">
                <Col span={5} offset={2}>
                  <Label itext="贸易融资类型" trn="bptopn" />
                </Col>
                <Col span={14}>
                  <SelectItem InputProps={bind("fintyp")} code={CodeTable.fintyp} disabled={true} />
                </Col>
              </Row>
            </Col>
          </Col>
          <Col span={12}>
            <Ptspta1 model={this.model} argArr={{ desc: "融资申请人", prefix: 'pts', url: 'bptopn/fiap_sel', flg: 'B', datakey: '\\bptp\\fiap\\ptslst' }} isDisabled={true} />
          </Col>
        </Row>
				
				<Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="计息方式" trn="bptopn" />
              </Col>
              <Col span={14}>
                <SelectItem InputProps={bind("iratyp")} code={CodeTable.iratyp} />
              </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("pts_extact")} />
              </Col>
            </Row>
          </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}}  />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="起息日" trn="bptopn" />
              </Col>
              <Col span={14}>
                <DatePickerItem InputProps={bind("opndat")}  dateDisabled={this.dateDisabled}  />
              </Col>
            </Row>
          </Col>
        </Row>
				
				<Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="融资比例" trn="bptopn" />
              </Col>
              <Col span={6}>
                <InputItem InputProps={bind("pctfin")} disabled={true} />
              </Col>
              <Col span={1} offset={1}>
                <Label itext="%" trn="bptopn" />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="融资到期日" trn="bptopn" />
              </Col>
              <Col span={14}>
                <DatePickerItem InputProps={bind("expdat")}  desp="融资到期日" />
              </Col>
            </Row>
          </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("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}} />
              </Col>
            </Row>
          </Col>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="计息天数" trn="bptopn" />
              </Col>
              <Col span={12}>
                <InputItem InputProps={bind("intday")}   desp="计息天数" disabled={true} />
              </Col>
              <Col span={1} offset={1}>
                <Label itext="天" trn="bptopn" />	
              </Col>
            </Row>
          </Col>
        </Row>

        <Row>
          <Col span={12}>
            <Row className="row">
              <Col span={5} offset={2}>
                <Label itext="融资利率" trn="bptopn" />
              </Col>
              <Col span={6}>
                <InputItem InputProps={bind("basrat")}  desp="融资利率" />
              </Col>
              <Col span={1} offset={1}>
                <Label itext="%" trn="bptopn" />
              </Col>
            </Row>
          </Col>
        </Row>
				
				{/* 底部按钮 */}
        <BottomBtn _this={this} />
			</div >
		)
	}
}
