xuqiaoying 3 жил өмнө
parent
commit
acb57ab6ef

+ 99 - 32
pages2/bank/detail.vue

@@ -138,32 +138,28 @@
 			<view class="popup_box">
                 <view class="check_head">
                     <view class="headers">
-                    	<view class="grade">选择规格</view>
+                    	<view class="grade">选择规格{{ isCheckSku }}</view>
                         <u-icon name="close" color="#9C9C9C" size="40" @click="closePop()"></u-icon>
                     </view>
                 </view>
-                <view class="pop_prices">
+                <view v-if="Object.keys(skuItem).length" class="pop_prices">
                     <view class="lefts">
-						<!-- <image :src="$method.splitImgHost(item.coverUrl, true)" class="imgs"></image> -->
-						<image src="" class="imgs"></image>
+						<image :src="$method.splitImgHost(skuItem.coverUrl, true)" class="imgs"></image>
 					</view>
 					<view class="rights">
-						<view class="goods_titles">【建筑全科】2022年一建精华 2022年一建精华班</view>
-						<view class="goods_price">¥154.00</view>
+						<view class="goods_titles">{{ skuItem.goodsName }}</view>
+						<view class="goods_price">¥{{ skuItem.standPrice }}</view>
 					</view>
                 </view>
 				<view class="lines"></view>
                 <view class="check_con">
-					<view class="grades">班级</view>
-					<view class="grade_names">
-						<view class="course_items" v-for="(item, index) in courseSku" :key="index" :class="{nactive: skuIndex == index}" @click="selectSku(item, index)">
-							{{ item }}
-						</view>
-					</view>
-					<view class="areas">地区</view>
-					<view class="grade_names">
-						<view class="course_items" v-for="(item, index) in courseSku" :key="index" :class="{nactive: skuIndex == index}" @click="selectSku(item, index)">
-							{{ item }}
+					<view v-for="(item, index) in specList" :key="index" class="check_items">
+						<view class="grades">{{ item.name }}</view>
+						<view class="grade_names">
+							<view class="course_items" v-for="(child, c_index) in item.specAttrList" :key="c_index" :class="{'nactive': child.check }"
+							 @click="selectSku(child, index)">
+								{{ child.name }}
+							</view>
 						</view>
 					</view>
                 </view>
@@ -195,9 +191,9 @@ export default {
 			bugCourseModel: false, // 弹窗
 			hadBuyCourse: {}, // 已购买课程信息
 			toggleSkuShow: false,
-			courseSku: ['基础班', '钻石班', '基础班', '钻石班', '基础班', '钻石班'],
 			skuItem: {},
-            skuIndex: -1,
+			isCarOrBuy: 1, // 1加入购物车 2立即购买
+			specList: [], // 规格列表
 		};
 	},
 	filters: {
@@ -208,7 +204,23 @@ export default {
 		}
 	},
 	onUnload() {},
-	computed: { ...mapGetters(['userInfo','hideBuyState']) },
+	computed: { 
+		...mapGetters(['userInfo','hideBuyState']),
+		isCheckSku() {
+			let checkCout = 0
+			this.specList.forEach((item, index) => {
+				if (item.specAttrList && item.specAttrList.length) {
+					item.specAttrList.forEach((child, c_index) => {
+						if (child.check) {
+							checkCout++
+						}
+					})
+				}
+				
+			})
+			return checkCout
+		},
+	},
 	onLoad(option) {
 		this.id = option.id;
 		this.getDetail();
@@ -349,6 +361,8 @@ export default {
 			this.$navTo.togo('/pages2/order/confirm_list?id=' + this.id);
 		},
 		addCart() {
+			// this.getSpecDetail()
+			// return
 			if (this.$method.isGoLogin()) {
 				return;
 			}
@@ -372,8 +386,27 @@ export default {
 				}
 			});
 		},
