Points.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <div class="page-container">
  3. <el-card>
  4. <PageHeader slot="header" title="积分管理">
  5. <el-button type="primary" size="small" @click="handleRefresh" :loading="loading">刷新</el-button>
  6. </PageHeader>
  7. <!-- 搜索筛选 -->
  8. <el-form :inline="true" :model="searchForm" class="form-mb20">
  9. <el-form-item label="成员姓名">
  10. <el-input
  11. v-model="searchForm.keyword"
  12. placeholder="请输入成员姓名"
  13. clearable
  14. @keyup.enter.native="handleSearch"
  15. ></el-input>
  16. </el-form-item>
  17. <el-form-item label="家庭">
  18. <el-select
  19. v-model="searchForm.familyId"
  20. placeholder="全部家庭"
  21. clearable
  22. filterable
  23. class="select-220"
  24. @change="handleSearch"
  25. >
  26. <el-option
  27. v-for="f in familyOptions"
  28. :key="f.id"
  29. :label="f.name"
  30. :value="f.id"
  31. ></el-option>
  32. </el-select>
  33. </el-form-item>
  34. <el-form-item label="类型">
  35. <el-select v-model="searchForm.type" placeholder="全部类型" clearable @change="handleSearch">
  36. <el-option label="获得" value="earn"></el-option>
  37. <el-option label="消耗" value="spend"></el-option>
  38. <el-option label="奖励" value="bonus"></el-option>
  39. <el-option label="扣罚" value="penalty"></el-option>
  40. <el-option label="调整" value="adjust"></el-option>
  41. <el-option label="退还" value="refund"></el-option>
  42. </el-select>
  43. </el-form-item>
  44. <el-form-item>
  45. <el-button type="primary" @click="handleSearch">搜索</el-button>
  46. <el-button @click="handleReset">重置</el-button>
  47. </el-form-item>
  48. </el-form>
  49. <!-- 积分流水列表 -->
  50. <div class="adm-table-wrap">
  51. <el-table :data="tableData" border v-loading="loading" class="table-full" height="100%">
  52. <el-table-column prop="id" label="ID" width="80">
  53. <template slot="header">
  54. <span class="sort-header" @click.stop="onSortClick('id', $event)">ID<span v-if="sortIndex('id') !== null" class="sort-index" :class="sortClass('id') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('id') }}</span>{{ sortIcon('id') }}</span>
  55. </template>
  56. </el-table-column>
  57. <el-table-column prop="memberName" label="成员姓名" width="140">
  58. <template slot-scope="scope">
  59. <span>{{ scope.row.memberName || '-' }}</span>
  60. </template>
  61. </el-table-column>
  62. <el-table-column prop="familyName" label="所属家庭" min-width="180">
  63. <template slot-scope="scope">
  64. <span>{{ scope.row.familyName || '-' }}</span>
  65. </template>
  66. </el-table-column>
  67. <el-table-column prop="amount" label="积分变动" width="120">
  68. <template slot-scope="scope">
  69. <span :style="{ color: scope.row.amount > 0 ? 'var(--adm-success)' : 'var(--adm-error)', fontWeight: 'bold' }">
  70. {{ scope.row.amount > 0 ? '+' : '' }}{{ scope.row.amount }}
  71. </span>
  72. </template>
  73. <template slot="header">
  74. <span class="sort-header" @click.stop="onSortClick('amount', $event)">积分变动<span v-if="sortIndex('amount') !== null" class="sort-index" :class="sortClass('amount') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('amount') }}</span>{{ sortIcon('amount') }}</span>
  75. </template>
  76. </el-table-column>
  77. <el-table-column prop="type" label="类型" width="100">
  78. <template slot-scope="scope">
  79. <StatusTag :type="getTypeTag(scope.row.type)" :text="getTypeText(scope.row.type)" size="small" />
  80. </template>
  81. <template slot="header">
  82. <span class="sort-header" @click.stop="onSortClick('type', $event)">类型<span v-if="sortIndex('type') !== null" class="sort-index" :class="sortClass('type') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('type') }}</span>{{ sortIcon('type') }}</span>
  83. </template>
  84. </el-table-column>
  85. <el-table-column prop="description" label="描述" min-width="200">
  86. <template slot="header">
  87. <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>
  88. </template>
  89. </el-table-column>
  90. <el-table-column prop="taskId" label="任务ID" width="100">
  91. <template slot-scope="scope">
  92. <span>{{ scope.row.taskId || '-' }}</span>
  93. </template>
  94. <template slot="header">
  95. <span class="sort-header" @click.stop="onSortClick('taskId', $event)">任务ID<span v-if="sortIndex('taskId') !== null" class="sort-index" :class="sortClass('taskId') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('taskId') }}</span>{{ sortIcon('taskId') }}</span>
  96. </template>
  97. </el-table-column>
  98. <el-table-column prop="createdAt" label="时间" width="180">
  99. <template slot-scope="scope">
  100. {{ formatDate(scope.row.createdAt) }}
  101. </template>
  102. <template slot="header">
  103. <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>
  104. </template>
  105. </el-table-column>
  106. </el-table>
  107. </div>
  108. <!-- 分页 -->
  109. <el-pagination
  110. class="pagination-right-20"
  111. @size-change="handleSizeChange"
  112. @current-change="handleCurrentChange"
  113. :current-page="pagination.current"
  114. :page-sizes="[10, 20, 50, 100]"
  115. :page-size="pagination.size"
  116. :total="pagination.total"
  117. layout="total, sizes, prev, pager, next, jumper"
  118. ></el-pagination>
  119. </el-card>
  120. </div>
  121. </template>
  122. <script>
  123. import SortMixin from '@/mixins/SortMixin'
  124. import ListStateMixin from '@/mixins/ListStateMixin'
  125. import { getPointsLogs, getFamilyList } from '@/api/admin'
  126. export default {
  127. name: 'Points',
  128. mixins: [SortMixin, ListStateMixin],
  129. computed: {
  130. tableHeight() {
  131. return window.innerHeight - 340
  132. }
  133. },
  134. data() {
  135. return {
  136. loading: false,
  137. tableData: [],
  138. familyOptions: [],
  139. sortableColumns: { id: 'ID', amount: '积分变动', type: '类型', description: '描述', taskId: '任务ID', createdAt: '时间' },
  140. searchForm: {
  141. keyword: '',
  142. familyId: '',
  143. type: ''
  144. },
  145. pagination: {
  146. current: 1,
  147. size: 10,
  148. total: 0
  149. }
  150. }
  151. },
  152. mounted() {
  153. this.loadFamilyOptions()
  154. this.loadPointsLogs()
  155. },
  156. methods: {
  157. async loadFamilyOptions() {
  158. try {
  159. const res = await getFamilyList({ page: 1, size: 500 })
  160. this.familyOptions = (res.data && res.data.records) ? res.data.records : (res.data || [])
  161. } catch (error) {
  162. this.familyOptions = []
  163. }
  164. },
  165. loadList() {
  166. this.loadPointsLogs()
  167. },
  168. async loadPointsLogs() {
  169. this.loading = true
  170. try {
  171. const params = {
  172. page: this.pagination.current,
  173. size: this.pagination.size,
  174. ...this.searchForm
  175. }
  176. if (this.sortState.length > 0) params.sort = this.sortState
  177. const res = await getPointsLogs(params)
  178. this.tableData = res.data.records || res.data || []
  179. this.pagination.total = res.data.total || this.tableData.length
  180. } catch (error) {
  181. this.$message.error(error.message || '加载积分流水失败')
  182. } finally {
  183. this.loading = false
  184. }
  185. },
  186. handleSearch() {
  187. this.pagination.current = 1
  188. this.loadPointsLogs()
  189. },
  190. handleReset() {
  191. this.searchForm = {
  192. keyword: '',
  193. familyId: '',
  194. type: ''
  195. }
  196. this.handleSearch()
  197. },
  198. handleRefresh() {
  199. this.loadPointsLogs()
  200. },
  201. handleSizeChange(val) {
  202. this.pagination.size = val
  203. this.pagination.current = 1
  204. this.loadPointsLogs()
  205. },
  206. handleCurrentChange(val) {
  207. this.pagination.current = val
  208. this.loadPointsLogs()
  209. },
  210. getTypeTag(type) {
  211. const tags = {
  212. earn: 'success',
  213. spend: 'warning',
  214. bonus: 'success',
  215. penalty: 'danger',
  216. adjust: 'info',
  217. reset: 'warning',
  218. refund: 'success'
  219. }
  220. return tags[type] || 'info'
  221. },
  222. getTypeText(type) {
  223. const texts = {
  224. earn: '获得',
  225. spend: '消耗',
  226. bonus: '奖励',
  227. penalty: '扣罚',
  228. adjust: '调整',
  229. reset: '清零',
  230. refund: '退还'
  231. }
  232. return texts[type] || type
  233. },
  234. }
  235. }
  236. </script>
  237. <style scoped>
  238. /* == C 批内联清理工具类 == */
  239. .form-mb20 { margin-bottom: 24px; }
  240. .select-220 { width: 220px; }
  241. .table-full { width: 100%; }
  242. .pagination-right-20 { margin-top: 24px; text-align: right; }
  243. </style>