PointsLog.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <div class="points-log admin-page">
  3. <el-card>
  4. <PageHeader slot="header" title="积分记录">
  5. <div class="admin-page-actions">
  6. <el-select v-model="filter.type" placeholder="类型筛选" size="mini" clearable @change="loadData">
  7. <el-option label="全部" value="" />
  8. <el-option label="任务奖励" value="task" />
  9. <el-option label="系统调整" value="adjust" />
  10. <el-option label="兑换扣除" value="exchange" />
  11. <el-option label="退款返还" value="refund" />
  12. <el-option label="超时扣分" value="timeout" />
  13. </el-select>
  14. <el-select v-model="filter.category" placeholder="分类筛选" size="mini" clearable @change="loadData">
  15. <el-option label="全部" value="" />
  16. <el-option label="任务积分" value="task" />
  17. <el-option label="系统积分" value="system" />
  18. </el-select>
  19. <el-input v-model="filter.childKeyword" placeholder="搜索孩子 ID..." prefix-icon="el-icon-search" size="mini" clearable @keyup.enter.native="handleSearch" @clear="handleSearch" />
  20. </div>
  21. </PageHeader>
  22. <div class="adm-table-wrap">
  23. <el-table height="100%" :data="list" v-loading="loading" border stripe>
  24. <el-table-column prop="createdAt" label="时间" width="160">
  25. <template slot-scope="{ row }">{{ formatTime(row.createdAt) }}</template>
  26. <template slot="header">
  27. <span class="sort-header" @click.stop="onSortClick('createdAt', $event)">时间<span v-if="sortIndex('createdAt') !== null" class="sort-index" :class="sortClass('createdAt') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('createdAt') }}</span>{{ sortIcon('createdAt') }}</span>
  28. </template>
  29. </el-table-column>
  30. <el-table-column prop="childId" label="孩子ID" width="80">
  31. <template slot="header">
  32. <span class="sort-header" @click.stop="onSortClick('childId', $event)">孩子ID<span v-if="sortIndex('childId') !== null" class="sort-index" :class="sortClass('childId') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('childId') }}</span>{{ sortIcon('childId') }}</span>
  33. </template>
  34. </el-table-column>
  35. <el-table-column label="类型" width="100">
  36. <template slot-scope="{ row }">{{ typeLabel(row.type) }}</template>
  37. </el-table-column>
  38. <el-table-column label="分类" width="100">
  39. <template slot-scope="{ row }">
  40. <StatusTag size="mini" :type="row.category === 'task' ? 'success' : 'warning'" :text="row.category === 'task' ? '任务积分' : '系统积分'" />
  41. </template>
  42. </el-table-column>
  43. <el-table-column label="变动" width="100">
  44. <template slot-scope="{ row }">
  45. <span :style="{ color: row.amount > 0 ? 'var(--adm-success)' : 'var(--adm-error-text)', fontWeight: 'bold' }">
  46. {{ row.amount > 0 ? '+' : '' }}{{ row.amount }}
  47. </span>
  48. </template>
  49. </el-table-column>
  50. <el-table-column prop="description" label="描述" min-width="200" show-overflow-tooltip>
  51. <template slot="header">
  52. <span class="sort-header" @click.stop="onSortClick('description', $event)">描述<span v-if="sortIndex('description') !== null" class="sort-index" :class="sortClass('description') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('description') }}</span>{{ sortIcon('description') }}</span>
  53. </template>
  54. </el-table-column>
  55. <el-table-column prop="expireAt" label="过期时间" width="160">
  56. <template slot-scope="{ row }">
  57. <span v-if="row.expireAt" :style="{ color: row.expired ? 'var(--adm-text-45)' : 'var(--adm-warning-text)' }">
  58. {{ formatTime(row.expireAt) }}
  59. </span>
  60. <span v-else class="no-image">永久有效</span>
  61. </template>
  62. <template slot="header">
  63. <span class="sort-header" @click.stop="onSortClick('expireAt', $event)">过期时间<span v-if="sortIndex('expireAt') !== null" class="sort-index" :class="sortClass('expireAt') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('expireAt') }}</span>{{ sortIcon('expireAt') }}</span>
  64. </template>
  65. </el-table-column>
  66. <el-table-column label="操作" width="200" fixed="right">
  67. <template slot-scope="{ row }">
  68. <el-button size="mini" type="primary" @click="handleDetail(row)">详情</el-button>
  69. <el-dropdown trigger="hover" @command="(cmd) => handleMoreCmd(row, cmd)">
  70. <el-button size="mini">
  71. 更多<i class="el-icon-arrow-down el-icon--right"></i>
  72. </el-button>
  73. <el-dropdown-menu slot="dropdown">
  74. <el-dropdown-item command="adjust" icon="el-icon-edit">手动调整</el-dropdown-item>
  75. </el-dropdown-menu>
  76. </el-dropdown>
  77. </template>
  78. </el-table-column>
  79. </el-table>
  80. </div>
  81. <el-pagination
  82. v-if="total > 0"
  83. @size-change="handleSizeChange"
  84. @current-change="handlePageChange"
  85. :current-page="filter.page"
  86. :page-sizes="[10, 20, 50]"
  87. :page-size="filter.size"
  88. layout="total, sizes, prev, pager, next, jumper"
  89. :total="total"
  90. class="pagination-wrap"
  91. />
  92. </el-card>
  93. <!-- 详情对话框 -->
  94. <el-dialog title="积分记录详情" :visible.sync="detailVisible" width="500px">
  95. <div v-if="currentRow" class="detail-content">
  96. <el-descriptions :column="2" border>
  97. <el-descriptions-item label="记录ID">{{ currentRow.id }}</el-descriptions-item>
  98. <el-descriptions-item label="孩子ID">{{ currentRow.childId }}</el-descriptions-item>
  99. <el-descriptions-item label="类型">{{ typeLabel(currentRow.type) }}</el-descriptions-item>
  100. <el-descriptions-item label="分类">
  101. <StatusTag size="mini" :type="currentRow.category === 'task' ? 'success' : 'warning'" :text="currentRow.category === 'task' ? '任务积分' : '系统积分'" />
  102. </el-descriptions-item>
  103. <el-descriptions-item label="变动">
  104. <span :style="{ color: currentRow.amount > 0 ? 'var(--adm-success)' : 'var(--adm-error-text)', fontWeight: 'bold' }">
  105. {{ currentRow.amount > 0 ? '+' : '' }}{{ currentRow.amount }}
  106. </span>
  107. </el-descriptions-item>
  108. <el-descriptions-item label="过期时间">
  109. {{ currentRow.expireAt ? formatTime(currentRow.expireAt) : '永久有效' }}
  110. </el-descriptions-item>
  111. <el-descriptions-item label="描述" :span="2">{{ currentRow.description || '—' }}</el-descriptions-item>
  112. <el-descriptions-item label="创建时间" :span="2">{{ formatTime(currentRow.createdAt) }}</el-descriptions-item>
  113. </el-descriptions>
  114. </div>
  115. </el-dialog>
  116. </div>
  117. </template>
  118. <script>
  119. import SortMixin from '@/mixins/SortMixin'
  120. import ListStateMixin from '@/mixins/ListStateMixin'
  121. import { getPointsLogs } from '@/api/admin'
  122. const TYPE_MAP = {
  123. task: { label: '任务奖励', type: 'success' },
  124. adjust: { label: '系统调整', type: 'warning' },
  125. exchange: { label: '兑换扣除', type: 'danger' },
  126. refund: { label: '退款返还', type: 'info' },
  127. timeout: { label: '超时扣分', type: 'danger' }
  128. }
  129. export default {
  130. name: 'PointsLog',
  131. mixins: [SortMixin, ListStateMixin],
  132. computed: {
  133. tableHeight() {
  134. return window.innerHeight - 300
  135. }
  136. },
  137. data() {
  138. return {
  139. loading: false,
  140. list: [],
  141. total: 0,
  142. filter: {
  143. type: '',
  144. category: '',
  145. childKeyword: '',
  146. page: 1,
  147. size: 10
  148. },
  149. detailVisible: false,
  150. currentRow: null,
  151. sortableColumns: { createdAt: '时间', childId: '孩子ID', description: '描述', expireAt: '过期时间' }
  152. }
  153. },
  154. created() {
  155. this.loadData()
  156. },
  157. methods: {
  158. typeLabel(type) {
  159. return (TYPE_MAP[type] && TYPE_MAP[type].label) || type || '—'
  160. },
  161. async loadData() {
  162. this.loading = true
  163. try {
  164. const params = {
  165. page: this.filter.page,
  166. size: this.filter.size
  167. }
  168. if (this.filter.type) params.type = this.filter.type
  169. if (this.filter.category) params.category = this.filter.category
  170. if (this.filter.childKeyword) {
  171. const childId = parseInt(this.filter.childKeyword)
  172. if (!isNaN(childId)) params.memberId = childId
  173. }
  174. if (this.sortState.length > 0) params.sort = this.sortState
  175. const res = await getPointsLogs(params)
  176. this.list = (res.data && res.data.records) || []
  177. this.total = (res.data && res.data.total) || 0
  178. } catch (e) {
  179. this.$message && this.$message.error && this.$message.error('加载积分记录失败')
  180. } finally {
  181. this.loading = false
  182. }
  183. },
  184. handleSizeChange(size) {
  185. this.filter.size = size
  186. this.filter.page = 1
  187. this.loadData()
  188. },
  189. handlePageChange(page) {
  190. this.filter.page = page
  191. this.loadData()
  192. },
  193. handleSearch() {
  194. this.filter.page = 1
  195. this.loadData()
  196. },
  197. handleDetail(row) {
  198. this.currentRow = row
  199. this.detailVisible = true
  200. },
  201. handleMoreCmd(row, cmd) {
  202. switch (cmd) {
  203. case 'adjust':
  204. this.$message.info('请在 "积分管理" 页面中对指定孩子进行积分调整')
  205. break
  206. }
  207. }
  208. }
  209. }
  210. </script>
  211. <style scoped>
  212. .points-log { padding: 24px; }
  213. .detail-content { padding: 10px 0; }
  214. /* == C 批内联清理工具类 == */
  215. .no-image { color: var(--adm-text-45); }
  216. </style>