import React,{Component,Fragment} from 'react'
import PropTypes from 'prop-types'
import {Page,Validator,Notification,FormItem,DatePickerItem,TextAreaItem,CheckboxItem,Checkbox,
    InputItem,Input,Bind,SelectItem,Button,Label,Image,Table,Steps} from '@/components/Common-Library'
import Api from '@/service/api'
import mDetcan from '../model'
import CodeTableFactory from '@/components/CodeTable'
import "./index.less"
import { inject, observer } from 'mobx-react'
import { action, observable,runInAction } from 'mobx'

import { Card } from 'antd'

import Ovwp from './Ovwp'

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


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

@inject('UserContext')
@inject('i18n')
@observer
export default class DetcanScreen extends Page
{
    
    @observable
		formBlur=false
		
		@observable
		extra = { inifrm: 'detcan', sptinr: '', oldinr:'', bchlevelLst: [] };

    constructor(props)
    {
        super(props)
        this.model = new mDetcan()    
				this.bind = Bind.bind(this)
				this.state={
          flag:true
        }
    }
	
		async componentWillMount() 
		{
			/*
			*添加初始化代码
			*/
      let dedinr = '';
      //如果携带参数，接收参数再发请求
      if(this.props.location.query){
        if(this.props.location.query.from=="sptsel"){
          //经办夹进入
          this.extra.sptinr = this.props.location.query.sptinr
        }else{
          dedinr = this.props.location.query.dedinr
        }
      }
      const rtnmsg = await Api.post(this.extra.inifrm + '/init', { params: { sptinr:this.extra.sptinr, dedinr } })
			
			if (rtnmsg.retcod == SUCCESS) {
        Object.assign(this.model, rtnmsg.data)
        //给oldinr赋值为当前inr，为修改、退回等做准备
				this.extra.oldinr = rtnmsg.data.inr;
				this.setState({ flag: false });
			}
			else {
				Notification.error({ message: '服务端请求失败!' })
			}
	
			//快照模式下，不必开启校验，否则，静默校验，和记录变动
			!this.loadDisplay() && this.model.openMonitor() //开启校验
	
		}


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

    docgrdm_docgrdHeader=[
    	{
    		title:<Label itext="一次" />, 
    		dataIndex:"cmail1",
    		key:"cmail1",
    		width:60,
    		sorter: (r1,r2)=>ColSorter(r1.cmail1,r2.cmail1),
    	},
    	{
    		title:<Label itext="二次" />, 
    		dataIndex:"cmail2",
    		key:"cmail2",
    		width:60,
    		sorter: (r1,r2)=>ColSorter(r1.cmail2,r2.cmail2),
    	},
    	{
    		title:<Label itext="单据" />, 
    		dataIndex:"docnam",
    		key:"docnam",
    		width:240,
    		sorter: (r1,r2)=>ColSorter(r1.docnam,r2.docnam),
    	},
    ]


    //按钮事件
    onOthp_sel= ()=>{
        this.formBlur=true  //已触发表单提交处理
        Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
                if(errors)
                    return 
                const rtnmsg = await Api.post('detcan/othp_sel',{data:this.model})
                if(rtnmsg.retcod == SUCCESS)
                {
                    Notification.success({message:'数据提交成功!'})
                    
                }
                else
                {
                	Notification.error({message:'服务端请求失败!'})
                }
                //余下逻辑处理
                    
        })
    }
    onOthp_ptysel= ()=>{
        this.formBlur=true  //已触发表单提交处理
        Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
                if(errors)
                    return 
                const rtnmsg = await Api.post('detcan/othp_ptysel',{data:this.model})
                if(rtnmsg.retcod == SUCCESS)
                {
                    Notification.success({message:'数据提交成功!'})
                    
                }
                else
                {
                	Notification.error({message:'服务端请求失败!'})
                }
                //余下逻辑处理
                    
        })
    }
    

    //交易内实现
    renderPage(){
    	const bind = this.bind
      const {i18n} = this.props
			
			return (
				<Card title="注销/闭卷" size="small" className="transTitle">
					<Steps>
					
						<StepItem title="概要">
							<Ovwp model={this.model} extra={this.extra} flag={this.state.flag} />
						</StepItem>
			
            <StepItem title="表外明细">
							<Engp model={this.model} extra={this.extra} fcdflg="DE" />
						</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>
			)
	}
}