-		open(item) {
-			item.showChildren = !item.showChildren;
+		getSpecDetail() {
+			this.$http({
+				url: `/app/common/spec/${this.goodsData.specTemplateId}`,
+				method: 'get',
+				noToken: true
+			}).then((res) => {
+				if (res.data.code == 200) {
+					this.toggleSkuShow = true
+					let data = res.data.data
+					if (data) {
+						this.specList = data && (data.specList || [])
+						this.specList.forEach((item, index) => {
+							item.specAttrList.forEach((child, i_index) => {
+								this.$set(this.specList[index].specAttrList[i_index], 'check', false)
+							})
+						})
+					}
+				} else {
+					this.$u.toast('暂无数据')
+				}
+			})
 		},
 		change(index) {
 			this.current = index;
@@ -450,21 +483,55 @@ export default {
 		},
 		closePop() {
             this.toggleSkuShow = false
+			this.skuItem = {}
         },
 		selectSku(item, index) {
-            console.log('defhd', item, index)
-            this.skuItem = item
-            this.skuIndex = index
+            this.specList[index].specAttrList.forEach((i_item, i_index) => {
+				if (item.specAttributeId == i_item.specAttributeId) {
+					this.$set(this.specList[index].specAttrList[i_index], 'check', true)
+				} else {
+					this.$set(this.specList[index].specAttrList[i_index], 'check', false)
+				}
+			})
+			// console.log('this.specList', this.specList, this.isCheckSku)
+			if (this.specList.length == this.isCheckSku) {
+				let specAttrIds = []
+				this.specList.forEach((item) => {
+					let result = item.specAttrList.find(e => e.check)
+					if (result) {
+						specAttrIds.push(result.specAttributeId)
+					}
+				})
+				this.getGoodsInfos(specAttrIds)
+			}
         },
+		// 获取规格属性值对应的商品信息
+		getGoodsInfos(specAttrIds) {
+			this.$http({
+				url: '/app/common/attr/goods',
+				method: 'get',
+				data: {
+					specTemplateId: this.goodsData.specTemplateId,
+					specAttrIds: specAttrIds.join(',')
+				},
+				noToken: true
+			}).then((res) => {
+				if (res.data.code == 200) {
+					this.skuItem = res.data.data || {}
+				}
+			})
+		},
         rightNowBuy() {
-            // if (Object.keys(this.skuItem).length == 0) {
-            //     this.$u.toast('请选择科目')
-            //     return
-            // }
-            // if(this.$method.isGoLogin()){
-			// 	return
-			// }
-			// this.$navTo.togo('/pages2/order/confirm_list?id='+this.skuItem.goodsId)
+            if (this.specList.length != this.isCheckSku) {
+				this.$u.toast('请先选择所有的规格')
+				return
+			}
+            if (this.isCarOrBuy == 1) { // 加入购物车
+				this.addShopCart()
+			} else {
+				this.$navTo.togo('/pages2/order/confirm_list?id='+this.id);
+			}
+			this.closePop()
         }
 	}
 };

+ 75 - 93
pages3/course/detail.vue

@@ -170,18 +170,17 @@
 			<view class="popup_box">
                 <view class="check_head">
                     <view class="headers">
-                    	<view class="grade">选择规格</view>
+                    	<view class="grade">选择规格{{ isCheckSku }}</view>
                         <u-icon name="close" color="#9C9C9C" size="40" @click="closePop()"></u-icon>
                     </view>
                 </view>
-                <view class="pop_prices">
+                <view v-if="Object.keys(skuItem).length" class="pop_prices">
                     <view class="lefts">
-						<!-- <image :src="$method.splitImgHost(item.coverUrl, true)" class="imgs"></image> -->
-						<!-- <image src="" class="imgs"></image> -->
+						<image :src="$method.splitImgHost(skuItem.coverUrl, true)" class="imgs"></image>
 					</view>
 					<view class="rights">
-						<view class="goods_titles">【建筑全科】2022年一建精华 2022年一建精华班</view>
-						<view class="goods_price">¥154.00</view>
+						<view class="goods_titles">{{ skuItem.goodsName }}</view>
+						<view class="goods_price">¥{{ skuItem.standPrice }}</view>
 					</view>
                 </view>
 				<view class="lines"></view>
