import React, { Component, Fragment } from 'react'
import {
	Page, Validator, Notification, FormItem, BottomBtn,
	InputItem, Input, Bind, SelectItem, Button, Label, DatePickerItem, Section, Table, TextArea, ConfirmButton, Steps,AmountLabel
} from '@/components/Common-Library'
import Api from '@/service/api'
import CodeTableFactory from '@/components/CodeTable'
import "./index.less"
import { inject, observer } from 'mobx-react'
import { action, observable } from 'mobx'
import { Row, Col, Popconfirm, Modal,Spin } from 'antd';
import { ButtonModal, ModalTest } from '@/components/Business-Library'
import { Link, withRouter } from 'react-router-dom'
import { height } from 'window-size';
import Business from '@/views/Public/Business'
import { TableExpansion } from '@/components/Business-Library'
import mElschk from '../model'
const { Pre, Next, StepWrapper } = Steps
import Hedui from './Hedui'
const CodeTable = CodeTableFactory.getInstance()
const confirm = Modal.confirm
@withRouter
@inject('UserContext')
@inject('i18n')
@observer
export default class Chakancreen extends Page
{

    constructor(props) {
		super(props)
        // this.model = props.model
        this.model = new mElschk()
		this.bind = Bind.bind(this)
    }
   
	chkp_smhlstHeader=[
    	{
    		title:<Label itext="操作人员" />, 
    		dataIndex:"creusr",
    		key:"creusr",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.creusr,r2.creusr),
    	},
    	{
    		title:<Label itext="收发报方向" />, 
    		dataIndex:"dir",
    		key:"dir",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.dir,r2.dir),
    		render:(val, row, index)=>{
    			let text = val
    			let em = CodeTable.intout.find(item=>item.value==val)
    			if(em)
    				text= em.label
    			return text
    		}
    	},
    	{
    		title:<Label itext="报文类型" />, 
    		dataIndex:"msgtyp",
    		key:"msgtyp",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.msgtyp,r2.msgtyp),
    		render:(val, row, index)=>{
    			let text = val
    			let em = CodeTable.msgtyp.find(item=>item.value==val)
    			if(em)
    				text= em.label
    			return text
    		}
    	},
    	{
    		title:<Label itext="报文状态" />, 
    		dataIndex:"staflg",
    		key:"staflg",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.staflg,r2.staflg),
    		render:(val, row, index)=>{
    			let text = val
    			let em = CodeTable.smhstaflg.find(item=>item.value==val)
    			if(em)
    				text= em.label
    			return text
    		}
    	},
    	{
    		title:<Label itext="创建时间" />, 
    		dataIndex:"credattim",
    		key:"credattim",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.credattim,r2.credattim),
    	},
    	{
    		title:<Label itext="报文路径" />, 
    		dataIndex:"docpth",
    		key:"docpth",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.docpth,r2.docpth),
		},
		{
            title: '操作',
            dataIndex: "op",
            key: "op",
            width: 120,
            render: (val, row, index) => {
                return (
                    <div>   
                            {/* <span>   <Link to={{ pathname: 'urgrel', query: { usrinr: row.inr } }}>核对</Link>   </span>  */}
							<a href='javascript:;' onClick={() => { this.onHedui( row.inr) }} >核对</a>
                    </div>
                )
            }
        },
    ]


    chkp_chkrstlstHeader=[
    	{
    		title:<Label itext="对账时间" />, 
    		dataIndex:"credat",
    		key:"credat",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.credat,r2.credat),
    	},
    	{
    		title:<Label itext="报文标识号" />, 
    		dataIndex:"busmsgid",
    		key:"busmsgid",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.busmsgid,r2.busmsgid),
    	},
    	{
    		title:<Label itext="发起接收标识" />, 
    		dataIndex:"sndrrcvrind",
    		key:"sndrrcvrind",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.sndrrcvrind,r2.sndrrcvrind),
    		render:(val, row, index)=>{
    			let text = val
    			let em = CodeTable.sndorrcv.find(item=>item.value==val)
    			if(em)
    				text= em.label
    			return text
    		}
    	},
    	{
    		title:<Label itext="发起直接参与机构" />, 
    		dataIndex:"instgagt",
    		key:"instgagt",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.instgagt,r2.instgagt),
    	},
    	{
    		title:<Label itext="报文类型" />, 
    		dataIndex:"msgtp",
    		key:"msgtp",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.msgtp,r2.msgtp),
    		render:(val, row, index)=>{
    			let text = val
    			let em = CodeTable.msgtyp.find(item=>item.value==val)
    			if(em)
    				text= em.label
    			return text
    		}
    	},
    	{
    		title:<Label itext="报文处理状态" />, 
    		dataIndex:"orgnlmsgprcsts",
    		key:"orgnlmsgprcsts",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.orgnlmsgprcsts,r2.orgnlmsgprcsts),
    		render:(val, row, index)=>{
    			let text = val
    			let em = CodeTable.smhstaflg.find(item=>item.value==val)
    			if(em)
    				text= em.label
    			return text
    		}
    	},
    	{
    		title:<Label itext="核对结果" />, 
    		dataIndex:"result",
    		key:"result",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.result,r2.result),
    		render:(val, row, index)=>{
    			let text = val
    			let em = CodeTable.chksta.find(item=>item.value==val)
    			if(em)
    				text= em.label
    			return text
    		}
    	},
    ]

    onSel = () => {
        this.formBlur = true  //已触发表单提交处理
        Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
            if (errors)
                return
                const rtnmsg = await Api.post('elschk/sel',{data:this.model})
            if (rtnmsg.retcod == SUCCESS) {
                //Notification.success({message:'数据提交成功!'})
                this.model.chkp_smhlst = rtnmsg.data['chkp_smhlst'];
                console.log(this.model)
            }
            else {
                Notification.error({ message: '查询失败!' })
            }
            //余下逻辑处理
      
        })
      }
    
    onHedui=async(chkinr)=>{
		const rtnmsg = await Api.post('elschk/chk', { params: { chkinr } })
		if (rtnmsg.retcod == SUCCESS) {
			this.model.chkp_chkrstlst = rtnmsg.data["chkp_chkrstlst"];
			Modal.info({
				title: '核对结果', content: <div style={{ height: 300, overflow: 'auto' }}> <br /><Table pagination={{ pageSize: 10, hideOnSinglePage: true }} columns={this.chkp_chkrstlstHeader} dataSource={this.model.chkp_chkrstlst} /></div>,
				width: 1000,
			})
									  }
		else
		{
			Notification.error({message:"服务端请求失败!"})
		}
    }
    

    renderPage() {
        const bind = this.bind
        const { i18n } = this.props
        return (	<div style={{ position: 'relative' }}>
        <Business wrappedComponentRef={ref => (this.com = ref)}  extra={this.props.extra} model={this.model} />
        {/* 第一行 */}
        <Row>
                    <Col span={24}>

                        <Row>
                            <Col span={12}>
                                <Row className='row'>
                                    <Col span={5} offset={2}>
                                    <Label   itext="开始日期"/>
                                    </Col>
                                    <Col span={14}>
                                    <DatePickerItem InputProps={bind("strdat")}  desp="开始日期" path="/strdat" />
                                    </Col>
                                </Row>
                            </Col>
                            <Col span={12}>
                                <Row className='row'>
                                    <Col span={5} offset={2}>
                                    <Label itext="结束日期" trn="fresel" />	
                                    </Col>
                                    <Col span={14}>
                                    <DatePickerItem InputProps={bind("enddat")}  desp="结束日期" path="/enddat" />
                                    </Col>
                                    
                                </Row>
                            </Col>
                        </Row>


                    </Col>
                </Row>

                <div className='button0'>
                    <div className='button2'>
                        <Button type="primary" icon="search" onClick={this.onSel}>
                            <Label i18nId="MTABUT_BT000022" />
                        </Button>
                    </div>
    
                </div>
                <Row >
                    <Col span={23} style={{marginLeft:40}}>
                        <Table pagination={{ pageSize: 10, hideOnSinglePage: true }} columns={this.chkp_smhlstHeader} dataSource={this.model.chkp_smhlst}  />
                    </Col>
                </Row>
    </div >)
    }
}