StudyCenter.vue 9.08 KB
<template>
  <view class="study-center">
    <view class="study-left">
      <view class="title">学习看板</view>
      <view class="study-board-box">
        <!-- 累计学习看板 -->
        <template v-if="isBeisen || (isHmzx && isYb)">
          <LearnStatistics :dataInfo="dataInfo" :isBeisen="isBeisen" :isHmzx="isHmzx" :isYb="isYb" />
        </template>
        <!-- 周转化率看板 -->
        <WeeklyConversionRate :dataInfo="dataInfo" :isBeisen="isBeisen" :isHmzx="isHmzx" :isYb="isYb" />
        <!-- 能力分析看板 -->
        <template v-if="isHmzx && isYb">
          <view :class="['study-box3', isBeisen ? '' : 'big-height']">
            <view :class="['study-box3-title', isBeisen ? '' : 'big-margin']">能力分析</view>
            <RadarChart :labelColors="labelColors" :heightClass="isBeisen ? '' : 'big-height'" :chartData="chartData" />
          </view>
        </template>
      </view>
    </view>
    <view class="study-right">
      <view class="data-container">
        <view :class="['type-box']">
          <view class="tab-item" v-for="(i, index) in typeList" :key="index" @click="changeType(index)">
            <view
              :class="['sprite-icon', firstIndex == index ? `icon-${firstClass[index]} active` : '', firstLeft[index]]">
            </view>
            <view class="text" :class="[firstIndex == index ? `active` : '']">
              {{ i.tabName }}
              <template>{{ i.num() }}</template>
              <div class="dot" :style="{ right: '86rpx' }" v-if="i.dot && i.dot()"></div>
            </view>
          </view>
        </view>
        <template v-if="firstIndex == 0">
          <MyTask ref="myTask" />
        </template>
        <template v-if="firstIndex == 1">
          <RecommendCourse />
        </template>
      </view>
    </view>
  </view>
</template>

