Blame view

antis-ncc-admin/src/components/kpi-drill/mixins.js 1.09 KB
5e0c6e5a   “wangming”   feat: 完善会员画像功能,优化...
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
  import request from '@/utils/request'
  import dayjs from 'dayjs'
  
  /**
   * KPI穿透组件公共mixin
   */
  export const kpiDrillMixin = {
    methods: {
      formatMoney(v) {
        const num = Number(v || 0)
        return num.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })
      },
      buildDateRange() {
        const { startTime, endTime } = this.filters || {}
        if (!startTime || !endTime) return null
        const start = dayjs(startTime).format('YYYY-MM-DD')
        const end = dayjs(endTime).format('YYYY-MM-DD')
        const startTs = dayjs(`${start} 00:00:00`).valueOf()
        const endTs = dayjs(`${end} 23:59:59`).valueOf()
        return { start, end, startTs, endTs }
      },
      getStoreId() {
        return (this.filters && this.filters.storeIds && this.filters.storeIds.length === 1)
          ? this.filters.storeIds[0]
          : undefined
      },
      getMonth() {
        return this.filters && this.filters.month
          ? this.filters.month.toString()
          : (this.buildDateRange() ? dayjs(this.buildDateRange().start).format('YYYYMM') : dayjs().format('YYYYMM'))
      }
    }
  }