<!-- @desc:  @auth:洪旭东  @time:2022-05-14 11:30 -->
<template>
  <div class="user-avator-dropdown" >
    <Dropdown @on-click="handleClick">
      <Badge :dot="!!messageUnreadCount">
        <Avatar :src="userAvator"/>
      </Badge>
      <!--设置语言-->
      <!--      <Icon :size="18" type="md-arrow-dropdown"></Icon>-->
      <DropdownMenu slot="list" style="line-height: 0;" class="dropDownCp">
        <!--切换公司-->
<!--        <Dropdown placement="left">-->
<!--          <DropdownItem name="changeCp">-->
<!--            {{ $t('changeCp') }}-->
<!--            <Icon type="ios-arrow-forward"></Icon>-->
<!--          </DropdownItem>-->

<!--          <DropdownMenu slot="list">-->
<!--            <DropdownItem v-for="(item,index) in joinedCpList" :key="index+'l'" :name="'changeCp_' + item.cpId"-->
<!--                          :selected="item.cpId === $store.state.user.cpId">-->
<!--              {{ (item.cpId === $store.state.user.cpId ? '●' : '\u00A0\u00A0') + "\u3000" + item.cpName }}-->
<!--            </DropdownItem>-->
<!--          </DropdownMenu>-->
<!--        </Dropdown>-->
        <Dropdown placement="left">
          <DropdownItem name="lang">
            {{ $t('languageSetting') }}
            <Icon type="ios-arrow-forward"></Icon>
          </DropdownItem>
          <DropdownMenu slot="list">
            <DropdownItem v-for="(item,index) in langList" :key="index+'l'" :name="item.key"
                          :selected="item.key === currentLang">
              {{ (item.key === currentLang ? '●' : '\u00A0\u00A0') + "\u3000" + item.label }}
            </DropdownItem>
          </DropdownMenu>
        </Dropdown>
        <!--设置字体-->
        <Dropdown placement="left">
          <DropdownItem name="lang">
            {{ $t('fontSetting') }}
            <Icon type="ios-arrow-forward"></Icon>
          </DropdownItem>
          <DropdownMenu slot="list">
            <DropdownItem v-for="(item,index) in fontSizeList" :key="index+'l'" :name="item.key"
                          :selected="item.key === currentFontSize">
              {{ (item.key === currentFontSize ? '●' : '\u00A0\u00A0') + "\u3000" + item.label }}
            </DropdownItem>
          </DropdownMenu>
        </Dropdown>
        <!--        <DropdownItem name="personalInfo">{{ $t('personalInfo') }}</DropdownItem>-->
        <DropdownItem name="refresh">{{ $t('refreshBasicData') }}</DropdownItem>
        <DropdownItem name="update">{{ $t('editPassword') }}</DropdownItem>
        <DropdownItem name="changeMenu">{{ menuType === 'drawer' ? $t('treeMenu') : $t('drawerMenu') }}</DropdownItem>
        <DropdownItem name="logout">{{ $t('logout') }}</DropdownItem>
      </DropdownMenu>
    </Dropdown>

    <!--  修改个人信息  -->
    <DkModal
      v-model="personalFlag"
      width="900"
      :closable="!imageViewerFlag"
      :loading="saveLoading"
      @modalOk="updatePersonalInfo"
      title="个人资料">
      <div style="width: 100%;position:relative;">
        <image-viewer v-if="imageViewerFlag" :on-close="closeViewer"
                      :url-list="[personalInfo.imagePathType === 'AL-OSS'?$config.imgUrl+personalInfo.imagePath:personalInfo.imagePath]"/>
        <div style="position: absolute;right: 0;top: 0;">
          <Button type="primary" :loading="pullLoading">企信拉取</Button>
        </div>
        <!--        <Button type="primary" @click="bigPic">查看大图</Button>-->
        <DkForm v-model="personalInfo" :label-max-words="4" style="width: 98%;padding-top: 10px"
                :rules="personalInfoRules" ref="form">
          <div style="width: 100%;display: flex;justify-content: center;align-items: center;">
            <div style="width: 80px;height: 80px;border-radius: 50%;overflow: hidden;position: relative;">
              <el-image v-if="personalInfo.imagePath" style="cursor:pointer;width:100%;height:100%;object-fit:cover;"
                        fit="cover"
                        :src="personalInfo.imagePathType === 'AL-OSS'?$config.imgUrl+personalInfo.imagePath:personalInfo.imagePath"/>
              <img v-else style="cursor:pointer;width:100%;height:100%;object-fit:cover;" :src="dkLogo"/>
              <div class="avatar-zz"
                   style="width: 100%;height: 100%;position: absolute;background-color: rgba(26,26,26,0.53);top:0;opacity: 0">
                <input style="display: none;" ref="upload-btn" type="file" accept="image/*" @change="changeFile"/>
                <div style="width: 100%;display: flex;align-items: center;justify-content: space-around;">
                  <Icon type="md-create" color="#fff" size="20" @click="uploadBtn"/>
                  <Icon type="md-eye" color="#fff" size="20" @click="bigPic"/>
                </div>

              </div>
            </div>
          </div>

          <Divider orientation="left">个人信息</Divider>
          <DkRow>
            <Col class="Col" span="12">
              <DkFormItem prop="userCode" label="账号">
                <InputPop v-model="personalInfo.userCode" readonly/>
              </DkFormItem>
            </Col>
            <Col class="Col" span="12">
              <DkFormItem prop="userName" required>
                <InputPop v-model="personalInfo.userName"/>
              </DkFormItem>
            </Col>
          </DkRow>

          <DkRow>
            <Col class="Col" span="12">
              <DkFormItem prop="jobName">
                <InputPop v-model="personalInfo.jobName" readonly/>
              </DkFormItem>
            </Col>
            <Col class="Col" span="12">
              <DkFormItem prop="contactPhone" :label="$t('contactPhone')"
                          required>
                <InputPop v-model="personalInfo.contactPhone"/>
              </DkFormItem>
            </Col>
          </DkRow>

          <DkRow>
            <Col class="Col" span="12">
              <DkFormItem prop="postName" :label="$t('postName')">
                <InputPop v-model="personalInfo.postName" readonly/>
              </DkFormItem>
            </Col>
            <Col class="Col" span="12">
              <DkFormItem prop="department">
                <InputPop v-model="personalInfo.orgLevelName" readonly/>
              </DkFormItem>
            </Col>
          </DkRow>

          <Divider orientation="left">公司信息</Divider>

          <DkRow>
            <Col class="Col" span="12">
              <DkFormItem prop="saleOneName">
                <InputPop v-model="personalInfo.cpName" readonly/>
              </DkFormItem>
            </Col>
            <Col class="Col" span="12">
              <DkFormItem prop="qvUserid" label="企微账号">
                <InputPop v-model="personalInfo.qvUserid" readonly/>
              </DkFormItem>
            </Col>
          </DkRow>
          <DkRow>
            <Col class="Col" span="12">
              <DkFormItem prop="saleTwoName">
                <InputPop v-model="personalInfo.sale2Name" readonly/>
              </DkFormItem>
            </Col>
            <Col class="Col" span="12">
              <DkFormItem prop="erpUserCode" label="ERP用户">
                <InputPop v-model="personalInfo.erpUserCode" readonly/>
              </DkFormItem>
            </Col>
          </DkRow>

          <DkRow>
            <Col class="Col" span="12">
              <DkFormItem prop="storeName">
                <InputPop v-model="personalInfo.storeName" readonly/>
              </DkFormItem>
            </Col>
            <Col class="Col" span="12">
              <DkFormItem prop="erpStaffCode" label="ERP员工">
                <InputPop v-model="personalInfo.erpStaffCode" readonly/>
              </DkFormItem>
            </Col>
          </DkRow>
        </DkForm>
      </div>
    </DkModal>


    <!--修改密码-->
    <DkModal
      :z-index="1000"
      :fullscreen="flgInitPwd || pwdValidFlag"
      :closable="!flgInitPwd && !pwdValidFlag"
      :mask-closable="!flgInitPwd && !pwdValidFlag"
      v-model="updateModal"
      :show-header-icon="true"
      :title="$t('editPassword')"
      @modalOk="confirm"
      @modalCancel="cancel"
      @on-cancel="cancel"
      width="400px"
      :cancel-visible-flag="!flgInitPwd && !pwdValidFlag"
      valid-form-name="passwordForm"
    >
      <DkForm v-model="password" ref="passwordForm" name="passwordForm" :col-count="1">
        <!--旧密码-->
        <DkFormItem prop="oldPassword" :required="true">
          <InputPop :upper-flag="false" password v-model="password.oldPassword" clearable/>
        </DkFormItem>
        <!--新密码-->
        <DkFormItem prop="newPassword" :required="true">
          <InputPop :upper-flag="false" password v-model="password.newPassword" clearable/>
        </DkFormItem>
        <!--确认密码-->
        <DkFormItem prop="confirmPassword" :required="true">
          <InputPop :upper-flag="false" password v-model="password.confirmPassword" clearable/>
        </DkFormItem>
      </DkForm>
      <div class="error-tag" style="margin-top: 10px; height: 22px;">
        <Tag color="red" v-if="errorMessage">{{ errorMessage }}</Tag>
      </div>
      <DkTable slot="headerTip" :data="rule" :page-flag="false" :page-total-flag="false" :choose-flag="false"
               :show-setting-flag="false">
        <DkTableColumn :filter=false field="data" :title="$t('passwordRule')" :width="250"
                       :freeze="false"></DkTableColumn>
      </DkTable>
    </DkModal>
  </div>
