ソースを参照

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

Xiaogang Liao 21 時間 前
親
コミット
811d73b351
1 ファイル変更、359 行追加、0 行削除
  1. 359 0
      cfc-web/src/views/admin/RewardsPanel.vue

+ 359 - 0
cfc-web/src/views/admin/RewardsPanel.vue

@@ -0,0 +1,359 @@
+<template>
+  <div class="rewards-panel">
+    <el-tabs v-model="activeTab" @tab-click="handleTabClick">
+      <!-- 奖励列表 -->
+      <el-tab-pane label="奖励列表" name="list">
+        <!-- 搜索筛选(家庭锁定) -->
+        <el-form :inline="true" :model="searchForm" class="mb-20">
+          <el-form-item label="家庭">
+            <el-input :value="familyId" disabled class="family-lock-input"></el-input>
+          </el-form-item>
+          <el-form-item label="状态">
+            <el-select v-model="searchForm.status" placeholder="全部状态" clearable @change="handleSearch">
+              <el-option label="可用" value="available"></el-option>
+              <el-option label="待审批" value="pending"></el-option>
+              <el-option label="已兑换" value="exchanged"></el-option>
+              <el-option label="已拒绝" value="rejected"></el-option>
+            </el-select>
+          </el-form-item>
+          <el-form-item>
+            <el-button type="primary" @click="handleSearch">搜索</el-button>
+            <el-button @click="handleReset">重置</el-button>
+          </el-form-item>
+        </el-form>
+
+        <div class="adm-table-wrap">
+          <el-table :data="tableData" border v-loading="loading" class="full-width" height="100%">
+            <el-table-column prop="id" label="ID" width="80">
+              <template slot="header">
+                <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>
+              </template>
+            </el-table-column>
+            <el-table-column prop="title" label="奖励名称" min-width="200">
+              <template slot="header">
+                <span class="sort-header" @click.stop="onSortClick('title', $event)">奖励名称<span v-if="sortIndex('title') !== null" class="sort-index" :class="sortClass('title') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('title') }}</span>{{ sortIcon('title') }}</span>
+              </template>
+            </el-table-column>
+            <el-table-column prop="pointsRequired" label="所需积分" width="120">
+              <template slot-scope="scope">
+                <StatusTag type="warning" :text="String(scope.row.pointsRequired)" />
+              </template>
+              <template slot="header">
+                <span class="sort-header" @click.stop="onSortClick('pointsRequired', $event)">所需积分<span v-if="sortIndex('pointsRequired') !== null" class="sort-index" :class="sortClass('pointsRequired') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('pointsRequired') }}</span>{{ sortIcon('pointsRequired') }}</span>
+              </template>
+            </el-table-column>
+            <el-table-column prop="category" label="分类" width="100">
+              <template slot="header">
+                <span class="sort-header" @click.stop="onSortClick('category', $event)">分类<span v-if="sortIndex('category') !== null" class="sort-index" :class="sortClass('category') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('category') }}</span>{{ sortIcon('category') }}</span>
+              </template>
+            </el-table-column>
+            <el-table-column prop="familyId" label="家庭ID" width="80">
+              <template slot="header">
+                <span class="sort-header" @click.stop="onSortClick('familyId', $event)">家庭ID<span v-if="sortIndex('familyId') !== null" class="sort-index" :class="sortClass('familyId') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('familyId') }}</span>{{ sortIcon('familyId') }}</span>
+              </template>
+            </el-table-column>
+            <el-table-column prop="status" label="状态" width="100">
+              <template slot-scope="scope">
+                <StatusTag :type="getStatusType(scope.row.status)" :text="getStatusText(scope.row.status)" size="small" />
+              </template>
+              <template slot="header">
+                <span class="sort-header" @click.stop="onSortClick('status', $event)">状态<span v-if="sortIndex('status') !== null" class="sort-index" :class="sortClass('status') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('status') }}</span>{{ sortIcon('status') }}</span>
+              </template>
+            </el-table-column>
+            <el-table-column prop="createdAt" label="创建时间" width="180">
+              <template slot-scope="scope">
+                {{ formatDate(scope.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 label="操作" width="200" fixed="right">
+              <template slot-scope="{ row }">
+                <el-button
+                  v-if="row.status === 'pending'"
+                  size="mini"
+                  type="primary"
+                  @click="handleApprove(row, true)"
+                >
+                  通过
+                </el-button>
+                <el-dropdown v-if="row.status === 'pending'" trigger="hover" @command="(cmd) => handleActionCmd(row, cmd)">
+                  <el-button size="mini">
+                    更多<i class="el-icon-arrow-down el-icon--right"></i>
+                  </el-button>
+                  <el-dropdown-menu slot="dropdown">
+                    <el-dropdown-item command="reject" icon="el-icon-close">拒绝</el-dropdown-item>
+                  </el-dropdown-menu>
+                </el-dropdown>
+              </template>
+            </el-table-column>
+          </el-table>
+        </div>
+
+        <el-pagination
+          class="pagination-mt20"
+          @size-change="handleSizeChange"
+          @current-change="handleCurrentChange"
+          :current-page="pagination.current"
+          :page-sizes="[10, 20, 50, 100]"
+          :page-size="pagination.size"
+          :total="pagination.total"
+          layout="total, sizes, prev, pager, next, jumper"
+        ></el-pagination>
+      </el-tab-pane>
+
+      <!-- 奖励模板(全局配置,照搬原页面) -->
+      <el-tab-pane label="奖励模板" name="templates">
+        <el-button type="primary" size="small" class="mb-15" @click="showCreateTemplate">
+          新建模板
+        </el-button>
+        <div class="adm-table-wrap">
+          <el-table :data="templates" border v-loading="loadingTemplates" class="full-width" height="100%">
+            <el-table-column prop="id" label="ID" width="80"></el-table-column>
+            <el-table-column prop="title" label="模板名称" min-width="200"></el-table-column>
+            <el-table-column prop="pointsRequired" label="所需积分" width="120">
+              <template slot-scope="scope">
+                <StatusTag type="warning" :text="String(scope.row.pointsRequired)" />
+              </template>
+            </el-table-column>
+            <el-table-column prop="category" label="分类" width="100"></el-table-column>
+            <el-table-column prop="createdAt" label="创建时间" width="180">
+              <template slot-scope="scope">
+                {{ formatDate(scope.row.createdAt) }}
+              </template>
+            </el-table-column>
+            <el-table-column label="操作" width="150" fixed="right">
+              <template slot-scope="{ row }">
+                <el-button size="mini" @click="handleDeleteTemplate(row)">删除</el-button>
+              </template>
+            </el-table-column>
+          </el-table>
+        </div>
+      </el-tab-pane>
+    </el-tabs>
+
+    <!-- 创建奖励模板对话框 -->
+    <el-dialog title="新建奖励模板" :visible.sync="dialogVisible" width="500px">
+      <el-form :model="templateForm" label-width="100px">
+        <el-form-item label="奖励名称">
+          <el-input v-model="templateForm.title" placeholder="请输入奖励名称"></el-input>
+        </el-form-item>
+        <el-form-item label="所需积分">
+          <el-input-number v-model="templateForm.pointsRequired" :min="1" :max="10000"></el-input-number>
+        </el-form-item>
+        <el-form-item label="分类">
+          <el-select v-model="templateForm.category" placeholder="请选择分类">
+            <el-option label="玩具" value="玩具"></el-option>
+            <el-option label="图书" value="图书"></el-option>
+            <el-option label="美食" value="美食"></el-option>
+            <el-option label="娱乐" value="娱乐"></el-option>
+            <el-option label="其他" value="其他"></el-option>
+          </el-select>
+        </el-form-item>
+      </el-form>
+      <div slot="footer">
+        <el-button @click="dialogVisible = false">取消</el-button>
+        <el-button type="primary" @click="handleCreateTemplate" :loading="creating">确定</el-button>
+      </div>
+    </el-dialog>
+  </div>
+</template>
+
+<script>
+import SortMixin from '@/mixins/SortMixin'
+import { getRewardsList, getRewardTemplates, createRewardTemplate, deleteRewardTemplate, approveReward } from '@/api/admin'
+
+export default {
+  name: 'RewardsPanel',
+  mixins: [SortMixin],
+  props: {
+    familyId: {
+      type: [Number, String],
+      default: null
+    }
+  },
+  data() {
+    return {
+      activeTab: 'list',
+      loading: false,
+      loadingTemplates: false,
+      tableData: [],
+      templates: [],
+      sortableColumns: { id: 'ID', title: '奖励名称', pointsRequired: '所需积分', category: '分类', familyId: '家庭ID', status: '状态', createdAt: '创建时间' },
+      searchForm: {
+        status: ''
+      },
+      pagination: {
+        current: 1,
+        size: 10,
+        total: 0
+      },
+      dialogVisible: false,
+      creating: false,
+      templateForm: {
+        title: '',
+        pointsRequired: 100,
+        category: ''
+      }
+    }
+  },
+  mounted() {
+    this.loadRewards()
+  },
+  methods: {
+    handleActionCmd(row, cmd) {
+      switch (cmd) {
+        case 'approve': this.handleApprove(row, true); break;
+        case 'reject': this.handleApprove(row, false); break;
+        case 'deleteTemplate': this.handleDeleteTemplate(row); break;
+      }
+    },
+    async loadRewards() {
+      this.loading = true
+      try {
+        const params = {
+          page: this.pagination.current,
+          size: this.pagination.size,
+          status: this.searchForm.status
+        }
+        if (this.familyId != null) params.familyId = this.familyId
+        if (this.sortState.length > 0) params.sort = this.sortState
+        const res = await getRewardsList(params)
+        this.tableData = res.data.records || res.data || []
+        this.pagination.total = res.data.total || this.tableData.length
+      } catch (error) {
+        this.$message.error(error.message || '加载奖励列表失败')
+      } finally {
+        this.loading = false
+      }
+    },
+    async loadTemplates() {
+      this.loadingTemplates = true
+      try {
+        const res = await getRewardTemplates()
+        this.templates = res.data || []
+      } catch (error) {
+        this.$message.error(error.message || '加载模板失败')
+      } finally {
+        this.loadingTemplates = false
+      }
+    },
+    handleTabClick(tab) {
+      if (tab.name === 'templates' && this.templates.length === 0) {
+        this.loadTemplates()
+      }
+    },
+    handleSearch() {
+      this.pagination.current = 1
+      this.loadRewards()
+    },
+    handleReset() {
+      this.searchForm = {
+        status: ''
+      }
+      this.handleSearch()
+    },
+    handleSizeChange(val) {
+      this.pagination.size = val
+      this.pagination.current = 1
+      this.loadRewards()
+    },
+    handleCurrentChange(val) {
+      this.pagination.current = val
+      this.loadRewards()
+    },
+    async handleApprove(row, approved) {
+      this.$confirm(
+        approved ? `确定通过 "${row.title}" 的兑换申请吗?` : `确定拒绝 "${row.title}" 的兑换申请吗?`,
+        '提示',
+        {
+          confirmButtonText: '确定',
+          cancelButtonText: '取消',
+          type: 'warning'
+        }
+      ).then(async () => {
+        try {
+          await approveReward(row.id, { approved })
+          this.$message.success(approved ? '已通过' : '已拒绝')
+          this.loadRewards()
+        } catch (error) {
+          this.$message.error(error.message || '操作失败')
+        }
+      }).catch(() => {})
+    },
+    getStatusType(status) {
+      const types = {
+        available: 'success',
+        pending: 'warning',
+        exchanged: 'info',
+        rejected: 'danger'
+      }
+      return types[status] || 'info'
+    },
+    getStatusText(status) {
+      const texts = {
+        available: '可用',
+        pending: '待审批',
+        exchanged: '已兑换',
+        rejected: '已拒绝'
+      }
+      return texts[status] || status
+    },
+    showCreateTemplate() {
+      this.templateForm = {
+        title: '',
+        pointsRequired: 100,
+        category: ''
+      }
+      this.dialogVisible = true
+    },
+    async handleCreateTemplate() {
+      if (!this.templateForm.title) {
+        this.$message.warning('请输入奖励名称')
+        return
+      }
+      if (!this.templateForm.category) {
+        this.$message.warning('请选择分类')
+        return
+      }
+      this.creating = true
+      try {
+        await createRewardTemplate(this.templateForm)
+        this.$message.success('创建成功')
+        this.dialogVisible = false
+        this.loadTemplates()
+      } catch (error) {
+        this.$message.error(error.message || '创建失败')
+      } finally {
+        this.creating = false
+      }
+    },
+    handleDeleteTemplate(row) {
+      this.$confirm('确定要删除该模板吗?', '提示', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning'
+      }).then(async () => {
+        try {
+          await deleteRewardTemplate(row.id)
+          this.$message.success('删除成功')
+          this.loadTemplates()
+        } catch (error) {
+          this.$message.error(error.message || '删除失败')
+        }
+      }).catch(() => {})
+    }
+  }
+}
+</script>
+
+<style scoped>
+.family-lock-input { width: 140px; }
+.mb-20 { margin-bottom: 24px; }
+.mb-15 { margin-bottom: 15px; }
+.cursor-pointer { cursor: pointer; }
+.pagination-mt15 { margin-top: 15px; text-align: right; }
+.pagination-mt20 { margin-top: 24px; text-align: right; }
+.full-width { width: 100%; }
+</style>