<script setup lang="ts" name="MineIndex">
import { ref, reactive, computed, onMounted } from 'vue'
import Tabbar from '@/components/Tabbar.vue'
import { onLoad, onShow, onHide } from '@dcloudio/uni-app'

import { useUserStore } from '../../store/modules/user'

import MyAvatar from '@/components/Avatar/MyAvatar.vue'
import login from './modules/loginSub.vue'
import { selectEmployeesDetailByCode } from '@/api/user'
// import Qs from 'qs'

const userStore = useUserStore()
// const { userInfo }:any = storeToRefs(userStore)
// console.log('userInfo',userInfo)
const userInfo = userStore.userInfo

const detail = ref<any>({})



// 页面显示时触发（每次进入页面都会触发）
onShow(() => {
 if(userStore.accessToken) {
     console.log(2)
    selectEmployeesDetailByCode({
      employeesCode: userInfo.userCode
    }).then(res => {
      detail.value = res.data || {}
    })
  }
})

// 修改密码
const changePassword = () => {

  uni.navigateTo({url: '/changePwd/index'})
}

// 退出登录
const exitClick = () => {
  uni.showModal({
    title: '退出登录',
    content: '确定退出登录',
    success: (res) => {
      if (res.confirm) {
        userStore.logout().then(() => {
          uni.switchTab({ url: '/pages/stage/index' })
        })
      } else if (res.cancel) {
        console.log('用户点击取消')
      }
    }
  })
  // showConfirmDialog({
  //   title: '退出登录',
  //   message: '确定退出登录'
  // }).then(() => {
  //   userStore.logout().then(() => {
  //     router.push('/login')
  //   })
  // })
}

// 个人信息
function onClickUserCard() {
  uni.navigateTo({ url:'/userInfo/index'})
}

// 工资条
function onClickPayslip() {
  uni.navigateTo({ url:'/salary/index'})
}
// 我的绩效
function onClickKPI() {
  uni.navigateTo({ url:'/Kpi/index'})
}
// 设置
function onClickSetting() {
  uni.navigateTo({ url:'/mine/setting'})
}

</script>

<template>
  <login v-if="!userStore.accessToken"></login>
  <div  v-else class="container full float-bottom mine-container">
    <div class="container__body">
      <div class="mine-user" @click="onClickUserCard">
        <div class="mine-user__card-back" />
        <div class="mine-user__card">
          <div class="mine-user__card-inner">
            <div class="mine-user__card-top">
              <div class="mine-user__card-top-name">{{ detail.name }}</div>
              <text v-if="detail.sex && detail.sex === '0'" class="iconfont icon-male mine-user__card-top-icon"></text> 
              <text v-if="detail.sex && detail.sex === '1'" class="iconfont icon-male mine-user__card-top-icon"></text> 
            </div>
            <div class="mine-user__card-sub">
              <div class="mine-user__card-sub-name">{{ detail.serviceDeptName }}</div>
              <van-divider vertical />
              <div class="mine-user__card-sub-name">{{ detail.servicePostName }}</div>
            </div>
            <div class="mine-user__card-remain">
              <div class="">剩余年假: {{ detail.remainAnnualLeave }}天</div>
              <van-divider vertical />
              <div class="">剩余调休假: {{ detail.remainRestHour }}小时</div>
            </div>
            <div class="mine-user__card-business-card">
              <text class="iconfont icon-business-card mine-user__card-business-card-icon"></text> 
              <div class="mine-user__card-business-card-label">{{ detail.servicePostName }}</div>
            </div>
          </div>
          <div class="mine-user__card-userinfo" @click.stop="onClickUserCard">
            <text class="iconfont icon-edit mine-user__card-userinfo-icon"></text> 
            <div class="mine-user__card-userinfo-label">完善信息</div>
          </div>
        </div>
        <div class="mine-user__card-front">
          <div class="mine-user__card-front-title">员工编号</div>
          <div class="mine-user__card-front-code">{{ detail.employeesCode }}</div>
          <MyAvatar
            class="mine-user__card-front-head"
            width="5.9rem"
            height="5.9rem"
            :src="userInfo.avatar" />
        </div>
      </div>
      <div class="container__card flex">
        <div class="cell-list">
          <!-- <van-cell title="工资条" is-link @click="onClickPayslip">
            <template #icon>
              <div class="icon-salary">
               <uv-icon name="order" color="rgba(11, 211, 249, 1)"></uv-icon>
              </div>
            </template>
          </van-cell> -->
          <van-cell title="修改密码" is-link @click="changePassword">
            <template #icon>
              <div class="icon-password">
              <uv-icon name="lock" color="rgba(243, 164, 7, 1)"></uv-icon>
              </div>
            </template>
          </van-cell>
          <!-- <van-cell title="我的绩效" is-link @click="onClickKPI">
            <template #icon>
              <div class="icon-jixiao">
                <uv-icon name="level" color="#2979ff"></uv-icon>
              </div>
            </template>
          </van-cell> -->
        </div>
      </div>
    </div>
    <uv-button customStyle="position: fixed;bottom:250rpx;width:700rpx;" class="button-submit float-bottom" shape="circle" color="linear-gradient(to bottom, #4773FC, #6D9BFD)" @click="exitClick">退出登录</uv-button>
  </div>

  <Tabbar :selected="4"/>