</template>

<script>
import './user.less'
import {mapActions, mapMutations} from 'vuex'
import md5 from 'js-md5'
import {button as buttonList} from '@/locale/lang/zh-CN'
import dk_logo from '@/assets/images/dongke_logo.png'
import ImageViewer from 'element-ui/packages/image/src/image-viewer';
import {localRead, localSave} from "@/libs/base/util";
import {convertToChildrenMain, handleMenu} from "@/libs/tools/user-tools";


export default {
  name: 'User',
  components: {ImageViewer},
  inject: ['dkMain'],
  props: {
    userAvator: {
      type: String,
      default: ''
    },
    messageUnreadCount: {
      type: Number,
      default: 0
    },
  },
  data() {
    let self = this
    return {
      saveLoading: false,
      pullLoading: false,
      imageViewerFlag: false,
      dkLogo: dk_logo,
      personalFlag: false,
      // joinedCpList: self.$store.state.user.joinedCpList,// 加入公司
      imagePathType: null, /* WXQY AL-OSS */
      personalInfo: {},
      langList: self.$config.languages,   // 语言包
      fontSizeList: self.$config.fontSizes,   // 字体
      currentFontSize: localRead('fontSize') || '12', // 读取字体（默认字体12）
      personalInfoRules: {
        userName: [
          {required: true, trigger: 'none'}
        ],
        contactPhone: [
          {required: true, trigger: 'none'}
        ],
      },
      updateModal: false,
      password: {
        oldPassword: '',
        newPassword: '',
        confirmPassword: ''
      },
      // 密码过期flag true 过期 false 未过期
      pwdValidFlag: false,
      // 密码规则
      rule: [],
      // 保存当前键盘事件
      documentKeyDownContent: null,
      //错误信息
      errorMessage: '',
      errMessage: {},
    }
  },
  computed: {
    /**
     * @desc   : 密码是否是初始状态
     * @author : 洪旭东
     * @date   : 2022-05-14 11:32
     */
    flgInitPwd() {
      return this.$store.state.user.flgInitPwd
    },
    /**
     * @desc   : 菜单类型
     * @author : 洪旭东
     * @date   : 2023-08-11 15:46
     */
    menuType() {
      return this.$store.state.app.menuType
    }
  },
  watch: {
    updateModal(n, o) {
      if (!n) {
        //恢复快捷键
        document.onkeydown = this.documentKeyDownContent
      } else {
        this.addKeyBoardEvent()
      }
    }
  },
  methods: {
    ...mapActions([
      'handleLogOut', 'cleanTokenAccess', 'setUserTableSettingAfter', 'setMenuListAfter', 'handleLogin',
      'afterLogin',
      'updateCompany',
      'updateToken',
      'changeCp',
      'getInfoAfterLogin',
      'handleAfterLoginInfo'
    ]),
    ...mapMutations([
      'setMenuType',
    ]),
    changeFile(e) {
      const files = [...e.target.files]
      e.target.value = null
      if (files.length > 0) this.upLoadImg = true
      const _dataValue = []
      try {
        for (let i = 0; i < files.length; i++) {
          const {type} = files[i]``
          const imgType = type.split('/')[0]
          if (imgType !== 'image') {
            this.upLoadImg = false
            this.$message.warning('请上传图片文件。')
            return
          }
          const blob = new Blob([files[i]])
          let param = new FormData()
          param.append('file', blob, files[i].name)
          hgUploadService.upload(param, 't_m_user/introduction_phone').then(res => {
            if (res.code === 200) {
              this.personalInfo.imagePath = res.data.relativePath
              this.personalInfo.imagePathType = 'AL-OSS'
            } else {
              this.$Message.warning(res.message)
            }
          })
        }
      } catch {
        // loading动画消失
        this.upLoadImg = false
      }
    },
    uploadBtn() {
      // console.log(this.$refs['upload-btn'].click())
    },
    uploadImg() {
      hgUploadService.upload(param, 't_m_goods_spu/introduction_phone').then(res => {
        _dataValue.push(res.data.absolutelyPath)
        this.upLoadImg = false
      })
    },
    bigPic() {
      this.imageViewerFlag = true
    },
    closeViewer() {
      this.imageViewerFlag = false
    },
    updatePersonalInfo() {
      this.$refs['form'].validate().then(valid => {
        if (valid) {
          this.saveLoading = true
          userService.update(this.personalInfo).then(res => {
            this.saveLoading = false
            if (res.code === 200) {
              this.personalFlag = false
              // this.$Modal.confirm({
              //   title: '提示',
              //   content: '<p>个人资料更新成功，是否需要重新登录？</p>',
              //   onOk: () => {
              this.logout()
              //   },
              // });
            } else {
              this.$Message.warning(res.message)
            }
          })
        } else {

        }
      })
    },

    /**
     * @desc   : 修改密码弹窗的快捷键
     * @author : 洪旭东
     * @date   : 2022-05-20 08:52
     */
    addKeyBoardEvent() {
      let code = 0
      let self = this
      this.documentKeyDownContent = document.onkeydown
      document.onkeydown = function (e) {
        const evn = e || event
        const key = evn.keyCode || evn.which || evn.charCode
        // alt：code = 18
        if (key === 18) {
          code = 18
        }
        let btList = Object.values(self.$config.button);
        btList.forEach(forIt => {
          if (code === 18 && forIt.hotKey?.toLowerCase() === e.key.toLowerCase()) {
            e.returnValue = false
            if (self.$refs[forIt.name]) {
              self.$refs[forIt.name].$el.click()
            }
          }
        })
      }
      // 监听全局键盘按钮松开的事件
      document.onkeyup = function (e) {
        const evn = e || event
        const key = evn.keyCode || evn.which || evn.charCode
        if (key === 18) {
          code = 0
        }
        // 一秒钟失效，避免因为按了alt+tab之后再回来，按其他什么英文字母都不好使了的问题
        setTimeout(() => {
          code = 0
        }, 1000)
      }
    },
    /**
     * @desc   : 获取系统参数 校验密码
     * PWD_011,"{""zh_CN"": ""字母""}"
     * PWD_012,"{""zh_CN"": ""大小写字母""}"
     * PWD_013,"{""zh_CN"": ""数字""}"
     * PWD_014,"{""zh_CN"": ""特殊字符""}"
     * PWD_015,"{""zh_CN"": ""最小密码长度""}"
     * @author : 常皓宁
     * @date   : 2023-01-31 13:07
     */
    getSettings(password) {
      let params = {
        settingKind: this.$config.basicTypeCode.passwordSecurity,
        ftyId: this.$store.state.user.ftyId,
      }
      // TODO
      // return new Promise((resolve => {
      //   this.excute(this.$service.systemService, this.$service.systemService.getSettingValue, params).then(res => {
      //     if (res.code === this.$config.SUCCESS_CODE) {
      //       // 密码规则
      //       if (!password) {
      //         this.rule = []
      //       }
      //       //收集每个条件校验结果
      //       let flag = []
      //       //校验 11 - 15，16去后台校验
      //       for (let it of res.data) {
      //         if (password) {
      //           // 有密码，做检验
      //           if (this.$config.sysCode.SYS_CODE_011 == it.settingCode && (it.settingValue === 'TRUE' || it.settingValue === '1')) {
      //             // 密码规则校验：用户密码必须包括【英文字母】
      //             let rg = /([A-Za-z])/g
      //             let result = !!password.match(rg)
      //             if (!result) {
      //               this.errorMessage = this.$t('W_021')
      //               return
      //             }
      //             flag.push(result)
      //           } else if (this.$config.sysCode.SYS_CODE_012 == it.settingCode && (it.settingValue === 'TRUE' || it.settingValue === '1')) {
      //             // 密码规则校验：用户密码必须包括【大小写字母】
      //             let rg1 = /([A-Z])/g
      //             let rg2 = /([a-z])/g
      //             let result = !!password.match(rg1) && !!password.match(rg2)
      //             if (!result) {
      //               this.errorMessage = this.$t('W_022')
      //               return
      //             }
      //             flag.push(result)
      //           } else if (this.$config.sysCode.SYS_CODE_013 == it.settingCode && (it.settingValue === 'TRUE' || it.settingValue === '1')) {
      //             // 密码规则校验：用户密码必须包括【数字】
      //             let rg = /([0-9])/g
      //             let result = !!password.match(rg)
      //             if (!result) {
      //               this.errorMessage = this.$t('W_023')
      //               return
      //             }
      //             flag.push(result)
      //           } else if (this.$config.sysCode.SYS_CODE_014 == it.settingCode && (it.settingValue === 'TRUE' || it.settingValue === '1')) {
      //             // 密码规则校验：用户密码必须包括【特殊字符】
      //             let rg = /(\W)/g
      //             let result = !!password.match(rg)
      //             if (!result) {
      //               this.errorMessage = this.$t('W_024')
      //               return
      //             }
      //             flag.push(result)
      //           } else if (this.$config.sysCode.SYS_CODE_015 == it.settingCode) {
      //             // 密码规则校验：用户密码最小长度
      //             let result = password.length >= parseInt(it.settingValue)
      //             if (!result) {
      //               this.errorMessage = this.$t('W_025') + it.settingValue
      //               return
      //             }
      //             flag.push(result)
      //           }
      //         } else {
      //           // 无密码，拼规则
      //           if (this.$config.sysCode.SYS_CODE_011 == it.settingCode && it.settingValue === '1') {
      //             this.rule.push({data: this.$t('W_021')})
      //           } else if (this.$config.sysCode.SYS_CODE_012 == it.settingCode && it.settingValue === '1') {
      //             this.rule.push({data: this.$t('W_022')})
      //           } else if (this.$config.sysCode.SYS_CODE_013 == it.settingCode && it.settingValue === '1') {
      //             this.rule.push({data: this.$t('W_023')})
      //           } else if (this.$config.sysCode.SYS_CODE_014 == it.settingCode && it.settingValue === '1') {
      //             this.rule.push({data: this.$t('W_024')})
      //           } else if (this.$config.sysCode.SYS_CODE_015 == it.settingCode) {
      //             this.rule.push({data: this.$t('W_025') + '【' + it.settingValue + '】'})
      //           }
      //         }
      //       }
      //       // 返回规则校验结果
      //       resolve(!flag.some(s => !s))
      //     } else {
      //       this.$Message.warning(res.message)
      //     }
      //   })
      // }))
    },
    /**
     * @desc   : 提交密码保存
     * @author : 常皓宁
     * @date   : 2023-01-31 13:07
     */
    confirm() {
      this.errorMessage = '';
      /* 先校验两次密码输入是不是一致 */
      if (this.password.confirmPassword !== this.password.newPassword) {
        this.errorMessage = this.$t('Q_006')
        return
      }
      //校验规则
      this.getSettings(this.password.newPassword).then(flag => {
        if (flag) {
          let param = {
            password: md5(this.password.oldPassword),
            newPassword: md5(this.password.newPassword),
            confirmPassword: md5(this.password.confirmPassword)
          }
          // 提交修改
          this.excute(this.$service.userService, this.$service.userService.updatePassWord, param).then(res => {
            //密码保存成功后的操作
            this.afterUpdatePassword(res)
          })
        }
      })
    },
    /**
     * @desc   : desc
     * @author : 沈博
     * @date   : 2022/8/12 10:18
     */
    getUserByCurrentLogin() {
      userService.selectById(this.$store.state.user.id).then(res => {
        if (res.code === 200) {
          this.personalInfo = res.data
        } else {
          this.$Message.warning(res.message)
        }
      })
    },
    /**
     * @desc   : 密码保存成功后的操作
     * @author : 常皓宁
     * @date   : 2023-01-31 13:07
     */
    afterUpdatePassword(res) {
      if (res.code === this.$config.SUCCESS_CODE) {
        /* 修改store里面的初始密码标识 */
        this.$store.dispatch('refreshFlgInitPwd', false)
        this.$Message.success(this.$t('I_002'))
        this.updateModal = false
      } else if (res.code === this.$config.ERROR_CODE_2009 || res.code === this.$config.ERROR_CODE_2011) {
        this.password.newPassword = ''
        this.password.confirmPassword = ''
        this.$Message.warning(res.message)
      } else if (res.code === this.$config.ERROR_CODE_2010) {
        this.password.oldPassword = ''
        this.$Message.warning(res.message)
      } else {
        this.$Message.warning(res.message)
      }
    },
    /**
     * @desc   : 修改密码取消按钮
     * @author : 洪旭东
     * @date   : 2022-05-14 11:27
     */
    cancel() {
      this.errorMessage = '';
      this.updateModal = false
      this.$refs.passwordForm.$refs.passwordForm.resetFields()
    },
    /**
     * @desc   : 退出
     * @author : 洪旭东
     * @date   : 2022-05-14 11:27
     */
    logout() {
      this.handleLogOut().then(() => {
        this.$router.push({
          name: 'login'
        })
      })
    },
    /**
     * @desc   : 切换语言
     * @author : 周兴
     * @date   : 2022/12/21 13:01
     */
    changeLang(name) {
      if (name !== this.currentLang) {
        // 设置语言的缓存
        localSave('local', name);
        this.currentLang = name;
        this.$i18n.locale = name
        // 关闭所有的窗体
        if (this.dkMain) {
          this.dkMain.handleAllClose();
        }
      }
    },
    /**
     * @desc   : 刷新基础数据
     * @author : 周兴
     * @date   : 2023/5/11 10:26
     */
    refreshBasicData() {
      this.excute(this.$service.commonService, this.$service.commonService.refreshBasicData,
        {appCode: this.$config.appCode.WEB}, true, this.$t('refresh')).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          if (res.data) {
            let menu = res.data.menu;
            let menuCopy = menu.copy();
            menuCopy = menuCopy.filter(it => it.objectCode !== 'home')
            sessionStorage.setItem('menu', JSON.stringify(menuCopy))
            // 功能权限
            if (res.data.function) {
              sessionStorage.setItem('function', JSON.stringify(res.data.function))
            }
            // 用户隐藏列
            this.setUserTableSettingAfter(res.data.userTableSetting);
            menu = handleMenu(menu);
            let arr = convertToChildrenMain(menu);
            sessionStorage.setItem('route', JSON.stringify(arr))
            this.setMenuListAfter(arr)
            // 关闭所有的窗体
            if (this.dkMain) {
              this.dkMain.handleAllClose();
            }
            // 刷新页面
            location.reload();
          }
        }
      })
    },
    /**
     * @desc   : 切换字体
     * @author : 周兴
     * @date   : 2023/1/28 20:06
     */
    changeFontSize(name) {
      if (name !== this.currentFontSize) {
        // 设置字体缓存
        localSave('fontSize', name);
        this.currentFontSize = name;
        // 刷新页面
        location.reload();
      }
    },
    // /**
    //  * @desc   : 切换公司
    //  * @author : 周兴
    //  * @date   : 2024/3/19 14:18
    //  */
    // async chooseCp(cpId) {
    //   if (cpId) {
    //     let item = this.joinedCpList.filter(it=>it.cpId == cpId);
    //     if(!item || item.length == 0){
    //       return;
    //     }
    //     await this.updateCompany(item[0]);
    //     // 点击切换公司
    //     this.changeCp(this.joinedCps).then(res => {
    //       // 更新token
    //       this.updateToken(res.data);
    //       setTimeout(() => {
    //         // 登录后获取信息
    //         this.getInfoAfterLogin().then(r => {
    //           if (r.code == this.$config.SUCCESS_CODE) {
    //             this.handleAfterLoginInfo(r.data);
    //             // 关闭所有的窗体
    //             if (this.dkMain) {
    //               this.dkMain.handleAllClose();
    //             }
    //             // 刷新页面
    //             location.reload();
    //           }
    //         });
    //       }, 50)
    //     })
    //   }
    // },
    /**
     * @desc   : 下拉点击
     * @author : 洪旭东
     * @date   : 2022-05-14 11:28
     */
    handleClick(name) {
      switch (name) {
        case 'logout':
          this.logout()
          break
        case 'update':
          this.password = {
            oldPassword: '',
            newPassword: '',
            confirmPassword: ''
          }
          // 获取系统参数
          this.getSettings()
          this.updateModal = true
          break
        case 'refresh': // 刷新基础数据
          this.refreshBasicData();
          break
        case 'personalInfo':
          this.getUserByCurrentLogin();
          this.personalFlag = true
          break
        // 切换语言
        case 'zh-CN':
        case 'en-US':
          this.changeLang(name);
          break
        // 切换字体
        case '12':
        case '13':
        case '14':
          this.changeFontSize(name);
          break
        case 'changeMenu':
          if (this.menuType === 'drawer') {
            this.setMenuType('tree')
          } else {
            this.setMenuType('drawer')
          }
          // 把菜单打开模式保存到缓存中
          localSave('sideMenuType', this.menuType)
          // this.excute(this.$service.userBasicSetService, this.$service.userBasicSetService.update,
          //   {menuType:this.$store.state.app.menuType}).then(res=>{
          //     if (res.code === this.$config.SUCCESS_CODE) {
          //
          //     } else {
          //       this.$Message.error(res.message)
          //     }
          //   })
          break
      }
      if(name.indexOf('changeCp')>= 0){
        let values = name.split('_')
        if(values && values.length > 1){
          // 切换公司
          this.chooseCp(values[1])
        }
      }
    }
  },
  created() {
    if (this.$store.state.user.flgInitPwd) {
      this.getSettings()
      // 密码为初始
      this.$Message.warning(this.$t('W_019'))
      this.updateModal = true
    } else {
      // TODO
      // this.excute(this.$service.commonService, this.$service.commonService.getSettingValue, {
      //   code: this.$config.sysCode.SYS_CODE_010,
      //   ftyId: this.$store.state.user.ftyId
      // }).then(res=>{
      //   if (res.code === this.$config.SUCCESS_CODE) {
      //     let days = parseInt(res.data)
      //     if (this.$store.state.user.pwdDate && (new Date(this.$store.state.user.pwdDate).getTime() + days*24*60*60*1000) < new Date().getTime()) {
      //       // 密码过期
      //       this.getSettings()
      //       this.$Message.warning(this.$t('W_020'))
      //       this.pwdValidFlag = true
      //       this.updateModal = true
      //     }
      //   } else {
      //     this.$Message.warning(res.message)
      //   }
      // })
    }
    this.currentLang = this.currentLang ? this.currentLang : this.$config.currentLang
  }
}
</script>
<style scoped>
/*使遮罩层大于菜单的层数*/
.ivu-modal-fullscreen .ivu-modal-body {
  display: flex;
  justify-content: center;
}

/*错误提示tag*/
.error-tag {
  text-align: center;
  width: 100%;
}

/*拉长tag长度*/
.ivu-tag {
  width: 100%;
}

.avatar-zz {
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}

.avatar-zz:hover {
  opacity: 1 !important;
}

/*下拉菜单层级*/
.user-avator-dropdown /deep/ .ivu-select-dropdown {
  z-index: 99999;
}

.dropDownCp /deep/ .ivu-dropdown-menu {
  /*min-width: auto;*/
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
.ivu-badge{
  display: flex;
  align-items: center;
}
/deep/ .ivu-select-dropdown{
  width: min-content!important;
}
</style>
