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

355 行
9.4 KiB
Vue

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<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="card-head ss-flex ss-col-center">
<view class="card-title">本月已结算收益(元)</view>
</view>
<view class="money-num ss-m-t-24">{{ state.overview.month_income || '0.00' }}</view>
<view class="card-sub ss-m-t-20">
本月未达成 {{ state.overview.skip_count || 0 }} 笔
</view>
</view>
</view>
<su-sticky>
<su-tabs
:list="tabMaps"
@change="onChangeTab"
:scrollable="true"
:current="state.currentTab"
></su-tabs>
</su-sticky>
<s-empty
v-if="state.inited && state.pagination.total === 0"
icon="/static/data-empty.png"
text="暂无收益记录,推荐好友下单后将在此展示。"
></s-empty>
<view v-if="state.pagination.total > 0">
<view
class="wallet-list ss-flex border-bottom"
v-for="item in state.pagination.data"
:key="item.id || item.createtime"
@tap="onOpenDetail(item)"
>
<view class="list-content">
<view class="title-box ss-flex ss-row-between ss-m-b-12">
<text class="title ss-line-1">{{ item.reward_type_text || item.reward_type || '收益' }}</text>
<view class="money">
<text :class="Number(item.amount) >= 0 ? 'add' : 'minus'">
{{ formatAmount(item.amount) }}
</text>
</view>
</view>
<view class="desc ss-line-1">
来自 {{ item.buyer_nickname || '好友' }}
<text v-if="item.order_id"> · 订单 {{ item.order_id }}</text>
</view>
<view class="ss-flex ss-row-between ss-m-t-8">
<text class="time">{{ item.createtime || '' }}</text>
<text class="status-text">{{ item.status_text || '' }}</text>
</view>
<view v-if="item.skip_reason_text" class="skip-text ss-m-t-8">
{{ item.skip_reason_text }}
</view>
</view>
</view>
</view>
<uni-load-more
v-if="state.pagination.total > 0"
:status="state.loadStatus"
:content-text="{
contentdown: '上拉加载更多',
}"
/>
<su-popup :show="state.showDetail" type="bottom" round="20" @close="state.showDetail = false" showClose>
<view class="ss-p-x-30 ss-p-y-30" v-if="state.current">
<view class="model-title ss-m-b-20">{{ state.current.reward_type_text || '收益详情' }}</view>
<view class="detail-row ss-m-b-12">
金额:{{ state.current.amount || '0.00' }}
</view>
<view class="detail-row ss-m-b-12">
状态:{{ state.current.status_text || '--' }}
</view>
<view class="detail-row ss-m-b-12" v-if="state.current.buyer_nickname">
来自:{{ state.current.buyer_nickname }}
</view>
<view class="detail-row ss-m-b-12" v-if="state.current.order_id">
订单:{{ state.current.order_id }}
</view>
<view class="detail-row ss-m-b-12" v-if="state.current.createtime">
时间:{{ state.current.createtime }}
</view>
<view class="detail-row ss-m-b-12" v-if="state.current.formula">
测算:{{ state.current.formula }}
</view>
<view class="skip-text" v-if="state.current.skip_reason_text">
{{ state.current.skip_reason_text }}
</view>
</view>
</su-popup>
</s-layout>
</template>
<script setup>
import { computed, reactive } from 'vue';
import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app';
import sheep from '@/sheep';
import _ from 'lodash';
const headerBg = sheep.$url.css('/assets/addons/shopro/uniapp/user/wallet_card_bg.png');
const userInfo = computed(() => sheep.$store('user').userInfo);
const agentInfo = computed(() => sheep.$store('user').agentInfo);
const roleNames = computed(() => {
return (
userInfo.value?.custom_role_names ||
userInfo.value?.role_names ||
agentInfo.value?.custom_role_names ||
agentInfo.value?.role_names ||
{}
);
});
const tabMaps = computed(() => [
{ name: '全部', value: 'all' },
{ name: '开拓奖', value: 'push3' },
{ name: roleNames.value.maker || '创客', value: 'maker' },
{ name: roleNames.value.venue || '酒道馆', value: 'venue' },
{ name: roleNames.value.county || '区县', value: 'county' },
{ name: '加权奖励', value: 'share' },
]);
const emptyPagination = {
data: [],
current_page: 1,
total: 0,
last_page: 1,
};
const state = reactive({
currentTab: 0,
inited: false,
pagination: { ...emptyPagination },
loadStatus: '',
showDetail: false,
current: null,
overview: {
month_income: '0.00',
skip_count: 0,
},
});
function formatAmount(amount) {
const value = Number(amount);
if (Number.isNaN(value)) return amount || '0.00';
return value >= 0 ? `+${amount}` : `${amount}`;
}
function pickList(payload) {
if (!payload) return { ...emptyPagination };
if (Array.isArray(payload)) {
return { data: payload, current_page: 1, last_page: 1, total: payload.length };
}
const listWrap = payload.list || payload;
const data = listWrap?.data || payload.data || [];
return {
data: Array.isArray(data) ? data : [],
current_page: listWrap?.current_page || payload.current_page || 1,
last_page: listWrap?.last_page || payload.last_page || 1,
total: listWrap?.total ?? payload.total ?? (Array.isArray(data) ? data.length : 0),
};
}
async function getOverview() {
try {
const res = await sheep.$api.partner.overview();
if (res?.code === 1) {
state.overview.month_income = res.data?.month_income || '0.00';
state.overview.skip_count = res.data?.skip_count || 0;
}
} catch (e) {}
}
async function getLogList(page = 1, list_rows = 10) {
state.loadStatus = 'loading';
try {
const res = await sheep.$api.partner.rewards({
tab: tabMaps[state.currentTab]?.value || 'all',
page,
list_rows,
});
if (res?.code === 1) {
const pageData = pickList(res.data);
state.pagination = {
...pageData,
data: page === 1 ? pageData.data : _.concat(state.pagination.data, pageData.data),
};
if (res.data?.month_income !== undefined) {
state.overview.month_income = res.data.month_income;
}
if (res.data?.skip_count !== undefined) {
state.overview.skip_count = res.data.skip_count;
}
state.loadStatus =
state.pagination.current_page < state.pagination.last_page ? 'more' : 'noMore';
state.inited = true;
return;
}
} catch (e) {}
if (page === 1) {
state.pagination = { ...emptyPagination };
}
state.loadStatus = 'noMore';
state.inited = true;
}
function onChangeTab(e) {
state.currentTab = e.index;
state.pagination = { ...emptyPagination };
getLogList();
}
function onOpenDetail(item) {
state.current = item || {};
state.showDetail = true;
}
onLoad(() => {
getOverview();
getLogList();
});
onPullDownRefresh(async () => {
state.pagination = { ...emptyPagination };
await Promise.all([getOverview(), getLogList(1)]);
uni.stopPullDownRefresh();
});
onReachBottom(() => {
if (state.loadStatus !== 'noMore') {
getLogList(state.pagination.current_page + 1);
}
});
</script>
<style lang="scss" scoped>
.header-box {
background-color: $white;
padding: 30rpx;
.card-box {
width: 100%;
min-height: 220rpx;
padding: 40rpx;
background-size: 100% 100%;
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;
}
.card-head,
.card-title,
.money-num,
.card-sub {
position: relative;
z-index: 3;
color: $white;
}
.card-title {
font-size: 24rpx;
}
.money-num {
font-size: 40rpx;
font-weight: 500;
font-family: OPPOSANS;
}
.card-sub {
font-size: 24rpx;
opacity: 0.9;
}
}
}
.wallet-list {
padding: 30rpx;
background-color: #ffffff;
.list-content {
flex: 1;
.title {
font-size: 28rpx;
color: $dark-3;
width: 400rpx;
}
.desc,
.time,
.status-text {
color: $gray-c;
font-size: 22rpx;
}
.skip-text {
font-size: 22rpx;
color: #c48a3a;
}
}
.money {
font-size: 28rpx;
font-weight: bold;
font-family: OPPOSANS;
.add {
color: var(--ui-BG-Main);
}
.minus {
color: $dark-3;
}
}
}
.model-title {
font-size: 36rpx;
font-weight: bold;
color: #333333;
}
.detail-row {
font-size: 26rpx;
color: #666666;
line-height: 40rpx;
}
.skip-text {
font-size: 24rpx;
color: #c48a3a;
line-height: 36rpx;
}
</style>