</template>

<style lang="less" scoped>
.mine-container { 
  padding-bottom: calc(12rpx + env(safe-area-inset-bottom) + 20rpx + env(safe-area-inset-bottom));
}

.mine-user {
  position: relative;
  line-height: 1;
  color: #fff;
  &__card {
    position: relative;
    border-radius: 24rpx;
    box-shadow: 0 4rpx 40rpx rgba(64, 103, 251, 0.14);
    &-back {
      position: absolute;
      z-index: 0;
      right: 22rpx;
      top: -12rpx;
      width: 162rpx;
      height: 192rpx;
      border-radius: 40rpx 40rpx 10em 10em;
      background: linear-gradient(180deg, rgba(90, 170, 254, 1) 0%, rgba(60, 137, 254, 1) 100%);
      box-shadow: inset 0 2rpx 4rpx rgba(255, 255, 255, 0.31);
    }
    &-front {
      display: flex;
      flex-direction: column;
      align-items: center;
      position: absolute;
      right: 30rpx;
      top: -12rpx;
      padding-top: 18rpx;
      width: 146rpx;
      height: 222rpx;
      border-radius: 8rpx 8rpx 10em 10em;
      background: linear-gradient(180deg, rgba(118, 207, 255, 1) 0%, rgba(105, 191, 255, 1) 99.13%);
      box-shadow: inset 0 2rpx 4rpx rgba(255, 255, 255, 0.31);
      &-title {
        font-size: 20rpx;
      }
      &-code {
        margin-top: 12rpx;
        font-size: 20rpx;
      }
      &-head {
        position: absolute;
        left: 14rpx;
        right: 14rpx;
        bottom: 14rpx;
      }
    }
    &-inner {
      padding: 34rpx 34rpx 40rpx;
      width: 100%;
      height: 100%;
      border-radius: 24rpx;
      background: linear-gradient(270deg, rgba(59, 135, 254, 1) 0%, rgba(120, 194, 255, 1) 100%);
    }
    &-top {
      display: flex;
      align-items: center;
      &-name {
        min-width: 80rpx;
        max-width: 260rpx;
        font-size: 40rpx;
        font-weight: 500;
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
      }
      &-icon {
        margin-left: 18rpx;
        font-size: 28rpx;
      }
    }
    &-sub {
      display: flex;
      align-items: center;
      margin-top: 18rpx;
    }
    &-usertype {
      border-radius: 8rpx;
      background: linear-gradient(180deg, rgba(255, 255, 255, 0.23) 4.2%, rgba(255, 255, 255, 0.21) 99.63%);
      border: 2rpx solid rgba(151, 151, 151, 1);
    }
    &-business-card {
      display: flex;
      justify-content: center;
      align-items: center;
      margin-top: 28rpx;
      padding: 10rpx 18rpx 8rpx 12rpx;
      width: max-content;
      font-size: 28rpx;
      background: linear-gradient(180deg, rgba(255, 255, 255, 0.23) 4.2%, rgba(255, 255, 255, 0.21) 99.63%);
      border-radius: 8rpx;
      border: 2rpx solid #fff;
      &-icon {
        font-size: 28rpx;
      }
      &-label {
        margin-left: 12rpx;
        font-size: 20rpx;
      }
    }
    &-remain {
      display: flex;
      align-items: center;
      margin-top: 20rpx;
      font-size: 24rpx;
    }
    &-userinfo {
      display: flex;
      align-items: center;
      position: absolute;
      top: 38rpx;
      right: 200rpx;
      font-size: 24rpx;
      &-icon {
        font-size: 28rpx;
      }
      &-label {
        margin-left: 12rpx;
      }
    }
  }
}

.container__card {
  margin-top: 40rpx;
}
.cell-list {
  border-radius: 24rpx;
  .van-cell__left-icon {
    margin-right: 0;
    font-size: 32rpx;
    color: #4773FC;
  }
  .van-cell {
    align-items: center;
  }
}

.icon-salary,
.icon-password,
.icon-kpi,
.icon-jixiao,
.icon-setting {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-right: 22rpx;
  width: 48rpx;
  height: 48rpx;
  border-radius: 2px;
}

.icon-salary {
  background: linear-gradient(180deg, rgba(198, 255, 245, 0.5) 0%, rgba(170, 245, 255, 0.5) 100%);
}
.icon-password {
  background: linear-gradient(180deg, rgba(255, 230, 156, 0.5) 0%, rgba(255, 233, 189, 0.5) 100%);
}
.icon-kpi {
  background: linear-gradient(180deg, rgba(207, 228, 243, 0.5) 0%, rgba(179, 217, 244, 0.5) 100%);
}
.icon-jixiao{
  background: linear-gradient(180deg, rgba(207, 228, 243, 0.5) 0%, rgba(179, 217, 244, 0.5) 100%);
}
.icon-setting {
  background: linear-gradient(180deg, rgba(53, 108, 236, 0.3) 0%, rgba(179, 217, 244, 0.5) 100%);
}

</style>
