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, ConfirmButton
} from '@/components/Common-Library'
import Api from '@/service/api'
import mSysels from '../model'
import CodeTableFactory from '@/components/CodeTable'
import "./index.less"
import { inject, observer } from 'mobx-react'
import { action, observable, runInAction } from 'mobx'
import { Col, Row, notification, Card, Modal, Divider } from 'antd'
import ELCMessage from '@/components/Business-Library/ELCMessage'
const CodeTable = CodeTableFactory.getInstance()
import DateFormat from '@/utils/DateUtil'


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

    constructor(props)
    {
        super(props)
        this.model = new mSysels()    
        this.bind = Bind.bind(this)
    }
	
	async componentWillMount() 
	{
    this.model.comrtn_prcsts = "SUCD"
    this.model.comrtn_prccd = "BB1I0000"
    this.model.comrtn_rjctinf = "处理成功"
    this.model.comrtn_prcdt = DateFormat()
		//快照模式下，不必开启校验，否则，静默校验，和记录变动
		!this.loadDisplay() && this.model.openMonitor && this.model.openMonitor() //开启校验	
	}
    componentWillUnmount()
    {
        this.model.stopMonitor&&this.model.stopMonitor()//关闭校验
    }

    compms_pmslstHeader=[
    	{
    		title:<Label itext="机构号" />, 
    		dataIndex:"ptcptbk",
    		key:"ptcptbk",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.ptcptbk,r2.ptcptbk),
    	},
    	{
    		title:<Label itext="注册状态" />, 
    		dataIndex:"regsta",
    		key:"regsta",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.regsta,r2.regsta),
    	},
    	{
    		title:<Label itext="接收发送" />, 
    		dataIndex:"msgdir",
    		key:"msgdir",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.msgdir,r2.msgdir),
    	},
    	{
    		title:<Label itext="报文类型" />, 
    		dataIndex:"msgtyp",
    		key:"msgtyp",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.msgtyp,r2.msgtyp),
    	},
    	{
    		title:<Label itext="参数状态" />, 
    		dataIndex:"prmsta",
    		key:"prmsta",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.prmsta,r2.prmsta),
    	},
    ]
    
    //信用证业务对账申请报文 展示和发送按钮
    onComchk_show= ()=>{
      this.formBlur=true  //已触发表单提交处理
      Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
              if(errors)
                  return 
              const rtnmsg = await Api.post('sysels/comchk_show',{data:this.model})
              if(rtnmsg.retcod == SUCCESS)
              {
                  Modal.info({
                    title: '电证报文', content: <div style={{ height: 400, overflow: 'auto' }}><ELCMessage mty={"elcs.721.001.01"} message={rtnmsg.data["\\elcmod\\msgdat"]} /></div>,
                    width: 1000,
                  })
                  
              }
              else
              {
                Notification.error({message:'服务端请求失败!'})
              }
              //余下逻辑处理
                  
      })
    }

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

    //原报文下载申请报文 展示和发送按钮
    onComdow_show= ()=>{
      this.formBlur=true  //已触发表单提交处理
      Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
              if(errors)
                  return 
              const rtnmsg = await Api.post('sysels/comdow_show',{data:this.model})
              if(rtnmsg.retcod == SUCCESS)
              {
                  Modal.info({
                    title: '电证报文', content: <div style={{ height: 400, overflow: 'auto' }}><ELCMessage mty={"elcs.722.001.01"} message={rtnmsg.data["\\elcmod\\msgdat"]} /></div>,
                    width: 1000,
                  })
              }
              else
              {
                Notification.error({message:'服务端请求失败!'})
              }
              //余下逻辑处理
                  
      })
    }

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

    //登录、退出申请报文 展示和发送按钮
    onConlog_show= ()=>{
      this.formBlur=true  //已触发表单提交处理
      Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
              if(errors)
                  return 
              const rtnmsg = await Api.post('sysels/conlog_show',{data:this.model})
              if(rtnmsg.retcod == SUCCESS)
              {
                  Modal.info({
                    title: '电证报文', content: <div style={{ height: 400, overflow: 'auto' }}><ELCMessage mty={"elcs.805.001.01"} message={rtnmsg.data["\\elcmod\\msgdat"]} /></div>,
                    width: 1000,
                  })
              }
              else
              {
                Notification.error({message:'服务端请求失败!'})
              }
              //余下逻辑处理
                  
      })
    }

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

    //业务开通注册报文 展示和发送按钮
    onCompms_show= ()=>{
      this.formBlur=true  //已触发表单提交处理
      Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
              if(errors)
                  return 
              const rtnmsg = await Api.post('sysels/compms_show',{data:this.model})
              if(rtnmsg.retcod == SUCCESS)
              {
                  Modal.info({
                    title: '电证报文', content: <div style={{ height: 400, overflow: 'auto' }}><ELCMessage mty={"elcs.902.001.01"} message={rtnmsg.data["\\elcmod\\msgdat"]} /></div>,
                    width: 1000,
                  })
              }
              else
              {
                Notification.error({message:'服务端请求失败!'})
              }
              //余下逻辑处理
                  
      })
    }

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

    //通用处理确认报文 展示和发送按钮
    onComrtn_show= ()=>{
      this.formBlur=true  //已触发表单提交处理
      Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
              if(errors)
                  return 
              const rtnmsg = await Api.post('sysels/comrtn_show',{data:this.model})
              if(rtnmsg.retcod == SUCCESS)
              {
                  Modal.info({
                    title: '电证报文', content: <div style={{ height: 400, overflow: 'auto' }}><ELCMessage mty={"ccms.900.001.02"} message={rtnmsg.data["\\comrtn\\elcmod\\msgdat"]} /></div>,
                    width: 1000,
                  })
              }
              else
              {
                Notification.error({message:'服务端请求失败!'})
              }
              //余下逻辑处理
                  
      })
    }

    onComrtn_sndbut= ()=>{
      this.formBlur=true  //已触发表单提交处理
      Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
              if(errors)
                  return 
              const rtnmsg = await Api.post('sysels/comrtn_sndbut',{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' }}>
            
            <Divider orientation="left" className="sysfenge">信用证业务对账申请报文</Divider>

            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="对账日期" trn="sysels" />
                  </Col>
                  <Col span={14}>
                    <DatePickerItem InputProps={bind("comchk_chkdat")} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row type="flex" justify="center">
              <Col>
                <div className='button2'>
                  <ConfirmButton
                    type="primary"
                    onOK={this.onComchk_sndbut}
                    message="确定发送？"
                  >
                    <Label i18nId="发送报文" />
                  </ConfirmButton>
                </div>
                <div className='button2'>
                  <Button type="primary" onClick={this.onComchk_show}>
                    <Label i18nId="展示报文" />
                  </Button>
                </div>
              </Col>
            </Row>

            <br/><br/>

            <Divider orientation="left" className="sysfenge">原报文下载申请报文</Divider>

            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="通信级标识号" trn="sysels" />
                  </Col>
                  <Col span={14}>
                    <InputItem InputProps={bind("comdow_mesgid")}  maxLength={35} />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="发起直接参与机构" trn="sysels" />
                  </Col>
                  <Col span={14}>
                    <InputItem InputProps={bind("comdow_instgagt")}  maxLength={20} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="报文类型代码" trn="sysels" />	
                  </Col>
                  <Col span={14}>
                    <InputItem InputProps={bind("comdow_mesgtype")}  maxLength={35} />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="发起接收标识" trn="sysels" />
                  </Col>
                  <Col span={14}>
                    <SelectItem InputProps={bind("comdow_sndrrcvrind")} code={CodeTable.srindi} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="对账日期" trn="sysels" />
                  </Col>
                  <Col span={14}>
                    <DatePickerItem InputProps={bind("comdow_chkdat")} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row type="flex" justify="center">
              <Col>
                <div className='button2'>
                  <ConfirmButton
                    type="primary"
                    onOK={this.onComdow_sndbut}
                    message="确定发送？"
                  >
                    <Label i18nId="发送报文" />
                  </ConfirmButton>
                </div>
                <div className='button2'>
                  <Button type="primary" onClick={this.onComdow_show}>
                    <Label itext="展示报文" />
                  </Button>
                </div>
              </Col>
            </Row>

            <br /><br />

            <Divider orientation="left" className="sysfenge">登录、退出申请报文</Divider>
            
            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="操作类型" trn="sysels" />
                  </Col>
                  <Col span={14}>
                    <SelectItem InputProps={bind("conlog_loginoprtp")} code={CodeTable.logtyp} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row type="flex" justify="center">
              <Col>
                <div className='button2'>
                  <ConfirmButton
                    type="primary"
                    onOK={this.onConlog_sndbut}
                    message="确定发送？"
                  >
                    <Label i18nId="发送报文" />
                  </ConfirmButton>
                </div>
                <div className='button2'>
                  <Button type="primary" onClick={this.onConlog_show}>
                    <Label i18nId="展示报文" />
                  </Button>
                </div>
              </Col>
            </Row>

            <br/><br/>

            <Divider orientation="left" className="sysfenge">业务开通注册报文</Divider>
            
            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="机构号" trn="sysels" />
                  </Col>
                  <Col span={14}>
                    <InputItem InputProps={bind("compms_ptcptbk")} maxLength={20} />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="注册状态" trn="sysels" />
                  </Col>
                  <Col span={14}>
                    <SelectItem InputProps={bind("compms_regsta")} code={CodeTable.regsta} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="报文发送权限集合" trn="sysels" />
                  </Col>
                  <Col span={14}>
                    <TextAreaItem InputProps={bind("compms_sndmsg")} rows={5} style={{ resize: "none" }} />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="报文接收权限集合" trn="sysels" />
                  </Col>
                  <Col span={14}>
                    <TextAreaItem InputProps={bind("compms_rcvmsg")} rows={5} style={{ resize: "none" }} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row type="flex" justify="center" style={{marginTop:10}}>
              <Col>
                <div className='button2'>
                  <ConfirmButton
                    type="primary"
                    onOK={this.onCompms_sndbut}
                    message="确定发送？"
                  >
                    <Label i18nId="发送报文" />
                  </ConfirmButton>
                </div>
                <div className='button2'>
                  <Button type="primary" onClick={this.onCompms_show} >
                    <Label itext="展示报文" />
                  </Button>
                </div>
              </Col>
            </Row>

            <br/><br/>

            <Divider orientation="left" className="sysfenge">通用处理确认报文</Divider>
          
            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="原报文标识号" trn="sysels" />
                  </Col>
                  <Col span={14}>
                    <InputItem InputProps={bind("comrtn_orgnlmsgid")} maxLength={50} />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="原报文发送机构" trn="sysels" />
                  </Col>
                  <Col span={14}>
                    <InputItem InputProps={bind("comrtn_orgnlinstgpty")} maxLength={20} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="原报文类型" trn="sysels" />
                  </Col>
                  <Col span={14}>
                    <SelectItem InputProps={bind("comrtn_orgnlmt")} code={CodeTable.docnam} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="业务状态" trn="sysels" />
                  </Col>
                  <Col span={14}>
                    <SelectItem InputProps={bind("comrtn_prcsts")}  code={CodeTable.smhstaflg} />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="业务处理码" trn="sysels" />
                  </Col>
                  <Col span={14}>
                    <InputItem InputProps={bind("comrtn_prccd")}  maxLength={8} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="拒绝信息" trn="sysels" />
                  </Col>
                  <Col span={14}>
                    <InputItem InputProps={bind("comrtn_rjctinf")}  maxLength={100} />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="处理日期" trn="sysels" />
                  </Col>
                  <Col span={14}>
                    <DatePickerItem InputProps={bind("comrtn_prcdt")} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row type="flex" justify="center" style={{marginTop:10}}>
              <Col>
                <div className='button2'>
                  <ConfirmButton
                    type="primary"
                    onOK={this.onComrtn_sndbut}
                    message="确定发送？"
                  >
                    <Label i18nId="发送报文" />
                  </ConfirmButton>
                </div>
                <div className='button2'>
                  <Button type="primary" onClick={this.onComrtn_show} >
                    <Label itext="展示报文" />
                  </Button>
                </div>
              </Col>
            </Row>
          </div>
        </Card>
      )
	  }
}
