wangguoyu 2 päivää sitten
vanhempi
commit
c0f1f0e6a1
1 muutettua tiedostoa jossa 27 lisäystä ja 23 poistoa
  1. 27 23
      pages/mall/mallPage.vue

+ 27 - 23
pages/mall/mallPage.vue

@@ -23,7 +23,7 @@
 									<view class="content-text">{{item.intro}}</view>
 									<view class="content-row">
 										<view class="content-yuanjia">原价:{{item.yuanjia}}</view>
-										<view class="shop-car-box" @click="addProduct(item.id)">
+										<view class="shop-car-box" @click="addProduct(item)">
 											<icon v-if="productData.selectedIds.includes(item.id)" class="car-change">
 											</icon>
 										</view>
@@ -52,7 +52,7 @@
 				<!-- 需要换成从接口中取得 wgy -->
 				<view class="price-icon-box">
 					<text class="red-price fh-text">¥</text>
-					<text class="red-price">1999.8</text>明细
+					<text class="red-price">{{totalPrice}}</text>明细
 					<icon :class="mxjtClass"></icon>
 				</view>
 				<view>购买即同意虚拟产品不支持退订</view>
@@ -80,6 +80,7 @@
 <script setup>
 	import {
 		reactive,
+		computed,
 		nextTick,
 		ref
 	} from "vue";
@@ -111,6 +112,12 @@
 		list: [],
 		selectedIds: [] // 新增选中状态存储
 	})
+	const totalPrice = computed(() => {
+		return productData.list
+			.filter(item => productData.selectedIds.includes(item.id))
+			.reduce((sum, item) => sum + parseFloat(item.xianjia || 0), 0)
+			.toFixed(2)
+	})
 
 	function switchPayWay() {
 		showPayWay.value = !showPayWay.value
@@ -140,7 +147,8 @@
 
 	function onChangeTab(e) {
 		console.log('e', e);
-		productData.current = e.currentIndex
+		productData.current = e.currentIndex
+		productData.selectedIds = [] // 清空选中
 		getMore()
 	}
 
@@ -183,23 +191,14 @@
 		}
 	}
 
-	function addProduct(id) {
-		// 当存在外部cardId时禁止操作
-		// if (productData.cardId) return
-		// const index = productData.selectedIds.indexOf(id)
-		// if (index > -1) {
-		// 	productData.selectedIds.splice(index, 1)
-		// } else {
-		// 	productData.selectedIds.push(id)
-		// }
-		
-		
-		
+	function addProduct(item) {
+		console.log('item', item);
+
 		const temp = [...productData.selectedIds]
-		const index = temp.indexOf(id)
-		index > -1 ? temp.splice(index, 1) : temp.push(id)
-		productData.selectedIds = temp
-		console.log('productData.selectedIds',productData.selectedIds);
+		const index = temp.indexOf(item.id)
+		index > -1 ? temp.splice(index, 1) : temp.push(item.id)
+		productData.selectedIds = temp
+		console.log('productData.selectedIds', productData.selectedIds);
 	}
 
 	function isItemSelected(id) {
@@ -221,10 +220,15 @@
 		}
 	}
 
-	onLoad((options) => {
-		productData.current = Number(options.subjectId) - 1
-		productData.cardId = options.cardId
-		productData.from = options.from
+	onLoad((options) => {
+		if(options.from =='daoPage'){
+			productData.current = Number(options.subjectId) - 1
+			productData.cardId = options.cardId
+			productData.from = options.from
+		}else{
+			productData.current  = Number(cacheManager.get('auth').subjectId)-1
+		}
+
 		getMore();
 	})
 </script>