Blame view

antis-ncc-admin/src/components/workbench/widgets/attendance-mine.vue 3.92 KB
e1dcb3a0   “wangming”   1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
  <template>
    <workbench-card title="我的考勤" :subtitle="monthLabel" icon="el-icon-time" tone="blue" :loading="loading">
      <template #extra>
        <el-button type="text" size="mini" @click="goMore">更多</el-button>
      </template>
      <div v-if="hasData" class="wb-metric-row wb-metric-row--3">
        <div class="wb-metric wb-metric--green" @click="goMore">
          <div class="wb-metric__icon"><i class="el-icon-success" /></div>
          <div class="wb-metric__body">
            <div class="wb-metric__num">{{ stats.normal }}</div>
            <div class="wb-metric__label">正常</div>
          </div>
        </div>
        <div class="wb-metric wb-metric--orange" @click="goMore">
          <div class="wb-metric__icon"><i class="el-icon-warning" /></div>
          <div class="wb-metric__body">
            <div class="wb-metric__num">{{ stats.late }}</div>
            <div class="wb-metric__label">迟到</div>
          </div>
        </div>
        <div class="wb-metric wb-metric--red" @click="goMore">
          <div class="wb-metric__icon"><i class="el-icon-error" /></div>
          <div class="wb-metric__body">
            <div class="wb-metric__num">{{ stats.abnormal }}</div>
            <div class="wb-metric__label">异常</div>
          </div>
        </div>
      </div>
      <div v-else class="wb-empty">
        <div class="wb-empty__circle"><i class="el-icon-time" /></div>
        <div class="wb-empty__title">本月暂无考勤数据</div>
        <div class="wb-empty__desc">打卡后将在此展示你的考勤概况</div>
      </div>
    </workbench-card>
  </template>
  
  <script>
  import { mapGetters } from 'vuex'
  import { getAttendanceMonthReport } from '@/api/extend/attendanceRecord'
  import WorkbenchCard from '../workbench-card.vue'
  
  export default {
    name: 'WidgetAttendanceMine',
    components: { WorkbenchCard },
    data() {
      return {
        loading: false,
        found: false,
        stats: { normal: 0, late: 0, abnormal: 0 }
      }
    },
    computed: {
      ...mapGetters(['userInfo']),
      month() {
        const d = new Date()
        return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}`
      },
      monthLabel() {
        return `${this.month} · 本人`
      },
      hasData() {
        return this.found
      },
      myUserId() {
        return (this.userInfo && (this.userInfo.userId || this.userInfo.id)) || ''
      }
    },
    mounted() {
      this.load()
    },
    methods: {
      unwrap(res) {
        if (!res || typeof res !== 'object') return {}
        let inner = res.data != null ? res.data : res
        if (inner && typeof inner === 'object' && inner.data != null && (inner.data.list != null || inner.data.List != null)) {
          inner = inner.data
        }
        return inner && typeof inner === 'object' ? inner : {}
      },
      async load() {
        if (!this.myUserId) {
          this.found = false
          return
        }
        this.loading = true
        try {
          const res = await getAttendanceMonthReport({
            month: this.month,
            currentPage: 1,
            pageSize: 200
          })
          const data = this.unwrap(res)
          const list = data.list || data.List || []
          const me = list.find(r => String(r.userId || r.UserId || '') === String(this.myUserId))
          if (me) {
            const ms = me.monthStats || me.MonthStats || {}
            this.stats = {
              normal: Number(ms.normal != null ? ms.normal : ms.Normal) || 0,
              late: Number(ms.late != null ? ms.late : ms.Late) || 0,
              abnormal: Number(ms.abnormal != null ? ms.abnormal : ms.Abnormal) || 0
            }
            this.found = true
          } else {
            this.found = false
            this.stats = { normal: 0, late: 0, abnormal: 0 }
          }
        } catch (e) {
          this.found = false
          this.stats = { normal: 0, late: 0, abnormal: 0 }
        } finally {
          this.loading = false
        }
      },
      goMore() {
        this.$router.push('/attendance-record').catch(() => {})
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  @import '../widget-common.scss';
  </style>