Jelajahi Sumber

规格缺货提示

yuxingxing 2 tahun lalu
induk
melakukan
31cf4ecca7

+ 5 - 2
components/productWindow/index.vue

@@ -34,7 +34,8 @@
 							<view class="itemn" :class="attr.attrValueId === itemn.id ? 'on' : ''"
 								v-for="(itemn, indexn) in attr.productAttr" @click="tapAttr(itemn, indexn)"
 								:key="indexn">
-								{{ itemn.spceName }}
+								<text>{{ itemn.spceName }}</text>
+								<text style="margin-left: 10px;" v-if="!itemn.canSale">缺货</text>
 							</view>
 						</view>
 					</view>
@@ -170,7 +171,9 @@ export default {
 		},
 		tapAttr: function (item, indexn) {
 			let that = this;
-			that.$emit("ChangeAttr", item);
+			if(item.canSale){
+				that.$emit("ChangeAttr", item);
+			}
 		},
 		//获取被选中属性;
 		getCheckedValue: function () {

+ 1 - 0
pages/goods/order_confirm/index.vue

@@ -447,6 +447,7 @@ export default {
 		console.log(options);
 		this.num = options.num || 0;
 		this.goodsSpecId = options.goodsSpecId || 0;
+		this.integral = options.obtainIntegral || 0;
 		this.couponId = options.couponId || 0;
 		this.noCoupon = Number(options.noCoupon) || 0;
 		this.pinkId = options.pinkId ? parseInt(options.pinkId) : 0;

+ 45 - 11
pages/goods_details/index.vue

@@ -824,8 +824,16 @@ export default {
 					},
 				});
 			} else {
-				this.attrValue = this.skuArr[0].spceName
+				this.attrValue = item.spceName
+				this.storeInfo.obtainIntegral = item.obtainIntegral - 0
+				this.storeInfo.salePrice = item.salePrice - 0
+				this.attr.productSelect.totalStock = item.stock - 0
 				this.attr.attrValueId = item.id
+				if(!item.canSale){
+					this.availableCheck = false
+				}else{
+					this.availableCheck = true
+				}
 			}
 		},
 		/**
@@ -857,6 +865,7 @@ export default {
 		 *
 		 */
 		getGoodsDetails: function () {
+			uni.showLoading({ title: '商品信息加载中' });
 			let that = this;
 			getGoodsDetail({ id: that.id })
 				.then((res) => {
@@ -865,7 +874,7 @@ export default {
 					that.skuArr = storeInfo.goodsSpecList
 					that.$set(that, "storeInfo", storeInfo);
 					that.$set(that.attr, "productAttr", storeInfo.goodsSpecList);
-					that.DefaultSelect();
+					that.getUserAddressByUserId()
 					setTimeout(function () {
 						that.infoScroll();
 					}, 500);
@@ -939,13 +948,7 @@ export default {
 				success: function () { },
 			});
 		},
-		/**
-		 * 默认选中属性
-		 *
-		 */
-		DefaultSelect: function () {
-			this.attrValue = this.skuArr[0].spceName
-			this.attr.attrValueId = this.skuArr[0].id
+		getUserAddressByUserId(){
 			getUserAddressByUserId({
 				userId: this.$store.state.app.uid,
 				type: 1
@@ -954,13 +957,44 @@ export default {
 				this.getAvailableCheck()
 			})
 		},
+		/**
+		 * 默认选中属性
+		 *
+		 */
+		DefaultSelect: function () {
+			//找到第一个可销售的规格
+			if(this.skuArr.length >= 0){
+				this.skuArr.every(value => {
+					if(value.canSale){
+						this.attrValue = value.spceName
+						this.storeInfo.obtainIntegral = value.obtainIntegral - 0
+						this.storeInfo.salePrice = value.salePrice - 0
+						this.attr.productSelect.totalStock = value.stock - 0
+						this.attr.attrValueId = value.id
+						this.availableCheck = true
+						return false;
+					}
+				})
+			}
+			uni.hideLoading();
+		},
 		// 可销售检测
 		getAvailableCheck(){
 			getAvailableCheck({
 				goodsInfoId: this.id,
 				userAddressId: this.attrAddrValue.id
 			}).then(res => {
-				this.availableCheck = res.success
+				//处理缺货的规格
+				let ban = res.data.ban
+				if (ban !== undefined){
+					this.storeInfo.goodsSpecList.forEach((value,key) =>{
+						if(ban.includes(value.id-0) || ban.includes(value.optionId-0)){
+							this.storeInfo.goodsSpecList[key].canSale = false
+						}
+					})
+				}
+				// this.availableCheck = res.success
+				this.DefaultSelect();
 			})
 		},
 		/**
@@ -1147,7 +1181,7 @@ export default {
 					uni.navigateTo({
 						url: "/pages/goods/order_confirm/index?num=" + that.attr.productSelect.totalSales + "&productId=" +
 							that.attr.productSelect.id + "&addressId=" + that.attrAddrValue.id +
-							"&goodsSpecId=" + that.attr.attrValueId,
+							"&goodsSpecId=" + that.attr.attrValueId+"&obtainIntegral="+that.storeInfo.obtainIntegral,
 					});
 				} else {
 					that.$util.Tips({