| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450 |
- <template>
- <view class="page">
- <view class="tab-bar">
- <view
- v-for="(tab, idx) in tabs"
- :key="idx"
- class="tab-item"
- :class="activeTab === idx ? 'active' : ''"
- @click="switchTab(idx)"
- >
- <text>{{ tab.name }}</text>
- </view>
- </view>
- <!-- 赠送 -->
- <scroll-view v-if="activeTab === 0" scroll-y class="content" refresher-enabled
- :refresher-triggered="refreshing" @refresherrefresh="onRefresh">
- <view class="tip">把你的会员券转赠给推荐的人(直推 / 隔级),对方可直接用它购买会员。</view>
- <view class="section">
- <view class="section-title">1. 选择接收人(你的推荐下级)</view>
- <view v-if="recipients.length === 0" class="empty-tip">暂无可赠送的推荐下级(仅支持直推/隔级推荐人)</view>
- <view v-for="r in recipients" :key="r.userId" class="recipient-item"
- :class="selectedRecipient && selectedRecipient.userId === r.userId ? 'selected' : ''"
- @click="pickRecipient(r)">
- <image v-if="r.avatar" class="avatar" :src="r.avatar" mode="aspectFill"></image>
- <view v-else class="avatar avatar-default">{{ r.nickname | firstChar }}</view>
- <view class="recipient-info">
- <text class="nick">{{ r.nickname }}</text>
- <text class="level-tag">{{ r.giftLevel === 2 ? '隔级' : '直推' }}</text>
- </view>
- <view v-if="selectedRecipient && selectedRecipient.userId === r.userId" class="check">✓</view>
- </view>
- </view>
- <view class="section">
- <view class="section-title">2. 选择要赠送的会员券</view>
- <view v-if="coupons.length === 0" class="empty-tip">你还没有可赠送的会员券</view>
- <view v-for="c in coupons" :key="c.id" class="coupon-item"
- :class="selectedCoupon && selectedCoupon.id === c.id ? 'selected' : ''"
- @click="pickCoupon(c)">
- <view class="coupon-left">
- <text class="coupon-value">{{ formatValue(c) }}</text>
- <text class="coupon-type">{{ typeName(c) }}</text>
- </view>
- <view class="coupon-body">
- <text class="coupon-name">{{ c.name }}</text>
- <text class="coupon-cond">{{ conditionText(c.minSpend) }}</text>
- <text class="coupon-exp">有效期至 {{ formatDate(c.validUntil) }}</text>
- </view>
- <view v-if="selectedCoupon && selectedCoupon.id === c.id" class="check">✓</view>
- </view>
- </view>
- <view class="section" v-if="coupons.length > 0">
- <view class="section-title">3. 留言(选填)</view>
- <input class="remark-input" v-model="remark" placeholder="写句祝福吧~" maxlength="30" />
- </view>
- <view class="action-bar">
- <button class="gift-btn" :disabled="!canGift || sending" @click="doGift">
- {{ sending ? '赠送中...' : '赠送' }}
- </button>
- </view>
- </scroll-view>
- <!-- 赠送记录 -->
- <scroll-view v-else scroll-y class="content" refresher-enabled
- :refresher-triggered="refreshing" @refresherrefresh="onRefresh">
- <view v-if="sentList.length === 0" class="empty-state">
- <text class="empty-icon">🎁</text>
- <text class="empty-text">还没有赠送记录</text>
- </view>
- <view v-for="item in sentList" :key="item.transferId" class="sent-item">
- <view class="sent-row">
- <text class="sent-name">{{ item.couponName }}</text>
- <text class="sent-status" :class="'st-' + item.status">{{ statusLabel(item.status) }}</text>
- </view>
- <view class="sent-row sub">
- <text>赠给:{{ item.receiverNickname }}</text>
- <text class="sent-level">{{ item.giftLevelLabel }}</text>
- </view>
- <view v-if="item.remark" class="sent-remark">留言:{{ item.remark }}</view>
- <button v-if="item.status === 'GIFTED'" class="revoke-btn" @click="doRevoke(item)">撤回</button>
- </view>
- </scroll-view>
- </view>
- </template>
- <script>
- import {
- getGiftRecipients,
- getGiftableCoupons,
- giftCoupon,
- revokeGiftCoupon,
- getSentGifts
- } from '../../utils/api.js'
- export default {
- data() {
- return {
- tabs: [{ name: '赠送会员券' }, { name: '赠送记录' }],
- activeTab: 0,
- recipients: [],
- coupons: [],
- selectedRecipient: null,
- selectedCoupon: null,
- remark: '',
- sending: false,
- sentList: [],
- refreshing: false
- }
- },
- computed: {
- canGift: function() {
- return !!this.selectedRecipient && !!this.selectedCoupon && !this.sending
- }
- },
- onShow: function() {
- this.loadAll()
- },
- filters: {
- firstChar: function(name) {
- if (!name) return '友'
- return name.substring(0, 1)
- }
- },
- methods: {
- loadAll: function() {
- var self = this
- self.refreshing = true
- Promise.all([getGiftRecipients(), getGiftableCoupons()]).then(function(res) {
- self.recipients = (res[0] && res[0].data) || []
- self.coupons = (res[1] && res[1].data) || []
- }).catch(function(e) {
- console.error('加载可赠送数据失败', e)
- }).then(function() {
- self.refreshing = false
- })
- self.loadSent()
- },
- loadSent: function() {
- var self = this
- getSentGifts().then(function(res) {
- self.sentList = (res && res.data) || []
- }).catch(function(e) {
- console.error('加载赠送记录失败', e)
- })
- },
- onRefresh: function() {
- this.loadAll()
- },
- switchTab: function(idx) {
- this.activeTab = idx
- },
- pickRecipient: function(r) {
- this.selectedRecipient = r
- },
- pickCoupon: function(c) {
- this.selectedCoupon = c
- },
- doGift: function() {
- var self = this
- if (!self.canGift) return
- self.sending = true
- giftCoupon(self.selectedRecipient.userId, self.selectedCoupon.id, self.remark).then(function(res) {
- if (res && res.code === 200) {
- uni.showToast({ title: '赠送成功', icon: 'success' })
- self.selectedRecipient = null
- self.selectedCoupon = null
- self.remark = ''
- self.loadAll()
- } else {
- uni.showToast({ title: (res && res.message) || '赠送失败', icon: 'none' })
- }
- }).catch(function(e) {
- uni.showToast({ title: '赠送失败,请重试', icon: 'none' })
- console.error('赠送失败', e)
- }).then(function() {
- self.sending = false
- })
- },
- doRevoke: function(item) {
- var self = this
- uni.showModal({
- title: '撤回转赠',
- content: '确定撤回赠给「' + item.receiverNickname + '」的券吗?',
- success: function(m) {
- if (!m.confirm) return
- revokeGiftCoupon(item.transferId).then(function(res) {
- if (res && res.code === 200) {
- uni.showToast({ title: '已撤回', icon: 'success' })
- self.loadSent()
- } else {
- uni.showToast({ title: (res && res.message) || '撤回失败', icon: 'none' })
- }
- }).catch(function(e) {
- uni.showToast({ title: '撤回失败', icon: 'none' })
- console.error(e)
- })
- }
- })
- },
- formatValue: function(c) {
- if (c.type === 'DISCOUNT') {
- return (c.discountRate ? (c.discountRate / 100).toFixed(1) : '9.0') + '折'
- }
- return '¥' + (c.value ? (c.value / 100).toFixed(2) : '0.00')
- },
- typeName: function(c) {
- if (c.type === 'FIXED') return '满减券'
- if (c.type === 'DISCOUNT') return '折扣券'
- return '代金券'
- },
- conditionText: function(minSpend) {
- if (!minSpend || minSpend <= 0) return '无门槛'
- return '满' + (minSpend / 100).toFixed(2) + '元可用'
- },
- formatDate: function(d) {
- if (!d) return '长期有效'
- var dt = new Date(d)
- if (isNaN(dt.getTime())) return String(d)
- var m = dt.getMonth() + 1
- var day = dt.getDate()
- return dt.getFullYear() + '-' + (m < 10 ? '0' + m : m) + '-' + (day < 10 ? '0' + day : day)
- },
- statusLabel: function(status) {
- if (status === 'GIFTED') return '待使用'
- if (status === 'USED') return '已使用'
- if (status === 'REVOKED') return '已撤回'
- return status
- }
- }
- }
- </script>
- <style scoped>
- .page {
- display: flex;
- flex-direction: column;
- height: 100vh;
- background: #f5f6fa;
- }
- .tab-bar {
- display: flex;
- background: #fff;
- border-bottom: 1px solid #eee;
- }
- .tab-item {
- flex: 1;
- text-align: center;
- padding: 24rpx 0;
- font-size: 30rpx;
- color: #888;
- }
- .tab-item.active {
- color: #ff6b35;
- font-weight: bold;
- border-bottom: 4rpx solid #ff6b35;
- }
- .content {
- flex: 1;
- padding: 24rpx;
- }
- .tip {
- background: #fff7f2;
- color: #ff6b35;
- font-size: 24rpx;
- padding: 18rpx 22rpx;
- border-radius: 12rpx;
- margin-bottom: 24rpx;
- }
- .section {
- background: #fff;
- border-radius: 16rpx;
- padding: 24rpx;
- margin-bottom: 24rpx;
- }
- .section-title {
- font-size: 30rpx;
- font-weight: bold;
- margin-bottom: 20rpx;
- color: #333;
- }
- .empty-tip {
- font-size: 26rpx;
- color: #aaa;
- text-align: center;
- padding: 30rpx 0;
- }
- .recipient-item,
- .coupon-item {
- display: flex;
- align-items: center;
- padding: 20rpx;
- border: 2rpx solid #eee;
- border-radius: 12rpx;
- margin-bottom: 16rpx;
- position: relative;
- }
- .recipient-item.selected,
- .coupon-item.selected {
- border-color: #ff6b35;
- background: #fff7f2;
- }
- .avatar {
- width: 72rpx;
- height: 72rpx;
- border-radius: 50%;
- margin-right: 18rpx;
- }
- .avatar-default {
- background: #ff6b35;
- color: #fff;
- font-size: 30rpx;
- text-align: center;
- line-height: 72rpx;
- }
- .recipient-info {
- display: flex;
- flex-direction: column;
- flex: 1;
- }
- .nick {
- font-size: 28rpx;
- color: #333;
- }
- .level-tag {
- font-size: 22rpx;
- color: #ff6b35;
- margin-top: 6rpx;
- }
- .coupon-left {
- width: 140rpx;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- border-right: 2rpx dashed #eee;
- padding-right: 16rpx;
- }
- .coupon-value {
- font-size: 36rpx;
- color: #ff6b35;
- font-weight: bold;
- }
- .coupon-type {
- font-size: 22rpx;
- color: #999;
- margin-top: 6rpx;
- }
- .coupon-body {
- flex: 1;
- padding-left: 20rpx;
- display: flex;
- flex-direction: column;
- }
- .coupon-name {
- font-size: 28rpx;
- color: #333;
- }
- .coupon-cond,
- .coupon-exp {
- font-size: 22rpx;
- color: #999;
- margin-top: 6rpx;
- }
- .check {
- color: #ff6b35;
- font-size: 36rpx;
- font-weight: bold;
- margin-left: 12rpx;
- }
- .remark-input {
- background: #f7f7f7;
- border-radius: 10rpx;
- padding: 18rpx 20rpx;
- font-size: 28rpx;
- }
- .action-bar {
- padding: 20rpx 0 40rpx;
- }
- .gift-btn {
- background: #ff6b35;
- color: #fff;
- font-size: 32rpx;
- border-radius: 44rpx;
- }
- .gift-btn[disabled] {
- background: #ffc4ad;
- }
- .empty-state {
- text-align: center;
- padding: 120rpx 0;
- }
- .empty-icon {
- font-size: calc($uni-font-size-5xl * var(--font-scale, 1));
- display: block;
- }
- .empty-text {
- font-size: 28rpx;
- color: #aaa;
- margin-top: 20rpx;
- }
- .sent-item {
- background: #fff;
- border-radius: 16rpx;
- padding: 24rpx;
- margin-bottom: 20rpx;
- }
- .sent-row {
- display: flex;
- justify-content: space-between;
- align-items: center;
- }
- .sent-row.sub {
- margin-top: 10rpx;
- font-size: 24rpx;
- color: #999;
- }
- .sent-name {
- font-size: 30rpx;
- color: #333;
- font-weight: bold;
- }
- .sent-level {
- font-size: 22rpx;
- color: #ff6b35;
- }
- .sent-status {
- font-size: 24rpx;
- }
- .st-GIFTED { color: #ff6b35; }
- .st-USED { color: #999; }
- .st-REVOKED { color: #bbb; }
- .sent-remark {
- font-size: 24rpx;
- color: #888;
- margin-top: 10rpx;
- }
- .revoke-btn {
- margin-top: 18rpx;
- background: #fff;
- color: #ff6b35;
- border: 2rpx solid #ff6b35;
- font-size: 26rpx;
- border-radius: 30rpx;
- padding: 4rpx 0;
- }
- </style>
|