Quellcode durchsuchen

feat(admin): PointsPanel 家庭工作台内嵌组件(familyId 锁定)

Xiaogang Liao vor 2 Tagen
Ursprung
Commit
e54c7b0525
1 geänderte Dateien mit 207 neuen und 0 gelöschten Zeilen
  1. 207 0
      cfc-web/src/views/admin/PointsPanel.vue

+ 207 - 0
cfc-web/src/views/admin/PointsPanel.vue

@@ -0,0 +1,207 @@
+<template>
+  <div class="points-panel">
+    <div class="admin-page-actions">
+      <el-select v-model="filter.type" placeholder="类型筛选" size="mini" clearable @change="handleSearch">
+        <el-option label="全部" value="" />
+        <el-option label="任务奖励" value="task" />
+        <el-option label="系统调整" value="adjust" />
+        <el-option label="兑换扣除" value="exchange" />
+        <el-option label="退款返还" value="refund" />
+        <el-option label="超时扣分" value="timeout" />
+      </el-select>
+      <el-select v-model="filter.category" placeholder="分类筛选" size="mini" clearable @change="handleSearch">
+        <el-option label="全部" value="" />
+        <el-option label="任务积分" value="task" />
+        <el-option label="系统积分" value="system" />
+      </el-select>
+      <el-input v-model="filter.childKeyword" placeholder="搜索孩子 ID..." prefix-icon="el-icon-search" size="mini" clearable @keyup.enter.native="handleSearch" @clear="handleSearch" />
+      <el-tag size="small" type="info">当前家庭 #{{ familyId }}</el-tag>
+    </div>
+
+    <div class="adm-table-wrap">
+      <el-table height="100%" :data="list" v-loading="loading" border stripe>
+        <el-table-column prop="createdAt" label="时间" width="160">
+          <template slot-scope="{ row }">{{ formatTime(row.createdAt) }}</template>
+          <template slot="header">
+            <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>
+          </template>
+        </el-table-column>
+        <el-table-column prop="childId" label="孩子ID" width="80">
+          <template slot="header">
+            <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>
+          </template>
+        </el-table-column>
+        <el-table-column label="类型" width="100">
+          <template slot-scope="{ row }">{{ typeLabel(row.type) }}</template>
+        </el-table-column>
+        <el-table-column label="分类" width="100">
+          <template slot-scope="{ row }">
+            <StatusTag size="mini" :type="row.category === 'task' ? 'success' : 'warning'" :text="row.category === 'task' ? '任务积分' : '系统积分'" />
+          </template>
+        </el-table-column>
+        <el-table-column label="变动" width="100">
+          <template slot-scope="{ row }">
+            <span :style="{ color: row.amount > 0 ? 'var(--adm-success)' : 'var(--adm-error-text)', fontWeight: 'bold' }">
+              {{ row.amount > 0 ? '+' : '' }}{{ row.amount }}
+            </span>
+          </template>
+        </el-table-column>
+        <el-table-column prop="description" label="描述" min-width="200" show-overflow-tooltip>
+          <template slot="header">
+            <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>
+          </template>
+        </el-table-column>
+        <el-table-column prop="expireAt" label="过期时间" width="160">
+          <template slot-scope="{ row }">
+            <span v-if="row.expireAt" :style="{ color: row.expired ? 'var(--adm-text-45)' : 'var(--adm-warning-text)' }">
+              {{ formatTime(row.expireAt) }}
+            </span>
+            <span v-else class="no-image">永久有效</span>
+          </template>
+          <template slot="header">
+            <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>
+          </template>
+        </el-table-column>
+        <el-table-column label="操作" width="100" fixed="right">
+          <template slot-scope="{ row }">
+            <el-button size="mini" type="primary" @click="handleDetail(row)">详情</el-button>
+          </template>
+        </el-table-column>
+      </el-table>
+    </div>
+
+    <el-pagination
+        v-if="total > 0"
+        @size-change="handleSizeChange"
+        @current-change="handlePageChange"
+        :current-page="filter.page"
+        :page-sizes="[10, 20, 50]"
+        :page-size="filter.size"
+        layout="total, sizes, prev, pager, next, jumper"
+        :total="total"
+        class="pagination-wrap"
+      />
+
+    <!-- 详情对话框 -->
+    <el-dialog title="积分记录详情" :visible.sync="detailVisible" width="500px">
+      <div v-if="currentRow" class="detail-content">
+        <el-descriptions :column="2" border>
+          <el-descriptions-item label="记录ID">{{ currentRow.id }}</el-descriptions-item>
+          <el-descriptions-item label="孩子ID">{{ currentRow.childId }}</el-descriptions-item>
+          <el-descriptions-item label="类型">{{ typeLabel(currentRow.type) }}</el-descriptions-item>
+          <el-descriptions-item label="分类">
+            <StatusTag size="mini" :type="currentRow.category === 'task' ? 'success' : 'warning'" :text="currentRow.category === 'task' ? '任务积分' : '系统积分'" />
+          </el-descriptions-item>
+          <el-descriptions-item label="变动">
+            <span :style="{ color: currentRow.amount > 0 ? 'var(--adm-success)' : 'var(--adm-error-text)', fontWeight: 'bold' }">
+              {{ currentRow.amount > 0 ? '+' : '' }}{{ currentRow.amount }}
+            </span>
+          </el-descriptions-item>
+          <el-descriptions-item label="过期时间">
+            {{ currentRow.expireAt ? formatTime(currentRow.expireAt) : '永久有效' }}
+          </el-descriptions-item>
+          <el-descriptions-item label="描述" :span="2">{{ currentRow.description || '—' }}</el-descriptions-item>
+          <el-descriptions-item label="创建时间" :span="2">{{ formatTime(currentRow.createdAt) }}</el-descriptions-item>
+        </el-descriptions>
+      </div>
+    </el-dialog>
+  </div>
+</template>
+
+<script>
+import SortMixin from '@/mixins/SortMixin'
+import { getPointsLogs } from '@/api/admin'
+
+const TYPE_MAP = {
+  task: { label: '任务奖励', type: 'success' },
+  adjust: { label: '系统调整', type: 'warning' },
+  exchange: { label: '兑换扣除', type: 'danger' },
+  refund: { label: '退款返还', type: 'info' },
+  timeout: { label: '超时扣分', type: 'danger' }
+}
+
+export default {
+  name: 'PointsPanel',
+  mixins: [SortMixin],
+  props: {
+    familyId: {
+      type: [Number, String],
+      default: null
+    }
+  },
+  data() {
+    return {
+      loading: false,
+      list: [],
+      total: 0,
+      filter: {
+        type: '',
+        category: '',
+        childKeyword: '',
+        page: 1,
+        size: 10
+      },
+      detailVisible: false,
+      currentRow: null,
+      sortableColumns: { createdAt: '时间', childId: '孩子ID', description: '描述', expireAt: '过期时间' }
+    }
+  },
+  created() {
+    this.loadData()
+  },
+  methods: {
+    typeLabel(type) {
+      return (TYPE_MAP[type] && TYPE_MAP[type].label) || type || '—'
+    },
+
+    async loadData() {
+      this.loading = true
+      try {
+        const params = {
+          page: this.filter.page,
+          size: this.filter.size
+        }
+        if (this.filter.type) params.type = this.filter.type
+        if (this.filter.category) params.category = this.filter.category
+        if (this.filter.childKeyword) {
+          const childId = parseInt(this.filter.childKeyword)
+          if (!isNaN(childId)) params.memberId = childId
+        }
+        if (this.familyId != null) params.familyId = this.familyId
+        if (this.sortState.length > 0) params.sort = this.sortState
+        const res = await getPointsLogs(params)
+        this.list = (res.data && res.data.records) || []
+        this.total = (res.data && res.data.total) || 0
+      } catch (e) {
+        this.$message && this.$message.error && this.$message.error('加载积分记录失败')
+      } finally {
+        this.loading = false
+      }
+    },
+    handleSizeChange(size) {
+      this.filter.size = size
+      this.filter.page = 1
+      this.loadData()
+    },
+    handlePageChange(page) {
+      this.filter.page = page
+      this.loadData()
+    },
+    handleSearch() {
+      this.filter.page = 1
+      this.loadData()
+    },
+    handleDetail(row) {
+      this.currentRow = row
+      this.detailVisible = true
+    }
+  }
+}
+</script>
+
+<style scoped>
+.admin-page-actions { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
+.adm-table-wrap { margin-bottom: 16px; }
+.detail-content { padding: 10px 0; }
+.no-image { color: var(--adm-text-45); }
+</style>