tech-teacher-ranking.vue 3.04 KB
<template>
  <workbench-card title="科技部老师排行" :subtitle="deptName || 'Top5 总业绩'" icon="el-icon-medal" tone="cyan" :loading="loading">
    <template #extra>
      <el-button type="text" size="mini" @click="goMore">更多</el-button>
    </template>
    <div v-if="list.length" class="wb-list">
      <div
        v-for="(item, idx) in list"
        :key="item.EmployeeId || item.employeeId || idx"
        class="wb-list-item"
        @click="goMore"
      >
        <div class="wb-list-item__left">
          <span class="wb-list-item__dot" :style="{ background: rankColor(idx) }" />
          <span class="wb-list-item__title">{{ idx + 1 }}. {{ item.EmployeeName || item.employeeName || '无' }}</span>
        </div>
        <span class="wb-list-item__meta">¥{{ formatMoney(item.TotalPerformance != null ? item.TotalPerformance : item.totalPerformance) }}</span>
      </div>
    </div>
    <div v-else class="wb-empty">
      <div class="wb-empty__circle" style="background:#ecfeff;color:#06b6d4"><i class="el-icon-medal" /></div>
      <div class="wb-empty__title">暂无排行数据</div>
      <div class="wb-empty__desc">本月科技部老师排行将显示在这里</div>
    </div>
  </workbench-card>
</template>

<script>
import request from '@/utils/request'
import WorkbenchCard from '../workbench-card.vue'
import { formatMoney, getCurrentMonthYm } from '../utils'

export default {
  name: 'WidgetTechTeacherRanking',
  components: { WorkbenchCard },
  data() {
    return {
      loading: false,
      techDepartmentId: '',
      deptName: '',
      list: []
    }
  },
  mounted() {
    this.load()
  },
  methods: {
    formatMoney,
    rankColor(idx) {
      return ['#f59e0b', '#94a3b8', '#cd7f32', '#06b6d4', '#06b6d4'][idx] || '#06b6d4'
    },
    async resolveDept() {
      const res = await request({
        url: '/api/Extend/Organize/GetByName',
        method: 'get',
        data: { organizeName: '科技部' }
      })
      const list = res.data || []
      const first = list[0]
      if (!first) return
      this.techDepartmentId = first.Id || first.id || ''
      this.deptName = first.FullName || first.fullName || '科技部'
    },
    async load() {
      this.loading = true
      try {
        await this.resolveDept()
        if (!this.techDepartmentId) {
          this.list = []
          return
        }
        const res = await request({
          url: '/api/Extend/LqTechDepartmentDashboard/GetTeacherRanking',
          method: 'post',
          data: {
            statisticsMonth: getCurrentMonthYm(),
            techDepartmentId: this.techDepartmentId,
            storeIds: []
          }
        })
        const rows = (res.data && (res.data.RankingData || res.data.rankingData)) || []
        this.list = (Array.isArray(rows) ? rows : []).slice(0, 5)
      } catch (e) {
        this.list = []
      } finally {
        this.loading = false
      }
    },
    goMore() {
      this.$router.push('/extend/techDepartmentDashboard').catch(() => {})
    }
  }
}
</script>

<style lang="scss" scoped>
@import '../widget-common.scss';
</style>