import React, { Component, Fragment } from 'react'
import {
	Page, Validator, Notification, FormItem, DatePickerItem,
	InputItem, Input, Bind, SelectItem, Button, Label, Image, Table
} from '@/components/Common-Library'
import Api from '@/service/api'
import mAutsel from '../model'
import CodeTableFactory from '@/components/CodeTable'
import "./index.less"
import { inject, observer } from 'mobx-react'
import { action, observable } from 'mobx'
import { Col, Row, Card, Divider } from 'antd'


const CodeTable = CodeTableFactory.getInstance()


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

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

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

	trnlstHeader = [
		{
			title: <Label value="交易码" />,
			dsp: `交易码`,
			dataIndex: "inifrm",
			key: "inifrm",
			width: 80,
		},
		{
			title: <Label value="经办柜员" />,
			dsp: `经办柜员`,
			dataIndex: "iniusr",
			key: "iniusr",
			width: 80,
		},
		{
			title: <Label value="经办日期" />,
			dsp: `经办日期`,
			dataIndex: "inidattim",
			key: "inidattim",
			width: 120,
		},
		{
			title: <Label value="业务编号" />,
			dsp: `业务编号`,
			dataIndex: "ownref",
			key: "ownref",
			width: 80,
		},
		{
			title: <Label value="交易描述" />,
			dsp: `交易描述`,
			dataIndex: "objnam",
			key: "objnam",
			width: 150,
		},
		{
			title: <Label value="币种" />,
			dsp: `币种`,
			dataIndex: "reloricur",
			key: "relcur",
			width: 70,
		},
		{
			title: <Label value="金额" />,
			dsp: `金额`,
			dataIndex: "reloriamt",
			key: "relamt",
			width: 80,
		},
		{
			title: <Label value="状态" />,
			dsp: `状态`,
			dataIndex: "relflg",
			key: "relflg",
			width: 80,
			render: (val, row, index) => {
				let text = val
				let em = CodeTable.relflg.find(item => item.value == val)
				if (em)
					text = em.label
				return text
			}
		},
	]
	sptlstHeader = [
		{
			title: <Label value="交易码" />,
			dsp: `交易码`,
			dataIndex: "frm",
			key: "frm",
			width: 80,
		},
		{
			title: <Label value="交易描述" />,
			dsp: `交易描述`,
			dataIndex: "objnam",
			key: "objnam",
			width: 150,
		},
		{
			title: <Label value="创建柜员" />,
			dsp: `创建柜员`,
			dataIndex: "creusr",
			key: "creusr",
			width: 80,
		},
		{
			title: <Label value="创建日期" />,
			dsp: `创建日期`,
			dataIndex: "credattim",
			key: "credattim",
			width: 120,
		},
		{
			title: <Label value="币种" />,
			dsp: `币种`,
			dataIndex: "relcur",
			key: "relcur",
			width: 80,
			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 value="金额" />,
			dsp: `金额`,
			dataIndex: "relamt",
			key: "relamt",
			width: 100,
		},
		{
			title: <Label value="机构" />,
			dsp: `机构`,
			dataIndex: "ownbchkey",
			key: "ownbchkey",
			width: 100,
		},
		{
			title: <Label value="客户号" />,
			dsp: `客户号`,
			dataIndex: "cusref",
			key: "cusref",
			width: 100,
		},
	]


	//按钮事件
	onSelbut = () => {
		this.formBlur = true  //已触发表单提交处理
		Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
			if (errors)
				return
			const rtnmsg = await Api.post('autsel/selbut', { data: this.model })
			if (rtnmsg.retcod == SUCCESS) {
				this.model.sptlst = rtnmsg.data.sptlst;
				if (!this.model.sptlst[0])
					Notification.success({ message: '查询结果为空!' })
			}
			else {
				Notification.error({ message: '服务端请求失败!' })
			}
			//余下逻辑处理

		})
	}
	onSeltrn = () => {
		this.formBlur = true  //已触发表单提交处理
		Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
			if (errors)
				return
			const rtnmsg = await Api.post('autsel/seltrn', { data: this.model })
			if (rtnmsg.retcod == SUCCESS) {
				this.model.trnlst = rtnmsg.data.trnlst;
				if (!this.model.trnlst[0])
					Notification.success({ message: '查询结果为空!' })
			}
			else {
				Notification.error({ message: '服务端请求失败!' })
			}
			//余下逻辑处理

		})
	}
	onSptmid = () => {
		this.formBlur = true  //已触发表单提交处理
		Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
			if (errors)
				return
			const rtnmsg = await Api.post('autsel/sptmid', { data: this.model })
			if (rtnmsg.retcod == SUCCESS) {
				this.model.sptlst = rtnmsg.data.sptlst;
				if (!this.model.sptlst[0])
					Notification.success({ message: '查询结果为空!' })

			}
			else {
				Notification.error({ message: '服务端请求失败!' })
			}
			//余下逻辑处理

		})
	}
	onSptaut = () => {
		this.formBlur = true  //已触发表单提交处理
		Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
			if (errors)
				return
			const rtnmsg = await Api.post('autsel/sptaut', { data: this.model })
			if (rtnmsg.retcod == SUCCESS) {
				Notification.success({ message: '批量经办完成!' })
				this.model.sptlst = rtnmsg.data.sptlst;

			}
			else {
				Notification.error({ message: '服务端请求失败!' })
			}
			//余下逻辑处理

		})
	}
	onTrnaut = () => {
		this.formBlur = true  //已触发表单提交处理
		Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
			if (errors)
				return
			const rtnmsg = await Api.post('autsel/trnaut', { data: this.model })
			if (rtnmsg.retcod == SUCCESS) {
				Notification.success({ message: '批量复核完成!' })

			}
			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 style={{marginBottom:10}} gutter={16}>
						<Col span={3}>
							<Label value="自动经办客户清单" desp="自动经办客户清单" />
						</Col>
						<div style={{textAlign:"right"}}>
							<Button style={{marginRight:20}} type="primary" onClick={this.onSptmid} desp="自动经办服务" path="/sptaut">
								<Label value="查询" desp="查询" />
							</Button>
						</div>
						{/* <Col span={1} offset={20}>
							<Button type="primary" onClick={this.onSptmid} desp="自动经办服务" path="/sptaut">
								<Label value="查询" desp="查询" />
							</Button>
						</Col> */}
					</Row>
					<Row style={{marginBottom:10}} >
						<Col span={24} >
							<Table pagination={{ pageSize: 10, hideOnSinglePage: true }} rowKey="inr" columns={this.sptlstHeader} dataSource={this.model.sptlst} path="/sptlst" />
						</Col>
					</Row>
					<div className='button0'>
						<div className='button2'>
							<Button type="primary" onClick={this.onSptaut} desp="自动经办服务" path="/sptaut">
								<Label value="批量经办" desp="批量经办" />
							</Button>
						</div>
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					   <div className='button2'>
							<Button type="primary" icon="search" onClick={this.onSelbut} desp="自动经办筛选" path="/selbut">
								<Label value="自动经办筛选" desp="自动经办筛选" />
							</Button>
						</div>
					</div>


					<Row >
						<Col type="flex" justify="left">
							<Label value="自动复核柜员清单" desp="自动复核柜员清单" />
						</Col>
					</Row>

					<Row >
						<Col span={24} >
							<Table pagination={{ pageSize: 10, hideOnSinglePage: true }} rowKey="inr" columns={this.trnlstHeader} dataSource={this.model.trnlst} path="/trnlst" />
						</Col>
					</Row>
					<div className='button0'>
						<div className='button2'>
							<Button type="primary" onClick={this.onTrnaut} desp="自动复核服务" path="/trnaut">
								<Label value="批量复核" desp="批量复核" />
							</Button>
						</div>
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					   <div className='button2'>
							<Button type="primary" icon="search" onClick={this.onSeltrn} desp="自动复核筛选" path="/seltrn">
								<Label value="自动复核筛选" desp="自动复核筛选" />
							</Button>
						</div>
					</div>
				</div>
			</Card>
		)
	}
}