@@ -189,8 +188,8 @@
 					<view v-for="(item, index) in specList" :key="index" class="check_items">
 						<view class="grades">{{ item.name }}</view>
 						<view class="grade_names">
-							<!-- :class="{nactive: skuIndex == index}"   -->
-							<view class="course_items" v-for="(child, c_index) in item.specAttrList" :key="c_index" @click="selectSku(child, index, c_index)">
+							<view class="course_items" v-for="(child, c_index) in item.specAttrList" :key="c_index" :class="{'nactive': child.check }"
+							 @click="selectSku(child, index, c_index)">
 								{{ child.name }}
 							</view>
 						</view>
@@ -241,67 +240,28 @@ export default {
 			States: {0: 0},
 			goodsType: 1, // 1视频2题库 3补考 4前培 6直播
 			toggleSkuShow: false,
-			courseSku: ['基础班', '钻石班', '基础班', '钻石班', '基础班', '钻石班'],
 			skuItem: {},
-            skuIndex: -1,
 			isCarOrBuy: 1, // 1加入购物车 2立即购买
-			specList: [
-						{
-							"specId":62,
-							"specTemplateId":28,
-							name:"一建规格-001",
-							"code":null,
-							"sort":null,
-							"status":1,
-							specAttrList: [
-								{
-									"specAttributeId":115,
-									"specId":62,
-									name:"一建规格属性0011",
-									"code":null,
-									"sort":null,
-									"status":1
-								},
-								{
-									"specAttributeId":116,
-									"specId":62,
-									name:"一建规格属性0012",
-									"code":null,
-									"sort":null,
-									"status":1
-								}
-							]
-						},
-						{
-							"specId":63,
-							"specTemplateId":28,
-							name:"一建规格-002",
-							"code":null,
-							"sort":null,
-							"status":1,
-							specAttrList: [
-								{
-									"specAttributeId":117,
-									"specId":63,
-									name:"一建规格属性0021",
-									"code":null,
-									"sort":null,
-									"status":1
-								},
-								{
-									"specAttributeId":118,
-									"specId":63,
-									name:"一建规格属性0022",
-									"code":null,
-									"sort":null,
-									"status":1
-								}
-							]
-						}
-					], // 规格列表
+			specList: [], // 规格列表
 		};
 	},
