approval-summary.vue 5.57 KB
<template>
  <workbench-card title="审批中心" subtitle="多类型待审一览" icon="el-icon-s-claim" tone="blue" :loading="loading">
    <div class="approval-hub">
      <div
        v-for="item in items"
        :key="item.key"
        class="approval-hub__row"
        :class="'is-' + item.tone"
        @click="go(item.path)"
      >
        <span class="approval-hub__icon"><i :class="item.icon" /></span>
        <div class="approval-hub__main">
          <div class="approval-hub__name">{{ item.label }}</div>
          <div class="approval-hub__hint">{{ item.hint }}</div>
        </div>
        <span class="approval-hub__count" :class="{ 'has-num': item.count > 0 }">{{ item.count }}</span>
        <i class="el-icon-arrow-right approval-hub__arrow" />
      </div>
    </div>
  </workbench-card>
</template>

<script>
import request from '@/utils/request'
import WorkbenchCard from '../workbench-card.vue'
import { fetchFlowWorkbenchCounts } from '../flow-counts'

export default {
  name: 'WidgetApprovalSummary',
  components: { WorkbenchCard },
  data() {
    return {
      loading: false,
      flowTodo: 0,
      reimbursement: 0,
      inventory: 0,
      abnormal: 0
    }
  },
  computed: {
    items() {
      return [
        {
          key: 'flow',
          label: '流程待审',
          hint: '待我审核的流程单据',
          icon: 'el-icon-s-check',
          tone: 'orange',
          path: '/workFlow/flowTodo',
          count: this.flowTodo
        },
        {
          key: 'reimb',
          label: '报销待审',
          hint: '待审批的报销申请',
          icon: 'el-icon-wallet',
          tone: 'green',
          path: '/lqReimbursementApplication',
          count: this.reimbursement
        },
        {
          key: 'inv',
          label: '领用待审',
          hint: '库存领用待审批',
          icon: 'el-icon-box',
          tone: 'cyan',
          path: '/lqInventory/application-list',
          count: this.inventory
        },
        {
          key: 'abn',
          label: '异常耗卡',
          hint: '待处理异常消耗',
          icon: 'el-icon-warning-outline',
          tone: 'red',
          path: '/lqXhHyhk',
          count: this.abnormal
        }
      ]
    }
  },
  mounted() {
    this.load()
  },
  methods: {
    go(path) {
      if (path) this.$router.push(path).catch(() => {})
    },
    async load() {
      this.loading = true
      try {
        const [flowCounts, reimbRes, invRes, abnRes] = await Promise.all([
          fetchFlowWorkbenchCounts().catch(() => ({ toBeReviewed: 0 })),
          request({
            url: '/api/Extend/LqReimbursementApplication/Actions/PendingApproval',
            method: 'get',
            data: { currentPage: 1, pageSize: 1 }
          }).catch(() => ({ data: {} })),
          request({
            url: '/api/Extend/LqInventoryUsage/GetPendingApprovalList',
            method: 'get',
            data: { currentPage: 1, pageSize: 1 }
          }).catch(() => ({ data: {} })),
          request({
            url: '/api/Extend/LqXhHyhk/Actions/GetAbnormalConsumeCount',
            method: 'get',
            data: {}
          }).catch(() => ({ data: {} }))
        ])
        this.flowTodo = flowCounts.toBeReviewed || 0
        this.reimbursement = this.extractTotal(reimbRes.data)
        this.inventory = this.extractTotal(invRes.data)
        this.abnormal = (abnRes.data && abnRes.data.count) || 0
      } finally {
        this.loading = false
      }
    },
    extractTotal(data) {
      if (!data) return 0
      if (data.pagination && data.pagination.total !== undefined) return data.pagination.total
      if (data.pagination && data.pagination.Total !== undefined) return data.pagination.Total
      return 0
    }
  }
}
</script>

<style lang="scss" scoped>
.approval-hub {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}

.approval-hub__row {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 200ms ease, border-color 200ms ease, box-shadow 200ms ease;

  &:hover {
    background: #fff;
    border-color: #d6e8ff;
    box-shadow: 0 4px 12px rgba(64, 158, 255, 0.08);
  }
}

.approval-hub__icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.is-orange .approval-hub__icon { background: #fff7ed; color: #f59e0b; }
.is-green .approval-hub__icon { background: #ecfdf5; color: #10b981; }
.is-cyan .approval-hub__icon { background: #ecfeff; color: #06b6d4; }
.is-red .approval-hub__icon { background: #fef2f2; color: #ef4444; }

.approval-hub__main {
  flex: 1;
  min-width: 0;
}

.approval-hub__name {
  font-size: 13px;
  font-weight: 600;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.approval-hub__hint {
  margin-top: 1px;
  font-size: 11px;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.approval-hub__count {
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border-radius: 14px;
  background: #eef2f7;
  color: #64748b;
  font-size: 14px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;

  &.has-num {
    background: #ecf5ff;
    color: #409eff;
  }
}

.is-red .approval-hub__count.has-num {
  background: #fef2f2;
  color: #ef4444;
}

.approval-hub__arrow {
  color: #cbd5e1;
  font-size: 12px;
  flex-shrink: 0;
}
</style>