Files
kangyuan-mobile/pages/home/wallet.vue
T

315 lines
8.7 KiB
Vue

<template>
<s-pages title="钱包" :pink_bg="true">
<!-- 头部 -->
<view class="header" :style="{ backgroundImage: 'url(' + $url + 'home/wallet2.png' + ')' }" @click.stop>
<view class="header-content">
<view class="header-top">
<view class="title" @click="jumpPage('充值', '/pages/home/recharge')">
钱包余额 <uni-icons type="right" color="#fff" size="28rpx" />
</view>
<view class="more-trigger" @click.stop="toggleLiquidationMenu">
<uni-icons type="more-filled" color="#fff" size="34rpx" />
</view>
<view v-if="showLiquidationMenu && enabledLiquidations.length" class="more-menu">
<view
v-for="item in enabledLiquidations"
:key="item.type"
class="more-menu-item"
@click.stop="goLiquidationByType(item)"
>
{{ item.title }}
</view>
</view>
</view>
<view class="num size68 m-y-8" @click="jumpPage('充值', '/pages/home/recharge')">
{{ $fen2yuan(money_obj?.balance || 0) }}
</view>
<view class="line" />
<view class="flex m-t-22 withdraw_row">
<view class="title"> 可提现金额 </view>
<view class="num m-l-34" @click="onWithdrawClick">
{{ $fen2yuan(money_obj?.withdrawAmount || 0) }}
</view>
</view>
</view>
</view>
<!-- 标题 -->
<view class="list-content">
<view class="title-left" />
<view class="title"> 好物推荐 </view>
<view class="title-right" />
</view>
<!-- 商品 -->
<su-sticky top="0">
<view class="goodsIndex">
<goods :list="tagList" v-if="tagList?.length"></goods>
</view>
</su-sticky>
</s-pages>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import * as api from '@/sheep/api/home/pay';
import * as apiIndex from '@/sheep/api/index/index';
import * as incrementApi from '@/sheep/api/increment';
import goods from '@/components/goods/goods.vue';
const money_obj = ref();
const tagList = ref([]);
const showLiquidationMenu = ref(false);
const tradeChannelList = ref([]);
const LIQUIDATION_TYPE_META = {
1: { type: 1, title: '去变现', keywords: ['千里马', '去变现', '变现'] },
2: { type: 2, title: '无双变现', keywords: ['无双'] },
3: { type: 3, title: '华夏变现', keywords: ['华夏'] },
};
const matchLiquidationMeta = (channel) => {
const lt = Number(channel?.liquidationType);
if ([1, 2, 3].includes(lt) && LIQUIDATION_TYPE_META[lt]) {
return { type: lt, meta: LIQUIDATION_TYPE_META[lt] };
}
const name = String(channel?.channelName || channel?.name || '').trim();
if (!name) return null;
for (const key of Object.keys(LIQUIDATION_TYPE_META)) {
const m = LIQUIDATION_TYPE_META[key];
const keywords = Array.isArray(m?.keywords) ? m.keywords : [];
if (keywords.some((kw) => name.includes(kw))) {
return { type: Number(key), meta: m };
}
}
return null;
};
const enabledLiquidations = computed(() => {
const channels = Array.isArray(tradeChannelList.value) ? tradeChannelList.value : [];
const list = [];
const added = new Set();
channels.forEach((it) => {
if (Number(it?.status) !== 1) return;
const matched = matchLiquidationMeta(it);
if (!matched) return;
const type = matched.type;
const meta = matched.meta;
if (added.has(type)) return;
added.add(type);
list.push({
type,
title: meta.title,
channelId: it?.id ?? it?.channelId,
});
});
return list;
});
const withdrawChannelEnabled = computed(() => {
const channels = Array.isArray(tradeChannelList.value) ? tradeChannelList.value : [];
const exact = channels.find(
(it) => String(it?.channelName || it?.name || '').trim() === '去提现'
);
if (exact) return Number(exact?.status) === 1;
const fuzzy = channels.find((it) => {
const name = String(it?.channelName || it?.name || '').trim();
return name.includes('去提现');
});
if (fuzzy) return Number(fuzzy?.status) === 1;
const anyWithdrawLike = channels.find((it) => {
const name = String(it?.channelName || it?.name || '').trim();
return name.includes('提现');
});
if (anyWithdrawLike) return Number(anyWithdrawLike?.status) === 1;
return !channels.length;
});
const fetchTradeChannels = async () => {
try {
const res = await incrementApi.getTradeChannelList();
if (res?.code === 0 && Array.isArray(res?.data)) {
tradeChannelList.value = res.data;
}
} catch (e) {}
};
//获取钱包
function getData() {
api.getWallet().then((res) => {
if (res.code === 0) {
money_obj.value = res.data;
}
});
// 标签列表
apiIndex
.getproducttaglist({
categoryId: 1,
})
.then((res) => {
tagList.value = res.data || [];
});
}
onLoad(() => {
getData();
});
onMounted(() => {
fetchTradeChannels();
});
//充值提现弹框提示去跳转
function onWithdrawClick() {
showLiquidationMenu.value = false;
if (!withdrawChannelEnabled.value) {
return;
}
jumpPage('提现', '/pages/home/pay/withdraw');
}
function jumpPage(typeTxt, url) {
showLiquidationMenu.value = false;
uni.showModal({
content: '是否去' + typeTxt,
showCancel: true,
success: (res) => {
if (res.confirm) {
uni.navigateTo({ url: url });
}
},
});
}
function toggleLiquidationMenu() {
showLiquidationMenu.value = !showLiquidationMenu.value;
}
function goLiquidationByType(item) {
showLiquidationMenu.value = false;
const type = Number(item?.type || 1);
const title = item?.title || LIQUIDATION_TYPE_META[type]?.title || '去变现';
const channelId = item?.channelId ? `&channelId=${item.channelId}` : '';
if (type === 1) {
uni.showModal({
content: '是否去' + title,
showCancel: true,
success: (res) => {
if (!res.confirm) return;
uni.navigateTo({
url: `/pages/home/liquidation?type=${type}${channelId}`,
});
},
});
return;
}
uni.navigateTo({
url: `/pages/home/liquidation?type=${type}${channelId}`,
});
}
</script>
<style lang="scss" scoped>
.header {
height: 318rpx;
margin: 32rpx;
background-size: 100% 100%;
background-repeat: no-repeat;
position: relative;
.header-content {
padding: 80rpx 32rpx 24rpx;
.header-top {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
}
.title {
font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
font-weight: 400;
font-size: 28rpx;
color: #ffffff;
line-height: 40rpx;
}
.more-trigger {
width: 52rpx;
height: 52rpx;
border-radius: 26rpx;
background: rgba(255, 255, 255, 0.14);
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.more-menu {
position: absolute;
top: 58rpx;
right: 0;
min-width: 200rpx;
padding: 10rpx;
border-radius: 18rpx;
background: rgba(26, 45, 88, 0.98);
box-shadow: 0 12rpx 30rpx rgba(0, 0, 0, 0.28);
z-index: 9999;
}
.more-menu-item {
height: 64rpx;
padding: 0 24rpx;
border-radius: 14rpx;
color: #ffffff;
font-size: 26rpx;
display: flex;
align-items: center;
white-space: nowrap;
}
.num {
font-family: Avenir, Avenir;
font-weight: 900;
font-size: 32rpx;
color: #ffffff;
}
.line {
width: 394rpx;
height: 4rpx;
background: linear-gradient(
117deg,
rgba(255, 255, 255, 0.41) 0%,
rgba(255, 255, 255, 0) 100%
);
}
.withdraw_row {
align-items: center;
}
}
}
.list-content {
display: flex;
align-items: center;
justify-content: center;
.title {
font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
font-weight: 500;
font-size: 32rpx;
color: #000;
margin: 0 16rpx;
}
.title-left {
width: 42rpx;
height: 6rpx;
background: linear-gradient(90deg, rgba(255, 255, 255, 0) 7.14%, #f25353 100%);
}
.title-right {
width: 42rpx;
height: 6rpx;
background: linear-gradient(-90deg, rgba(255, 255, 255, 0) 7.14%, #f25353 100%);
}
}
</style>