瀏覽代碼

【Add】SKU配图

liuxiangxin 6 月之前
父節點
當前提交
1b3e301028
共有 1 個文件被更改,包括 11 次插入3 次删除
  1. 11 3
      pages/product/index.vue

+ 11 - 3
pages/product/index.vue

@@ -2,7 +2,7 @@
 	<page-meta :page-style="'overflow:'+(show?'hidden':'visible')"></page-meta>
 	<view>
 		<view class="product_image_box" v-if="!productInfo.photo_list.length">
-			<image class="product_image" :src="productInfo.thumb"></image>
+			<image class="product_image" :src="sku_thumb"></image>
 		</view>
 		<view class="product_image_box" v-if="productInfo.photo_list.length">
 			<swiper class="photo_list" :autoplay="true" >
@@ -65,7 +65,7 @@
 				</view>
 				<view class="car_item" >
 					<view class="box_left">
-						<image class="car_image" :src="productInfo.thumb" mode=""></image>
+						<image class="car_image" :src="sku_thumb" mode=""></image>
 					</view>
 					<view class="box_right">
 						<view class="car_name">{{productInfo.name}}</view>
@@ -253,6 +253,7 @@
 				isShowPrice:false,
 				// 选择的skuid
 				sku_id:0,
+				sku_thumb:"",
 			}
 		},
 		onLoad(param) {
@@ -302,6 +303,8 @@
 						this.productInfo = re.data;
 						//设置默认sku
 						this.sku_id = 0;
+						// 显示图片
+						this.sku_thumb = this.productInfo.thumb;
 					}else{
 						if( re.code != 'no_login' ){
 							uni.showModal({
@@ -430,7 +433,6 @@
 				productInfo = JSON.stringify(productInfo);
 				//加密json格式成编码数组
 				let encodedArray = encodeURIComponent(productInfo);
-				
 				// 需要下单的产品列表
 				let productList = [{product_id:this.productInfo.id,buy_num:this.quantity,product_skuid:this.sku_id}];
 				// 转成json字符串传输
@@ -775,6 +777,12 @@
 						this.productInfo.stock = this.productInfo.product_sku[i].stock;
 						// 产品SKU
 						this.sku_id = this.productInfo.product_sku[i].id;
+						// 有图替换,没图使用产品原缩略图
+						this.sku_thumb = this.productInfo.product_sku[i].sku_thumb ? this.productInfo.product_sku[i].sku_thumb : this.productInfo.thumb;
+						// 如果有图册
+						if( this.productInfo.photo_list.length ){
+							this.productInfo.photo_list[0].thumb = this.sku_thumb;
+						}
 						// 计算价格
 						this.priceHandler();
 						// 优惠券是否可用