feat: 兑换添加手动价格、添加撤单功能

This commit is contained in:
2026-10-08 16:58:47 +08:00
parent 1c34e15f8a
commit 39100c71be
2 changed files with 311 additions and 113 deletions
+245 -61
View File
@@ -54,24 +54,28 @@
{{ 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 class="change-card" :class="Number(v.status) === 0 ? 'change-card--pending' : ''">
<view v-if="Number(v.status) === 0" class="change-card__pending-tag">
<text class="record-item__status record-item__status--pending">
{{ statusMap[Number(v.status)] || v.statusDesc || '' }}
</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 class="change-card__left" :class="Number(v.status) === 0 ? 'change-card__left--pending' : ''">
<view class="change-card__price-label">兑换价格</view>
<view class="change-card__price-row" :class="Number(v.status) === 0 ? 'change-card__price-row--with-cancel' : ''">
<view class="change-card__price-main">
<text class="change-card__price-symbol">¥</text>
<text class="change-card__price-value">{{ formatRecordPrice(v.price) }}</text>
</view>
<view v-if="Number(v.status) === 0" class="cancel-btn cancel-btn--inline" @click="handleCancel(v)">撤单</view>
</view>
</view>
</view>
<view class="change-card__divider"></view>
<view class="change-card__right" :class="getStatusRightClass(v.status)">
<view v-if="Number(v.status) !== 0" class="change-card__divider"></view>
<view v-if="Number(v.status) !== 0" class="change-card__right" :class="[getStatusRightClass(v.status)]">
<view class="change-card__right-top">
<view class="record-item__status" :class="getStatusClass(v.status)">
{{ v.statusDesc || statusMap[Number(v.status)] || '' }}
{{ statusMap[Number(v.status)] || v.statusDesc || '' }}
</view>
</view>
</view>
</view>
@@ -125,6 +129,13 @@
</view>
<view class="popup-fixed-tag">每笔固定 {{ exchangeAmount }} 金种子</view>
</view>
<view class="popup-input-box">
<view class="popup-input-label">兑换价格</view>
<view class="popup-input-row">
<text class="popup-input-symbol">¥</text>
<input class="popup-input" type="digit" :value="inputPrice" @input="onPriceInput" placeholder="请输入兑换价格" />
</view>
</view>
<view class="popup-tip">
<uni-icons type="info" color="#C6C6C6" size="20" />
<text class="popup-tip-text">请慎重考虑,一经提交,不可撤销</text>
@@ -149,6 +160,7 @@ const { proxy } = getCurrentInstance();
const PAGE_SIZE = 20;
const exchangeAmount = ref(100);
const inputPrice = ref('');
const popupVisible = ref(false);
const detailList = ref([]);
const dataObj = reactive({});
@@ -161,19 +173,20 @@ const statusMap = {
0: '待审核',
1: '审核通过',
2: '审核拒绝',
3: '已撤单',
};
const getStatusClass = (status) => {
const s = Number(status);
if (s === 1) return 'record-item__status--pass';
if (s === 2) return 'record-item__status--reject';
if (s === 2 || s === 3) 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';
if (s === 2 || s === 3) return 'change-card__right--reject';
return 'change-card__right--pending';
};
@@ -212,6 +225,26 @@ const formatAmount = (val) => {
return n.toLocaleString();
};
const formatRecordPrice = (val) => {
const n = Number(val);
if (!Number.isFinite(n)) return '0.0000';
return n.toFixed(4);
};
const onPriceInput = (e) => {
let val = e?.detail?.value ?? '';
val = val.replace(/[^\d.]/g, '');
const firstDot = val.indexOf('.');
if (firstDot !== -1) {
val = val.slice(0, firstDot + 1) + val.slice(firstDot + 1).replace(/\./g, '');
}
const parts = val.split('.');
if (parts.length > 1 && parts[1].length > 4) {
val = parts[0] + '.' + parts[1].slice(0, 4);
}
inputPrice.value = val;
};
const formatDateTime = (val) => {
if (!val) return '';
const d = new Date(Number(val));
@@ -275,18 +308,29 @@ const refresh = async () => {
const openExchangePopup = async () => {
await fetchExchangeConfig();
inputPrice.value = '';
popupVisible.value = true;
};
const closeExchangePopup = () => {
popupVisible.value = false;
inputPrice.value = '';
};
const submitExchange = async () => {
const amount = Number(exchangeAmount.value) || 0;
const price = Number(inputPrice.value);
if (!Number.isFinite(price) || price <= 0) {
uni.showToast({
title: '请输入兑换价格',
icon: 'none',
mask: true,
duration: 2000,
});
return;
}
let errorMsg = '';
try {
const res = await homeApi.goldSeedExchangeCreate({ packageAmount: amount });
const res = await homeApi.goldSeedExchangeCreate({ price });
if (res?.code === 0) {
closeExchangePopup();
fetchAsset();
@@ -299,7 +343,6 @@ const submitExchange = async () => {
errorMsg = (e && (e.msg || e.message)) ? (e.msg || e.message) : '请求异常,请稍后重试';
}
if (errorMsg) {
// 先关闭弹窗,避免遮罩层级遮挡导致 toast 不显示
closeExchangePopup();
setTimeout(() => {
uni.showToast({
@@ -312,6 +355,41 @@ const submitExchange = async () => {
}
};
const handleCancel = (item) => {
uni.showModal({
title: '提示',
content: '确定要撤销该兑换申请吗?',
confirmColor: '#ee0a24',
success: async (res) => {
if (!res.confirm) return;
let errorMsg = '';
try {
const cancelRes = await homeApi.goldSeedExchangeCancel({
packageId: item.id,
});
if (cancelRes?.code === 0) {
uni.showToast({ title: '撤销成功', icon: 'none', duration: 1500 });
fetchAsset();
setTimeout(() => getList(true), 300);
return;
}
errorMsg = cancelRes?.msg
|| (cancelRes && typeof cancelRes.code === 'number' ? '操作失败' : '网络异常');
} catch (e) {
errorMsg = (e && (e.msg || e.message)) ? (e.msg || e.message) : '请求异常,请稍后重试';
}
if (errorMsg) {
uni.showToast({
title: errorMsg,
icon: 'none',
mask: true,
duration: 2500,
});
}
},
});
};
onShow(() => {
refresh();
});
@@ -537,76 +615,139 @@ onReachBottom(() => {
.change-card {
display: flex;
align-items: stretch;
border-radius: 20rpx;
border-radius: 16rpx;
overflow: hidden;
margin-bottom: 20rpx;
margin-bottom: 16rpx;
position: relative;
}
.change-card--pending {
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);
}
.change-card__pending-tag {
position: absolute;
top: 10rpx;
right: 24rpx;
z-index: 2;
}
.change-card__left {
flex: 1;
padding: 22rpx 24rpx;
padding: 22rpx 28rpx;
min-width: 0;
display: flex;
flex-direction: column;
justify-content: center;
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;
border-radius: 16rpx 0 0 16rpx;
}
.change-card__row {
.change-card__left > view + view {
margin-top: 10rpx;
}
.change-card__left--pending {
border: none;
border-radius: 16rpx;
min-height: 120rpx;
}
.change-card__left--pending > view + view {
margin-top: 12rpx;
}
.change-card__price-row--with-cancel {
display: flex;
align-items: flex-end;
justify-content: flex-start;
}
.change-card__price-main {
display: inline-block;
min-width: 0;
flex-shrink: 1;
line-height: 44rpx;
height: 44rpx;
white-space: nowrap;
}
.cancel-btn--inline {
margin-left: auto;
height: 40rpx;
padding: 0 12rpx;
border-radius: 12rpx;
border: none;
color: #ee0a24;
font-size: 20rpx;
display: flex;
align-items: center;
justify-content: space-between;
gap: 10rpx;
justify-content: center;
box-sizing: border-box;
border: 1rpx solid #ee0a24;
}
.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 {
.change-card__price-label {
font-size: 22rpx;
color: #585654;
opacity: 0.85;
color: #8b8b8b;
line-height: 30rpx;
}
.change-card__value {
font-size: 30rpx;
font-weight: 600;
.change-card__price-row {
line-height: 44rpx;
height: 44rpx;
white-space: nowrap;
}
.change-card__price-symbol {
display: inline-block;
font-size: 26rpx;
font-weight: 700;
color: #f7772e;
line-height: 44rpx;
height: 44rpx;
vertical-align: top;
margin-right: 4rpx;
}
.change-card__price-value {
display: inline-block;
font-size: 44rpx;
font-weight: 800;
color: #111;
line-height: 1.1;
}
.change-card__arrow {
flex-shrink: 0;
padding: 0 12rpx;
font-size: 28rpx;
color: #585654;
opacity: 0.7;
line-height: 44rpx;
height: 44rpx;
vertical-align: top;
letter-spacing: 1rpx;
}
.change-card__divider {
width: 1rpx;
background: rgba(0, 0, 0, 0.1);
border-left: 2rpx dashed rgba(0, 0, 0, 0.15);
flex-shrink: 0;
}
.change-card__right {
width: 180rpx;
flex-shrink: 0;
display: flex;
flex-direction: column;
align-items: stretch;
justify-content: center;
padding: 22rpx 18rpx;
border-left: none;
border-radius: 0 16rpx 16rpx 0;
min-height: 120rpx;
}
.change-card__right-top {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
padding: 20rpx 16rpx;
border-left: none;
border-radius: 0 20rpx 20rpx 0;
}
.change-card__right--pending {
@@ -620,8 +761,8 @@ onReachBottom(() => {
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);
background: linear-gradient(135deg, rgba(156, 163, 175, 0.08) 0%, rgba(107, 114, 128, 0.06) 100%);
border: 1rpx solid rgba(156, 163, 175, 0.2);
border-left: none;
}
@@ -633,7 +774,7 @@ onReachBottom(() => {
.record-item__status--pending { color: #f59e0b; }
.record-item__status--pass { color: #10b981; }
.record-item__status--reject { color: #ef4444; }
.record-item__status--reject { color: #9ca3af; }
.record-item__meta-row {
display: flex;
@@ -806,6 +947,49 @@ onReachBottom(() => {
opacity: 0.85;
}
.popup-input-box {
background: #f6f5f5;
border-radius: 16rpx;
padding: 24rpx 24rpx 20rpx;
margin-bottom: 8rpx;
}
.popup-input-label {
font-size: 24rpx;
color: #585654;
font-weight: 600;
line-height: 34rpx;
}
.popup-input-row {
margin-top: 14rpx;
display: flex;
align-items: center;
background: #fff;
border-radius: 12rpx;
padding: 0 20rpx;
height: 88rpx;
border: 1rpx solid rgba(0, 0, 0, 0.08);
}
.popup-input-symbol {
font-size: 32rpx;
font-weight: 800;
color: #f7772e;
margin-right: 8rpx;
line-height: 1;
}
.popup-input {
flex: 1;
min-width: 0;
font-size: 32rpx;
font-weight: 700;
color: #111;
height: 88rpx;
line-height: 88rpx;
}
.popup-tip {
margin-top: 8rpx;
display: flex;
+15 -1
View File
@@ -96,7 +96,7 @@ export const goldSeedExchangeCreate = (params) => {
return request({
url: '/member/app/gold-seed-exchange/create',
method: 'POST',
data: params,
params: params,
custom: {
showSuccess: true,
showError: false,
@@ -105,6 +105,20 @@ export const goldSeedExchangeCreate = (params) => {
},
});
};
// 撤销金种子兑换
export const goldSeedExchangeCancel = (params) => {
return request({
url: '/member/app/gold-seed-exchange/cancel',
method: 'POST',
params: params,
custom: {
showSuccess: true,
showError: false,
loadingMsg: '撤销中',
successMsg: '撤销成功',
},
});
};
// 社员统计
export const getTeamStats = (params) => {
return request({