doum
2026-06-18 93de43267e1663031fe5dc2f5ae40d128a182a76
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<template>
  <view class="cu-page cu-page--with-fab cu-recharge-record-page">
    <view class="cu-recharge-record-page__header">
      <view class="cu-recharge-filter-panel">
        <view class="cu-recharge-filter-panel__section">
          <text class="cu-recharge-filter-panel__label">充值状态</text>
          <scroll-view scroll-x class="cu-recharge-status-tabs" :show-scrollbar="false">
            <view
              v-for="(opt, i) in statusOptions"
              :key="opt.value == null ? 'all' : opt.value"
              :class="['cu-recharge-status-tab', statusIdx === i ? 'cu-recharge-status-tab--active' : '', opt.tabClass]"
              @click="switchStatus(i)"
            >{{ opt.label }}</view>
          </scroll-view>
        </view>
 
        <view class="cu-recharge-filter-panel__divider" />
 
        <view class="cu-recharge-filter-panel__section">
          <view class="cu-recharge-filter-panel__row">
            <text class="cu-recharge-filter-panel__label">时间筛选</text>
            <view class="cu-recharge-date-mode">
              <view
                :class="['cu-recharge-date-mode__item', dateMode === 'month' ? 'cu-recharge-date-mode__item--active' : '']"
                @click="switchDateMode('month')"
              >按月</view>
              <view
                :class="['cu-recharge-date-mode__item', dateMode === 'range' ? 'cu-recharge-date-mode__item--active' : '']"
                @click="switchDateMode('range')"
              >按时间段</view>
            </view>
          </view>
 
          <view class="cu-recharge-filter-panel__dates">
            <template v-if="dateMode === 'month'">
              <picker mode="date" fields="month" :value="monthPickerValue" @change="onMonthChange">
                <view :class="['cu-recharge-date-field', month ? 'cu-recharge-date-field--active' : '']">
                  <text class="cu-recharge-date-field__text">{{ monthLabel }}</text>
                  <text class="cu-recharge-date-field__arrow">▾</text>
                </view>
              </picker>
              <text v-if="month" class="cu-recharge-date-clear" @click="clearMonth">重置</text>
            </template>
 
            <template v-else>
              <view class="cu-recharge-date-range">
                <picker mode="date" fields="day" :value="dateStart || today" @change="onDateStartChange">
                  <view :class="['cu-recharge-date-field', dateStart ? 'cu-recharge-date-field--active' : '']">
                    <text class="cu-recharge-date-field__text">{{ dateStart || '开始日期' }}</text>
                    <text class="cu-recharge-date-field__arrow">▾</text>
                  </view>
                </picker>
                <text class="cu-recharge-date-sep">至</text>
                <picker mode="date" fields="day" :value="dateEnd || today" @change="onDateEndChange">
                  <view :class="['cu-recharge-date-field', dateEnd ? 'cu-recharge-date-field--active' : '']">
                    <text class="cu-recharge-date-field__text">{{ dateEnd || '结束日期' }}</text>
                    <text class="cu-recharge-date-field__arrow">▾</text>
                  </view>
                </picker>
              </view>
              <text v-if="dateStart || dateEnd" class="cu-recharge-date-clear" @click="clearRange">重置</text>
            </template>
          </view>
        </view>
      </view>
 
      <view class="cu-recharge-summary">
        <text class="cu-recharge-summary__count">{{ list.length }}</text>
        <text class="cu-recharge-summary__label">条充值记录</text>
      </view>
    </view>
 
    <view class="cu-list-wrap">
      <view v-for="item in list" :key="item.id" class="cu-recharge-card">
        <view :class="['cu-recharge-card__accent', accentClass(item)]" />
        <view class="cu-recharge-card__body">
          <view class="cu-recharge-card__top">
            <view :class="['cu-recharge-card__type', typeTagClass(item.type)]">
              <text class="cu-recharge-card__type-icon">{{ item.type === 1 ? '❄' : '⚡' }}</text>
              <text class="cu-recharge-card__type-text">{{ typeText(item.type) }}</text>
            </view>
            <text :class="['cu-status', statusClass(item.status)]">{{ item.statusText }}</text>
          </view>
 
          <text class="cu-recharge-card__title">{{ item.deviceInfo || item.name || '充值记录' }}</text>
          <text v-if="item.rechargeUserName" class="cu-recharge-card__operator">充值人 {{ item.rechargeUserName }}</text>
 
          <view class="cu-recharge-card__amount-box">
            <view class="cu-recharge-card__amount-main">
              <text class="cu-recharge-card__amount-label">充值金额</text>
              <text class="cu-recharge-card__amount-value">¥{{ formatMoney(item.money) }}</text>
            </view>
            <view class="cu-recharge-card__amount-side">
              <text class="cu-recharge-card__amount-label">充后余额</text>
              <text :class="['cu-recharge-card__amount-side-value', balanceToneClass(item.balanceAfter)]">{{ formatMoney(item.balanceAfter) }}</text>
            </view>
          </view>
 
          <view class="cu-recharge-card__foot">
            <text class="cu-recharge-card__time">{{ formatTime(item.createDate) }}</text>
          </view>
        </view>
      </view>
      <u-empty v-if="!list.length" text="暂无记录" margin-top="80" />
    </view>
    <cu-workbench-fab />
  </view>
