import React, { Component, Fragment } from 'react'
import {
	Page, Validator, Notification, FormItem, BottomBtn,
	InputItem, Input, Bind, SelectItem, Button, Label, DatePickerItem, Section, Table, TextArea, ConfirmButton, Steps
} from '@/components/Common-Library'
import ELCMessage from '@/components/Business-Library/ELCMessage'

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 } from 'antd';
import { ButtonModal, ModalTest } from '@/components/Business-Library'
import { Link, withRouter } from 'react-router-dom'
import { Divider } from 'antd'
import Business from '@/views/Public/Business'

const CodeTable = CodeTableFactory.getInstance()
const { Pre, Next, StepWrapper } = Steps
const confirm = Modal.confirm

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

	constructor(props) {
		super(props)
		this.model = props.model
		this.bind = Bind.bind(this)
	}
	async componentWillMount() {
	}

	componentWillUnmount() {
	}

	onTabFocus = async () => {
		this.com.wrappedInstance.wrappedInstance.onReldoc();
	}

	onTrndoc_butshw = async (row) => {
		this.formBlur = true  //已触发表单提交处理

		//Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
		//        if(errors)
		//            return 
		let cortyp = row.cortyp
		if (cortyp == 'SWT'|| cortyp == 'FMT' || cortyp == 'CMT') {
			this.model.msgmod_doccod = row.id
			rtnmsg = await Api.post(this.props.extra.inifrm + '/msgmod_butshw', { data: this.model })
		} else {
			this.model.trndoc_doccod = row.id
			this.model.trndoc_cortyp = cortyp
			rtnmsg = await Api.post(this.props.extra.inifrm + '/trndoc_butshw', { data: this.model })
		}

		if (rtnmsg.retcod == SUCCESS) {
			if (cortyp == 'SWT' || cortyp == 'FMT' || cortyp == 'CMT') {
				let viewurl = "/psbcfront" + rtnmsg.data.msgmod_docpth;
				window.open(viewurl, 'newwindow', 'height=1200,width=800,top=100,left=100,toolbar=no,resizable=no,menubar=no,location=no, status=no');
			} 
			else if(cortyp == 'ELC')
			{
				Modal.info({title:'电证报文',content:<div style={{height:400,overflow:'auto'}}><ELCMessage mty={row.id} message={rtnmsg.data["\\trnmod\\trndoc\\docinf"]}/></div>,
						width:1000,
						
					})
			}
			 else {
				let url = "/psbcfront" + rtnmsg.data.trndoc_docpth;
				// let url = rtnmsg.data.trndoc_docpth;
				let viewurl = "/psbcfront/pdfjs/web/viewer.html";
        viewurl += "?file=" + url;
				window.open(viewurl, 'newwindow', 'height=1200,width=800,top=100,left=100,toolbar=no,resizable=no,menubar=no,location=no, status=no');
			}
		}
		else {
			Notification.error({ message: '服务端请求失败!' })
		}
		//余下逻辑处理

		//})
	}
	doclstHeader = [
		{
			title: <Label i18nId="TRNDOC_TH004773" />,
			dataIndex: "role",
			key: "role",
			width: 60,
			render:(val, row, index)=>{
    			let text = val
    			let em = CodeTable.rol.find(item=>item.value==val)
    			if(em)
    				text= em.label
    			return text
    		}
		},
		{
			title: <Label i18nId="TRNDOC_TH004775" />,
			dataIndex: "cortyp",
			key: "cortyp",
			width: 60,
		},
		{
			title: <Label value="凭证代码" />,
			dataIndex: "id",
			key: "id",
			width: 60,
		},
		{
			title: <Label value="凭证名称" />,
			dataIndex: "docnam",
			key: "docnam",
			width: 100,
		},
		

		{
			title: '操作',
			dataIndex: "op",
			key: "op",
			width: 60,
			render: (val, row, index) => {
				return (
					<div>
						<a href="javascript:void(0)" onClick={() => this.onTrndoc_butshw(row)}>显示</a>
					</div>
				)
			}
		},
	]
	//交易内实现
	renderPage() {
		const bind = this.bind
		const { i18n } = this.props

		return (
			<div style={{ position: 'relative' }}>
				<Business wrappedComponentRef={ref => (this.com = ref)} extra={this.props.extra} steps={this.props.steps} model={this.model} />
				<Row>
					<Col>
						<Row>
							<Label i18nId={"TRNDOC_LT004772"} />
							<Table pagination={{ pageSize: 10, hideOnSinglePage: true }} rowKey="inr" columns={this.doclstHeader} dataSource={this.model.docmod_doclst} scroll={{ x: 340 }} />
						</Row>
					</Col>
				</Row>
				{/* 底部按钮 */}
        <BottomBtn _this={this} />
			</div >
		)
	}
}
