Browse Source

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

Xiaogang Liao 1 week ago
parent
commit
51ed41b9ef
1 changed files with 480 additions and 0 deletions
  1. 480 0
      cfc-web/src/views/admin/WishesPanel.vue

+ 480 - 0
cfc-web/src/views/admin/WishesPanel.vue

@@ -0,0 +1,480 @@
+<template>
+  <div class="wishes-panel">
+    <el-tabs v-model="activeTab" @tab-click="handleTabClick">
+      <!-- 待处理列表 -->
+      <el-tab-pane label="待处理" name="pending">
+        <!-- 统计卡片 -->
+        <el-row :gutter="20" class="mb-20">
+          <el-col :span="6">
+            <StatCard label="待定价" :value="draftCount" color="info" icon="el-icon-price-tag" />
+          </el-col>
+          <el-col :span="6">
+            <StatCard label="待审批" :value="pendingCount" color="warning" icon="el-icon-time" />
+          </el-col>
+          <el-col :span="6">
+            <StatCard label="待兑现" :value="approvedCount" color="primary" icon="el-icon-circle-check" />
+          </el-col>
+          <el-col :span="6">
+            <StatCard label="待收货" :value="exchangingCount" color="primary" icon="el-icon-box" />
+          </el-col>
+        </el-row>
+
+        <el-tag size="small" type="info" class="mb-20">当前家庭 #{{ familyId }}</el-tag>
+
+        <!-- 待定价列表 -->
+        <div v-if="draftWishes.length > 0" class="wish-section">
+          <SectionTitle title="待定价" />
+          <div class="adm-table-wrap">
+            <el-table class="full-width" height="100%" :data="draftWishes" border v-loading="loading">
+              <el-table-column prop="id" label="ID" width="80"></el-table-column>
+              <el-table-column prop="childName" label="孩子" width="100"></el-table-column>
+              <el-table-column prop="title" label="心愿名称" min-width="200"></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="200" fixed="right">
+                <template slot-scope="{ row }">
+                  <el-button size="mini" type="primary" @click="showPriceDialog(row)">定价</el-button>
+                  <el-dropdown 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>
+        </div>
+
+        <!-- 待审批兑换列表 -->
+        <div v-if="pendingExchangeWishes.length > 0" class="wish-section">
+          <SectionTitle title="⏳ 待审批兑换" />
+          <div class="adm-table-wrap">
+            <el-table :data="pendingExchangeWishes" border v-loading="loading" class="full-width" height="100%">
+              <el-table-column prop="id" label="ID" width="80"></el-table-column>
+              <el-table-column prop="childName" label="孩子" width="100"></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="exchangeRequestedAt" label="申请时间" width="180">
+                <template slot-scope="scope">
+                  {{ formatDate(scope.row.exchangeRequestedAt) }}
+                </template>
+              </el-table-column>
+              <el-table-column label="操作" width="200" fixed="right">
+                <template slot-scope="{ row }">
+                  <el-button size="mini" type="primary" @click="handleApproveExchange(row, true)">批准</el-button>
+                  <el-dropdown 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="rejectExchange" icon="el-icon-close">拒绝</el-dropdown-item>
+                    </el-dropdown-menu>
+                  </el-dropdown>
+                </template>
+              </el-table-column>
+            </el-table>
+          </div>
+        </div>
+
+        <!-- 待兑现列表 -->
+        <div v-if="approvedWishes.length > 0" class="wish-section">
+          <SectionTitle title="待兑现" />
+          <div class="adm-table-wrap">
+            <el-table :data="approvedWishes" border v-loading="loading" class="full-width" height="100%">
+              <el-table-column prop="id" label="ID" width="80"></el-table-column>
+              <el-table-column prop="childName" label="孩子" width="100"></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="success" :text="String(scope.row.pointsRequired)" />
+                </template>
+              </el-table-column>
+              <el-table-column prop="exchangeApprovedAt" label="批准时间" width="180">
+                <template slot-scope="scope">
+                  {{ formatDate(scope.row.exchangeApprovedAt) }}
+                </template>
+              </el-table-column>
+              <el-table-column label="操作" width="120" fixed="right">
+                <template slot-scope="{ row }">
+                  <el-button size="mini" @click="handleFulfill(row)">已购买</el-button>
+                </template>
+              </el-table-column>
+            </el-table>
+          </div>
+        </div>
+
+        <!-- 待收货列表 -->
+        <div v-if="exchangingWishes.length > 0" class="wish-section">
+          <SectionTitle title="待收货确认" />
+          <div class="adm-table-wrap">
+            <el-table :data="exchangingWishes" border v-loading="loading" class="full-width" height="100%">
+              <el-table-column prop="id" label="ID" width="80"></el-table-column>
+              <el-table-column prop="childName" label="孩子" width="100"></el-table-column>
+              <el-table-column prop="title" label="心愿名称" min-width="200"></el-table-column>
+              <el-table-column prop="fulfilledAt" label="购买时间" width="180">
+                <template slot-scope="scope">
+                  {{ formatDate(scope.row.fulfilledAt) }}
+                </template>
+              </el-table-column>
+              <el-table-column label="状态" width="100">
+                <template slot-scope="scope">
+                  <StatusTag type="info" text="等待确认" />
+                </template>
+              </el-table-column>
+            </el-table>
+          </div>
+        </div>
+
+        <!-- 空状态 -->
+        <el-empty v-if="pendingWishes.length === 0" description="暂无待处理心愿"></el-empty>
+      </el-tab-pane>
+
+      <!-- 全部心愿 -->
+      <el-tab-pane label="全部心愿" name="all">
+        <!-- 搜索筛选(家庭锁定) -->
+        <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="draft"></el-option>
+              <el-option label="积攒中" value="active"></el-option>
+              <el-option label="待审批" value="pending_exchange"></el-option>
+              <el-option label="已批准" value="approved"></el-option>
+              <el-option label="待收货" value="exchanging"></el-option>
+              <el-option label="已完成" value="fulfilled"></el-option>
+              <el-option label="已拒绝" value="rejected"></el-option>
+              <el-option label="已取消" value="cancelled"></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="childName" label="孩子" width="100">
+              <template slot="header">
+                <span class="sort-header" @click.stop="onSortClick('childName', $event)">孩子<span v-if="sortIndex('childName') !== null" class="sort-index" :class="sortClass('childName') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('childName') }}</span>{{ sortIcon('childName') }}</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 v-if="scope.row.pointsRequired" type="warning" :text="String(scope.row.pointsRequired)" />
+                <span v-else class="no-price">未定价</span>
+              </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="status" label="状态" width="100">
+              <template slot-scope="scope">
+                <StatusTag :type="getStatusType(scope.row.status)" :text="scope.row.statusText" 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="creatorType" label="创建者" width="80">
+              <template slot-scope="scope">
+                <StatusTag :type="scope.row.creatorType === 'parent' ? 'primary' : 'success'" :text="scope.row.creatorType === 'parent' ? '家长' : '孩子'" size="small" />
+              </template>
+              <template slot="header">
+                <span class="sort-header" @click.stop="onSortClick('creatorType', $event)">创建者<span v-if="sortIndex('creatorType') !== null" class="sort-index" :class="sortClass('creatorType') === 'sort-asc' ? 'sort-asc-badge' : 'sort-desc-badge'">{{ sortIndex('creatorType') }}</span>{{ sortIcon('creatorType') }}</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>
+        </div>
+
+        <el-pagination
+          class="mb-20-rows"
+          @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-tabs>
+
+    <!-- 定价对话框 -->
+    <el-dialog title="设置积分" :visible.sync="priceDialogVisible" width="400px">
+      <el-form label-width="100px">
+        <el-form-item label="心愿名称">
+          <span>{{ currentWish && currentWish.title }}</span>
+        </el-form-item>
+        <el-form-item label="所需积分">
+          <el-input-number v-model="priceValue" :min="1" :max="10000"></el-input-number>
+        </el-form-item>
+      </el-form>
+      <div slot="footer">
+        <el-button @click="priceDialogVisible = false">取消</el-button>
+        <el-button type="primary" @click="submitPrice" :loading="submitting">确定</el-button>
+      </div>
+    </el-dialog>
+  </div>
+</template>
+
+<script>
+import SortMixin from '@/mixins/SortMixin'
+import {
+  getWishesList,
+  getPendingWishes,
+  setWishPrice,
+  rejectWish,
+  approveWishExchange,
+  markWishFulfilled
+} from '@/api/admin'
+
+export default {
+  name: 'WishesPanel',
+  mixins: [SortMixin],
+  props: {
+    familyId: {
+      type: [Number, String],
+      default: null
+    }
+  },
+  data() {
+    return {
+      activeTab: 'pending',
+      loading: false,
+      submitting: false,
+      tableData: [],
+      sortableColumns: { id: 'ID', childName: '孩子', title: '心愿名称', pointsRequired: '所需积分', category: '分类', status: '状态', creatorType: '创建者', createdAt: '创建时间' },
+      pendingWishes: [],
+      searchForm: {
+        status: ''
+      },
+      pagination: {
+        current: 1,
+        size: 10,
+        total: 0
+      },
+      priceDialogVisible: false,
+      currentWish: null,
+      priceValue: 100
+    }
+  },
+  computed: {
+    draftWishes() {
+      return this.pendingWishes.filter(w => w.status === 'draft')
+    },
+    pendingExchangeWishes() {
+      return this.pendingWishes.filter(w => w.status === 'pending_exchange')
+    },
+    approvedWishes() {
+      return this.pendingWishes.filter(w => w.status === 'approved')
+    },
+    exchangingWishes() {
+      return this.pendingWishes.filter(w => w.status === 'exchanging')
+    },
+    draftCount() { return this.draftWishes.length },
+    pendingCount() { return this.pendingExchangeWishes.length },
+    approvedCount() { return this.approvedWishes.length },
+    exchangingCount() { return this.exchangingWishes.length }
+  },
+  mounted() {
+    this.loadPendingWishes()
+  },
+  methods: {
+    handleActionCmd(row, cmd) {
+      switch (cmd) {
+        case 'price': this.showPriceDialog(row); break;
+        case 'reject': this.handleReject(row); break;
+        case 'approve': this.handleApproveExchange(row, true); break;
+        case 'rejectExchange': this.handleApproveExchange(row, false); break;
+        case 'fulfill': this.handleFulfill(row); break;
+      }
+    },
+    async loadPendingWishes() {
+      this.loading = true
+      try {
+        // familyId 由父组件锁定的 prop 注入(原页面读 localStorage,面板不适用)
+        if (this.familyId != null) {
+          const res = await getPendingWishes(this.familyId)
+          this.pendingWishes = res.data || []
+        }
+      } catch (error) {
+        this.$message.error(error.message || '加载待处理列表失败')
+      } finally {
+        this.loading = false
+      }
+    },
+    async loadWishes() {
+      this.loading = true
+      try {
+        const params = {
+          page: this.pagination.current,
+          size: this.pagination.size,
+          familyId: this.familyId != null ? this.familyId : undefined,
+          status: this.searchForm.status || undefined
+        }
+        if (this.sortState.length > 0) params.sort = this.sortState
+        const res = await getWishesList(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
+      }
+    },
+    handleTabClick(tab) {
+      if (tab.name === 'all' && this.tableData.length === 0) {
+        this.loadWishes()
+      }
+    },
+    handleSearch() {
+      this.pagination.current = 1
+      this.loadWishes()
+    },
+    handleReset() {
+      this.searchForm = { status: '' }
+      this.handleSearch()
+    },
+    handleSizeChange(val) {
+      this.pagination.size = val
+      this.pagination.current = 1
+      this.loadWishes()
+    },
+    handleCurrentChange(val) {
+      this.pagination.current = val
+      this.loadWishes()
+    },
+    showPriceDialog(wish) {
+      this.currentWish = wish
+      this.priceValue = wish.pointsRequired || 100
+      this.priceDialogVisible = true
+    },
+    async submitPrice() {
+      if (!this.priceValue || this.priceValue <= 0) {
+        this.$message.warning('请输入有效积分')
+        return
+      }
+      this.submitting = true
+      try {
+        await setWishPrice(this.currentWish.id, this.priceValue)
+        this.$message.success('定价成功')
+        this.priceDialogVisible = false
+        this.loadPendingWishes()
+      } catch (error) {
+        this.$message.error(error.message || '定价失败')
+      } finally {
+        this.submitting = false
+      }
+    },
+    async handleReject(row) {
+      this.$confirm(`确定要拒绝 "${row.title}" 吗?`, '提示', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning'
+      }).then(async () => {
+        try {
+          await rejectWish(row.id, '不符合要求')
+          this.$message.success('已拒绝')
+          this.loadPendingWishes()
+        } catch (error) {
+          this.$message.error(error.message || '操作失败')
+        }
+      }).catch(() => {})
+    },
+    async handleApproveExchange(row, approved) {
+      const action = approved ? '批准' : '拒绝'
+      this.$confirm(`确定要${action} "${row.title}" 的兑换申请吗?`, '提示', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning'
+      }).then(async () => {
+        try {
+          await approveWishExchange(row.id, approved)
+          this.$message.success(`已${action}`)
+          this.loadPendingWishes()
+        } catch (error) {
+          this.$message.error(error.message || '操作失败')
+        }
+      }).catch(() => {})
+    },
+    async handleFulfill(row) {
+      this.$confirm(`确定已购买 "${row.title}" 吗?`, '提示', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning'
+      }).then(async () => {
+        try {
+          await markWishFulfilled(row.id)
+          this.$message.success('已标记')
+          this.loadPendingWishes()
+        } catch (error) {
+          this.$message.error(error.message || '操作失败')
+        }
+      }).catch(() => {})
+    },
+    getStatusType(status) {
+      const types = {
+        draft: 'info',
+        active: 'success',
+        pending_exchange: 'warning',
+        approved: 'primary',
+        exchanging: 'primary',
+        fulfilled: 'success',
+        cancelled: 'info',
+        rejected: 'danger'
+      }
+      return types[status] || 'info'
+    }
+  }
+}
+</script>
+
+<style scoped>
+.wish-section {
+  margin-bottom: 30px;
+}
+.no-price {
+  color: var(--adm-text-45);
+  font-size: 12px;
+}
+.mb-20 { margin-bottom: 24px; }
+.mb-20-rows { margin-top: 24px; text-align: right; }
+.full-width { width: 100%; }
+</style>