import React,{Component,Fragment} from 'react'
import {Page,Validator,Notification,FormItem,DatePickerItem,
    InputItem,Input,Bind,SelectItem,Button,Label,Image,Table,TextAreaItem} from '@/components/Common-Library'
import Api from '@/service/api'
import mDbiaut from '../model'
import CodeTableFactory from '@/components/CodeTable'
import "./index.less"
import { inject, observer } from 'mobx-react'
import { action, observable } from 'mobx'
import { Col, Row ,Card,Divider,Checkbox} from 'antd'


const CodeTable = CodeTableFactory.getInstance()


@inject('UserContext')
@inject('i18n')
@observer
export default class DbiautScreen extends Page
{
    @observable
    formBlur=false
	
	@observable
	bchlevelLst: [] 

    constructor(props)
    {
        super(props)
        this.model = new mDbiaut()
        this.model.openValidate() //开启校验
        this.bind = Bind.bind(this)
    }

      componentWillUnmount()
    {
        this.model.closeValidate()//关闭校验
    }
    
	async componentWillMount() {
		if(this.props.location.query){
			let selinr = this.props.location.query.inr
			const rtnmsg = await Api.post('dbiaut/init', { params: {selinr} })
			if (rtnmsg.retcod == SUCCESS) {
				Object.assign(this.model,rtnmsg.data)
				this.bchlevelLst = rtnmsg.codetable['bchkey'];
			}
			else {
				Notification.error({ message: '服务端请求失败!' })
			}	
		}	
	}
	
