major-project-kpi.vue 9.38 KB
<template>
  <workbench-card title="大项目核心指标" :subtitle="deptName || '大项目部当月'" icon="el-icon-data-line" tone="purple" compact :loading="loading">
    <template #extra>
      <el-button type="text" size="mini" @click="goMore">更多</el-button>
    </template>
    <div v-if="majorProjectDepartmentId" class="mp-kpi-grid">
      <div
        v-for="item in metricItems"
        :key="item.key"
        class="mp-kpi-item"
        :class="'mp-kpi-item--' + item.tone"
        @click="goMore"
      >
        <div class="mp-kpi-item__icon"><i :class="item.icon" /></div>
        <div class="mp-kpi-item__body">
          <div class="mp-kpi-item__label">{{ item.label }}</div>
          <div class="mp-kpi-item__value">{{ item.value }}</div>
          <div v-if="item.key === 'rate'" class="mp-kpi-item__progress" aria-hidden="true">
            <div class="mp-kpi-item__progress-bar" :style="{ width: ratePercent + '%' }" />
          </div>
        </div>
      </div>
    </div>
    <div v-else class="wb-empty">
      <div class="wb-empty__circle mp-empty-icon"><i class="el-icon-data-line" /></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: 'WidgetMajorProjectKpi',
  components: { WorkbenchCard },
  data() {
    return {
      loading: false,
      majorProjectDepartmentId: '',
      deptName: '',
      stats: {}
    }
  },
  computed: {
    ratePercent() {
      const rate = Number(this.stats.CompletionRate || 0)
      if (Number.isNaN(rate)) return 0
      return Math.min(Math.max(rate, 0), 100)
    },
    rateText() {
      return this.ratePercent.toFixed(2)
    },
    metricItems() {
      const cat = this.$catName('医美')
      return [
        {
          key: 'billing',
          tone: 'purple',
          icon: 'el-icon-s-finance',
          label: cat + '开单',
          value: '¥' + formatMoney(this.stats.BillingPerformance)
        },
        {
          key: 'refund',
          tone: 'red',
          icon: 'el-icon-refresh-left',
          label: '退款金额',
          value: '¥' + formatMoney(this.stats.RefundAmount)
        },
        {
          key: 'net',
          tone: 'green',
          icon: 'el-icon-data-line',
          label: '净业绩',
          value: '¥' + formatMoney(this.stats.NetPerformance)
        },
        {
          key: 'rate',
          tone: 'cyan',
          icon: 'el-icon-aim',
          label: '完成率',
          value: this.rateText + '%'
        }
      ]
    }
  },
  mounted() {
    this.load()
  },
  methods: {
    formatMoney,
    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.majorProjectDepartmentId = first.Id || first.id || ''
      this.deptName = first.FullName || first.fullName || '大项目部'
    },
    async load() {
      this.loading = true
      try {
        await this.resolveDept()
        if (!this.majorProjectDepartmentId) return
        const res = await request({
          url: '/api/Extend/LqMajorProjectDashboard/GetStatistics',
          method: 'post',
          data: {
            statisticsMonth: getCurrentMonthYm(),
            businessUnitId: this.majorProjectDepartmentId,
            storeIds: []
          }
        })
        this.stats = res.data || {}
      } catch (e) {
        this.stats = {}
      } finally {
        this.loading = false
      }
    },
    goMore() {
      this.$router.push('/extend/majorProjectDashboard').catch(() => {})
    }
  }
}
</script>

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

.mp-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-content: start;
}