-	computed: { ...mapGetters(['userInfo','goodsAuditionConfigIdList','playSectionId','hideBuyState']) },
+	computed: { 
+		...mapGetters(['userInfo','goodsAuditionConfigIdList','playSectionId','hideBuyState']),
+		isCheckSku() {
+			let checkCout = 0
+			this.specList.forEach((item, index) => {
+				if (item.specAttrList && item.specAttrList.length) {
+					item.specAttrList.forEach((child, c_index) => {
+						if (child.check) {
+							checkCout++
+						}
+					})
+				}
+				
+			})
+			return checkCout
+		},
+	},
 	onLoad(option) {
 		// this.id => goodsId
 		this.id = option.id;
@@ -673,14 +633,7 @@ export default {
 		},
 		addCart(){
 			// this.getSpecDetail()
-			this.toggleSkuShow = true
-			this.specList.forEach((item, index) => {
-				item.specAttrList.forEach((child) => {
-					child['check'] = false
-				})
-			})
-			console.log('000', this.specList)
-			return
+			// return
 			if(this.$method.isGoLogin()){
 				return
 			}
@@ -693,11 +646,9 @@ export default {
 			this.addShopCart()
 		},
 		getSpecDetail() {
-			// ${this.detail.specTemplateId}
-			// 这里id到时候需要改回来
-			console.log('1111111111')
+			// || 35
 			this.$http({
-				url: `/app/common/spec/28`,
+				url: `/app/common/spec/${this.detail.specTemplateId}`,
 				method: 'get',
 				noToken: true
 			}).then((res) => {
@@ -707,11 +658,10 @@ export default {
 					if (data) {
 						this.specList = data && (data.specList || [])
 						this.specList.forEach((item, index) => {
-							item.specAttrList.forEach((child) => {
-								child['check'] = false
+							item.specAttrList.forEach((child, i_index) => {
+								this.$set(this.specList[index].specAttrList[i_index], 'check', false)
 							})
 						})
-						console.log('this.specList', this.specList)
 					}
 				} else {
 					this.$u.toast('暂无数据')
@@ -861,23 +811,55 @@ export default {
 		},
 		closePop() {
             this.toggleSkuShow = false
+			this.skuItem = {}
         },
 		selectSku(item, index, c_index) {
-            console.log('defhd', item, index, c_index)
-			this.$set(this.specList[index].specAttrList[c_index], '')
-			// this.specList
-            // this.skuItem = item
-            // this.skuIndex = index
+			this.specList[index].specAttrList.forEach((i_item, i_index) => {
+				if (item.specAttributeId == i_item.specAttributeId) {
+					this.$set(this.specList[index].specAttrList[i_index], 'check', true)
+				} else {
+					this.$set(this.specList[index].specAttrList[i_index], 'check', false)
+				}
+			})
+			// console.log('this.specList', this.specList, this.isCheckSku)
+			if (this.specList.length == this.isCheckSku) {
+				let specAttrIds = []
+				this.specList.forEach((item) => {
+					let result = item.specAttrList.find(e => e.check)
+					if (result) {
+						specAttrIds.push(result.specAttributeId)
+					}
+				})
+				this.getGoodsInfos(specAttrIds)
+			}
         },
+		// 获取规格属性值对应的商品信息
+		getGoodsInfos(specAttrIds) {
+			this.$http({
+				url: '/app/common/attr/goods',
+				method: 'get',
+				data: {
+					specTemplateId: this.detail.specTemplateId,
+					specAttrIds: specAttrIds.join(',')
+				},
+				noToken: true
+			}).then((res) => {
+				if (res.data.code == 200) {
+					this.skuItem = res.data.data || {}
+				}
+			})
+		},
         rightNowBuy() {
-            // if (Object.keys(this.skuItem).length == 0) {
-            //     this.$u.toast('请选择科目')
-            //     return
-            // }
-            // if(this.$method.isGoLogin()){
-			// 	return
-			// }
-			// this.$navTo.togo('/pages2/order/confirm_list?id='+this.skuItem.goodsId)
+			if (this.specList.length != this.isCheckSku) {
+				this.$u.toast('请先选择所有的规格')
+				return
+			}
+            if (this.isCarOrBuy == 1) { // 加入购物车
+				this.addShopCart()
+			} else {
+				this.$navTo.togo('/pages2/order/confirm_list?id='+this.id);
+			}
+			this.closePop()
         }
 	}
 };

+ 8 - 1
pages3/course/index.scss

@@ -133,6 +133,7 @@
       display: flex;
       align-items: center;
       justify-content: space-between;
+	  margin-bottom: 48rpx;
       .grade {
         font-size: 40rpx;
         font-weight: bold;
@@ -141,16 +142,21 @@
     }
 	.pop_prices {
 		width: 100%;
+		min-height: 120rpx;
 		display: flex;
 		align-items: center;
 		justify-content: space-between;
-		margin: 48rpx 0rpx 40rpx 0rpx;
+		margin: 0rpx 0rpx 40rpx 0rpx;
 		.imgs {
 			width: 204rpx;
 			height: 120rpx;
 			border-radius: 16rpx;
 			margin-right: 24rpx;
 		}
+		.rights {
+			width: 100%;
+			min-height: 120rpx;
+		}
 		.goods_titles {
 			font-size: 28rpx;
 			font-weight: 500;
@@ -160,6 +166,7 @@
 			font-size: 28rpx;
 			font-weight: 500;
 			color: #FC3F3F;
+			margin-top: 20rpx;	
 		}
 	}
 	.lines {