import React, { Component, Fragment } from 'react'
import {
    Page, Validator, Notification, FormItem,
    InputItem, Input, Bind, SelectItem, Button, Label, Table, Section, DatePickerItem
} from '@/components/Common-Library'
import { Divider } from 'antd'
import Api from '@/service/api'
import mDblact from '../model'
import CodeTableFactory from '@/components/CodeTable'
import "./index.less"
import { inject, observer } from 'mobx-react'
import { action, observable } from 'mobx'
import { Col, Row } from 'antd'
import { Link } from 'react-router-dom'
import Moment from 'moment'
import {Card} from 'antd'
const CodeTable = CodeTableFactory.getInstance()

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

    constructor(props) {
        super(props)
        this.model = new mDblact()
        this.model.openValidate() //开启校验
        this.bind = Bind.bind(this)
    }

    componentWillUnmount() {
        this.model.closeValidate()//关闭校验
    }

	componentWillMount() {
		 if (this.props.location.state) {
             let selflg = this.props.location.state.selflg
		     if (selflg)
				this.onSel()
		 }	
	}
    actlstHeader = [
        {
            title: <Label i18nId="ACTP_TH000011" />,
            dataIndex: "nam",
            key: "nam",
            width: 100,
        },
        {
            title: <Label i18nId="ACTP_TH000009" />,
            dataIndex: "ptyextkey",
            key: "ptyextkey",
            width: 80,
        },
        {
            title: <Label i18nId="ACTP_TH000008" />,
            dataIndex: "cur",
            key: "cur",
            width: 50,
            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 i18nId="ACTP_TH000007" />,
            dataIndex: "extkey",
            key: "extkey",
            width: 100,
        },
        {
            title: <Label i18nId="ACTP_TH000012" />,
            dataIndex: "dsp",
            key: "dsp",
            width: 100,
        },
        {
            title: <Label i18nId="ACTP_TH000013" />,
            dataIndex: "trmcod",
            key: "trmcod",
            width: 100,
        },
        {
            title: <Label i18nId="ACTP_TH000014" />,
            dataIndex: "cshflg",
            key: "cshflg",
            width: 100,
            render: (val, row, index) => {
                let text = val
                let em = CodeTable.cshflg.find(item => item.value == val)
                if (em)
                    text = em.label
                return text
            }
        },
        {
            title: <Label i18nId="ACTP_TH000015" />,
            dataIndex: "acctyp",
            key: "acctyp",
            width: 100,
            render: (val, row, index) => {
                let text = val
                let em = CodeTable.acctyp.find(item => item.value == val)
                if (em)
                    text = em.label
                return text
            }
        },
        {
            title: <Label i18nId="ACTP_TH000010" />,
            dataIndex: "sta",
            key: "sta",
            width: 100,
            render: (val, row, index) => {
                let text = val
                let em = CodeTable.actsta.find(item => item.value == val)
                if (em)
                    text = em.label
                return text
            }
        },
        {
            title: '操作',
            dataIndex: "op",
            key: "op",
            width: 120,
            render: (val, row, index) => {
                return (
                    <div>
                        <Link to={{ pathname: 'dbeact', query: { inr: row.inr } }}>修改</Link>
                        <Divider type="vertical" />
                        <Link to={{ pathname: 'dbiact', query: { inr: row.inr } }}>明细</Link>
                        <Divider type="vertical" />
                        <Link to={{ pathname: 'dbdact', query: { inr: row.inr } }}>删除</Link>
                    </div>
                )
            }
        },
    ]


    //按钮事件
    onAdd = () => {
        this.props.history.push('dbaact')
    }
    onSel = () => {
        this.formBlur = true  //已触发表单提交处理
        Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
            if (errors)
                return
            const rtnmsg = await Api.post('dblact/sel', { data: this.model })
            if (rtnmsg.retcod == SUCCESS) {
                //Notification.success({ message: '数据提交成功!' })
                this.model.actgrp_actlst = rtnmsg.data.actgrp_actlst;
            }
            else {
                Notification.error({ message: '服务端请求失败!' })
            }
            //余下逻辑处理
            console.log(this.model)
        })
    }
    //交易内实现
    renderPage() {
        const bind = this.bind
        const { i18n } = this.props


        return (
		<Card title="账户管理" size="small" className="transTitle">
            <div style={{ position: 'relative' }}>

                <Row>
                    <Col span={20}>

                        <Row>
                            <Col span={12}>
                                <Row className='row'>
                                    <Col span={5} offset={2}>
                                        <Label i18nId={"ACTP_LT000002"} />
                                    </Col>
                                    <Col span={14}>
                                        <InputItem InputProps={bind("ownpty_extkey")} />
                                    </Col>
                                </Row>
                            </Col>
                            <Col span={12}>
                                <Row className='row'>
                                    <Col span={5} offset={2}>
                                        <Label i18nId={"ACTP_LT000004"} />
                                    </Col>
                                    <Col span={14}>
                                        <InputItem InputProps={bind("extkey")} />
                                    </Col>
                                </Row>
                            </Col>
                        </Row>

                        <Row>
                            <Col span={12}>
                                <Row className='row'>
                                    <Col span={5} offset={2}>
                                        <Label i18nId={"ACTP_LT000005"} />
                                    </Col>
                                    <Col span={14}>
                                        <InputItem InputProps={bind("bchkey")} />
                                    </Col>
                                </Row>
                            </Col>
                            <Col span={12}>
                                <Row className='row'>
                                    <Col span={5} offset={2}>
                                        <Label i18nId={"ACTP_LT000006"} />
                                    </Col>
                                    <Col span={14}>
                                        <SelectItem InputProps={bind("cur")} code={CodeTable.curtxt} />
                                    </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>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				 <div className='button2'>
                        <Button type="primary" onClick={this.onAdd}>
                            <Label i18nId="MTABUT_BT000182" />
                        </Button>
                    </div>
                </div>
                <Row >
                    <Col span={23} style={{ marginLeft: 40 }}>
                <Table pagination={{ pageSize: 10, hideOnSinglePage: true }} key='inr' columns={this.actlstHeader} dataSource={this.model.actgrp_actlst} />
                    </Col>
                </Row>
            </div>
			</Card>
        )
    }
}
