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

import { TableExpansion } from '@/components/Business-Library'

const CodeTable = CodeTableFactory.getInstance()

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

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

	componentWillUnmount() {
		// this.model.closeValite()//关闭校验
	}
	// async componentWillMount() {
	// 	if (this.props.location.state) {
	// 		let selflg = this.props.location.state.selflg
	// 		if (selflg)
	// 			this.onSel()
	// 	} else {
	// 		const rtnmsg = await Api.post('dbitsk/init', {})
	// 		if (rtnmsg.retcod == SUCCESS) {
	// 			Object.assign(this.model, rtnmsg.data)
	// 			this.bchlevelLst = rtnmsg.codetable['bclp_bchkey'];
	// 		}
	// 		else {
	// 			Notification.error({ message: '服务端请求失败!' })
	// 		}
	// 	}
	// }
	//按钮事件
	onDelbut = () => {
		this.formBlur = true  //已触发表单提交处理
		Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
			if (errors)
				return
			const rtnmsg = await Api.post('dbitsk/delbut', { data: this.model })
			if (rtnmsg.retcod == SUCCESS) {
				Notification.success({ message: '数据提交成功!' })

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

		})
	}
	onAddbut = () => {
		this.formBlur = true  //已触发表单提交处理
		Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
			if (errors)
				return
			const rtnmsg = await Api.post('dbitsk/addbut', { data: this.model })
			if (rtnmsg.retcod == SUCCESS) {
				Notification.success({ message: '数据提交成功!' })

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

		})
	}

	ctklstHeader = [
		{
			title: <Label itext="中心" />,
			dataIndex: "bchcod",
			key: "bchcod",
			width: 80,
			sorter: (r1, r2) => ColSorter(r1.bchcod, r2.bchcod),
		},
		{
			title: <Label itext="组别" />,
			dataIndex: "usg",
			key: "usg",
			width: 60,
			sorter: (r1, r2) => ColSorter(r1.usg, r2.usg),
		},
		{
			title: <Label itext="阈值" />,
			dataIndex: "thrhld",
			key: "thrhld",
			width: 60,
			sorter: (r1, r2) => ColSorter(r1.thrhld, r2.thrhld),
		},
		{
			title: <Label itext="中心分配功能总开关状态" />,
			dataIndex: "staflg",
			key: "staflg",
			width: 190,
			sorter: (r1, r2) => ColSorter(r1.staflg, r2.staflg),
		},
		{
			title: <Label itext="自动任务分配状态" />,
			dataIndex: "sta",
			key: "sta",
			width: 150,
			sorter: (r1, r2) => ColSorter(r1.sta, r2.sta),
		},
		{
			title: <Label itext="启用获取分配工作模式状态" />,
			dataIndex: "usrtak",
			key: "usrtak",
			width: 200,
			sorter: (r1, r2) => ColSorter(r1.usrtak, r2.usrtak),
		},
	]


	//按钮事件
	onDelbut = () => {
		this.formBlur = true  //已触发表单提交处理
		Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
			if (errors)
				return
			const rtnmsg = await Api.post('dbitsk/delbut', { data: this.model })
			if (rtnmsg.retcod == SUCCESS) {
				Notification.success({ message: '数据提交成功!' })

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

		})
	}
	onClsbut = () => {
		this.formBlur = true  //已触发表单提交处理
		Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
			if (errors)
				return
			const rtnmsg = await Api.post('dbitsk/clsbut', { data: this.model })
			if (rtnmsg.retcod == SUCCESS) {
				Notification.success({ message: '数据提交成功!' })

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

		})
	}
	onInf = () => {
		this.formBlur = true  //已触发表单提交处理
		Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
			if (errors)
				return
			const rtnmsg = await Api.post('dbitsk/inf', { data: this.model })
			if (rtnmsg.retcod == SUCCESS) {
				// Notification.success({ message: '数据提交成功!' })
				this.model.ctklst=rtnmsg.data.ctklst;
			}
			else {
				Notification.error({ message: '服务端请求失败!' })
			}
			//余下逻辑处理

		})
	}
	onClssta = () => {
		this.formBlur = true  //已触发表单提交处理
		Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
			if (errors)
				return
			const rtnmsg = await Api.post('dbitsk/clssta', { data: this.model })
			if (rtnmsg.retcod == SUCCESS) {
				Notification.success({ message: '数据提交成功!' })

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

		})
	}
	onSavlin = () => {
		this.formBlur = true  //已触发表单提交处理
		Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
			if (errors)
				return
			const rtnmsg = await Api.post('dbitsk/savlin', { data: this.model })
			if (rtnmsg.retcod == SUCCESS) {
				Notification.success({ message: '数据提交成功!' })

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

		})
	}
	onOpnbut = () => {
		this.formBlur = true  //已触发表单提交处理
		Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
			if (errors)
				return
			const rtnmsg = await Api.post('dbitsk/opnbut', { data: this.model })
			if (rtnmsg.retcod == SUCCESS) {
				Notification.success({ message: '数据提交成功!' })

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

		})
	}
	onOpnsta = () => {
		this.formBlur = true  //已触发表单提交处理
		Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
			if (errors)
				return
			const rtnmsg = await Api.post('dbitsk/opnsta', { data: this.model })
			if (rtnmsg.retcod == SUCCESS) {
				Notification.success({ message: '数据提交成功!' })

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

		})
	}
	onAddbut = () => {
		this.formBlur = true  //已触发表单提交处理
		Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
			if (errors)
				return
			const rtnmsg = await Api.post('dbitsk/addbut', { data: this.model })
			if (rtnmsg.retcod == SUCCESS) {
				Notification.success({ message: '数据提交成功!' })

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

		})
	}
	onAddnew = () => {
		this.formBlur = true  //已触发表单提交处理
		Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
			if (errors)
				return
			const rtnmsg = await Api.post('dbitsk/addnew', { data: this.model })
			if (rtnmsg.retcod == SUCCESS) {
				Notification.success({ message: '数据提交成功!' })

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

		})
	}
	onCls = () => {
		this.formBlur = true  //已触发表单提交处理
		Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
			if (errors)
				return
			const rtnmsg = await Api.post('dbitsk/cls', { data: this.model })
			if (rtnmsg.retcod == SUCCESS) {
				Notification.success({ message: '数据提交成功!' })

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

		})
	}
	onOpn = () => {
		this.formBlur = true  //已触发表单提交处理
		Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
			if (errors)
				return
			const rtnmsg = await Api.post('dbitsk/opn', { data: this.model })
			if (rtnmsg.retcod == SUCCESS) {
				Notification.success({ message: '数据提交成功!' })

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

		})
	}


	//交易内实现
	renderPage() {
		const bind = this.bind
		const { i18n } = this.props
		// const CodeTable = CodeTableFactory.getInstance()

		return (
			<div style={{ position: 'relative' }}>

				<div style={{ textAlign: "right" }}>
					<Button style={{ marginLeft: 10, marginRight: 10 }} type="primary" onClick={this.onAddnew} desp="新增中心" path="/addnew">
						<Label itext="新增中心" />
					</Button>
					<Button type="primary" onClick={this.onInf} desp="查询" path="/inf">
						<Label itext="查询" />
					</Button>
				</div>
				<Table rowKey="inr" columns={this.ctklstHeader} dataSource={this.model.ctklst} path="/ctklst" />

				<Row style={{ marginTop: 30 }} type="flex" justify="space-around">
					<Col span={6} >
						<Button style={{ marginLeft: 10, marginRight: 10 }} type="primary" onClick={this.onOpnbut} desp="开启" path="/opnbut">
							<Label itext="开启" />
						</Button>
						<Button style={{ marginLeft: 10, marginRight: 10 }} type="primary" onClick={this.onClsbut} desp="关闭" path="/clsbut">
							<Label itext="关闭" />
						</Button>
						<br />
						<Label itext="控制一:中心分配总开关状态" />
						<br />
						<Label itext="注释1：开启状态才会生成待分配队列状态" />
					</Col >
					<Col span={6} >
						<Button style={{ marginLeft: 10, marginRight: 10 }} type="primary" onClick={this.onOpnsta} desp="运行" path="/opnsta">
							<Label itext="运行" />
						</Button>
						<Button style={{ marginLeft: 10, marginRight: 10 }} type="primary" onClick={this.onClssta} desp="停止" path="/clssta">
							<Label itext="停止" />
						</Button>
						<br />
						<Label itext="控制二:自动任务分配状态" />
						<br />
						<Label itext="注释2：运行状态下后台自动运行任务分配QUETSK" />
					</Col>
					<Col span={6} >
						<Button style={{ marginLeft: 10, marginRight: 10 }} type="primary" onClick={this.onOpn} desp="启用" path="/opn">
							<Label itext="启用" />
						</Button>
						<Button style={{ marginLeft: 10, marginRight: 10 }} type="primary" onClick={this.onCls} desp="不启用" path="/cls">
							<Label itext="不启用" />
						</Button>
						<br />
						<Label itext="控制三:中心启用获取分配工作模式状态" />
						<br />
						<Label itext="注释3：启用状态下，会校验WRKUSR和当前用户是否匹配" />

					</Col>
				</Row>
			</div>
		)
	}
}































