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 mCptadv from '../model'
import CodeTableFactory from '@/components/CodeTable'
import "./index.less"
import { inject, observer } from 'mobx-react'
import { action, observable } from 'mobx'
import Basic from './Basic'
import BaoSong from './Baosong'
import { Spin } from 'antd'
import Fee from '@/views/Public/Fee'
import Gle from '@/views/Public/Gle'
import Papper from '@/views/Public/Papper'
import Dba from '@/views/Public/Dba'
import Dbd from '@/views/Public/Dbd'
import Bspt from '@/views/Public/Bspt'
import { Card } from 'antd'
const StepItem = Steps.Item

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

	@observable
	extra = { inifrm: 'cptadv', sptinr: '', bchlevelLst: [] }

	constructor(props) {
		super(props)
		this.state = {
			flag: true
		}
		this.model = new mCptadv()
	}
	async componentWillMount() {
		let sptinr = '';
		let rtnmsg = [];
		if (this.props.location.query) {
			sptinr = this.props.location.query.sptinr
			this.extra.sptinr = sptinr
			rtnmsg = await Api.post(this.extra.inifrm + '/init', { params: { sptinr } })
		} else {
			rtnmsg = await Api.post(this.extra.inifrm + '/init', {})
		}
		if (rtnmsg.retcod == SUCCESS) {
			Object.assign(this.model, rtnmsg.data)
			this.extra.bchlevelLst = rtnmsg.codetable.ownbch;
			this.extra.stactyLst = rtnmsg.codetable.stacty;
			this.extra.bopmod_szflg = rtnmsg.codetable.bopmod_szflg;
			this.setState({ flag: false })
		}
		else {
			Notification.error({ message: '服务端请求失败!' })
		}


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

	componentWillUnmount() {
		// this.model.closeValidate()//关闭校验
		this.model.stopMonitor()//关闭校验
	}

	//清算路径
	onBaowen = () => {
		switch (this.model.swftyp) {
			case '103':
				return (<StepItem title="报文信息">
					<Mt103 model={this.model} extra={this.extra} />
				</StepItem>)
				break;
			case 'CM0':
				return (<StepItem title="报文信息">
					<Cmt100 model={this.model} extra={this.extra} />
				</StepItem>)
				break;
			default:
				return null
				break

		}
	}
	//清算路径
	onBspt = () => {
		switch (this.model.bopmod_szflg) {
			case '1':
				return (<StepItem title="涉外汇入申请书">
					<Dba model={this.model} extra={this.extra} />
				</StepItem>)
				break;
			case '2':
				return (<StepItem title="境内收入申报单">
					<Dbd model={this.model} extra={this.extra} />
				</StepItem>)
				break;
			case '3':
				return null
				break;
			default:
				return null
				break
		}
	}
	//报送信息
	onBSXX = () => {
		switch (this.model.max_cur) {
			case 'CNY':
				return (<StepItem title="报送信息">
					<BaoSong model={this.model} extra={this.extra} />
				</StepItem>)
				break;
			default:
				return null;
				break;
		}
	}
	//交易内实现
	renderPage() {
		return (
			<Card title="汇入汇款" size="small" className="transTitle">
				<Steps>
					<StepItem title="概况">
						<Basic model={this.model} extra={this.extra} flag={this.state.flag} />
					</StepItem>
					<StepItem title="费用">
						<Fee model={this.model} extra={this.extra} />
					</StepItem>
					<StepItem title="会计分录">
						<Gle model={this.model} extra={this.extra} />
					</StepItem>
					<StepItem title="外管申报">
						<Bspt model={this.model} extra={this.extra} />
					</StepItem>
					{this.onBspt()}
					{/* <StepItem title="报送信息">
						<BaoSong model={this.model} extra={this.extra} />
					</StepItem> */}
					{this.onBSXX()}
					<StepItem title="面函">
						<Papper model={this.model} extra={this.extra} />
					</StepItem>
				</Steps>
			</Card>
		)
	}
}
