|
@@ -73,7 +73,8 @@
|
|
|
|
|
|
<script>
|
|
<script>
|
|
import Toast from '@/components/Toast.vue';
|
|
import Toast from '@/components/Toast.vue';
|
|
-import { getLotteryPrize } from '@/api/profile';
|
|
|
|
|
|
+import { getLotteryPrize, exchangePrize } from '@/api/profile';
|
|
|
|
+
|
|
export default {
|
|
export default {
|
|
name: 'JifenPage',
|
|
name: 'JifenPage',
|
|
components: {
|
|
components: {
|
|
@@ -81,27 +82,16 @@ export default {
|
|
},
|
|
},
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
- userPoints: 0.00,
|
|
|
|
showConfirmDialog: false,
|
|
showConfirmDialog: false,
|
|
selectedProduct: null,
|
|
selectedProduct: null,
|
|
products: []
|
|
products: []
|
|
}
|
|
}
|
|
},
|
|
},
|
|
mounted() {
|
|
mounted() {
|
|
- // this.loadUserPoints();
|
|
|
|
this.loadProducts();
|
|
this.loadProducts();
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
- // 加载用户积分
|
|
|
|
- async loadUserPoints() {
|
|
|
|
- try {
|
|
|
|
- const res = await getLotteryPrize();
|
|
|
|
- this.userPoints = res.data.points;
|
|
|
|
- } catch (error) {
|
|
|
|
- console.error('加载用户积分失败:', error);
|
|
|
|
- this.$refs.toast.show('加载积分失败', 'error');
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
|
|
+
|
|
|
|
|
|
// 加载商品列表
|
|
// 加载商品列表
|
|
async loadProducts() {
|
|
async loadProducts() {
|
|
@@ -117,12 +107,7 @@ export default {
|
|
},
|
|
},
|
|
|
|
|
|
// 处理兑换点击
|
|
// 处理兑换点击
|
|
- handleExchange(product) {
|
|
|
|
- if (this.userPoints < product.points) {
|
|
|
|
- this.$refs.toast.show('积分不足,无法兑换', 'error');
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ handleExchange(product) {
|
|
this.selectedProduct = product;
|
|
this.selectedProduct = product;
|
|
this.showConfirmDialog = true;
|
|
this.showConfirmDialog = true;
|
|
},
|
|
},
|
|
@@ -136,21 +121,22 @@ export default {
|
|
// 确认兑换
|
|
// 确认兑换
|
|
async confirmExchange() {
|
|
async confirmExchange() {
|
|
try {
|
|
try {
|
|
- // 这里应该调用真实的兑换API
|
|
|
|
- // const response = await exchangeProduct({
|
|
|
|
- // productId: this.selectedProduct.id,
|
|
|
|
- // points: this.selectedProduct.points
|
|
|
|
- // });
|
|
|
|
-
|
|
|
|
- // 模拟兑换成功
|
|
|
|
- this.userPoints -= this.selectedProduct.points;
|
|
|
|
- this.$refs.toast.show('兑换成功!', 'success');
|
|
|
|
|
|
+ const res = await exchangePrize({
|
|
|
|
+ prize_id: this.selectedProduct.id,
|
|
|
|
+ });
|
|
|
|
+ console.log(res);
|
|
|
|
+ if(res.code == 1){
|
|
|
|
+ this.$refs.toast.show('兑换成功!', 'success');
|
|
|
|
+ this.userPoints -= this.selectedProduct.points;
|
|
|
|
+ this.showConfirmDialog = false;
|
|
|
|
+ this.selectedProduct = null;
|
|
|
|
+ }else{
|
|
|
|
+ this.$refs.toast.show('兑换失败,请重试', 'error');
|
|
|
|
+ }
|
|
|
|
|
|
this.showConfirmDialog = false;
|
|
this.showConfirmDialog = false;
|
|
this.selectedProduct = null;
|
|
this.selectedProduct = null;
|
|
|
|
|
|
- // 可以跳转到兑换记录页面
|
|
|
|
- // this.$router.push('/exchange-records');
|
|
|
|
|
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
console.error('兑换失败:', error);
|
|
console.error('兑换失败:', error);
|