</template>
 
<script>
import { customerRechargeRecordPage } from '@/api'
import { getBalanceTone } from '@/utils/utils.js'
 
const STATUS_OPTIONS = [
  { label: '全部', value: null, tabClass: '' },
  { label: '成功', value: 1, tabClass: 'cu-recharge-status-tab--ok' },
  { label: '失败', value: 2, tabClass: 'cu-recharge-status-tab--bad' },
  { label: '充值中', value: 0, tabClass: 'cu-recharge-status-tab--pending' }
]
 
export default {
  data () {
    const now = new Date()
    const today = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`
    return {
      list: [],
      dateMode: 'month',
      month: '',
      dateStart: '',
      dateEnd: '',
      today,
      statusIdx: 0,
      statusOptions: STATUS_OPTIONS
    }
  },
  computed: {
    monthPickerValue () {
      return this.month || this.today.substring(0, 7)
    },
    monthLabel () {
      if (!this.month) return '选择月份'
      const parts = this.month.split('-')
      if (parts.length >= 2) return `${parts[0]}年${parts[1]}月`
      return this.month
    }
  },
  onShow () {
    this.load()
  },
  methods: {
    load () {
      const model = { status: this.statusOptions[this.statusIdx].value }
      if (this.dateMode === 'month') {
        if (this.month) model.month = this.month
      } else {
        if (this.dateStart) model.createTimeBegin = `${this.dateStart} 00:00:00`
        if (this.dateEnd) model.createTimeEnd = `${this.dateEnd} 23:59:59`
      }
      customerRechargeRecordPage({
        page: 1,
        capacity: 50,
        model
      }).then(res => { this.list = (res.data && res.data.records) || [] })
    },
    switchStatus (i) {
      if (this.statusIdx === i) return
      this.statusIdx = i
      this.load()
    },
    switchDateMode (mode) {
      if (this.dateMode === mode) return
      this.dateMode = mode
      if (mode === 'month') {
        this.dateStart = ''
        this.dateEnd = ''
      } else {
        this.month = ''
      }
      this.load()
    },
    onMonthChange (e) {
      this.month = e.detail.value
      this.load()
    },
    onDateStartChange (e) {
      this.dateStart = e.detail.value
      if (this.dateEnd && this.dateStart > this.dateEnd) {
        this.dateEnd = this.dateStart
      }
      this.load()
    },
    onDateEndChange (e) {
      this.dateEnd = e.detail.value
      if (this.dateStart && this.dateEnd < this.dateStart) {
        this.dateStart = this.dateEnd
      }
      this.load()
    },
    clearMonth () {
      this.month = ''
      this.load()
    },
    clearRange () {
      this.dateStart = ''
      this.dateEnd = ''
      this.load()
    },
    typeText (type) {
      return type === 1 ? '空调充值' : '电表充值'
    },
    typeTagClass (type) {
      return type === 1 ? 'cu-recharge-card__type--conditioner' : 'cu-recharge-card__type--electric'
    },
    accentClass (item) {
      return item.type === 1 ? 'cu-recharge-card__accent--conditioner' : 'cu-recharge-card__accent--electric'
    },
    statusClass (s) {
      if (s === 1) return 'cu-status--ok'
      if (s === 2) return 'cu-status--bad'
      return 'cu-status--warn'
    },
    formatMoney (val) {
      if (val === null || val === undefined || val === '') return '-'
      const n = Number(val)
      return Number.isNaN(n) ? val : n.toFixed(2)
    },
    formatTime (t) {
      return t ? String(t).replace('T', ' ').substring(0, 19) : '-'
    },
    balanceToneClass (val) {
      const tone = getBalanceTone(val)
      return tone ? `cu-recharge-card__amount-side-value--${tone}` : ''
    }
  }
}
</script>