瀏覽代碼

Merge branch 'master' of http://git.cc-lotus.info/pointToNetwork/point-app

guhongwei 2 年之前
父節點
當前提交
b32769c1e8
共有 1 個文件被更改,包括 98 次插入53 次删除
  1. 98 53
      pagesHome/order/detail.vue

+ 98 - 53
pagesHome/order/detail.vue

@@ -122,7 +122,7 @@
 					</view>
 					<text>库存{{max}}</text>
 				</view>
-				<view @click="toBuy" class="button">{{type=='0'?'加入购物车':'立即购买'}}</view>
+				<view @click="toBuy(type)" class="button">{{type=='0'?'加入购物车':'立即购买'}}</view>
 			</view>
 		</uni-popup>
 	</mobile-frame>
@@ -184,11 +184,15 @@
 						type: '1'
 					}
 				],
+				// 商品id
 				id: '',
+				// 轮播图
 				bannerList: [],
-				// 详情
+				// 商品详情
 				info: {},
+				// 商店详情
 				shop: {},
+				// 规格情况
 				specs: [],
 				// 已选
 				Selected: '',
@@ -217,8 +221,9 @@
 		},
 		onShow: function() {},
 		methods: {
+			//店铺,购物车,客服跳转
 			onClick(e) {
-				if (e && e.content.route){
+				if (e && e.content.route) {
 					uni.navigateTo({
 						url: `/${e.content.route}`
 					})
@@ -230,11 +235,46 @@
 					url: `/${e}`
 				})
 			},
+			// 收藏
+			toCollect() {
+				const that = this;
+				that.collection = !that.collection;
+				if (that.collection == true) {
+					uni.showToast({
+						title: `收藏成功`,
+						icon: 'none'
+					})
+				} else {
+					uni.showToast({
+						title: `取消成功`,
+						icon: 'none'
+					})
+				}
+			},
+			//主菜单跳转
 			toPath(e) {
 				if (e && e.route) uni.reLaunch({
 					url: `/${e.route}`
 				})
 			},
+			// 菜单展开
+			toMenu() {
+				const that = this;
+				that.menu = !that.menu
+			},
+			// 计算高度
+			handleScroll(e) {
+				const that = this;
+				let scrollTop = e.detail.scrollTop;
+				that.isShow = scrollTop > 500;
+				that.topItem = '';
+			},
+			// 返回顶部
+			backTop() {
+				const that = this;
+				that.topItem = 'top'
+			},
+			//加入购物车,立即购买弹窗
 			buttonClick(e) {
 				const that = this;
 				if (e && e.content) that.type = e.content.type;
@@ -246,11 +286,6 @@
 				that.type = '1';
 				that.$refs.popup.open();
 			},
-			// 关闭弹框
-			toClose() {
-				const that = this;
-				that.$refs.popup.close()
-			},
 			// 修改样式
 			toStyle(e, index) {
 				const that = this;
@@ -265,56 +300,66 @@
 				const that = this;
 				that.num = e;
 			},
-			// 收藏
-			toCollect() {
-				const that = this;
-				that.collection = !that.collection;
-				if (that.collection == true) {
-					uni.showToast({
-						title: `收藏成功`,
-						icon: 'none'
-					})
-				} else {
-					uni.showToast({
-						title: `取消成功`,
-						icon: 'none'
-					})
-				}
-			},
-			// 菜单展开
-			toMenu() {
-				const that = this;
-				that.menu = !that.menu
-			},
 			// 立即购买
-			toBuy() {
-				const that = this;
-				if (that.Selected) {
-					uni.navigateTo({
-						url: `/pagesHome/order/order`
-					})
-				} else {
-					uni.showModal({
-						title: '提示',
-						content: '请选择规格',
-						confirmColor: '#ff0000',
-						showCancel: false,
-						success: function(res) {}
-					});
-				}
-			},
-			// 计算高度
-			handleScroll(e) {
+			toBuy(e) {
 				const that = this;
-				let scrollTop = e.detail.scrollTop;
-				that.isShow = scrollTop > 500;
-				that.topItem = '';
+				uni.getStorage({
+					key: 'token',
+					success: async function(res) {
+						let user = that.$jwt(res.data);
+						if (that.Selected) {
+							if (e == '0') {
+								let specs_id;
+								let specs = that.specs.find(i => i.name == that.Selected)
+								if (specs) specs_id = specs._id
+								let data = {
+									customer: user._id,
+									shop: that.shop._id,
+									goods: that.info._id,
+									goodsSpec: specs_id,
+									num: that.num
+								}
+								let arr = await that.$api(`/cart`, 'POST', data)
+								if (arr.errcode == '0') {
+									uni.showToast({
+										title: `加入购物车成功`,
+										icon: 'success'
+									})
+									that.$refs.popup.close()
+								} else {
+									uni.showToast({
+										title: arr.errmsg,
+										icon: 'none'
+									})
+								}
+							} else {
+								uni.navigateTo({
+									url: `/pagesHome/order/order`
+								})
+							}
+						} else {
+							uni.showModal({
+								title: '提示',
+								content: '请选择规格',
+								confirmColor: '#ff0000',
+								showCancel: false,
+								success: function(res) {}
+							});
+						}
+					},
+					fail: function(err) {
+						uni.navigateTo({
+							url: `/pages/login/index`
+						})
+					}
+				});
 			},
-			// 返回顶部
-			backTop() {
+			// 关闭弹框
+			toClose() {
 				const that = this;
-				that.topItem = 'top'
+				that.$refs.popup.close()
 			},
+			// 详情数据
 			async search() {
 				const that = this;
 				let res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {