/*
 * Creator:     ML
 * CreatDate:   2020-02-21
 * descripts：  黑名单信息 设置无效原因 弹窗
 * */
import React from 'react';
import { Form, Row, Col, Input, message, Select, Button, Modal, DatePicker, Table, Pagination,Popconfirm } from 'antd';
import { $http } from 'containers/config/https';

const BreakReasonModal = Form.create()(
  class BreakReasonModal extends React.Component {
    constructor(props) {
      super(props)
      var userData = JSON.parse(sessionStorage.getItem('userData'))
      this.state = {
        userData: userData,
        total: 0,//表格总数据
        tableData: [],//表格数据
        page: 1,//页数
        pageSize: 10,//显示数
        loading: false,//确定按钮 loading
        visible: false,//查看修改日志弹窗
        rowId: "",//控制行高亮
        checkStaus: false,//是否点击行
        StartDate: undefined,
        EndDate: undefined,
        search:"",
        size:"small"
      }
    }
    componentDidMount() {
      this.props.onReason(this);
      this.getReason()
    }
    handleOk = (e) => {
    }
    showModal = (v,record) => {
        this.props.form.setFieldsValue({ blackReasonDr: record.blackReasonID })
      this.setState({
        v,
        record,
        recordName:record.name,
        visible: true,
      },()=>{

      });
    }
    handleCancel =()=>{
        this.setState({
            visible: false,
            record:{}
        })
    }
    handleOk=()=>{
        this.props.form.validateFields((err, values) => {
            if (!err) {
              let data = {
                params: [{
                  ID: this.state.record && this.state.record.ID ? this.state.record.ID : "",
                  activeFlag: this.state.v ? "Y" : "N",//是否立即生效,
                  blackReasonDr:this.props.form.getFieldValue('blackReasonDr'),
                  createUserID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).userID : "",
                  updateUserID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).userID : "",
                }]
              }
              $http.post('urlS', this, {
                code: '03050186',
                data: data,
                success: function (res) {
                  if (+res.errorCode === 0) {
                      message.success(this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacUpdateCompleted ? this.setMessage('BlacklistInformationInterfacUpdateCompleted', 'descripts') : '更新成功')
                      this.setState({
                        visible: false,
                    })
                    this.props.handleQuery()
                  }
                }
              })
            }
          })
        
    }
      //获取原因下拉框
      getReason = () => {
        let data = {
          params: [{
            // BlackList 加入黑名单  CacelBlackList取消黑名单
            type:"CacelBlackList",
            language: this.state.userData.language,
          }],
        }
        $http.post('urlS', this, {
          code: '03050188',
          data: data,
          success: function (res) {
            if (+res.errorCode === 0) {
              this.setState({
                reasonArr: res.result.Data
              })
            }
          }
        })
      }
    //国际化
  setMessage(name, message) {
    return this.props.localeProvider ? this.props.localeProvider[name][message] : ''
  }
    render() {
      const { getFieldDecorator } = this.props.form;
      const { total, columns,recordName} = this.state
      const formLayoutRe = {
        labelCol: { span: 5 },
        wrapperCol: { span: 19 },
      }
       //原因
    let reasonOp = []
    this.state.reasonArr && this.state.reasonArr.map((item) => {
      reasonOp.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
    })
      return (
        <div
          tabIndex={1}
          onKeyDown={this.handleOnKeydown}
          style={{ outline: 'none' }}
        >
          <Modal
            className='breakTimes'
            width='500px'
            height="212px"
            visible={this.state.visible}
            title={this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacReasonForJoining ? this.setMessage('BlacklistInformationInterfacReasonForJoining', 'descripts') : "移除黑名单"}
            // onOk={this.handleOk}
            onCancel={this.handleCancel}
            footer={
                <div>
                <Button onClick={this.handleCancel}>{this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacCancel ? this.setMessage('BlacklistInformationInterfacCancel', 'descripts') : '取消'}</Button>
                <Popconfirm 
                title={this.state.userData.language == 'EN'?"Whether to	"+(recordName&&recordName?recordName:"--")+'Remove the blacklist. Once removed, the status cannot be changed again':'是否要将'+(recordName&&recordName?recordName:"--")+'移除黑名单，一旦移除，不能再次更改状态'}
                onConfirm={() => this.handleOk()}>
                <Button type="primary" >{this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacOk ? this.setMessage('BlacklistInformationInterfacOk', 'descripts') : '确定'}</Button>
              </Popconfirm>
                </div>
            }
          >
            <div style={{ minHeight: '30px' }}>
            <Form layout={'horizontal'}>
                <Row>
                <Col span={12}>
              <Form.Item label={this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacReason ? this.setMessage('BlacklistInformationInterfacReason', 'descripts') : '原因'} {...formLayoutRe}>
                {getFieldDecorator('blackReasonDr', {
                  initialValue:  undefined,
                  rules: [{ required: true, message: this.props.localeProvider && this.props.localeProvider.BlacklistInformationInterfacReason ? this.setMessage('BlacklistInformationInterfacReason', 'message') : '请选择原因' }],
                })(
                  <Select>
                    {reasonOp}
                  </Select>
                )}
              </Form.Item>
            </Col>
                </Row>
            </Form>
            </div>
          </Modal>
        </div>
      )
    }
  })
export default BreakReasonModal    