cmy 4 years ago
parent
commit
fe9e904dc0
1 changed files with 33 additions and 31 deletions
  1. 33 31
      pages/product/product.vue

+ 33 - 31
pages/product/product.vue

@@ -348,7 +348,6 @@ export default {
 			// 获取普通商品信息
 			if (obj.goodsType == 0) {
 				goodsDetail({}, this.goodsid).then(function({ data }) {
-					try {
 						obj.list = data;
 						console.log(obj.list, '普通商品数据');
 						obj.good_list = data.good_list; //保存猜你喜欢列表
@@ -363,42 +362,45 @@ export default {
 						if (obj.goodsObjact.description != null) {
 							obj.description = obj.goodsObjact.description.replace(/\<img/gi, '<img class="rich-img"');
 						} //小程序商品详情图超出屏幕问题
-						obj.imgList = goods.slider_image; //保存轮播图
-						obj.specList = data.productAttr; //保存分类列表
-						if (Array.isArray(data.productValue) != true) {
-							obj.many = 2;
-							obj.specList = data.productAttr; //保存产品属性
-							obj.productValue = data.productValue; //保存属性值
-							obj.specSelected = []; //初始化默认选择对象
-							const str = ''; //保存当前选中的默认对象
-							for (let i = 0; i < obj.specList.length; i++) {
-								// 设置默认数据
-								const ls = obj.specList[i].attr_value;
-								for (let s = 0; s < ls.length; i++) {
-									if (ls[s].check) {
-										obj.specSelected.push(ls[s].attr);
-									}
-								}
-							}
-							console.log(str, 'str');
-							// 设置默认值
-							obj.actionPrice = obj.productValue[str].price;
-							obj.goodsNumberMax = obj.productValue[str].stock;
-							obj.actionImage = obj.productValue[str].image;
-							obj.uniqueId = obj.productValue[str].unique;
-							obj.goodsStore = obj.productValue[str].stock;
-						} else {
-							obj.many = 1;
+					obj.imgList = goods.slider_image; //保存轮播图
+					obj.specList = data.productAttr; //保存分类列表
+					if (Array.isArray(data.productValue) != true) {
+						console.log('开始处理数据');
+						obj.many = 2;
+						obj.specList = data.productAttr; //保存产品属性
+						obj.productValue = data.productValue; //保存属性值
+						obj.specSelected = []; //初始化默认选择对象
+						for (let i = 0; i < obj.specList.length; i++) {
+							console.log('数据处理');
+							// 设置默认数据
+							const ls = obj.specList[i].attr_value;
+							ls[0].check = true;
+							obj.specSelected.push(ls[0].attr);
+							// console.log('数据处理对象',ls);
+							// for (let s = 0; s < ls.length; s++) {
+							// 	console.log(s);
+							// 	console.log('数据处理对象2',ls[s]);
+							// 	if (ls[s].check) {
+							// 	}
+							// }
 						}
+						const str = obj.specSelected.join(','); //保存当前选中的默认对象
+						console.log(str, 'str');
+						// 设置默认值
+						obj.actionPrice = obj.productValue[str].price;
+						obj.goodsNumberMax = obj.productValue[str].stock;
+						obj.actionImage = obj.productValue[str].image;
+						obj.uniqueId = obj.productValue[str].unique;
+						obj.goodsStore = obj.productValue[str].stock;
+					} else {
+						obj.many = 1;
 						obj.productValue = data.productValue; //保存分类查询数据
 						obj.actionPrice = goods.price; //保存默认选中商品价格
 						obj.actionImage = goods.image_base; //保存默认选中商品图片
 						obj.goodsNumberMax = goods.stock; //保存默认选中最大可购买商品数量
-						obj.shopId = data.mer_id; //保存商店id
-					} catch (e) {
-						console.log(e);
-						//TODO handle the exception
 					}
+					obj.shopId = data.mer_id; //保存商店id
+					console.log('数据处理完毕');
 				});
 			}
 			// 获取秒杀商品信息