import React, { Component, Fragment } from 'react'
import {
	Page, Validator, Notification, FormItem,
	InputItem, Input, Bind, SelectItem, Button, Label, Table, Section, DatePickerItem,ConfirmButton,TextAreaItem
} from '@/components/Common-Library'
import { Divider } from 'antd'
import Api from '@/service/api'
import mLckinf 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 } from 'antd'
import { Link } from 'react-router-dom'
import Moment from 'moment'
const CodeTable = CodeTableFactory.getInstance()

@inject('UserContext')
@inject('i18n')
@observer
export default class LckinfScreen extends Page {
	@observable
  formBlur = false
  
  @observable
  extra = { inifrm: 'lckinf', usrinr: ''}
  
  //提交按钮的禁用
  @observable
  isDisabled=false;

	constructor(props) {
		super(props)
		this.model = new mLckinf()
    this.bind = Bind.bind(this)
  }
  
  //初始化代码
  async componentWillMount() {

      const rtnmsg = await Api.post(this.extra.inifrm + '/init', {})
      if (rtnmsg.retcod == SUCCESS) {
        Object.assign(this.model, rtnmsg.data)
      }
      else {
        Notification.error({ message: '服务端请求失败!' })
      }
    
    //快照模式下，不必开启校验，否则，静默校验，和记录变动
    !this.loadDisplay() && this.model.openMonitor() //开启校验	
  }

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

    lcklstHeader=[
    	{
    		title:<Label itext="用户号" />, 
    		dataIndex:"nam",
    		key:"nam",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.nam,r2.nam),
    	},
    	{
    		title:<Label itext="用户名" />, 
    		dataIndex:"dspnam",
    		key:"dspnam",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.dspnam,r2.dspnam),
    	},
    	{
    		title:<Label itext="锁表" />, 
    		dataIndex:"objtyp",
    		key:"objtyp",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.objtyp,r2.objtyp),
    	},
    	{
    		title:<Label itext="表索引" />, 
    		dataIndex:"objinr",
    		key:"objinr",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.objinr,r2.objinr),
    	},
    	{
    		title:<Label itext="交易码" />, 
    		dataIndex:"frm",
    		key:"frm",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.frm,r2.frm),
    	},
    	{
    		title:<Label itext="交易名" />, 
    		dataIndex:"frmnam",
    		key:"frmnam",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.frmnam,r2.frmnam),
    	},
    	{
    		title:<Label itext="锁住时间" />, 
    		dataIndex:"dattim",
    		key:"dattim",
    		width:100,
    		sorter: (r1,r2)=>ColSorter(r1.dattim,r2.dattim),
		},
		{
            title: '操作',
            dataIndex: "op",
            key: "op",
            width: 120,
            render: (val, row, index) => {
                return (
                    <div>
                            <a href='javascript:;' onClick={() => { this.onRegdel( row.inr) }} >删除</a>     
                    </div>
                )
            }
        },
    ]

	onRegdel= ( selinr)=>{
        this.formBlur=true  //已触发表单提交处理
        Validator.validate(this.model,this.model.descriptor,async(errors,values)=>{
                // if(errors)
                //     return 
                const rtnmsg = await Api.post('lckinf/del',{data:this.model, params:{selinr}})
                if(rtnmsg.retcod == SUCCESS)
                {
                    Notification.success({message:'删除成功!'})
                    this.onSel();
                    
                }
                else
                {
                	Notification.error({message:'服务端请求失败!'})
                }
                //余下逻辑处理
                    
        })
	}
	
onSel = () => {
  this.formBlur = true  //已触发表单提交处理
  Validator.validate(this.model, this.model.descriptor, async (errors, values) => {
      if (errors)
      return 
                const rtnmsg = await Api.post('lckinf/sel',{data:this.model})
      if (rtnmsg.retcod == SUCCESS) {
          //Notification.success({message:'数据提交成功!'})
          this.model.lcklst = rtnmsg.data['lcklst'];
          console.log(this.model)
      }
      else {
          Notification.error({ message: '查询失败!' })
      }
      //余下逻辑处理

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

		return (
			<Card title="手工解锁" size="small" className="transTitle">
        <div style={{ position: 'relative' }}>
      
            <Row>
                    <Col span={24}>

                        <Row>
                            <Col span={12}>
                                <Row className='row'>
                                    <Col span={5} offset={2}>
                                    <Label   itext="用户名"/>
                                    </Col>
                                    <Col span={14}>
									<InputItem InputProps={bind("usrnam")}  maxLength={40}  desp="用户名" path="/usrnam" />
                                    </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>
    
                </div>
                <Row >
                    <Col span={23} style={{marginLeft:40}}>
                        <Table pagination={{ pageSize: 10, hideOnSinglePage: true }} columns={this.lcklstHeader} dataSource={this.model.lcklst}  />
                    </Col>
                </Row>
 

         
	

         
      
         
				</div>
			</Card>
		)
	}
}