.mp-kpi-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: #f8fafc;
  cursor: pointer;
  min-width: 0;
  align-self: start;
  transition: border-color 200ms ease, background 200ms ease, box-shadow 200ms ease;

  &:hover {
    background: #fff;
    border-color: #e2e8f0;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
  }

  &__icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    flex-shrink: 0;
  }

  &__body {
    min-width: 0;
    flex: 1;
  }

  &__label {
    font-size: 12px;
    color: #64748b;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  &__value {
    font-size: 14px;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.2;
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  &__progress {
    margin-top: 5px;
    height: 3px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.06);
    overflow: hidden;
  }

  &__progress-bar {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #06b6d4, #22d3ee);
    transition: width 300ms ease;
  }

  &--purple {
    border-left: 3px solid #8b5cf6;
    .mp-kpi-item__icon { background: #f5f3ff; color: #8b5cf6; }
    &:hover { border-color: #ddd6fe; }
  }

  &--red {
    border-left: 3px solid #ef4444;
    .mp-kpi-item__icon { background: #fef2f2; color: #ef4444; }
    &:hover { border-color: #fecaca; }
  }

  &--green {
    border-left: 3px solid #22c55e;
    .mp-kpi-item__icon { background: #ecfdf5; color: #22c55e; }
    &:hover { border-color: #bbf7d0; }
  }

  &--cyan {
    border-left: 3px solid #06b6d4;
    .mp-kpi-item__icon { background: #ecfeff; color: #06b6d4; }
    &:hover { border-color: #a5f3fc; }
  }
}

.mp-empty-icon {
  background: #faf5ff !important;
  color: #8b5cf6 !important;
}

@media (max-width: 1200px) {
  .mp-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  .mp-kpi-item,
  .mp-kpi-item__progress-bar {
    transition: none !important;
  }
}

::v-deep .wb-card__body {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  padding-top: 8px;
  padding-bottom: 10px;
}
</style>

<style lang="scss">
body.ncc-content-dark .mp-kpi-item,
.ncc-content-dark .mp-kpi-item {
  background: rgba(255, 255, 255, 0.04) !important;
  border-color: rgba(255, 255, 255, 0.08) !important;
  box-shadow: none !important;
}

body.ncc-content-dark .mp-kpi-item:hover,
.ncc-content-dark .mp-kpi-item:hover {
  background: rgba(255, 255, 255, 0.07) !important;
  border-color: rgba(255, 255, 255, 0.14) !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2) !important;
}

body.ncc-content-dark .mp-kpi-item__label,
.ncc-content-dark .mp-kpi-item__label {
  color: rgba(255, 255, 255, 0.55) !important;
}

body.ncc-content-dark .mp-kpi-item__value,
.ncc-content-dark .mp-kpi-item__value {
  color: rgba(255, 255, 255, 0.92) !important;
}

body.ncc-content-dark .mp-kpi-item__progress,
.ncc-content-dark .mp-kpi-item__progress {
  background: rgba(255, 255, 255, 0.08) !important;
}

body.ncc-content-dark .mp-kpi-item--purple,
.ncc-content-dark .mp-kpi-item--purple {
  border-left-color: #a78bfa !important;
}

body.ncc-content-dark .mp-kpi-item--purple .mp-kpi-item__icon,
.ncc-content-dark .mp-kpi-item--purple .mp-kpi-item__icon {
  background: rgba(139, 92, 246, 0.18) !important;
  color: #c4b5fd !important;
}

body.ncc-content-dark .mp-kpi-item--purple:hover,
.ncc-content-dark .mp-kpi-item--purple:hover {
  border-color: rgba(167, 139, 250, 0.35) !important;
}

body.ncc-content-dark .mp-kpi-item--red,
.ncc-content-dark .mp-kpi-item--red {
  border-left-color: #f87171 !important;
}

body.ncc-content-dark .mp-kpi-item--red .mp-kpi-item__icon,
.ncc-content-dark .mp-kpi-item--red .mp-kpi-item__icon {
  background: rgba(239, 68, 68, 0.15) !important;
  color: #fca5a5 !important;
}

body.ncc-content-dark .mp-kpi-item--red:hover,
.ncc-content-dark .mp-kpi-item--red:hover {
  border-color: rgba(248, 113, 113, 0.3) !important;
}

body.ncc-content-dark .mp-kpi-item--green,
.ncc-content-dark .mp-kpi-item--green {
  border-left-color: #4ade80 !important;
}

body.ncc-content-dark .mp-kpi-item--green .mp-kpi-item__icon,
.ncc-content-dark .mp-kpi-item--green .mp-kpi-item__icon {
  background: rgba(34, 197, 94, 0.15) !important;
  color: #86efac !important;
}

body.ncc-content-dark .mp-kpi-item--green:hover,
.ncc-content-dark .mp-kpi-item--green:hover {
  border-color: rgba(74, 222, 128, 0.3) !important;
}

body.ncc-content-dark .mp-kpi-item--cyan,
.ncc-content-dark .mp-kpi-item--cyan {
  border-left-color: #22d3ee !important;
}

body.ncc-content-dark .mp-kpi-item--cyan .mp-kpi-item__icon,
.ncc-content-dark .mp-kpi-item--cyan .mp-kpi-item__icon {
  background: rgba(6, 182, 212, 0.15) !important;
  color: #67e8f9 !important;
}

body.ncc-content-dark .mp-kpi-item--cyan:hover,
.ncc-content-dark .mp-kpi-item--cyan:hover {
  border-color: rgba(34, 211, 238, 0.3) !important;
}

body.ncc-content-dark .mp-empty-icon,
.ncc-content-dark .mp-empty-icon {
  background: rgba(139, 92, 246, 0.15) !important;
  color: #c4b5fd !important;
}
</style>