import React from 'react';
import { Button, List } from 'antd-mobile-v2';
import 'antd-mobile-v2/dist/antd-mobile.css';
// import ExamineMobile from './ExamineMobile';
import commonConfig from '../../utils/config';
import * as commonUtils from '../../utils/utils';
import CommobileBase from '../../mobile/common/CommobileBase';
import styles from '../mobile.less';
import setting from '../../assets/mobile/setting.png';
import mailList from '../../assets/mobile/mailList.png';
import recommendation from '../../assets/mobile/recommendation.png';
import CommobileListEvent from './CommobileListEvent';
import * as commonFunc from '../../components/Common/commonFunc';

// eslint-disable-next-line prefer-destructuring
const Item = List.Item;

class myselfMobile extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      sId: props.app.userinfo.sId,
      sUserName: props.app.userinfo.sUserName,
      sComponanyName: props.app.systemData.findIndex(item => item.sName === 'CbxCompanyName') > -1 ? props.app.systemData.filter(item => item.sName === 'CbxCompanyName')[0].sValue : '',
    };
  }
  btnOnclick = (value) => {
    const { dispatch } = this.props;
    const { sId } = this.state;
    if (value === 'loginOut') {
      const url = `${commonConfig.server_host}logout`;
      dispatch({ type: 'app/loginOut', payload: { url, sId, loginOutType: 'loginMobileOut' } });
    } else if (value === 'about') {
      window.open('about.html');
    } else {
      dispatch({
        type: 'content/onRouterMobile',
        payload: {
          url: `/indexMobile/${value}`,
        },
      });
    }
  }


  render() {
    const { sUserName, sComponanyName } = this.state;
    const { slaveData } = this.props;

    let sDepartName = '';
    if (commonUtils.isNotEmptyArr(slaveData) && commonUtils.isNotEmptyObject(sUserName)) {
      const findIndex = slaveData.findIndex(item => item.sEmployeeName === 'sUserName');
      if (findIndex > -1) {
        // eslint-disable-next-line prefer-destructuring
        sDepartName = slaveData[findIndex].sDepartName;
      } else {
        sDepartName = '暂无';
      }
    }
    const companyContactList = commonFunc.showLocalMessage(this.props, 'companyContactList', '企业通讯录');
    const ModifyPassword = commonFunc.showLocalMessage(this.props, 'ModifyPassword', '修改密码');
    const recommend = commonFunc.showLocalMessage(this.props, 'recommend', '推荐给好友');
    const aboutSoftware = commonFunc.showLocalMessage(this.props, 'aboutSoftware', '关于软件');
    const Logout = commonFunc.showLocalMessage(this.props, 'Logout', '退出登录');




    const sUserNameFirst = sUserName.charAt(0);
    return (
      <div>
        <div className={styles.myselfContent}>
          <div className={styles.company}>{sComponanyName}</div>
          <div className={styles.textInfo}>
            <div className={styles.myselfNameFirst}>{sUserNameFirst}</div>
            <div className={styles.myselfName}>
              <div className={styles.myselfNameInfo}>{sUserName}</div>
              <div className={styles.companyInfo}>{sDepartName}</div>
            </div>
          </div>
        </div>
        <List className={styles.myselfList}>
          <Item
            thumb={mailList}
            arrow="horizontal"
            onClick={this.btnOnclick.bind(this, 'contacts')}
            style={{ margin: '10px 0' }}
          >
            {companyContactList}
          </Item>
          <Item
            thumb={setting}
            onClick={this.btnOnclick.bind(this, 'revisePassword')}
            arrow="horizontal"
            style={{ margin: '10px 0' }}
          >
            {ModifyPassword}
          </Item>
          <Item
            thumb={recommendation}
            onClick={() => {}}
            arrow="horizontal"
            style={{ margin: '10px 0' }}
          >
            {recommend}
          </Item>
          <Item
            thumb={setting}
            onClick={this.btnOnclick.bind(this, 'about')}
            arrow="horizontal"
            style={{ margin: '10px 0' }}
          >
            {aboutSoftware}
          </Item>
        </List>
        <Button
          onClick={this.btnOnclick.bind(this, 'loginOut')}
          style={{ color: 'red', margin: '50px 0 10px 0' }}
        >
          {Logout}
        </Button>
      </div>
    );
  }
}

export default CommobileBase(CommobileListEvent(myselfMobile));
