tt0101 1 день тому
батько
коміт
fd222c60ba
3 змінених файлів з 29 додано та 54 видалено
  1. 5 1
      src/api/profile.js
  2. 16 30
      src/views/jifen.vue
  3. 8 23
      src/views/shdizhi.vue

+ 5 - 1
src/api/profile.js

@@ -71,4 +71,8 @@ export const setBankInfo = (data) => {
   });
 };
 // 获取积分商城商品列表 
-export const getLotteryPrize = () => request({ url: "/index/get_lottery_prize", method: "get", loading: true });
+export const getLotteryPrize = () => request({ url: "/index/get_lottery_prize", method: "get", loading: true });
+// 兑换奖品
+export const exchangePrize = (data) => request({ url: "/index/exchange_prize", method: "post", data, loading: true });
+// 设置收货地址 
+export const bindAddress = (data) => request({ url: "/index/bind_address", method: "post", data, loading: true });

+ 16 - 30
src/views/jifen.vue

@@ -73,7 +73,8 @@
 
 <script>
 import Toast from '@/components/Toast.vue';
-import { getLotteryPrize } from '@/api/profile';
+import { getLotteryPrize, exchangePrize } from '@/api/profile';
+
 export default {
   name: 'JifenPage',
   components: {
@@ -81,27 +82,16 @@ export default {
   },
   data() {
     return {
-      userPoints: 0.00,
       showConfirmDialog: false,
       selectedProduct: null,
       products: []
     }
   },
   mounted() {
-    // this.loadUserPoints();
     this.loadProducts();
   },
   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() {
@@ -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.showConfirmDialog = true;
     },
@@ -136,21 +121,22 @@ export default {
     // 确认兑换
     async confirmExchange() {
       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.selectedProduct = null;
         
-        // 可以跳转到兑换记录页面
-        // this.$router.push('/exchange-records');
         
       } catch (error) {
         console.error('兑换失败:', error);

+ 8 - 23
src/views/shdizhi.vue

@@ -72,7 +72,7 @@
 <script>
 import Toast from '@/components/Toast.vue';
 import NavBar from '@/components/NavBar.vue';
-
+import { bindAddress } from '@/api/profile';
 export default {
   name: 'ShdizhiPage',
   components: {
@@ -151,28 +151,13 @@ export default {
 
     // 保存地址
     async saveAddress() {
-      if (!this.isFormValid) {
-        this.$refs.toast.show('请填写完整的收货信息', 'error');
-        return;
-      }
-
-      if (!this.isValidPhone(this.addressForm.phone)) {
-        this.$refs.toast.show('请输入正确的手机号码', 'error');
-        return;
-      }
-
-      try {
-        localStorage.setItem('userAddress', JSON.stringify(this.addressForm));
-        this.$refs.toast.show('地址保存成功!', 'success');
-        
-        setTimeout(() => {
-          this.$router.back();
-        }, 1500);
-        
-      } catch (error) {
-        console.error('保存地址失败:', error);
-        this.$refs.toast.show('保存失败,请重试', 'error');
-      }
+    const res = await bindAddress({
+            name: this.addressForm.name,
+            phone: this.addressForm.phone,
+            address: this.addressForm.address
+    });
+    console.log(res);
+      
     }
   }
 }