文件
Henglianshutong/uniapp/pages/commission/voucher.vue

283 行
7.7 KiB
Vue

<template>
<s-layout class="wallet-wrap" title="兑换券">
<view class="header-box ss-flex ss-row-center ss-col-center">
<view class="card-box ui-BG-Main ui-Shadow-Main">
<view class="metric-grid">
<view class="metric-item">
<view class="metric-label">累计获得</view>
<view class="metric-value">{{ state.info.voucher_total || '0.00' }}</view>
</view>
<view class="metric-item">
<view class="metric-label">已释放</view>
<view class="metric-value">{{ state.info.voucher_released || '0.00' }}</view>
</view>
<view class="metric-item">
<view class="metric-label">已使用</view>
<view class="metric-value">{{ state.info.voucher_used || '0.00' }}</view>
</view>
<view class="metric-item">
<view class="metric-label">可用</view>
<view class="metric-value">{{ state.info.voucher_available || '0.00' }}</view>
</view>
</view>
<view class="progress-text">第 {{ state.progress.current || 0 }} / {{ state.progress.total || 365 }} 天</view>
<view class="progress-bar">
<view class="progress-inner" :style="{ width: progressWidth }"></view>
</view>
<button class="ss-reset-button exchange-btn" @tap="sheep.$router.go('/pages/index/index')">
去兑换
</button>
</view>
</view>
<s-empty
v-if="state.inited && state.plans.length === 0"
icon="/static/data-empty.png"
text="下单后将获得 1.5 倍兑换券,分 365 天释放。"
></s-empty>
<view v-if="state.plans.length > 0">
<view class="wallet-list border-bottom" v-for="(item, index) in state.plans" :key="item.id || index">
<view class="title-box ss-flex ss-row-between ss-m-b-12">
<text class="title">订单 {{ item.order_sn || item.order_id || '--' }}</text>
<text class="money">总额 {{ item.total || item.voucher_total || '0.00' }}</text>
</view>
<view class="desc ss-m-b-16">
已释放 {{ item.released || item.voucher_released || '0.00' }} · 可用
{{ item.available || item.voucher_available || '0.00' }} · 已用
{{ item.used || item.voucher_used || '0.00' }}
</view>
<view class="progress-bar">
<view class="progress-inner dark" :style="{ width: planProgress(item) }"></view>
</view>
<view class="desc ss-m-t-8">
{{ planDay(item) }} / {{ planTotal(item) }}
</view>
</view>
</view>
</s-layout>
</template>
<script setup>
import { computed, reactive } from 'vue';
import { onLoad, onPullDownRefresh } from '@dcloudio/uni-app';
import sheep from '@/sheep';
const headerBg = sheep.$url.css('/assets/addons/shopro/uniapp/user/wallet_card_bg.png');
const userInfo = sheep.$store('user').userInfo || {};
const agentInfo = sheep.$store('user').agentInfo || {};
const state = reactive({
info: {
voucher_total: agentInfo.voucher_total || '0.00',
voucher_released: agentInfo.voucher_released || '0.00',
voucher_used: agentInfo.voucher_used || '0.00',
voucher_available: agentInfo.voucher_available || userInfo.voucher_available || '0.00',
},
plans: [],
inited: false,
progress: {
current: 0,
total: 365,
},
});
const progressWidth = computed(() => {
const total = Number(state.progress.total) || 365;
const current = Number(state.progress.current) || 0;
const percent = Math.min(100, Math.max(0, (current / total) * 100));
return `${percent}%`;
});
function planDay(item = {}) {
return item.day || item.released_days || item.current_day || 0;
}
function planTotal(item = {}) {
return item.days || item.total_days || 365;
}
function planProgress(item = {}) {
const total = Number(planTotal(item)) || 365;
const current = Number(planDay(item)) || 0;
return `${Math.min(100, Math.max(0, (current / total) * 100))}%`;
}
function pickPlans(payload) {
if (!payload) return [];
if (Array.isArray(payload.plans)) return payload.plans;
if (Array.isArray(payload.list)) return payload.list;
if (Array.isArray(payload.data)) return payload.data;
return [];
}
function calcProgress(plans) {
if (!plans.length) {
state.progress.current = 0;
state.progress.total = 365;
return;
}
let maxCurrent = 0;
let total = 365;
plans.forEach((item) => {
const current = Number(planDay(item)) || 0;
if (current > maxCurrent) {
maxCurrent = current;
total = Number(planTotal(item)) || 365;
}
});
state.progress.current = maxCurrent;
state.progress.total = total;
}
async function getVoucher() {
try {
const res = await sheep.$api.partner.voucher();
if (res?.code === 1) {
const data = res.data || {};
state.info.voucher_total = data.voucher_total || state.info.voucher_total;
state.info.voucher_released = data.voucher_released || state.info.voucher_released;
state.info.voucher_used = data.voucher_used || state.info.voucher_used;
state.info.voucher_available = data.voucher_available || state.info.voucher_available;
state.plans = pickPlans(data);
calcProgress(state.plans);
state.inited = true;
return;
}
} catch (e) {}
state.plans = [];
state.inited = true;
}
onLoad(() => {
getVoucher();
});
onPullDownRefresh(async () => {
await getVoucher();
uni.stopPullDownRefresh();
});
</script>
<style lang="scss" scoped>
.header-box {
background-color: $white;
padding: 30rpx;
.card-box {
width: 100%;
min-height: 300rpx;
padding: 36rpx 30rpx 30rpx;
border-radius: 30rpx;
overflow: hidden;
position: relative;
z-index: 1;
box-sizing: border-box;
&::after {
content: '';
display: block;
width: 100%;
height: 100%;
z-index: 2;
position: absolute;
top: 0;
left: 0;
background: v-bind(headerBg) no-repeat;
pointer-events: none;
}
.metric-grid,
.progress-text,
.progress-bar,
.exchange-btn {
position: relative;
z-index: 3;
}
.metric-grid {
display: flex;
flex-wrap: wrap;
}
.metric-item {
width: 50%;
padding: 12rpx 0 20rpx;
box-sizing: border-box;
}
.metric-label {
font-size: 22rpx;
color: rgba(255, 255, 255, 0.85);
margin-bottom: 10rpx;
}
.metric-value {
font-size: 32rpx;
color: $white;
font-family: OPPOSANS;
font-weight: 500;
}
.progress-text {
font-size: 22rpx;
color: $white;
margin-bottom: 12rpx;
}
.exchange-btn {
margin-top: 24rpx;
width: 180rpx;
height: 60rpx;
line-height: 60rpx;
border-radius: 30rpx;
background: $white;
color: var(--ui-BG-Main);
font-size: 24rpx;
}
}
}
.progress-bar {
height: 12rpx;
background: rgba(255, 255, 255, 0.35);
border-radius: 8rpx;
overflow: hidden;
.progress-inner {
height: 100%;
background: $white;
border-radius: 8rpx;
&.dark {
background: var(--ui-BG-Main);
}
}
}
.wallet-list {
padding: 30rpx;
background-color: #ffffff;
.title {
font-size: 28rpx;
color: $dark-3;
}
.money {
font-size: 26rpx;
color: $dark-3;
font-family: OPPOSANS;
}
.desc {
color: $gray-c;
font-size: 22rpx;
}
.progress-bar {
background: #f3e6d2;
}
}
</style>