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 mSptrim 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'

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

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

    constructor(props)
    {
        super(props)
        this.model = new mSptrim()    
				this.bind = Bind.bind(this)
				this.state={
					flag:true
				}
    }
	
		async componentWillMount(){
			/*
			*添加初始化代码
			*/
			let sptinr = '';
			let rtnmsg = [];
			if (this.props.location.query) {
				sptinr = this.props.location.query.inr
				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.bopmod_szflg = rtnmsg.codetable.bopmod_szflg;
				this.setState({ flag: false })
			}
			else {
				Notification.error({ message: '服务端请求失败!' })
			}
	
			//快照模式下，不必开启校验，否则，静默校验，和记录变动
			!this.loadDisplay() && this.model.openMonitor() //开启校验	
		}

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



    //按钮事件
    onAdrp_sel= ()=>{
        this.formBlur=true  //已触发表单提交处理
        Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
                if(errors)
                    return 
                const rtnmsg = await Api.post('sptrim/adrp_sel',{data:this.model})
                if(rtnmsg.retcod == SUCCESS)
                {
                    Notification.success({message:'数据提交成功!'})
                    
                }
                else
                {
                	Notification.error({message:'服务端请求失败!'})
                }
                //余下逻辑处理
                    
        })
    }
    onAdrp_ptysel= ()=>{
        this.formBlur=true  //已触发表单提交处理
        Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
                if(errors)
                    return 
                const rtnmsg = await Api.post('sptrim/adrp_ptysel',{data:this.model})
                if(rtnmsg.retcod == SUCCESS)
                {
                    Notification.success({message:'数据提交成功!'})
                    
                }
                else
                {
                	Notification.error({message:'服务端请求失败!'})
                }
                //余下逻辑处理
                    
        })
    }
    onConget_search= ()=>{
        this.formBlur=true  //已触发表单提交处理
        Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
                if(errors)
                    return 
                const rtnmsg = await Api.post('sptrim/conget_search',{data:this.model})
                if(rtnmsg.retcod == SUCCESS)
                {
                    Notification.success({message:'数据提交成功!'})
                    
                }
                else
                {
                	Notification.error({message:'服务端请求失败!'})
                }
                //余下逻辑处理
                    
        })
    }
    onConget_sector= ()=>{
        this.formBlur=true  //已触发表单提交处理
        Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
                if(errors)
                    return 
                const rtnmsg = await Api.post('sptrim/conget_sector',{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>

					</Steps>
				</Card>
			)
						 
			
    //     return (
    //     	<div className="transPage">

	
	// <Label itext="业务" trn="sptrim" />	
	// <SelectItem InputProps={bind("conget_sector")} code={CodeTable.buscod}  desp="Business Sector" path="/conget/sector"/>
	// <Button  type="primary" icon="save"
	// 	  onClick={this.onSav} desp="Save" path="/sav">
	// 	<Label   itext="提交"/>
	// </Button>

	
	// <Label itext="交易" trn="sptrim" />	
	// <SelectItem InputProps={bind("spt_frm")}   desp="交易名称" path="/spt/frm"/>
	// <InputItem InputProps={bind("conget_selref")}  maxLength={40}  desp="Refecence of selected contract" path="/conget/selref" />
	// <InputItem InputProps={bind("conget_selnam")}  maxLength={40}  desp="name of selected contract" path="/conget/selnam" />

	
	// <Label itext="业务参考号" trn="sptrim" />	
	// <Button  type="primary"  onClick={this.onConget_search} desp="search" path="/conget/search">
	// 	<Label   itext="search"/>
	// </Button>

	
	// <Label itext="组别" trn="sptrim" />	
	// <SelectItem InputProps={bind("spt_ownusg")}   desp="指定用户组" path="/spt/ownusg"/>

	
	// <Label itext="当事人" trn="sptrim" />	
	// <InputItem InputProps={bind("pts_extkey")}  maxLength={16}  desp="客户编号" path="/trnmod/rimmod/rimrol/pts/extkey" />
	// <Button  type="primary" icon="search" onClick={this.onAdrp_sel} desp="查询" path="/trnmod/rimmod/adrp/sel">
	// 	<Label   itext="查询"/>
	// </Button>
	// <Button  type="primary" icon="search" onClick={this.onAdrp_ptysel} desp="客户查询" path="/trnmod/rimmod/adrp/ptysel">
	// 	<Label   itext="客户查询"/>
	// </Button>
	// <InputItem InputProps={bind("pts_namcn")}  maxLength={100}  desp="客户中文名称" path="/trnmod/rimmod/rimrol/pts/namcn" />
	// <InputItem InputProps={bind("pts_adrcn")}  maxLength={100}  desp="中文地址" path="/trnmod/rimmod/rimrol/pts/adrcn" />

	
	// <Label itext="金额" trn="sptrim" />	
	// <SelectItem InputProps={bind("rim_cur")}   desp="Currency" path="/trnmod/rimmod/rim/cur"/>
	// <InputItem InputProps={bind("rim_amt")}   desp="Amount" path="/trnmod/rimmod/rim/amt" />
	// <Button  type="primary"  onClick={this.onExi} desp="Exit" path="/exi">
	// 	<Label   itext="退出"/>
	// </Button>
	// 	</div>
	// 	)
	}
}