    autgrp_audlstHeader=[
    	{
    		title:<Label value="客户编号" />, 
    		dsp:`客户编号`,
    		dataIndex:"cusref",
    		key:"cusref",
    		width:100,
    	},
    	{
    		title:<Label value="客户名称" />, 
    		dsp:`客户名称`,
    		dataIndex:"cusnam",
    		key:"cusnam",
    		width:100,
    	},
    	{
    		title:<Label value="入账账号" />, 
    		dsp:`入账账号`,
    		dataIndex:"inact",
    		key:"inact",
    		width:100,
    	},
    	{
    		title:<Label value="出账账号" />, 
    		dsp:`出账账号`,
    		dataIndex:"outact",
    		key:"outact",
    		width:100,
    	},
    	{
    		title:<Label value="自动购汇汇出" />, 
    		dsp:`自动购汇汇出`,
    		dataIndex:"autbuy",
    		key:"autbuy",
    		width:100,
    	},
    	{
    		title:<Label value="自动结汇汇入" />, 
    		dsp:`自动结汇汇入`,
    		dataIndex:"autsel",
    		key:"autsel",
    		width:100,
    	},
    	{
    		title:<Label value="NRA账户标识" />, 
    		dsp:`NRA账户标识`,
    		dataIndex:"nraflg",
    		key:"nraflg",
    		width:100,
    	},
    ]
    autp_usrlstHeader=[
    	{
    		title:<Label value="选择" />, 
    		dsp:`选择`,
    		dataIndex:"pri",
    		key:"pri",
    		width:100,
            render:(val)=>{
                if(val=='X'){
                    return(
                        <Checkbox Checked={true}></Checkbox>
                        )
                }else{
                    return(
                    <Checkbox Checked={false}></Checkbox>
                    )
                }    
            }
    	},
    	{
    		title:<Label value="柜员号" />, 
    		dsp:`柜员号`,
    		dataIndex:"nam",
    		key:"nam",
    		width:100,
    	},
    	{
    		title:<Label value="柜员名称" />, 
    		dsp:`柜员名称`,
    		dataIndex:"dspnam",
    		key:"dspnam",
    		width:100,
    	},
    ]
    //按钮事件
    onFrm= ()=>{
        this.formBlur=true  //已触发表单提交处理
        Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
                if(errors)
                    return 
                const rtnmsg = await Api.post('dbaaut/frm',{data:this.model})
                if(rtnmsg.retcod == SUCCESS)
                {
                    Notification.success({message:'数据提交成功!'})
                    
                }
                else
                {
                	Notification.error({message:'服务端请求失败!'})
                }
                //余下逻辑处理
                    
        })
    }
    onSav= ()=>{
        this.formBlur=true  //已触发表单提交处理
        Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
                if(errors)
                    return 
                const rtnmsg = await Api.post('dbaaut/sav',{data:this.model})
                if(rtnmsg.retcod == SUCCESS)
                {
                    Notification.success({message:'数据提交成功!'})
                    
                }
                else
                {
                	Notification.error({message:'服务端请求失败!'})
                }
                //余下逻辑处理
                    
        })
    }
    onCusp_sel= ()=>{
        this.formBlur=true  //已触发表单提交处理
        Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
                if(errors)
                    return 
                const rtnmsg = await Api.post('dbaaut/cusp_sel',{data:this.model})
                if(rtnmsg.retcod == SUCCESS)
                {
                    Notification.success({message:'数据提交成功!'})
                    
                }
                else
                {
                	Notification.error({message:'服务端请求失败!'})
                }
                //余下逻辑处理
                    
        })
    }
    onRtn= ()=>{
        this.props.history.push("dblaut");
    }
    onChk= ()=>{
        this.formBlur=true  //已触发表单提交处理
        Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
                if(errors)
                    return 
                const rtnmsg = await Api.post('dbaaut/chk',{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">
        	   <div style={{position:'relative'}}>
			   
				<Row gutter={16}>
					<Col span={8} offset={3} className='item' >
						<Col span={7} >
						<Label value={"归属机构"}/>	
						</Col>
						<Col span={17}>
						<SelectItem InputProps={{...bind("bchkey"),disabled:true}}   code={this.bchlevelLst} desp="归属机构" path="/autgrp/rec/bchkey"/>
						</Col>
					</Col>
					<Col span={8} offset={2} className='item' >
						<Col span={7}>
						<Label value={"渠道"}/>	
						</Col>
						<Col span={17}>
						<SelectItem InputProps={{...bind("channel"),disabled:true}}  code={CodeTable.autcal}  desp="渠道" path="/autgrp/rec/channel"/>
						</Col>
					</Col>
			</Row>
			<Row gutter={16}>
				<Col span={8} offset={3} className='item' >
					<Col span={7} >
					<Label value={"交易码"}/>	
					</Col>
					<Col span={17}>
					<InputItem InputProps={{...bind("frm"),readOnly:true}}  maxLength={6}  desp="交易码" path="/autgrp/rec/frm" />
					</Col>
				</Col>
			    <Col span={8} offset={2} className='item' >
					<Col span={7} >
						<Label value={"交易名"}/>	
					</Col>
					<Col span={17}>
						<InputItem InputProps={{...bind("frmnam"),readOnly:true}}  maxLength={40}  desp="交易名" path="/autgrp/rec/frmnam" />
					</Col>
				</Col>
			</Row>
			<Row gutter={16}>
					<Col span={8} offset={3} className='item' >
						<Col span={7} >
						<Label value={"自动经办"}/>	
						</Col>
						<Col span={17}>
							<SelectItem InputProps={{...bind("autspt"),disabled:true}}   code={CodeTable.autflg} desp="自动经办" path="/autgrp/rec/autspt"/>
						</Col>
					</Col>
				<Col span={8} offset={2} className='item' >
				    <Col span={7} >
						<Label value={"自动复核"}/>	
						</Col>
							<Col span={17}>
						<SelectItem InputProps={{...bind("auttrn"),disabled:true}}   code={CodeTable.autflg} desp="自动复核" path="/autgrp/rec/auttrn"/>
						</Col>
					</Col>
				</Row>
				<Row gutter={16}>
					<Col span={8} offset={3} className='item' >
						     <Col span={7} >
						<Label value={"经办客户限制"}/>	
						</Col>
							<Col span={17}>
						<SelectItem InputProps={{...bind("sptcuslmt"),disabled:true}}  code={CodeTable.cuslim}  desp="经办客户限制" path="/autgrp/rec/sptcuslmt"/>
						</Col>
					</Col>
					<Col span={8} offset={2} >
						<Col span={7} >
						<Label value={"自动复核柜员限制"}/>	
						</Col>
							<Col span={17}>
						<SelectItem InputProps={{...bind("trnusrlmt"),disabled:true}}   code={CodeTable.cusflg} desp="自动复核柜员限制" path="/autgrp/rec/trnusrlmt"/>
						</Col>
					</Col>
				</Row>
				
				
					<Row gutter={16}>
						<Col span={8} offset={3} className='item' >
							<Col span={7} >
								<Label value={"对公/对私"} />
							</Col>
							<Col span={17}>
								<SelectItem InputProps={bind("custyp")}   code={CodeTable.custyp}  desp="对公/对私" path="/autgrp/rec/custyp"/>
							</Col>
						</Col>
						<Col span={8} offset={2} >
							<Col span={7} >
								<Label value={"账户类型"} />
							</Col>
							<Col span={17}>
									<SelectItem InputProps={bind("acttyp")}   code={CodeTable.acttyp2}   desp="账户类型" path="/autgrp/rec/acttyp"/>
							</Col>
						</Col>
					</Row>
					
					<Row gutter={16}>
						<Col span={8} offset={3} className='item' >
							<Col span={7} >
								<Label value={"外管客户状态"} />
							</Col>
							<Col span={17}>
								<SelectItem InputProps={bind("cussta")}  code={CodeTable.actsta2}  maxLength={1}  desp="外管客户状态" path="/autgrp/rec/cussta" />
							</Col>
						</Col>
						<Col span={8} offset={2} >
							<Col span={7} >
								<Label value={"关键字过滤"} />
							</Col>
							<Col span={17}>
							     <TextAreaItem rows={4} InputProps={bind("keywrod")} desp="关键字过滤" path="/autgrp/rec/keywrod"/>
							</Col>
						</Col>
					</Row>
					
					<Row gutter={16}>
				   <Col span={8} offset={3}>
						<Col span={7} >
						      <Label value={"自动经办金额限制"}/>	
						</Col>
						<Col span={7}>
								<SelectItem InputProps={{...bind("cur"),disabled:true}}  code={CodeTable.curtxt} />
						</Col>
						<Col span={10}>
							<InputItem InputProps={{...bind("sptamt"),readOnly:true}}   desp="自动经办金额限制" path="/autgrp/rec/sptamt" />
						</Col>
					</Col>
					
					<Col span={8} offset={2} >
						<Col span={7} >
						    <Label value={"自动复核金额限制"}/>	
						</Col>
						<Col span={7}>
								<SelectItem InputProps={{...bind("cur"),disabled:true}}  code={CodeTable.curtxt} />
							</Col>
						<Col span={10}>
							<InputItem InputProps={{...bind("trnamt"),readOnly:true}}   desp="自动复核金额限制" path="/autgrp/rec/trnamt" />
						</Col>
					</Col>
				</Row>
			     {/*<div className='button0'>
                     <div className='button2'>
                        <Button type="primary" onClick={this.onRtn}>
                           <Label value="返回" />      
                        </Button>
                    </div>
                </div>*/}
				<Table pagination={{ pageSize: 10, hideOnSinglePage: true }} rowKey="inr" columns={this.autgrp_audlstHeader}  dataSource={this.model.autgrp_audlst}   path="/autgrp/audlst"/>
		        <br />
				<Table  pagination={{ pageSize: 10, hideOnSinglePage: true }} rowKey="inr" columns={this.autp_usrlstHeader}  dataSource={this.model.autp_usrlst}   path="/autp/usrlst"/>

				<Row gutter={16} style={{marginTop:12}}>
                    <Col offset={11}>
                        <div className='bchbutton'>
                            <Button type="primary" onClick={this.onRtn}>
                                <Label value="返回" />
                            </Button>
                        </div>
                    </Col>
                </Row>
				  
			</div>	
			</Card>	
		)
	}
}
