Blame view

store-pc/src/components/duplicate-recharge-confirm.vue 2.71 KB
2c37ef74   “wangming”   feat: 发布 V2.0.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
  <template>
    <span class="duplicate-recharge-confirm-host" />
  </template>
  
  <script>
  import { checkSameDayDuplicate } from '@/api/businessUnitDashboard'
  
  function formatBizDate(bizDate) {
    if (!bizDate) {
      const d = new Date()
      const m = `${d.getMonth() + 1}`.padStart(2, '0')
      const day = `${d.getDate()}`.padStart(2, '0')
      return `${d.getFullYear()}-${m}-${day}`
    }
    if (typeof bizDate === 'string') {
      return bizDate.length >= 10 ? bizDate.substring(0, 10) : bizDate
    }
    try {
      const d = new Date(bizDate)
      const m = `${d.getMonth() + 1}`.padStart(2, '0')
      const day = `${d.getDate()}`.padStart(2, '0')
      return `${d.getFullYear()}-${m}-${day}`
    } catch (e) {
      return ''
    }
  }
  
  /**
   * 同自然日重复充值确认组件(软提醒)
   * 用法:ref.checkAndConfirm({ memberId, bizDate, scene, excludeId }) => Promise<boolean>
   */
  export default {
    name: 'DuplicateRechargeConfirm',
    methods: {
      /**
       * @param {Object} options
       * @param {string} options.memberId
       * @param {string|Date} options.bizDate
       * @param {'Billing'|'Consume'} options.scene
       * @param {string} [options.excludeId]
       * @returns {Promise<boolean>} true 继续提交;false 取消
       */
      async checkAndConfirm(options = {}) {
        const memberId = options.memberId
        const scene = options.scene || 'Billing'
        if (!memberId) return true
  
        const bizDate = formatBizDate(options.bizDate)
  
        try {
          const res = await checkSameDayDuplicate({
            memberId,
            bizDate,
            scene,
            excludeId: options.excludeId || undefined
          })
          const data = (res && res.data) || {}
          const hasDuplicate = !!(data.HasDuplicate || data.hasDuplicate)
          if (!hasDuplicate) return true
  
          const existingCount = data.ExistingCount != null
            ? data.ExistingCount
            : (data.existingCount || 0)
c4040263   “wangming”   feat: V2.0.2 会员标签...
64
65
66
67
          const defaultMessage = scene === 'Consume'
            ? '该会员当日已有有效耗卡记录,请确认是否继续操作'
            : '该会员当日已有有效开单记录,请确认是否继续操作'
          const message = data.Message || data.message || defaultMessage
2c37ef74   “wangming”   feat: 发布 V2.0.1(事...
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
  
          try {
            await this.$confirm(
              `${message}${existingCount ? `(已有 ${existingCount} 笔)` : ''}`,
              '重复充值提醒',
              {
                confirmButtonText: '继续提交',
                cancelButtonText: '取消',
                type: 'warning'
              }
            )
            return true
          } catch (e) {
            return false
          }
        } catch (e) {
          // 校验接口失败不阻断业务提交
          console.error('重复充值校验失败:', e)
          return true
        }
      }
    }
  }
  </script>