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

838 lines
20 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<s-pages :bgStyle="{ color: 'var(--color1)' }" title="金种子兑换" pink_bg>
<view class="pages w100 h100">
<view class="content h100">
<view class="con h100">
<view class="top-card-wrap p-x-20 p-y-40">
<view class="top-card">
<view class="top-card__main">
<view class="top-card__price-head">
<view class="top-card__price-col">
<view class="top-card__label">{{ assetData.priceLabel }}</view>
<view class="top-card__price-row">
<text class="top-card__price">{{ assetData.priceText }}</text>
</view>
</view>
<view class="top-card__action">
<view class="top-card__btn" @click="openExchangePopup">兑换</view>
</view>
</view>
<view class="top-card__stats">
<view class="top-card__stat">
<view class="top-card__stat-label">{{ assetData.holdLabel }}</view>
<view class="top-card__stat-value">{{ assetData.holdText }}</view>
</view>
<view class="top-card__divider-v"></view>
<view class="top-card__stat">
<view class="top-card__stat-label">{{ assetData.frozenLabel }}</view>
<view class="top-card__stat-value">{{ assetData.frozenText }}</view>
</view>
<view class="top-card__divider-v"></view>
<view class="top-card__stat">
<view class="top-card__stat-label">{{ assetData.writeOffLabel }}</view>
<view class="top-card__stat-value">{{ assetData.writeOffText }}</view>
</view>
<view class="top-card__divider-v"></view>
<view class="top-card__stat">
<view class="top-card__stat-label">{{ assetData.dividendLabel }}</view>
<view class="top-card__stat-value top-card__stat-value--accent">{{ assetData.dividendText }}</view>
</view>
</view>
</view>
</view>
</view>
<view class="record-card p-x-20 p-b-40">
<view class="record-card__inner r_16 p-20">
<view class="record-card__title center">兑换记录</view>
<view class="record-list__body">
<view v-for="(v, i) in detailList" :key="v.id || i" class="record-item">
<view class="record-item__left">
<view class="record-item__head">
<view class="record-item__title">兑换金种子</view>
<view class="record-item__amount">
{{ formatAmount(v.packageAmount) }} 枚
</view>
</view>
<view class="change-card">
<view class="change-card__left">
<view class="change-card__row">
<view class="change-card__col">
<text class="change-card__label">变动前</text>
<text class="change-card__value">{{ formatAmount(v.balanceBefore) }}</text>
</view>
<view class="change-card__arrow">→</view>
<view class="change-card__col change-card__col--right">
<text class="change-card__label">变动后</text>
<text class="change-card__value">{{ formatAmount(v.balanceAfter) }}</text>
</view>
</view>
</view>
<view class="change-card__divider"></view>
<view class="change-card__right" :class="getStatusRightClass(v.status)">
<view class="record-item__status" :class="getStatusClass(v.status)">
{{ v.statusDesc || statusMap[Number(v.status)] || '' }}
</view>
</view>
</view>
<view class="record-item__meta-row">
<text class="record-item__meta-label">创建时间:</text>
<text class="record-item__meta-value">{{ formatDateTime(v.createTime) }}</text>
</view>
<view v-if="v.approveTime" class="record-item__meta-row">
<text class="record-item__meta-label">审核时间:</text>
<text class="record-item__meta-value">{{ formatDateTime(v.approveTime) }}</text>
</view>
<view v-if="v.approveRemark" class="record-item__remark-row">
<text class="record-item__remark-label">备注:</text>
<text class="record-item__remark-text">{{ v.approveRemark }}</text>
</view>
</view>
</view>
<view v-if="detailList.length === 0 && !loadingList" class="empty-list">暂无兑换记录</view>
<view v-if="loadingList" class="empty-list">加载中...</view>
<view v-if="detailList.length > 0 && noMore" class="empty-list empty-list--hint">没有更多了</view>
</view>
</view>
</view>
</view>
</view>
</view>
<view v-if="popupVisible" class="popup-mask" @click="closeExchangePopup">
<view class="popup-dialog" @click.stop>
<view class="popup-header">
<view class="popup-title">兑换金种子</view>
<view class="popup-close" @click="closeExchangePopup">×</view>
</view>
<view class="popup-body">
<view class="popup-balance">
<view class="popup-balance__item">
<text class="popup-balance-label">当前持有</text>
<text class="popup-balance-value">{{ assetData.holdText }} 枚</text>
</view>
<view class="popup-balance__divider"></view>
<view class="popup-balance__item">
<text class="popup-balance-label">冻结数量</text>
<text class="popup-balance-value">{{ assetData.frozenText }} 枚</text>
</view>
</view>
<view class="popup-fixed-box">
<view class="popup-fixed-label">本次兑换</view>
<view class="popup-fixed-value">
<text class="popup-fixed-num">{{ exchangeAmount }}</text>
<text class="popup-fixed-unit">枚</text>
</view>
<view class="popup-fixed-tag">每笔固定 {{ exchangeAmount }} 金种子</view>
</view>
<view class="popup-tip">
<uni-icons type="info" color="#C6C6C6" size="20" />
<text class="popup-tip-text">请慎重考虑,一经提交,不可撤销</text>
</view>
</view>
<view class="popup-footer">
<view class="popup-btn popup-btn--cancel" @click="closeExchangePopup">取消</view>
<view class="popup-btn popup-btn--confirm" @click="submitExchange">确认兑换</view>
</view>
</view>
</view>
</s-pages>
</template>
<script setup>
import { ref, reactive, computed, getCurrentInstance } from 'vue';
import { onShow, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app';
import sheep from '@/sheep';
import * as homeApi from '@/sheep/api/home/index';
const { proxy } = getCurrentInstance();
const PAGE_SIZE = 20;
const exchangeAmount = ref(100);
const popupVisible = ref(false);
const detailList = ref([]);
const dataObj = reactive({});
const load = ref(false);
const pageNo = ref(1);
const loadingList = ref(false);
const noMore = ref(false);
const statusMap = {
0: '待审核',
1: '审核通过',
2: '审核拒绝',
};
const getStatusClass = (status) => {
const s = Number(status);
if (s === 1) return 'record-item__status--pass';
if (s === 2) return 'record-item__status--reject';
return 'record-item__status--pending';
};
const getStatusRightClass = (status) => {
const s = Number(status);
if (s === 1) return 'change-card__right--pass';
if (s === 2) return 'change-card__right--reject';
return 'change-card__right--pending';
};
const assetData = computed(() => {
const price = dataObj?.todayPrice;
const hold = dataObj?.myCount;
const frozen = dataObj?.frozenCount;
const writeOff = dataObj?.writeOffCount;
const dividend = dataObj?.dividendCount;
return {
priceLabel: '当前价格',
holdLabel: '持有数量',
frozenLabel: '冻结数量',
writeOffLabel: '已核销',
dividendLabel: '累计分红',
priceText: formatPrice(price) || '0.0000',
holdText: formatAmount(hold),
frozenText: formatAmount(frozen),
writeOffText: formatAmount(writeOff),
dividendText: `¥${formatAmount(dividend)}`,
};
});
const formatPrice = (val) => {
const n = Number(val);
if (!Number.isFinite(n)) return '0.0000';
return n.toLocaleString(undefined, {
minimumFractionDigits: 4,
maximumFractionDigits: 4,
});
};
const formatAmount = (val) => {
const n = Number(val);
if (!Number.isFinite(n)) return '0';
return n.toLocaleString();
};
const formatDateTime = (val) => {
if (!val) return '';
const d = new Date(Number(val));
if (!Number.isFinite(d.getTime())) return '';
const pad2 = (n) => String(n).padStart(2, '0');
return `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())} ${pad2(d.getHours())}:${pad2(d.getMinutes())}`;
};
const fetchExchangeConfig = async () => {
const res = await homeApi.goldSeedExchangeGetConfig();
if (res?.code === 0) {
const n = Number(res?.data);
if (Number.isFinite(n) && n > 0) {
exchangeAmount.value = n;
}
}
};
const fetchAsset = async () => {
const res = await homeApi.goldSeedIndex();
load.value = true;
if (res?.code === 0) {
Object.assign(dataObj, res?.data || {});
}
};
const getList = async (reset = false) => {
if (loadingList.value) return;
loadingList.value = true;
if (reset) {
pageNo.value = 1;
noMore.value = false;
}
try {
const params = { pageNo: pageNo.value, pageSize: PAGE_SIZE };
const res = await homeApi.goldSeedExchangePage(params);
if (res?.code === 0) {
const arr = res?.data?.list || [];
if (pageNo.value === 1) {
detailList.value = [];
}
detailList.value = detailList.value.concat(arr);
if (arr.length < PAGE_SIZE) {
noMore.value = true;
} else {
pageNo.value += 1;
}
} else {
noMore.value = true;
}
} finally {
loadingList.value = false;
}
};
const refresh = async () => {
await fetchAsset();
await getList(true);
try { uni.stopPullDownRefresh(); } catch (e) {}
};
const openExchangePopup = async () => {
await fetchExchangeConfig();
popupVisible.value = true;
};
const closeExchangePopup = () => {
popupVisible.value = false;
};
const submitExchange = async () => {
const amount = Number(exchangeAmount.value) || 0;
const res = await homeApi.goldSeedExchangeCreate({ packageAmount: amount });
if (res?.code === 0) {
closeExchangePopup();
fetchAsset();
setTimeout(() => getList(true), 300);
} else if (res && res.code !== undefined && res.code !== 0) {
if (res?.msg) {
sheep.$helper.toast(res.msg);
}
}
};
onShow(() => {
refresh();
});
onPullDownRefresh(() => {
refresh();
});
onReachBottom(() => {
if (!noMore.value) {
getList(false);
}
});
</script>
<style lang="scss" scoped>
.pages {
.content {
width: 100%;
padding-top: 30rpx;
}
.con {
padding: 0 0 100rpx;
box-sizing: border-box;
display: flex;
flex-direction: column;
}
}
.h100 { height: 100%; }
.w100 { width: 100%; }
.p-x-20 { padding-left: 40rpx; padding-right: 40rpx; }
.p-y-40 { padding-top: 80rpx; padding-bottom: 80rpx; }
.p-b-40 { padding-bottom: 80rpx; }
.p-20 { padding: 40rpx; }
.r_16 { border-radius: 32rpx; }
.center { text-align: center; }
.top-card-wrap {
padding-top: 40rpx;
padding-bottom: 20rpx;
flex-shrink: 0;
}
.top-card {
background: rgba(255, 255, 255, 0.85);
backdrop-filter: blur(10px);
border: 1rpx solid rgba(255, 255, 255, 0.5);
border-radius: 28rpx;
padding: 32rpx 28rpx;
}
.top-card__main {
width: 100%;
min-width: 0;
display: flex;
flex-direction: column;
gap: 14rpx;
}
.top-card__price-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18rpx;
}
.top-card__price-col {
display: flex;
flex-direction: column;
gap: 6rpx;
min-width: 0;
flex: 1;
}
.top-card__label {
font-size: 26rpx;
color: #585654;
opacity: 0.9;
}
.top-card__price-row {
margin-top: 6rpx;
display: flex;
align-items: flex-end;
gap: 10rpx;
}
.top-card__price {
font-size: 68rpx;
font-weight: 800;
color: #111;
line-height: 1;
}
.top-card__stats {
display: flex;
align-items: stretch;
justify-content: space-between;
margin-top: 22rpx;
}
.top-card__stat {
flex: 1;
display: flex;
flex-direction: column;
gap: 8rpx;
}
.top-card__stat-label {
font-size: 24rpx;
color: #585654;
opacity: 0.9;
}
.top-card__stat-value {
margin-top: 10rpx;
font-size: 28rpx;
font-weight: 700;
color: #111;
line-height: 1.1;
}
.top-card__stat-value--accent {
color: #e54035;
}
.top-card__divider-v {
width: 1rpx;
background: rgba(0, 0, 0, 0.08);
margin: 0 20rpx;
}
.top-card__action {
flex-shrink: 0;
display: flex;
align-items: center;
padding-top: 6rpx;
}
.top-card__btn {
height: 64rpx;
line-height: 64rpx;
padding: 0 32rpx;
border-radius: 32rpx;
background: linear-gradient(131deg, #f7772e 0%, #ee0a24 100%);
color: #fff;
font-size: 28rpx;
font-weight: 600;
text-align: center;
}
.record-card {
flex: 1;
min-height: 0;
flex-shrink: 0;
}
.record-card__inner {
height: 100%;
display: flex;
flex-direction: column;
background: rgba(255, 255, 255, 0.85);
backdrop-filter: blur(10px);
border: 1rpx solid rgba(255, 255, 255, 0.5);
}
.record-card__title {
font-size: 30rpx;
font-weight: 700;
color: #111;
padding-bottom: 24rpx;
border-bottom: 1rpx solid rgba(0, 0, 0, 0.06);
margin-bottom: 20rpx;
flex-shrink: 0;
}
.record-list__body {
flex: 1;
display: flex;
flex-direction: column;
gap: 20rpx;
min-height: 400rpx;
}
.empty-list {
padding: 80rpx 0;
text-align: center;
color: #999;
font-size: 26rpx;
}
.empty-list--hint {
padding: 40rpx 0;
font-size: 22rpx;
}
.record-item {
background: #ffffff;
border-radius: 20rpx;
padding: 24rpx 22rpx;
box-shadow: 0 4rpx 14rpx rgba(15, 23, 42, 0.05);
border: 1rpx solid rgba(0, 0, 0, 0.04);
}
.record-item__head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 18rpx;
}
.record-item__title {
font-size: 30rpx;
font-weight: 700;
color: #111;
}
.record-item__amount {
font-size: 28rpx;
font-weight: 700;
color: #111;
}
.change-card {
display: flex;
align-items: stretch;
border-radius: 20rpx;
overflow: hidden;
margin-bottom: 20rpx;
}
.change-card__left {
flex: 1;
padding: 22rpx 24rpx;
min-width: 0;
background: linear-gradient(135deg, rgba(107, 114, 128, 0.06) 0%, rgba(59, 130, 246, 0.05) 100%);
border: 1rpx solid rgba(107, 114, 128, 0.12);
border-right: none;
border-radius: 20rpx 0 0 20rpx;
}
.change-card__row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10rpx;
}
.change-card__col {
flex: 1;
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 10rpx;
min-width: 0;
}
.change-card__col--right {
align-items: flex-end;
}
.change-card__label {
font-size: 22rpx;
color: #585654;
opacity: 0.85;
}
.change-card__value {
font-size: 30rpx;
font-weight: 600;
color: #111;
line-height: 1.1;
}
.change-card__arrow {
flex-shrink: 0;
padding: 0 12rpx;
font-size: 28rpx;
color: #585654;
opacity: 0.7;
}
.change-card__divider {
width: 1rpx;
background: rgba(0, 0, 0, 0.1);
}
.change-card__right {
width: 180rpx;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
padding: 20rpx 16rpx;
border-left: none;
border-radius: 0 20rpx 20rpx 0;
}
.change-card__right--pending {
background: linear-gradient(135deg, rgba(245, 158, 11, 0.08) 0%, rgba(217, 119, 6, 0.06) 100%);
border: 1rpx solid rgba(245, 158, 11, 0.2);
border-left: none;
}
.change-card__right--pass {
background: linear-gradient(135deg, rgba(16, 185, 129, 0.08) 0%, rgba(5, 150, 105, 0.06) 100%);
border: 1rpx solid rgba(16, 185, 129, 0.2);
border-left: none;
}
.change-card__right--reject {
background: linear-gradient(135deg, rgba(248, 113, 113, 0.08) 0%, rgba(239, 68, 68, 0.06) 100%);
border: 1rpx solid rgba(248, 113, 113, 0.2);
border-left: none;
}
.record-item__status {
font-size: 26rpx;
font-weight: 700;
line-height: 1.2;
}
.record-item__status--pending { color: #f59e0b; }
.record-item__status--pass { color: #10b981; }
.record-item__status--reject { color: #ef4444; }
.record-item__meta-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 14rpx;
font-size: 24rpx;
line-height: 1.4;
}
.record-item__meta-label {
color: #585654;
opacity: 0.85;
}
.record-item__meta-value {
color: #111;
text-align: right;
}
.record-item__remark-row {
display: flex;
align-items: flex-start;
justify-content: space-between;
margin-top: 14rpx;
font-size: 24rpx;
line-height: 1.5;
}
.record-item__remark-label {
color: #585654;
opacity: 0.85;
flex-shrink: 0;
margin-right: 12rpx;
}
.record-item__remark-text {
color: #111;
text-align: right;
flex: 1;
}
/* 兑换弹窗 */
.popup-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 9999;
display: flex;
align-items: center;
justify-content: center;
padding: 40rpx;
}
.popup-dialog {
width: 100%;
max-width: 640rpx;
background: #fff;
border-radius: 24rpx;
overflow: hidden;
}
.popup-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 28rpx 32rpx;
border-bottom: 1rpx solid rgba(0, 0, 0, 0.06);
}
.popup-title {
font-size: 32rpx;
font-weight: 700;
color: #111;
}
.popup-close {
font-size: 44rpx;
line-height: 1;
color: #999;
padding: 0 10rpx;
}
.popup-body {
padding: 10rpx 32rpx 20rpx;
}
.popup-balance {
background: #f6f5f5;
border-radius: 16rpx;
padding: 20rpx 12rpx;
display: flex;
align-items: stretch;
justify-content: space-between;
margin-bottom: 28rpx;
margin-top: 20rpx;
}
.popup-balance__item {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 4rpx 12rpx;
gap: 10rpx;
}
.popup-balance__divider {
width: 1rpx;
background: rgba(0, 0, 0, 0.1);
margin: 10rpx 0;
}
.popup-balance-label {
font-size: 24rpx;
color: #666;
}
.popup-balance-value {
font-size: 32rpx;
font-weight: 700;
color: #111;
}
.popup-fixed-box {
background: linear-gradient(135deg, rgba(247, 119, 46, 0.1) 0%, rgba(238, 10, 36, 0.08) 100%);
border: 1rpx solid rgba(238, 10, 36, 0.15);
border-radius: 16rpx;
padding: 22rpx 24rpx;
display: flex;
flex-direction: column;
align-items: center;
gap: 8rpx;
margin-bottom: 20rpx;
}
.popup-fixed-label {
font-size: 24rpx;
color: #585654;
}
.popup-fixed-value {
display: flex;
align-items: baseline;
gap: 6rpx;
margin-top: 4rpx;
}
.popup-fixed-num {
font-size: 56rpx;
font-weight: 900;
color: #e54035;
line-height: 1;
}
.popup-fixed-unit {
font-size: 28rpx;
color: #e54035;
font-weight: 600;
}
.popup-fixed-tag {
margin-top: 10rpx;
font-size: 22rpx;
color: #585654;
opacity: 0.85;
}
.popup-tip {
margin-top: 8rpx;
display: flex;
align-items: center;
justify-content: flex-start;
gap: 8rpx;
padding: 14rpx 18rpx;
background: rgba(120, 120, 120, 0.06);
border-radius: 14rpx;
}
.popup-tip-text {
font-size: 22rpx;
color: #666;
line-height: 1.4;
}
.popup-footer {
display: flex;
align-items: center;
gap: 20rpx;
padding: 20rpx 32rpx 28rpx;
border-top: 1rpx solid rgba(0, 0, 0, 0.04);
}
.popup-btn {
flex: 1;
height: 88rpx;
line-height: 88rpx;
text-align: center;
border-radius: 44rpx;
font-size: 30rpx;
font-weight: 600;
}
.popup-btn--cancel {
background: #f2f2f2;
color: #555;
}
.popup-btn--confirm {
background: linear-gradient(131deg, #f7772e 0%, #ee0a24 100%);
color: #fff;
}
</style>