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


const CodeTable = CodeTableFactory.getInstance()


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

    constructor(props)
    {
        super(props)
        this.model = new mTctchk()    
        this.bind = Bind.bind(this)
    }
	
	async componentWillMount() 
	{
		/*
		*添加初始化代码
		*/
		const rtnmsg = await Api.post('trnrel/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()//关闭校验
    }

    tcwgrp_tcwlstHeader=[
    	{
    		title:<Label itext="SWIF行号" />, 
    		dataIndex:"bic",
    		key:"bic",
    		width:100,
    		sorter: (r1,r2)=>r1.bic-r2.bic,
    	},
    	{
    		title:<Label itext="账户行账号" />, 
    		dataIndex:"act",
    		key:"act",
    		width:100,
    		sorter: (r1,r2)=>r1.act-r2.act,
    	},
    	{
    		title:<Label itext="币种" />, 
    		dataIndex:"cur",
    		key:"cur",
    		width:100,
    		sorter: (r1,r2)=>r1.cur-r2.cur,
    		render:(val, row, index)=>{
    			let text = val
    			let em = CodeTable.curtxt.find(item=>item.value==val)
    			if(em)
    				text= em.label
    			return text
    		}
    	},
    	{
    		title:<Label itext="当日汇入金额" />, 
    		dataIndex:"inamt",
    		key:"inamt",
    		width:100,
    		sorter: (r1,r2)=>r1.inamt-r2.inamt,
    	},
    	{
    		title:<Label itext="当日汇出金额" />, 
    		dataIndex:"outamt",
    		key:"outamt",
    		width:100,
    		sorter: (r1,r2)=>r1.outamt-r2.outamt,
    	},
    	{
    		title:<Label itext="账户余额" />, 
    		dataIndex:"cbbamt",
    		key:"cbbamt",
    		width:100,
    		sorter: (r1,r2)=>r1.cbbamt-r2.cbbamt,
    	},
    ]


    //按钮事件
    onSel= ()=>{
        this.formBlur=true  //已触发表单提交处理
        Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
                if(errors)
                    return 
                const rtnmsg = await Api.post('tctchk/sel',{data:this.model})
                if(rtnmsg.retcod == SUCCESS)
                {
                    this.model.tcwgrp_tcwlst = rtnmsg.data.tcwgrp_tcwlst;
					console.log(this.model)
                    
                }
                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={21}>
	<Button  type="primary" icon="search" onClick={this.onSel} desp="查询" path="/sel">
		<Label   itext="查询"/>
	</Button></Col></Row>
	<Table rowKey="inr" columns={this.tcwgrp_tcwlstHeader}  dataSource={this.model.tcwgrp_tcwlst}   path="/tcwgrp/tcwlst"/>
		</div>
		</Card>
		)
	}
}
