abnormal-consume-alert.vue 2.78 KB
<template>
  <workbench-card title="异常耗卡提醒" subtitle="待处理异常" icon="el-icon-warning" tone="red" :loading="loading">
    <div class="alert" :class="{ 'is-danger': count > 0 }" @click="go">
      <div class="alert__icon"><i class="el-icon-warning-outline" /></div>
      <div class="alert__num">{{ count }}</div>
      <div class="alert__text">待处理异常耗卡</div>
      <div class="alert__link">立即处理 <i class="el-icon-arrow-right" /></div>
    </div>
  </workbench-card>
</template>

<script>
import { mapGetters } from 'vuex'
import request from '@/utils/request'
import WorkbenchCard from '../workbench-card.vue'

export default {
  name: 'WidgetAbnormalConsumeAlert',
  components: { WorkbenchCard },
  data() {
    return { loading: false, count: 0 }
  },
  computed: {
    ...mapGetters(['userInfo']),
    storeId() {
      return (this.userInfo && this.userInfo.mdid) || ''
    }
  },
  mounted() {
    this.load()
  },
  methods: {
    async load() {
      this.loading = true
      try {
        const d = new Date()
        const y = d.getFullYear()
        const m = String(d.getMonth() + 1).padStart(2, '0')
        const res = await request({
          url: '/api/Extend/LqXhHyhk/Actions/GetAbnormalConsumeCount',
          method: 'GET',
          data: {
            md: this.storeId || undefined,
            hksj: `${y}-${m}-01,${y}-${m}-${new Date(y, d.getMonth() + 1, 0).getDate()}`
          }
        })
        this.count = (res.data && res.data.count) || 0
      } catch (e) {
        this.count = 0
      } finally {
        this.loading = false
      }
    },
    go() {
      this.$router.push('/lqXhHyhk').catch(() => {})
    }
  }
}
</script>

<style lang="scss" scoped>
.alert {
  height: 100%;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  border-radius: 10px;
  background: #ecfdf5;
  border: 1px solid #d1fae5;
  cursor: pointer;
  transition: box-shadow 200ms ease, border-color 200ms ease;

  &:hover {
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.12);
  }

  &.is-danger {
    background: #fef2f2;
    border-color: #fecaca;
    .alert__icon { background: #fee2e2; color: #ef4444; }
    .alert__num { color: #ef4444; }
    &:hover { box-shadow: 0 4px 14px rgba(239, 68, 68, 0.12); }
  }
}

.alert__icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: #d1fae5;
  color: #10b981;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin-bottom: 8px;
}

.alert__num {
  font-size: 28px;
  font-weight: 700;
  color: #10b981;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.alert__text {
  margin-top: 4px;
  font-size: 13px;
  color: #64748b;
}

.alert__link {
  margin-top: 8px;
  font-size: 12px;
  color: #409eff;
}
</style>