|
|
@@ -0,0 +1,264 @@
|
|
|
+<template>
|
|
|
+ <div class="family-coupon-panel">
|
|
|
+ <el-tabs v-model="activeTab" @tab-click="onTabClick">
|
|
|
+ <!-- 发放 -->
|
|
|
+ <el-tab-pane label="发放" name="issue">
|
|
|
+ <el-form :inline="true" :model="issueForm" class="mb-12">
|
|
|
+ <el-form-item label="优惠券" required>
|
|
|
+ <el-select v-model="issueForm.couponId" placeholder="请选择优惠券" class="w-240">
|
|
|
+ <el-option
|
|
|
+ v-for="c in couponOptions"
|
|
|
+ :key="c.id"
|
|
|
+ :label="couponLabel(c)"
|
|
|
+ :value="c.id"
|
|
|
+ ></el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="发放数量">
|
|
|
+ <el-input-number v-model="issueForm.quantity" :min="1" :max="100" :step="1"></el-input-number>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <el-button type="primary" @click="confirmIssue" :loading="issueSubmitting">确认发放</el-button>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <el-tag size="small" type="info">当前家庭 #{{ familyId }}</el-tag>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ </el-tab-pane>
|
|
|
+
|
|
|
+ <!-- 券列表 -->
|
|
|
+ <el-tab-pane label="券列表" name="list">
|
|
|
+ <el-form :inline="true" class="mb-12">
|
|
|
+ <el-form-item label="状态">
|
|
|
+ <el-select v-model="statusFilter" placeholder="全部" clearable size="small" class="w-120" @change="handleFilterChange">
|
|
|
+ <el-option label="可用" value="AVAILABLE"></el-option>
|
|
|
+ <el-option label="已使用" value="USED"></el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <el-button size="small" @click="loadList">刷新</el-button>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <div class="adm-table-wrap">
|
|
|
+ <el-table :data="listData" border v-loading="listLoading" class="full-width" height="100%">
|
|
|
+ <el-table-column prop="name" label="券名称" min-width="140"></el-table-column>
|
|
|
+ <el-table-column prop="type" label="类型" width="80">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <StatusTag size="mini" :type="scope.row.type === 'DISCOUNT' ? 'primary' : 'success'" :text="scope.row.type === 'DISCOUNT' ? '折扣' : '满减'" />
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="面值/折扣" width="100">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <span v-if="scope.row.type === 'DISCOUNT' && scope.row.discountRate">{{ (scope.row.discountRate / 100).toFixed(1) }}折</span>
|
|
|
+ <span v-else-if="scope.row.value">{{ (scope.row.value / 100).toFixed(2) }}元</span>
|
|
|
+ <span v-else>-</span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="状态" width="80">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <StatusTag size="mini" :type="scope.row.status === 'AVAILABLE' ? 'success' : 'info'" :text="scope.row.status === 'AVAILABLE' ? '可用' : '已使用'" />
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="receivedAt" label="领取时间" width="160">
|
|
|
+ <template slot-scope="scope">{{ formatTime(scope.row.receivedAt) }}</template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="usedAt" label="使用时间" width="160">
|
|
|
+ <template slot-scope="scope">{{ formatTime(scope.row.usedAt) }}</template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ </div>
|
|
|
+ <el-pagination
|
|
|
+ class="pagination-wrap"
|
|
|
+ @size-change="onListSizeChange"
|
|
|
+ @current-change="onListPageChange"
|
|
|
+ :current-page="listPagination.current"
|
|
|
+ :page-sizes="[10, 20, 50]"
|
|
|
+ :page-size="listPagination.size"
|
|
|
+ :total="listPagination.total"
|
|
|
+ layout="total, sizes, prev, pager, next"
|
|
|
+ ></el-pagination>
|
|
|
+ </el-tab-pane>
|
|
|
+
|
|
|
+ <!-- 使用记录 -->
|
|
|
+ <el-tab-pane label="使用记录" name="usage">
|
|
|
+ <div class="adm-table-wrap">
|
|
|
+ <el-table :data="usageData" border v-loading="usageLoading" class="full-width" height="100%">
|
|
|
+ <el-table-column prop="name" label="券名称" min-width="140"></el-table-column>
|
|
|
+ <el-table-column prop="type" label="类型" width="80">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <StatusTag size="mini" :type="scope.row.type === 'DISCOUNT' ? 'primary' : 'success'" :text="scope.row.type === 'DISCOUNT' ? '折扣' : '满减'" />
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="面值/折扣" width="100">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <span v-if="scope.row.type === 'DISCOUNT' && scope.row.discountRate">{{ (scope.row.discountRate / 100).toFixed(1) }}折</span>
|
|
|
+ <span v-else-if="scope.row.value">{{ (scope.row.value / 100).toFixed(2) }}元</span>
|
|
|
+ <span v-else>-</span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="orderId" label="订单号" width="140">
|
|
|
+ <template slot-scope="scope">{{ scope.row.orderId || '-' }}</template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="usedAt" label="使用时间" width="160">
|
|
|
+ <template slot-scope="scope">{{ formatTime(scope.row.usedAt) }}</template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ </div>
|
|
|
+ <el-pagination
|
|
|
+ class="pagination-wrap"
|
|
|
+ @size-change="onUsageSizeChange"
|
|
|
+ @current-change="onUsagePageChange"
|
|
|
+ :current-page="usagePagination.current"
|
|
|
+ :page-sizes="[10, 20, 50]"
|
|
|
+ :page-size="usagePagination.size"
|
|
|
+ :total="usagePagination.total"
|
|
|
+ layout="total, sizes, prev, pager, next"
|
|
|
+ ></el-pagination>
|
|
|
+ </el-tab-pane>
|
|
|
+ </el-tabs>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import { getCouponList, issueFamilyCoupon, getFamilyCoupons, getFamilyCouponUsage } from '@/api/coupon'
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: 'FamilyCouponPanel',
|
|
|
+ props: {
|
|
|
+ familyId: {
|
|
|
+ type: [Number, String],
|
|
|
+ default: null
|
|
|
+ }
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ activeTab: 'list',
|
|
|
+ couponOptions: [],
|
|
|
+ issueForm: {
|
|
|
+ couponId: null,
|
|
|
+ quantity: 1
|
|
|
+ },
|
|
|
+ issueSubmitting: false,
|
|
|
+ listData: [],
|
|
|
+ listLoading: false,
|
|
|
+ listPagination: { current: 1, size: 20, total: 0 },
|
|
|
+ statusFilter: '',
|
|
|
+ usageData: [],
|
|
|
+ usageLoading: false,
|
|
|
+ usagePagination: { current: 1, size: 20, total: 0 }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.activeTab = 'list'
|
|
|
+ this.loadCouponOptions()
|
|
|
+ this.loadList()
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ onTabClick(tab) {
|
|
|
+ if (tab.name === 'usage') {
|
|
|
+ this.loadUsage()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ couponLabel(c) {
|
|
|
+ if (c.type === 'DISCOUNT') {
|
|
|
+ return `${c.name}(${(c.discountRate / 100).toFixed(1)}折)`
|
|
|
+ }
|
|
|
+ return `${c.name}(${(c.value / 100).toFixed(2)}元)`
|
|
|
+ },
|
|
|
+ async loadCouponOptions() {
|
|
|
+ try {
|
|
|
+ const res = await getCouponList({ page: 1, size: 999 })
|
|
|
+ this.couponOptions = res.data.records || res.data.list || res.data || []
|
|
|
+ } catch (error) {
|
|
|
+ this.$message.error(error.message || '加载优惠券列表失败')
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async confirmIssue() {
|
|
|
+ if (!this.issueForm.couponId) {
|
|
|
+ this.$message.warning('请选择优惠券')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.issueSubmitting = true
|
|
|
+ try {
|
|
|
+ await issueFamilyCoupon({
|
|
|
+ familyId: this.familyId,
|
|
|
+ couponId: this.issueForm.couponId,
|
|
|
+ quantity: this.issueForm.quantity
|
|
|
+ })
|
|
|
+ this.$message.success('发放成功')
|
|
|
+ this.issueForm.couponId = null
|
|
|
+ this.issueForm.quantity = 1
|
|
|
+ this.loadList()
|
|
|
+ } catch (error) {
|
|
|
+ this.$message.error(error.message || '发放失败')
|
|
|
+ } finally {
|
|
|
+ this.issueSubmitting = false
|
|
|
+ }
|
|
|
+ },
|
|
|
+ handleFilterChange() {
|
|
|
+ this.listPagination.current = 1
|
|
|
+ this.loadList()
|
|
|
+ },
|
|
|
+ async loadList() {
|
|
|
+ if (this.familyId == null) return
|
|
|
+ this.listLoading = true
|
|
|
+ try {
|
|
|
+ const res = await getFamilyCoupons({
|
|
|
+ familyId: this.familyId,
|
|
|
+ status: this.statusFilter || undefined,
|
|
|
+ page: this.listPagination.current,
|
|
|
+ size: this.listPagination.size
|
|
|
+ })
|
|
|
+ this.listData = res.data.records || []
|
|
|
+ this.listPagination.total = res.data.total || 0
|
|
|
+ } catch (error) {
|
|
|
+ this.$message.error(error.message || '加载优惠券列表失败')
|
|
|
+ } finally {
|
|
|
+ this.listLoading = false
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onListPageChange(val) {
|
|
|
+ this.listPagination.current = val
|
|
|
+ this.loadList()
|
|
|
+ },
|
|
|
+ onListSizeChange(val) {
|
|
|
+ this.listPagination.size = val
|
|
|
+ this.listPagination.current = 1
|
|
|
+ this.loadList()
|
|
|
+ },
|
|
|
+ async loadUsage() {
|
|
|
+ if (this.familyId == null) return
|
|
|
+ this.usageLoading = true
|
|
|
+ try {
|
|
|
+ const res = await getFamilyCouponUsage({
|
|
|
+ familyId: this.familyId,
|
|
|
+ page: this.usagePagination.current,
|
|
|
+ size: this.usagePagination.size
|
|
|
+ })
|
|
|
+ this.usageData = res.data.records || []
|
|
|
+ this.usagePagination.total = res.data.total || 0
|
|
|
+ } catch (error) {
|
|
|
+ this.$message.error(error.message || '加载使用记录失败')
|
|
|
+ } finally {
|
|
|
+ this.usageLoading = false
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onUsagePageChange(val) {
|
|
|
+ this.usagePagination.current = val
|
|
|
+ this.loadUsage()
|
|
|
+ },
|
|
|
+ onUsageSizeChange(val) {
|
|
|
+ this.usagePagination.size = val
|
|
|
+ this.usagePagination.current = 1
|
|
|
+ this.loadUsage()
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+.mb-12 { margin-bottom: 12px; }
|
|
|
+.full-width { width: 100%; }
|
|
|
+.w-120 { width: 120px; }
|
|
|
+.w-240 { width: 240px; }
|
|
|
+</style>
|