import React, { Component, Fragment } from 'react'
import {
	Page, Validator, Notification, FormItem,
	InputItem, Input, Bind, SelectItem, Button, Label, DatePickerItem, Section, Table, TextArea, ConfirmButton, Steps
} from '@/components/Common-Library'
import Api from '@/service/api'
import mBdtset from '../model'
import CodeTableFactory from '@/components/CodeTable'

import "./index.less"
import { inject, observer } from 'mobx-react'
import { action, observable, autorun } from 'mobx'

import Setp from './Setp'
import Rongzi from './Rongzi'

import Fee from '@/views/Public/Fee'
import Gle from '@/views/Public/Gle'
import Papper from '@/views/Public/Papper'
import Engp from '@/views/Public/Engp'
import Lixi from '@/views/Public/Lixi'

import { Card } from 'antd'



const CodeTable = CodeTableFactory.getInstance()
const StepItem = Steps.Item

@inject('UserContext')
@inject('i18n')
@observer
export default class BdtsetScreen extends Page {
	@observable
	formBlur = false

	@observable
	extra = { inifrm: 'bdtset', sptinr: '', oldinr:'',ownbch1: [] }



	constructor(props) {
		super(props)
		this.state = {
			flag: true
		}
		this.model = new mBdtset()
  }
	async componentWillMount() {
		let bddinr = '';
			
		if (this.props.location.query) {
			if(this.props.location.query.from=="sptsel"){
				this.extra.sptinr=this.props.location.query.sptinr;
			  }else{
				bddinr=this.props.location.query.bddinr;
			  }
			}
			const rtnmsg = await Api.post(this.extra.inifrm + '/init', { params: { sptinr:this.extra.sptinr,bddinr } })
		if (rtnmsg.retcod == SUCCESS) {
			Object.assign(this.model, rtnmsg.data)
			this.extra.ownbch1 = rtnmsg.codetable.ownbch1;
			this.extra.oldinr=this.model.inr;
			this.setState({ flag: false })
      this.model.setmod_doccur = 'CNY'
		}
		else {
			Notification.error({ message: '服务端请求失败!' })
		}

		//快照模式下，不必开启校验，否则，静默校验，和记录变动
		!this.loadDisplay() && this.model.openMonitor() //开启校验	
  }
  
	componentWillUnmount() {
    this.model.stopMonitor()//关闭校验
	}

  getRongzi = () => {
    if(this.model.trtcre_crefin === 'true'){
      return (
        <StepItem title="融资">
          <Rongzi model={this.model} extra={this.extra}/>
        </StepItem>
      )
    }else if(this.model.trtcre_crefin === 'false'){
      return null
    }else{
      return null
    }
  }

  getLixi = () => {
    if(this.model.trtcre_crefin === 'true'){
      return (
        <StepItem title="利息明细">
					<Lixi model={this.model} extra={this.extra}/>
				</StepItem>
      )
    }else if(this.model.trtcre_crefin === 'false'){
      return null
    }else{
      return null
    }
  }

	//交易内实现
	renderPage() {
		return (
			<Card title="买方单据付款" size="small" className="transTitle">
				<Steps>
					<StepItem title="付款">
						<Setp model={this.model} extra={this.extra}/>
					</StepItem>

          {/* 动态生成融资页面 */}
          {this.getRongzi()}

          {/* 动态生成利息页面 */}
          {this.getLixi()}

					<StepItem title="表外&保证金">
						<Engp model={this.model} extra={this.extra} />
					</StepItem>

					<StepItem title="费用&账务">
						<Fee model={this.model} extra={this.extra} />
					</StepItem>
					<StepItem title="会计分录">
						<Gle model={this.model} extra={this.extra} />
					</StepItem>

					<StepItem title="面函">
						<Papper model={this.model} extra={this.extra} />
					</StepItem>

				</Steps>
			</Card>
		)
		
	}
}