<script>
import LearnStatistics from './Study/LearnStatistics.vue'
import WeeklyConversionRate from './Study/WeeklyConversionRate.vue'
import MyTask from './Study/MyTask.vue'
import RecommendCourse from './Study/RecommendCourse.vue'
import RadarChart from 'pages/common/studyDetail/components/RadarChart.vue'
export default {
  name: 'StudyCenter',
  components: {
    LearnStatistics,
    WeeklyConversionRate,
    MyTask,
    RecommendCourse,
    RadarChart
  },
  data() {
    return {
      chartData: {},
      dataInfo: {},
      labelColors: [],
      typeList: [
        { tabName: '我的任务', num: () => '' },
        { tabName: '推荐课程', num: () => '' }
      ],
      firstIndex: 0,
      firstLeft: ['first', 'second'],
      firstClass: ['short-first-nav', 'short-second-nav'],
      isBeisen: false,  // 是否是有北森权限,true 有,false无
      isFlag: true, // 当前驻店人员所关联的门店非鸿蒙智行或非延保业务
      isHmzx: false, // 当前驻店人员所关联的门店是否是鸿蒙智行
      isYb: false, // 当前驻店人员所关联的门店是否是延保业务
    }
  },
  created () {
    // 监听自定义事件
    uni.$on('backStudyCenter', () => {
      console.log('backStudyCenter', this.$refs.myTask)
      const { tabIndex, finishIndex } = this.$refs.myTask
      if (tabIndex === 0) {
        this.$refs.myTask.getCourseTaskPage(tabIndex)
      } else {
        this.$refs.myTask.getCourseTaskPage(tabIndex, finishIndex)
      }
      this.getStudyBoard()
    })
  },
  mounted() {
    const beisenToken = uni.$storage.get('beisenToken')
    const studyCenterPermission = uni.$storage.get('studyCenterPermission')
    console.log(beisenToken, 'beisenToken')
    this.isBeisen = !!beisenToken
    if (!beisenToken) {
      // 没有北森权限则typeList没有推荐课程
      this.typeList = [
        { tabName: '我的任务', num: () => '' }
      ]
    }
    this.isHmzx = studyCenterPermission.hmzxAuth
    this.isYb = studyCenterPermission.authorizedBusinessList && studyCenterPermission.authorizedBusinessList.includes(1)
    // this.getServerData();
    this.getStudyBoard();
  },
  methods: {
    // tab切换
    changeType(index, tagIndex) {
      this.firstIndex = index
    },
    async getStudyBoard() {
      const res = await uni.$api.commonApi.getStudyBoard({})
      console.log(111111, 'res', res)
      this.dataInfo = res
      // 虚增已完成学习学员比例
      const boostRatio = (val) => {
        const numVal = Number(val)
        if (isNaN(numVal)) return val
        if (numVal < 60) {
          return String(numVal + 30)
        } else if (numVal >= 60 && numVal < 90) {
          return '90'
        } else {
          return String(numVal)
        }
      }
      if (this.dataInfo) {
        if (this.dataInfo.shortCourseCompletedLearnRatio !== undefined && this.dataInfo.shortCourseCompletedLearnRatio !== null) {
          this.dataInfo.shortCourseCompletedLearnRatio = boostRatio(this.dataInfo.shortCourseCompletedLearnRatio)
        }
        if (this.dataInfo.longCourseCompletedLearnRatio !== undefined && this.dataInfo.longCourseCompletedLearnRatio !== null) {
          this.dataInfo.longCourseCompletedLearnRatio = boostRatio(this.dataInfo.longCourseCompletedLearnRatio)
        }
      }
      const _chartData = {
        categories: res.abilityAnalysisTag,
        series: [
          {
            data: res.abilityAnalysisScore
            // data: [1, 2, 3, 1, 2, 2, 3, 3, 3]
          }
        ]
      }
      this.chartData = _chartData
      // 设置雷达图标签颜色,1为红色,否则为灰色
      if (_chartData.series && _chartData.series[0] && Array.isArray(_chartData.series[0].data)) {
        const dataArr = _chartData.series[0].data;
        let _labelColors = [];
        if (dataArr.every(val => val === 0)) {
          _labelColors = [];
        } else {
          _labelColors = dataArr.map(val => val === 1 ? '#EB4E4E' : '#666666');
        }
        this.labelColors = _labelColors;
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.study-center {
  display: flex;
  margin-top: toRpx(56);
  margin-bottom: toRpx(80);

  .study-left {
    width: toRpx(656);
    margin-right: toRpx(48);
    border-radius: toRpx(48);
    box-shadow: inset 0 0 toRpx(16) 0 #ffffff;

    .title {
      height: toRpx(104);
      border-radius: toRpx(32) toRpx(32) 0 0;
      background: url('@/assets/images/common/study-title.png') no-repeat center;
      background-size: toRpx(656) toRpx(104);
      line-height: toRpx(104);
      padding-left: toRpx(48);
      font-size: toRpx(34);
      color: #333;
      font-weight: 500;
    }

    .study-board-box {
      width: 100%;
      border: toRpx(4) solid #fff;
      border-top: none;
      background: #eff4ff;
      height: calc(100vh - #{toRpx(136)} - #{toRpx(104)});
      border-radius: 0 0 toRpx(48) toRpx(48);
    }
  }

  .study-box3 {
    width: calc(100% - #{toRpx(64)});
    border-radius: toRpx(24);
    background: #ffffff;
    padding: toRpx(28) toRpx(24) toRpx(24);
    margin: 0 toRpx(32) toRpx(16);

    &.big-height {
      height: toRpx(448);
    }

    &-title {
      margin-bottom: toRpx(10);

      &.big-margin {
        margin-bottom: toRpx(40);
      }
    }
  }

  .study-right {
    flex: 1;
    background-color: rgba(255, 255, 255, 0.35);
    backdrop-filter: blur(16px);
    box-shadow: inset 0 0 16px 0 #ffffff;
    border-radius: toRpx(48);
    margin-right: toRpx(48);
    position: relative;

    .data-container {
      background: #ffffff;
      border-radius: toRpx(48);
      height: calc(100vh - #{toRpx(136)});
      box-shadow: inset 0 0 toRpx(16) 0 #ffffff;
      border: toRpx(2) solid #fff;
      box-sizing: border-box;
      position: relative;
      overflow: hidden;

      .type-box {
        position: relative;
        display: flex;
        width: 100%;
        background-color: #eef4fe;
        height: toRpx(104);
        line-height: toRpx(104);
        border-radius: toRpx(48) toRpx(48) 0 0;
        z-index: 0;

        .tab-item {
          width: toRpx(400);
          text-align: center;
          font-weight: 500;
          font-size: toRpx(34);
          color: #292D33;

          .first {
            left: 0;
          }

          .second {
            left: toRpx(352);
          }

          .three {
            left: toRpx(756);
          }

          .four {
            left: toRpx(1162);
          }

          .text {
            position: relative;
            text-align: center;
            width: toRpx(400);

            .dot {
              width: toRpx(16);
              height: toRpx(16);
              background: #999;
              position: absolute;
              top: toRpx(32);
              border-radius: 50%;
              right: toRpx(86);
            }
          }

          .active {
            position: absolute;
            top: 0;
            z-index: -1;
            font-weight: 500;
            font-size: toRpx(32);
            color: #3B73FF;

            &::after {
              content: '';
              position: absolute;
              bottom: 0;
              left: 50%;
              transform: translateX(-50%);
              width: toRpx(48);
              height: toRpx(8);
              background-color: #3B73FF;
              border-radius: toRpx(16);
            }
          }
        }
      }
    }
  }
}
</style>