/*
 * Creator:     ML
 * CreatDate:   2020-06-24
 * descripts：  排班设置---
*/
import React from 'react';
import { Tabs, Row, Col, Icon, Divider, Modal, Drawer } from 'antd';
import store from '../../store';
import { $http } from '../../containers/config/https';
import ShiftSetting from './common/ShiftSetting';//排班设置

const TabPane = Tabs.TabPane;
class ShiftSettings extends React.Component {
  constructor(porps) {
    super(porps);
    this.state = {
      activeKey: '1',
      userInfo: {}, //用户数据
      visible: false,//是否弹
      localeProvider: []
    }
  }
  componentDidMount() {
    if (document.querySelector('.ant-drawer')) {
      document.querySelector('.ant-drawer').style.zIndex = "9999"
    }
  }
  onShiftSetting = (ref) => {
    this.onChildonShiftSetting = ref
  }

  handleHomeData = (name) => {
    let obj = {
      "1": () => {
        this.onChildView.getInfo()
        this.onChildView.loginMetods()
      },
      "2": () => {
        this.onChildModifyUserName.getUserName()
      },
      "3": () => {
        // this.onChildChangePassword.getUserName()
      },
      "4": () => {
        this.onChildSettingDefaultLoginSection.getLoc()
      }, "5": () => {
        this.onChildPerfectingContactWay.getType()
        this.onChildPerfectingContactWay.getTypeTable()
      }, "6": () => {
        this.onChildSittingApply.getBaseParams()
        this.onChildSittingApply.getIconUrl()
      }, "7": () => {
        this.handleIsApply()
        // this.onChildonShiftSetting.loginTencent()
      }, "8": () => {
        this.onChildConsultationTemplate.getData()
        // this.onChildConsultationTemplate.onInitData()
        // this.onChildConsultationTemplate.handleShiftType()
      },
    }
    if (obj[name]) {
      obj[name]()
    }
  }
  handleIsApply = () => {
    let userData = JSON.parse(sessionStorage.getItem('userData'));
    let data = {
      params: [{
        userID: userData && userData.userID || "",
        locID: userData && userData.locID || ""
      }]
    }
    $http.post('urlS', this, {
      code: '03100009',
      data: data,
      success: function (res) {
        if (+res.errorCode === 0) {
          this.onChildonShiftSetting.handleIsApplyTips(res.result, res.statusCode, res.statusDesc)
        }
      }
    })

  }
  // 导航栏切换
  callback = (key) => {
    this.setState({ activeKey: key }, () => {
        this.handleHomeData(key)
      if (key != "7" && this.onChildonShiftSetting) {
        this.onChildonShiftSetting.signOut("User")
      }
    })

  }
  // 获取主列表columns
  getMainTableColumns = () => {
    let userData = JSON.parse(sessionStorage.getItem('userData'));
    let data = {
      params: [{
        compontName: "PersonalInformation", // 医嘱查询coll表头
        reactCode: ['PersonalInformation'],
        type: 'C',
      }]
    }
    $http.post('urlS', this, {
      code: '01040073',
      data: data,
      success: function (res) {
        if (+res.errorCode === 0) {
          //   let arr = res.result && res.result.C.length > 0 ? JSON.parse(JSON.stringify(res.result.C)).map(item => {
          //     return {
          //       align: item.align,
          //       widthNum: parseInt(item.width),
          //       width: item.width,
          //       dataIndex: item.dataIndex,
          //       title: <div onDoubleClick={() => this.columnRef.onOpenModel()}>{this.state.userData.language == 'EN' ? item.enDescripts : item.title}</div>,
          //       display: item.display,
          //       key: item.seqNo
          //     }
          //   }) : '';
          //   let filterArr = arr.filter(function (item) { return item.display === 'Y' });
          this.setState({
            localeProvider: userData.language == 'EN' ? res.result.language.EN : res.result.language.CN
          }, () => {
            // console.log("----",this.state.localeProvider)
            // this.props.getDec(this.state.localeProvider)
          })
        }
      }
    })
  }
  redireBack = () => {
    // this.props.history.goBack()
    let routerData = store.getState().otherData.routerData;
    let path = '';
    for (var i = 0; i < routerData.length; i++) {
      if (routerData[i].title === '用户信息') {
        path = routerData[i].path;
        break;
      }
    }
    // console.log(routerData)
    this.props.history.push(path);
  }
  //展示弹窗
  showModal = () => {
    this.setState({
      visible: true,
      activeKey: "1",
    }, () => {
      this.getMainTableColumns()
      // this.handleHomeData("1")
      setTimeout(() => {
        this.handleHomeData("7")
      }, 300);
    });
  }
  //关闭关联信息弹窗
  handleCancel = () => {
    this.setState({
      visible: false,
    }, () => {
      if (this.onChildonShiftSetting) {
        this.onChildonShiftSetting.signOut("User")
      }
    })
  }
  //点击弹窗确认按钮
  // handleOk = (e) => {
  //   setTimeout(() => {
  //     this.setState({ visible: false });
  //   }, 3000);
  // }
  render() {
    let tabsHeight = store.getState().tableHeight.y + 'px'
    return (
      <div className="user-dom">
        {/* <Drawer
          title={this.state.localeProvider && this.state.localeProvider.PersonalInformationPersonalCenter ? this.state.localeProvider.PersonalInformationPersonalCenter.descripts : "个人设置"}
          width="80%"
          onClose={this.handleCancel}
          visible={this.state.visible}
          footer={null}
          // className="userInfoDom"
          style={{
            // overflow: 'auto',
            // height: 'calc(100% - 108px)',
            // paddingBottom: '108px',
          }}
        >
       
        </Drawer> */}
        <Modal
          title={"排班设置"}
          visible={this.state.visible}
          // onOk={this.handleOk}
          onCancel={this.handleCancel}
          pagination='false'
          footer={null}
          className={document.body.clientWidth < 1400 ?
            "apply-dom userInfoDom userInfoDomLimited shiftSetting-dom shift-dom" : "userInfoDom shiftSetting-dom"}

        >
          <ShiftSetting localeProvider={this.state.localeProvider} onShiftSetting={this.onShiftSetting} handleHomeData={this.callback} />
        </Modal>
      </div>

    )
  }
}
export default ShiftSettings