Ver Fonte

cart and addcart

2312970463@qq.com há 4 anos atrás
pai
commit
a720af309d

+ 17 - 7
api/product.js

@@ -20,12 +20,22 @@ export function getProducts(data) {
 	});
 }
 // 获取商品详情
-export function goodsDetail(data, id) {
+// export function goodsDetail(data, id) {
+// 	return request({
+// 		url: '/api/product/detail/' + id,
+// 		method: 'get',
+// 		data
+// 	});
+// }
+export function getProductDetail(id,data) {
 	return request({
-		url: '/api/product/detail/' + id,
+		url: '/api/store/product/detail/' + id,
 		method: 'get',
 		data
-	});
+	})
+	// return request.get('store/product/detail/' + id, {}, {
+	// 	noAuth: true
+	// });
 }
 
 // 砍价列表
@@ -245,10 +255,10 @@ export function getProductslist(data) {
 }
 //
 export function getProductHot(data) {
-	let dataa = {
-		page: data.page === undefined ? 1 : page,
-		limit: data.limit === undefined ? 10 : limit
-	}
+	// let dataa = {
+	// 	page: data.page === undefined ? 1 : page,
+	// 	limit: data.limit === undefined ? 10 : limit
+	// }
 	return request({
 		url: '/api/product/spu/recommend',
 		method: 'get',

+ 7 - 0
api/user.js

@@ -48,6 +48,13 @@ export function getAddressList(data) {
 		data
 	});
 }
+//获取单个地址
+ export function getAddressDetail(id) {
+	return request({
+		url: 'user/address/detail/' + id,
+		method: 'get'
+		});
+}
 // 修改地址
 export function addressEdit(data) {
 	return request({

+ 1 - 1
components/uni-number-box.vue

@@ -154,7 +154,7 @@
 		background:#f5f5f5;
 		/* border: 1px solid #C7C7C7; */
 		/* border-radius: 4rpx 4rpx 4rpx 4rpx; */
-		z-index: 999;
+		/* z-index: 999; */
 	}
 
 	.uni-numbox-minus,

+ 1 - 1
pages/cart/cart.vue

@@ -262,7 +262,7 @@ export default {
 			let goodsData = [];
 			list.forEach(item => {
 				if (item.checked) {
-					goodsData.push(item.id);
+					goodsData.push(item.cart_id);
 				}
 			});
 

+ 17 - 6
pages/index/index.vue

@@ -133,7 +133,7 @@
 								{{ item.price }}
 							</view>
 							<view class="font-size-sm">
-								<text class="font-color-gray">{{ item.sales }}人购买</text>
+								<!-- <text class="font-color-gray">{{ item.sales }}人购买</text> -->
 							</view>
 						</view>
 					</view>
@@ -500,8 +500,12 @@ export default {
 				this.swiperLength = this.carouselList.length;
 				this.menusList = data.menu;
 			})
-			getProductHot({page:1,limit:1}).then( ({data})=> {
+			getProductHot({page:1,limit:30}).then( ({data})=> {
 				console.log(data,"data+++++++++--------------")
+				this.bastList = data.list.filter(item => {
+					return item.product_type != 4
+				})
+				console.log(this.bastList,'this.bastList')
 			} )
 		},
 		//轮播图切换修改背景色
@@ -512,10 +516,17 @@ export default {
 		},
 		//详情页
 		navToDetailPage(item) {
-			let id = item.id;
-			uni.navigateTo({
-				url: '/pages/product/product?id=' + id
-			});
+			let id = item.product_id;
+			if(item.product_type == 2 || item.product_type == 3 || item.product_type == 0 ){
+				uni.navigateTo({
+					url: '/pages/product/product?id=' + id + '&type=0'
+				});
+			}else if(item.product_type == 1){
+				uni.navigateTo({
+					url: '/pages/product/product?id=' + id + '&type=' +item.product_type
+				});
+			}
+			
 		},
 
 		// 轮播图跳转

+ 101 - 39
pages/order/createOrder.vue

@@ -104,13 +104,13 @@
 			</view> -->
 			<!-- 商品列表 -->
 			<view class="g-item">
-				<image :src="ls.productInfo.image"></image>
+				<image :src="ls.productAttr.image"></image>
 				<view class="right">
-					<text class="title clamp">{{ ls.productInfo.store_name }}</text>
-					<text class="spec">{{ ls.productInfo.attrInfo ? ls.productInfo.attrInfo.suk : '默认' }}</text>
+					<text class="title clamp2">{{ ls.product.store_name }}</text>
+					<text class="spec">已选择 “{{ ls.productAttr.sku ? ls.productAttr.sku : '默认' }}"</text>
 					<view class="price-box">
-						<text class="price">¥{{ ls.productInfo.attrInfo ? ls.productInfo.attrInfo.price : ls.productInfo.price }}</text>
-						<text class="number">{{ 'x ' + ls.cart_num + (ls.productInfo.unit_name || '') }}</text>
+						<text class="price">¥{{ ls.productAttr.price ? ls.productAttr.price*ls.cart_num  : ls.product.price*ls.cart_num }}</text>
+						<text class="number">¥{{ ls.productAttr.ot_price }}</text>
 						<!-- <view><text class="price">¥{{lss.price}}</text></view> -->
 						<!-- <view class="number">
 							<uni-number-box class="step" :value="lss.number" :index="indx" @eventChange="numberChange"></uni-number-box>
@@ -162,11 +162,11 @@
 			</view>
 			<view class="item">
 				<text class="item-name">商品总价</text>
-				<text class="item-value">¥{{ payAllMoney }}</text>
+				<text class="item-value">¥{{ allMoney }}</text>
 			</view>
 			<view class="item">
 				<text class="item-name">物流费用</text>
-				<text class="item-value">{{ Postage }}</text>
+				<text class="item-value">{{ postagePrice ? '¥' + +postagePrice : '免邮费'}}</text>
 			</view>
 			<view class="item" v-if="moneyAll.vipPrice > 0">
 				<text class="item-name" >会员折扣</text>
@@ -228,7 +228,7 @@
 
 <script>
 import { confirm,computedOrderkey,couponsOrder } from '@/api/order.js';
-import { userinfo } from '@/api/user.js';
+import { getUserInfo, getAddressDetail, getAddressList, getConfirm } from '@/api/user.js';
 import { cartAdd } from '@/api/product.js';
 export default {
 	data() {
@@ -284,7 +284,11 @@ export default {
 			integralShow: false, //是否显示积分抵扣金额
 			payType: true, //是否可支付
 			pinkid: '', //保存拼团商品id
-			isshop:false
+			isshop:false,
+			addressId: 0,//地址ID
+			addressInfo: {},
+			address: {},
+			postagePrice: 0//邮费
 		};
 	},
 	onLoad(option) {
@@ -342,7 +346,7 @@ export default {
 		},
 		// 加载用户基础信息
 		userinfo() {
-			userinfo({}).then(({ data }) => {
+			getUserInfo({}).then(({ data }) => {
 				this.integralAll = data.integral;
 			});
 		},
@@ -399,19 +403,42 @@ export default {
 				this.maskState = state;
 			}, timer);
 		},
-		loadData() {
-			let obj = this;
-			confirm({ cart_id: obj.cartId+'' }).then(({ data }) => {
-				console.log(data,'+++++++++++++++++++++++Cartinfo')
-				obj.addressData = data.addressInfo || {};
-				obj.shopList = data.cartInfo; //商品列表
-				obj.moneyAll = data.priceGroup; //金额数据
-				obj.orderKey = data.orderKey; //订单key
-				// 计算金额
-				this.payMoneyNub();
-				// 加载优惠券
-				obj.couponsOrder(data.priceGroup.totalPrice);
-			});
+		loadData() {
+			let obj = this
+			// 判断是否有地址
+			if(obj.addressId){
+				console.log("++++++++++++++++++++++++")
+				//如果有则直接获取地址信息
+				getAddressDetail(obj.addressId).then(({data}) => {
+					data.is_default = parseInt(data.is_default);
+					obj.addressData = data || {};
+					obj.addressId = data.address_id || 0;
+					obj.address.addressId = data.address_id || 0;
+					obj.getConfirm(that.addressId);
+				})
+			}else {
+				//如果没有则获取地址列表
+				console.log("------------------------")
+				getAddressList().then(({data}) => {
+					console.log(data)
+					obj.addressData = data.list.length > 0 ? data.list[0] : {};
+					obj.addressId = data.list.length > 0 ? data.list[0].address_id : 0;
+					obj.address.addressId = data.list.length > 0 ? data.list[0].address_id : 0;
+					obj.getConfirm(obj.addressId);
+				})
+			}
+			// console.log(obj.cartId,"obj.cartId+++++++++")
+			// confirm({ cart_id: obj.cartId }).then(({ data }) => {
+			// 	console.log(data,'+++++++++++++++++++++++Cartinfo')
+			// 	obj.addressData = data.addressInfo || {};
+			// 	obj.shopList = data.cartInfo; //商品列表
+			// 	obj.moneyAll = data.priceGroup; //金额数据
+			// 	obj.orderKey = data.orderKey; //订单key
+			// 	// 计算金额
+			// 	this.payMoneyNub();
+			// 	// 加载优惠券
+			// 	obj.couponsOrder(data.priceGroup.totalPrice);
+			// });
 		},
 		// 购买数量变化
 		numberChange(data) {
@@ -440,7 +467,29 @@ export default {
 			});
 		},
 		// 获订单确认获取订单详细信息
-		
+		getConfirm(addressID) {
+			let obj = this
+			console.log(obj.cartId,'++++++++++obj.cartId----------------')
+			confirm({
+				cart_id: obj.cartId.split(","),
+				address_id: addressID
+			}).then(({data})=> {
+				console.log(data,"data++++++++++getConfirm")
+				// obj.shopList
+				let list = []
+				let postage_price = 0
+				let len = data.order.length - 1
+				for(let i = 0; i <= len ; i++) {
+					postage_price = postage_price + data.order[i].order.postage_price
+					list.push(...data.order[i].list)
+				}
+				console.log(list)
+				obj.shopList = list
+				obj.allMoney = data.total_price
+				obj.postagePrice = postage_price
+				obj.payPrice = data.order_price
+			})
+		}
 	}
 };
 </script>
@@ -579,13 +628,14 @@ page {
 
 	.g-item {
 		display: flex;
-		margin: 20rpx 30rpx;
-
+		margin: 20rpx 30rpx;
+		padding: 30rpx 0;
+		position: relative;
 		image {
 			flex-shrink: 0;
 			display: block;
-			width: 140rpx;
-			height: 140rpx;
+			width: 180rpx;
+			height: 180rpx;
 			border-radius: 4rpx;
 		}
 
@@ -594,14 +644,22 @@ page {
 			padding-left: 24rpx;
 			overflow: hidden;
 		}
-		.title {
+		.title {
+			width: 475rpx;
 			font-size: 30rpx;
 			color: $font-color-dark;
 		}
 
-		.spec {
-			font-size: 26rpx;
-			color: $font-color-light;
+		.spec {
+			display: inline-block;
+			position: absolute;
+			top: 130rpx;
+			// left: 243rpx;
+			font-size: 23rpx;
+			font-size: 24rpx;
+			font-weight: 500;
+			color: #8A857C;
+			line-height: 1;
 		}
 
 		.price-box {
@@ -610,15 +668,19 @@ page {
 			font-size: 32rpx;
 			color: $font-color-dark;
 			padding-top: 10rpx;
-
-			.price {
-				margin-bottom: 4rpx;
-				color: $color-red;
+			position: absolute;
+			top: 150rpx;
+			.price {
+				font-size: 32rpx;
+				font-weight: bold;
+				color: #901B21;
 			}
 			.number {
-				font-size: 26rpx;
-				color: $font-color-base;
-				margin-left: 20rpx;
+				margin-left: 20rpx;
+				font-size: 24rpx;
+				font-weight: 500;
+				color: #9D9D9D;
+				text-decoration:line-through;
 			}
 		}
 

+ 20 - 18
pages/product/common/productContent.vue

@@ -21,8 +21,8 @@
 			¥{{ goodsObjact.ot_price }}
 			<text>市场价</text>
 		</view> -->
-		<text class="title clamp2" v-if="goodsObjact.store_name">{{ goodsObjact.store_name }}</text>
-		<text class="title clamp2" v-else>{{ goodsObjact.title }}</text>
+		<text class="title clamp2" v-if="goodsObjact.title">{{ goodsObjact.title }}</text>
+		<text class="title clamp2" v-else>{{ goodsObjact.store_name }}</text>
 	</view>
 </template>
 
@@ -31,24 +31,26 @@ export default {
 	props: {
 		goodsObjact: {
 			type: Object,
-			default: function() {
-				return {
-					percent:1
-				};
-			}
-		}
-	},
-	filters: {
-		parseIntTo(percent) {
-			percent = +percent * 100;
-			if (percent % 1 === 0) {
-				return percent;
-			} else {
-				percent = percent.toFixed(1);
-				return percent;
-			}
+			// default: function() {
+			// 	return {
+			// 		percent:1
+			// 	};
+			// }
+			default: {}
+			
 		}
 	},
+	// filters: {
+	// 	parseIntTo(percent) {
+	// 		percent = +percent * 100;
+	// 		if (percent % 1 === 0) {
+	// 			return percent;
+	// 		} else {
+	// 			percent = percent.toFixed(1);
+	// 			return percent;
+	// 		}
+	// 	}
+	// },
 	data() {
 		return {};
 	}

+ 178 - 9
pages/product/product.vue

@@ -26,7 +26,22 @@
 			</view>
 		</view>
 		<!-- 标题 -->
-		<product-content :goodsObjact="goodsObjact" v-if="!isSckill"></product-content>
+		<view class="introduce-section"  v-if="!isSckill">
+			
+			<button open-type="share" class="shareDate" style="border: none;">
+				<image class="share-img" src="../../static/icon/share.png"></image>
+			</button>
+			<view class="price-box">
+				<text class="price-tip">¥</text>
+				<view class="price">
+					{{ goodInfo.price }}
+					<text class="m-price" v-if="goodInfo.ot_price*1 > goodInfo.price*1">¥{{ goodInfo.ot_price }}</text>
+				</view>
+			</view>
+			<text class="title clamp2" v-if="goodInfo.title">{{ goodInfo.title }}</text>
+			<text class="title clamp2" v-else>{{ goodInfo.store_name }}</text>
+		</view>
+		<product-content :goodsObjact="goodInfo"</product-content>
 		<view class="good-title clamp2" v-if="isSckill">{{ sckillGoodInfo.title }}</view>
 		<!-- 选择数量 -->
 		<!-- 		<view class="row b-b">
@@ -108,7 +123,7 @@
 </template>
 
 <script>
-import { goodsDetail, cartAdd, seckillGoods, getSeckillProductDetail, getStoreDetail } from '@/api/product.js';
+import { goodsDetail, cartAdd, seckillGoods, getSeckillProductDetail, getStoreDetail ,getProductDetail} from '@/api/product.js';
 import { mapState } from 'vuex';
 import store from '@/store/index.js';
 import { saveUrl } from '@/utils/loginUtils.js';
@@ -207,7 +222,8 @@ export default {
 			product_id: 0,
 			sckillGoodInfo: {}, //秒杀商品信息
 			shopInfo: {}, //店铺信息
-			product_type: 0
+			product_type: 0,
+			goodInfo: {}
 		};
 	},
 	filters: {
@@ -228,7 +244,7 @@ export default {
 		obj.userInfo = uni.getStorageSync('userInfo');
 		//保存商品id
 		this.goodsid = options.id;
-		this.getGoodsDetails();
+		
 		this.product_id = options.id;
 		this.goodsType = options.type;
 		// 判断有无人邀请
@@ -249,6 +265,9 @@ export default {
 		// }
 		if (options.type === '1') {
 			obj.isSckill = true;
+			this.getGoodsDetails();
+		}else if(options.type === '0' ){
+			this.getProductDetail()
 		}
 		// 注册邀请信息
 		// #ifdef H5
@@ -491,7 +510,7 @@ export default {
 			// };
 			let is_new = 0
 			if(obj.type == 1){
-				is_new = 1
+				is_new = 0
 			}
 			let data = {
 				product_id: goodId,
@@ -501,9 +520,6 @@ export default {
 				is_new: is_new
 			}
 			console.log("立即购买++++++",data);
-			if (obj.type == 2) {
-				data.new = 0;
-			}
 			cartAdd(data)
 				.then(function(e) {
 					console.log(e,"立即购买++++++fanhui")
@@ -521,7 +537,7 @@ export default {
 							duration: 2000,
 							icon: 'none'
 						});
-						obj.getGoodsDetails();
+						obj.getProductDetail();
 					}
 					obj.toggleSpec();
 				})
@@ -543,6 +559,7 @@ export default {
 		// getTime() {
 		// 	let start = new data()
 		// }
+		// 获取秒杀商品信息
 		getGoodsDetails() {
 			let obj = this;
 			getSeckillProductDetail({}, this.goodsid).then(({ data }) => {
@@ -600,6 +617,67 @@ export default {
 					
 				}
 			});
+		},
+		getProductDetail() {
+			let obj = this
+			getProductDetail(this.goodsid,{}).then(({data})=> {
+				console.log(data,"putong+++++++++++++++")
+				// console.log(data, 'goodInfo6666666666666');
+				obj.imgList = data.slider_image; //保存轮播图
+				obj.goodInfo.title = data.store_name; //保存商品名称
+				obj.goodInfo.price = data.price; //保存商品展示价格
+				obj.goodInfo.ot_price = data.ot_price; //保存商品市场价
+				console.log(obj.goodInfo,'goodInfo++++++++++++++')
+				// this.$forceUpdate()
+				obj.stopTimes = timeComputed(data.stop * 1000); //设置结束时间
+				obj.product_type = data.product_type//保存商品类型
+				//小程序商品详情图超出屏幕问题
+				if (data.content.content !== null) {
+					obj.description = data.content.content.replace(/\<img/gi, '<img class="rich-img"');
+				}
+				//获取保存店铺详细信息
+				getStoreDetail(data.mer_id).then(({ data }) => {
+					console.log(data, 'shop data');
+					obj.shopInfo = data;
+				});
+				// 获取商品属性
+				obj.specList = data.attr; //保存分类列表
+				if (data.attr.length != 0) {
+					console.log("有好多属性")
+					obj.many = 2;
+					obj.specList = data.attr; //保存产品属性
+					obj.productValue = data.sku; //保存属性值
+					obj.specSelected = []; //初始化默认选择对象
+					for (let i = 0; i < obj.specList.length; i++) {
+						// 设置默认数据
+						let attrValue = obj.specList[i].attr_value[0];
+						attrValue.check = true;
+						obj.specSelected.push(attrValue.attr);
+					}
+					let 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 {
+					console.log("zhiyou yige shuxing")
+					obj.many = 1;
+				
+					obj.productValue = data.sku[''];
+					console.log(obj.productValue,'obj.productValue11111111111')//保存分类查询数据
+					obj.actionPrice =obj.productValue.price; //保存默认选中商品价格
+					obj.actionImage = obj.productValue.image; //保存默认选中商品图片
+					obj.goodsNumberMax = data.stock; //保存默认选中最大可购买商品数量
+					// obj.shopId = data.mer_id; //保存商店id
+					obj.goodsStore = data.stock
+					obj.uniqueId = obj.productValue.unique
+					console.log(obj.uniqueId)
+					
+				}
+			})
 		}
 	}
 };
@@ -978,4 +1056,95 @@ page {
 	font-weight: 800;
 	color: #333333;
 }
+.introduce-section {
+	position: relative;
+	background: #fff;
+	padding: 35rpx 0rpx;
+	padding-left: 20rpx;
+	.title {
+		font-size: 32rpx;
+		color: $font-color-dark;
+		padding-right: 34rpx;
+		.tip-o {
+			color: #ff3334;
+			padding-left: 15rpx;
+		}
+	}
+	.shareDate {
+		position: absolute;
+		top: 25rpx;
+		right: 10rpx;
+		font-size: 26rpx;
+		color: #3d3f46;
+		border-radius: 15rpx;
+		background-color: #ffffff;
+		height: 60rpx;
+		line-height: 60rpx;
+		&::after {
+			border: none;
+		}
+	}
+	.share-img {
+		width: 30rpx;
+		height: 30rpx;
+		position: relative;
+		top: 5rpx;
+		left: 0;
+		margin-right: 10rpx;
+	}
+	.info {
+		color: #999999;
+		font-size: 26rpx;
+		padding-bottom: 15rpx;
+	}
+	.progress-box {
+		width: 260rpx;
+		position: relative;
+		margin-top: 15rpx;
+		line-height: 10px;
+		.number {
+			font-size: 17rpx;
+			position: absolute;
+			z-index: 999;
+			top: 3rpx;
+			left: 15rpx;
+			color: #ffffff;
+		}
+	}
+	.price-box {
+		display: flex;
+		align-items: baseline;
+		height: 64rpx;
+		padding: 10rpx 0;
+		font-size: 27rpx;
+		color: #EF041F;
+	}
+	.price {
+		font-size: $font-lg + 6rpx;
+		.text {
+			padding-left: 5rpx;
+			color: #b0b0b0;
+			font-size: 22rpx !important;
+		}
+	}
+	.price-green {
+		color: #2dbd59;
+		font-size: 28rpx !important;
+		text {
+			background: #2dbd59;
+			color: #ffffff;
+			padding: 0rpx 10rpx;
+			border-radius: 5rpx;
+			font-size: 22rpx !important;
+			margin-left: 15rpx;
+		}
+	}
+	.m-price {
+		margin: 0 12rpx;
+		color: $font-color-light;
+		text-decoration: line-through;
+		margin-left: 25rpx;
+		font-size: 24rpx;
+	}
+}
 </style>