import React, { Component, Fragment } from 'react'
import {
    Page, Validator, Notification, FormItem,
    InputItem, Input, Bind, SelectItem, Button, Label, DatePickerItem, Section, ConfirmButton, Steps, CheckboxItem, TextAreaItem, Table
} 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, Tooltip, Modal, Spin } from 'antd';
import { PtyPicker } from '@/components/Business-Library'
import { Link, withRouter } from 'react-router-dom'
import Ptspta1 from '@/views/Public/Ptspta1'
import Business from '@/views/Public/Business'

import moment from 'moment'
import mFptsel from '../model'
const { Pre, Next, StepWrapper } = Steps
const CodeTable = CodeTableFactory.getInstance()
const confirm = Modal.confirm

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

    constructor(props) {
        super(props)
        this.model = new mFptsel()
        this.bind = Bind.bind(this)
 
    }

    async componentWillMount() {
		/*
		*添加初始化代码
		*/
		// const rtnmsg = await Api.post('fptsel/init', { data: this.model })
		// if (rtnmsg.retcod == SUCCESS) {
		// 	const { data } = rtnmsg
		// 	runInAction(() => {
		// 		Object.assign(this.model, data)
		// 	})
		// }
		//快照模式下，不必开启校验，否则，静默校验，和记录变动
		!this.loadDisplay() && this.model.openMonitor && this.model.openMonitor() //开启校验	
	}
	componentWillUnmount() {
		this.model.stopMonitor && this.model.stopMonitor()//关闭校验
	}

    fptp_fpdlstHeader=[
    	{
    		title:<Label itext="福费廷编号" />, 
    		dataIndex:"ownref",
    		key:"ownref",
    		width:70,
    		sorter: (r1,r2)=>ColSorter(r1.ownref,r2.ownref),
    	},
    	{
    		title:<Label itext="描述" />, 
    		dataIndex:"nam",
    		key:"nam",
    		width:190,
    		sorter: (r1,r2)=>ColSorter(r1.nam,r2.nam),
    	},
    	{
    		title:<Label itext="起息日" />, 
    		dataIndex:"opndat",
    		key:"opndat",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.opndat,r2.opndat),
    	},
    	{
    		title:<Label itext="到期日" />, 
    		dataIndex:"expdat",
    		key:"expdat",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.expdat,r2.expdat),
    	},
    	{
    		title:<Label itext="单据金额" />, 
    		dataIndex:"docamt",
    		key:"docamt",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.docamt,r2.docamt),
    	},
    	{
    		title:<Label itext="信用证开立日期" />, 
    		dataIndex:"opndatlc",
    		key:"opndatlc",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.opndatlc,r2.opndatlc),
    	},
    	{
    		title:<Label itext="信用证失效日期" />, 
    		dataIndex:"expdatlc",
    		key:"expdatlc",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.expdatlc,r2.expdatlc),
    	},
    	{
    		title:<Label itext="宽限期" />, 
    		dataIndex:"grcdys",
    		key:"grcdys",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.grcdys,r2.grcdys),
        },
        {
			title: <Label itext="操作" />,
			width: 60,
			key: "operation",
			render: (val, row, index) => {
				return (

					<Link to={{ pathname: 'fptset', query: { inr: row.inr} }}>到期收款</Link>)
			}
		},
    ]

    onFptp_fpdsel= ()=>{
        this.formBlur=true  //已触发表单提交处理
        Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
                if(errors)
                    return 
                const rtnmsg = await Api.post('fptsel/fptp_fpdsel',{data:this.model})
                if(rtnmsg.retcod == SUCCESS)
                {
                    this.model.fptp_fpdlst = rtnmsg.data.fptp_fpdlst;
                    
                }
                else
                {
                	Notification.error({ message: '查询失败!!' })
                }
                //余下逻辑处理
                    
        })
    }
    
    //交易内实现
    renderPage() {
        const bind = this.bind
        const { i18n } = this.props
        const { bchlevelLst } = this.props.extra
        const dateFormat = 'YYYY-MM-DD';
        //const {next,pre} = this.props.steps

        return (
            <div style={{ position: 'relative' }}>
                <Business wrappedComponentRef={ref => (this.com = ref)} extra={this.props.extra} model={this.model} />
                {/* 第一行 */}
                <Row>
						<Col span={12}>
							<Row className="row">
								<Col span={5} >
									{/* 福费廷编号 */}
									<Label itext="福费廷编号" trn="fptsel" />
								</Col>
								<Col span={10}>
                                <InputItem InputProps={bind("fptp_ownref")}  maxLength={16}  desp="福费廷编号" path="/fptp/ownref" />
								</Col>
								<Col span={4} offset={1}>
									<Button type="primary" icon="search" onClick={this.onFptp_fpdsel} desp="查询" path="/sel">
										<Label itext="查询" />
									</Button>
								</Col>
							</Row>
						</Col>


					</Row>


					<Table rowKey="inr" columns={this.fptp_fpdlstHeader}  dataSource={this.model.fptp_fpdlst}   path="/fptp/fpdlst"/>



            </div >
        )
    }
}
