wangguoyu 3 giorni fa
parent
commit
55ed6b78bd
1 ha cambiato i file con 52 aggiunte e 22 eliminazioni
  1. 52 22
      pages/mall/mallPage.vue

+ 52 - 22
pages/mall/mallPage.vue

@@ -12,31 +12,31 @@
 				<view v-if="productData.current === 0">
 					<scroll-view scroll-y="true" :scroll-into-view="scrollIntoId" class="order-scroll-view">
 						<!--数学-->
-						<view :id="'item-' + item.id" v-for="item in productData.list" class="mall-list-item">
-								<view class="mall-content-box">
-									<!-- 需要换成从接口中取得 wgy -->
-									<img :src='item.cover' class="mall-image" />
-									<view class="content-body-box">
-										<view class="content-name">
-											<view class="name-text">{{item.name}}</view>
-										</view>
-										<view class="content-text">{{item.intro}}</view>
-										<view class="content-row">
-											<view class="content-yuanjia">原价:{{item.yuanjia}}</view>
-											<view class="shop-car-box">
-												<!-- 购物车上的对号需控制 wgy-->
-												<icon class="car-change"></icon>
-											</view>
+						<view :id="'item-' + item.id" v-for="item in productData.list" :key="`${item.id}-${isItemSelected(item.id)}`" class="mall-list-item">
+							<view class="mall-content-box">
+								<!-- 需要换成从接口中取得 wgy -->
+								<img :src='item.cover' class="mall-image" />
+								<view class="content-body-box">
+									<view class="content-name">
+										<view class="name-text">{{item.name}}</view>
+									</view>
+									<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)">
+											<!-- 购物车上的对号需控制 wgy-->
+											<icon v-if="isItemSelected(item.id)" class="car-change"></icon>
 										</view>
 									</view>
 								</view>
-								<view class="mall-bottom-row">
-									<!-- 组合课程显示课程包明细按钮 wgy -->
-									<view v-if="item.type ==1" class="kcb-btn" @click="productBtn">课程包明细<icon>
-										</icon>
-									</view>
-									<view class="hdj-text">活动价:{{item.xianjia}}</view>
+							</view>
+							<view class="mall-bottom-row">
+								<!-- 组合课程显示课程包明细按钮 wgy -->
+								<view v-if="item.type ==1" class="kcb-btn" @click="productBtn">课程包明细<icon>
+									</icon>
 								</view>
+								<view class="hdj-text">活动价:{{item.xianjia}}</view>
+							</view>
 						</view>
 					</scroll-view>
 				</view>
@@ -109,7 +109,8 @@
 		current: 1,
 		from: '',
 		cardId: '',
-		list: []
+		list: [],
+		selectedIds: [] // 新增选中状态存储
 	})
 
 	function switchPayWay() {
@@ -152,6 +153,13 @@
 		getMallist(opt).then(res => {
 			if (res.code == 0) {
 				productData.list = res.data
+				// 初始化选中状态(当有外部cardId时)
+				if (productData.cardId) {
+					const exist = res.data.some(item => item.id == productData.cardId)
+					if (exist) {
+						productData.selectedIds = [productData.cardId]
+					}
+				}
 				nextTick(() => {
 					scrollToIdFun(productData.cardId)
 				})
@@ -176,6 +184,28 @@
 		}
 	}
 
+	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)
+		// }
+		 const temp = [...productData.selectedIds]
+		  const index = temp.indexOf(id)
+		  index > -1 ? temp.splice(index, 1) : temp.push(id)
+		  productData.selectedIds = temp
+	}
+
+	function isItemSelected(id) {
+		return productData.cardId ?
+			id == productData.cardId // 有外部cardId时严格匹配
+			:
+			productData.selectedIds.includes(id) // 无cardId时检查选中列表
+	}
+
 	function goBack() {
 		if (productData.from == 'daoPage') {
 			uni.redirectTo({