import React,{Component,Fragment} from 'react'
import {Page,Validator,Notification,FormItem,DatePickerItem,TextAreaItem,CheckboxItem,Checkbox,
    InputItem,Input,Bind,SelectItem,Button,Label,Image,Table,ConfirmButton, BottomBtn} from '@/components/Common-Library'
import Api from '@/service/api'
import mBmtatt 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 Business from '@/views/Public/Business'
import Ptspta1 from '@/views/Public/Ptspta1'

const CodeTable = CodeTableFactory.getInstance()


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

    constructor(props)
    {
        super(props)
        this.model = new mBmtatt()    
        this.bind = Bind.bind(this)
        this.state = { flag: true }
    }

    @observable
		extra = { inifrm: 'bmtatt', sptinr: '', oldinr:'' };
	
	async componentWillMount() 
	{
		/*
		*添加初始化代码
		*/
    
    if(this.props.location.query){
      this.extra.sptinr = this.props.location.query.sptinr
    }
    const rtnmsg = await Api.post(this.extra.inifrm + '/init', { params: { sptinr:this.extra.sptinr } })
    if (rtnmsg.retcod == SUCCESS) {
      Object.assign(this.model, rtnmsg.data)
      //给oldinr赋值为当前inr，为修改、退回等做准备
			this.extra.oldinr = rtnmsg.data.inr;
			this.setState({ flag: false });
    }else {
			Notification.error({ message: '服务端请求失败!' })
		}
    
		//快照模式下，不必开启校验，否则，静默校验，和记录变动
		!this.loadDisplay() && this.model.openMonitor && this.model.openMonitor() //开启校验	
	}
    componentWillUnmount()
    {
        this.model.stopMonitor&&this.model.stopMonitor()//关闭校验
    }

    //交易内实现
    renderPage(){
    	const bind = this.bind
      const {i18n} = this.props
      if (this.state.flag == true) {
        return <Spin style={{ width: "100%", justifyContent: "center" }} spinning={this.state.flag} />
      }
      return (
        <Card title="到单确认" size="small" className="transTitle">
          <div style={{ position: 'relative', padding: 20 }}>
          <Business  wrappedComponentRef={ref => (this.com = ref)} page={this} steps={this.steps}  extra={this.extra}  model={this.model} />
            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="寄单索款编号" trn="bmtatt" />
                  </Col>
                  <Col span={14}>
                    <InputItem InputProps={bind("ownref")}  maxLength={16} disabled={true} />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="概要说明" trn="bmtatt" />
                  </Col>
                  <Col span={14}>
                    <InputItem InputProps={bind("nam")}  maxLength={40} disabled={true} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="单据类型" trn="bmtatt" />	
                  </Col>
                  <Col span={14}>
                    <SelectItem InputProps={bind("doctypcod")} code={CodeTable.avbby} disabled={true} />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="交单人类型" trn="bmtatt" />
                  </Col>
                  <Col span={14}>
                    <SelectItem InputProps={bind("docprbrol")} code={CodeTable.jiaodan} disabled={true} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Col span={24}>
                  <Row className='row'>
                    <Col span={5} offset={2}>
                      <Label itext="到单编号" trn="bmtatt" />	
                    </Col>
                    <Col span={14}>
                    <InputItem InputProps={bind("docref")} disabled={true} />
                    </Col>
                  </Row>
                </Col>
                <Col span={24}>
                  <Row className="row">
                    <Col span={5} offset={2}>
                      <Label itext="单据金额" trn="bmtatt" />	
                    </Col>
                    <Col span={6}>
                      <SelectItem InputProps={bind("max_cur")} code={CodeTable.curtxt} disabled={true} />
                    </Col>
                    <Col span={7} offset={1}>
                      <InputItem   InputProps={ {...bind("max_amt"), type:"amount", cur:this.model.max_cur} } disabled={true} />
                    </Col>
                  </Row>
                </Col>
                <Col span={24}>
                  <Row className="row">
                    <Col span={5} offset={2}>
                      <Label itext="交单行费用" trn="bmtatt" />
                    </Col>
                    <Col span={6}>
                      <SelectItem InputProps={bind("totcur")} code={CodeTable.curtxt} disabled={true} />
                    </Col>
                    <Col span={7} offset={1}>
                      <InputItem   InputProps={ {...bind("prbfee"), type:"amount", cur:this.model.totcur} } disabled={true} />
                    </Col>
                  </Row>
                </Col>
              </Col>
              <Col span={12}>
                <Ptspta1 model={this.model} argArr={{ desc: "交单人", prefix: 'pts1', url: 'bmtatt/prbp_ptysel', flg: 'C', datakey: '\\bmtp\\prbp\\ptslst' }} isDisabled={true} formBlur={this.formBlur} />
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Col span={24}>
                  <Row className="row">
                    <Col span={5} offset={2}>
                      <Label itext="索偿金额" trn="bmtatt" />	
                    </Col>
                    <Col span={6}>
                      <SelectItem InputProps={bind("totcur")} code={CodeTable.curtxt} disabled={true} />
                    </Col>
                    <Col span={7} offset={1}>
                      <InputItem   InputProps={ {...bind("totamt"), type:"amount", cur:this.model.totcur} } disabled={true} />
                    </Col>
                  </Row>
                </Col>
                <Col span={24}>
                  <Row className="row">
                    <Col span={5} offset={2}>
                      <Label itext="收单日期" trn="bmtatt" />
                    </Col>
                    <Col span={14}>
                      <DatePickerItem InputProps={bind("rcvdat")} disabled={true} />
                    </Col>
                  </Row>
                </Col>
                <Col span={24}>
                  <Row className="row">
                    <Col span={5} offset={2}>
                      <Label itext="寄单日期" trn="bmtatt" />
                    </Col>
                    <Col span={14}>
                      <DatePickerItem InputProps={bind("predat")} disabled={true} />
                    </Col>
                  </Row>
                </Col>
              </Col>
              <Col span={12}>
                <Ptspta1 model={this.model} argArr={{ desc: "交单行", prefix: 'pts', url: 'bmtatt/frep_ptysel', flg: 'B', datakey: '\\bmtp\\frep\\ptslst' }} isDisabled={true} formBlur={this.formBlur} />
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="装运日期" trn="bmtatt" />	
                  </Col>
                  <Col span={14}>
                    <DatePickerItem InputProps={bind("shpdat")} disabled={true} />
                  </Col>
                </Row>
              </Col>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="到单确认" trn="bmtatt" />
                  </Col>
                  <Col span={14}>
                    <SelectItem InputProps={bind("rcvsta")} code={CodeTable.rcvsta} />
                  </Col>
                </Row>
              </Col>
            </Row>

            <Row>
              <Col span={12}>
                <Row className="row">
                  <Col span={5} offset={2}>
                    <Label itext="到期日期" trn="bmtatt" />	
                  </Col>
                  <Col span={14}>
                    <DatePickerItem InputProps={bind("matdat")} disabled={true} />
                  </Col>
                </Row>
              </Col>
            </Row>

            {/* 底部按钮 */}
            <BottomBtn _this={this} />
          </div>
        </Card>
      )
	}
}
