diff --git a/store/modules/user.js b/store/modules/user.js index 2704c9c..2c86df9 100644 --- a/store/modules/user.js +++ b/store/modules/user.js @@ -5,6 +5,7 @@ export default { token: "" }, //保存用户登录信息, toPath: "", //要跳转过去的页面, + foodInfo:"", //美食套餐信息 }, // 类似 vue 里的 mothods(同步方法) mutations: { @@ -23,5 +24,9 @@ export default { url: '/pages/login/login' }) }, + // 线路下单 + changeFoodInfo(state, data){ + state.foodInfo = data + } } } diff --git a/subPackages/food/foodDetail.vue b/subPackages/food/foodDetail.vue index 2fbc3b7..b08c0ba 100644 --- a/subPackages/food/foodDetail.vue +++ b/subPackages/food/foodDetail.vue @@ -30,7 +30,7 @@ {{info.title}} - + 收藏 @@ -55,26 +55,26 @@ 美食下单 - - + + - {{item.title}} + {{skuItem.title}} - {{item.price/100}} + {{skuItem.price/100}} - + {{tag}} | - 购买 + 购买 @@ -96,6 +96,9 @@ isCollect: 0, }; }, + onShow() { + this.$store.commit('changeFoodInfo', null); + }, onLoad(option) { this.id = option.id; this.getDetail(); @@ -107,6 +110,7 @@ goods_id: this.id },'/api/goods/getGoodDetail').then(res => { res.data.goods_new_tag = (res.data.goods_new_tag ? res.data.goods_new_tag.split(',') : []).splice(0, 2); + this.isCollect = res.data.is_collect this.info = res.data }) }, @@ -124,7 +128,7 @@ // 收藏 collect() { this.Post({ - type: 16, + type: 3, id: this.id }, '/api/scenic/collect' @@ -141,10 +145,16 @@ }); }, order(item) { - uni.setStorageSync('order', JSON.stringify(item)); //规格 - uni.setStorageSync('info', JSON.stringify(this.info)); //商品 + // uni.setStorageSync('order', JSON.stringify(item)); //规格 + // uni.setStorageSync('info', JSON.stringify(this.info)); //商品 + this.$store.commit('changeFoodInfo', item); + uni.navigateTo({ + url: '/subPackages/food/foodOrder' + }); + }, + taocanDetail() { uni.navigateTo({ - url: '/subPackages/oneplus/oneplusOrder' + url: '/subPackages/food/taocanDetail' }); }, }, diff --git a/subPackages/food/foodOrder.vue b/subPackages/food/foodOrder.vue index 23dec02..05bd1c1 100644 --- a/subPackages/food/foodOrder.vue +++ b/subPackages/food/foodOrder.vue @@ -2,51 +2,64 @@ - + - 名称名称名称名称名称名称名称名称名称名称名称名称名称名称名称名称名称名称 + {{info.title}} - 9.9 + {{info.money/100}} - - - 1 - + + - + {{num}} + + - - - 优惠券 - - - 暂无可用优惠券 - - - + + +
优惠券
+
+ 请选择 +
+
+ -¥{{coupon.discounts/100}} + -{{coupon.percent}}% + > +
+
联系人: - + 手机号: - + - +
- + + + 合计: + + + ¥{{ allprice }} + + + + 去支付 +
@@ -55,11 +68,131 @@ export default { data() { return { - coupon:null, + coupon:"", + reserve_name: '', + reserve_phone: '', + info:null, + detail:null,//商品的信息 + allprice: 0, + num:0, + } + }, + onShow() { + this.coupon = this.$store.state.user.coupon + console.log('传过来的优惠券',this.coupon); + this.total() + }, + onLoad(option) { + this.$store.commit("choseCoupon", ""); + this.info = this.$store.state.user.foodInfo + // this.info = JSON.parse(uni.getStorageSync('order')) + // this.detail = JSON.parse(uni.getStorageSync('detail')); + this.num = this.info.buyNum?this.info.buyNum:1 + if (!this.info) { + uni.navigateBack(); } + console.log(this.info); + this.total() }, methods: { - + cha() { + this.reserve_phone = '' + }, + order() { + if (!this.reserve_name) { + uni.showToast({ + title: '请输入姓名', + icon: 'none' + }); + return; + } + if (!this.reserve_phone) { + uni.showToast({ + title: '请输入电话', + icon: 'none' + }); + return; + } + let goods = []; + let goodsItem = { + specifications_id: this.info.id, + num: this.num, + }; + goods.push(goodsItem); + let data = { + goods: goods, + coupon: this.coupon ? this.coupon.id : null, + is_post: this.info.is_post, + reserve_name: this.reserve_name, + reserve_phone: this.reserve_phone + }; + this.Post( + { + method: 'POST', + data: JSON.stringify(data) + }, + '/api/order/place' + ).then(res => { + if (res.code == 200) { + this.Post( + { + order_id: res.data.order_id, + type: 'miniprogram', + platform: 'miniprogram' + }, + '/api/pay/unify' + ).then(res => { + if (res.data) { + uni.requestPayment({ + nonceStr: res.data.nonceStr, + package: res.data.package, + paySign: res.data.paySign, + signType: res.data.signType, + timeStamp: res.data.timeStamp, + complete() { + uni.navigateTo({ + url: '/subPackages/order/trades' + }); + } + }); + } + }); + } + }); + }, + plus() { + this.num = Number(this.num); + this.coupon = '' + this.$nextTick(() => { + this.num += 1; + this.total() + }); + }, + reduce() { + this.num = Number(this.num); + this.coupon = '' + if (this.num > 1) { + this.$nextTick(() => { + this.num -= 1; + this.total() + }); + } + }, + // 总价 + total() { + let price = 0 + if (this.coupon) { + if (this.coupon.percent == 0) { + price = this.info.money * this.num - this.coupon.discounts + } else{ + price = this.info.money * this.num - ((this.info.money * this.num + this.post) * this.coupon.percent) + } + } else{ + price = this.info.money * this.num + } + price < 0 ? 0 : price + this.allprice = price / 100 + }, } } @@ -88,6 +221,8 @@ left: 0; right: 0; bottom: 0; + display: flex; + justify-content: space-between; } .img { @@ -176,6 +311,7 @@ border-bottom: 1rpx solid #CCC; display: flex; justify-content: space-between; + align-items: center; } .name-box { @@ -220,5 +356,66 @@ margin-left: 20rpx; } + .totalText { + margin-right: 20rpx; + font-family: PingFang SC; + font-weight: 500; + font-size: 29rpx; + color: #333333; + } + + .totalPrice { + font-family: PingFang SC; + font-weight: 500; + font-size: 36rpx; + color: #F84A56; + } + + .order { + width: 267rpx; + height: 87rpx; + background: #F84A56; + border-radius: 43rpx; + font-family: PingFang; + font-weight: bold; + font-size: 36rpx; + color: #FFFFFF; + text-align: center; + line-height: 87rpx; + } + + .center { + display: flex; + align-items: center; + } + + .coupon-btn { + width: 140rpx; + height: 57rpx; + border: 1px solid #333333; + border-radius: 29rpx; + font-size: 28rpx; + font-family: PingFangSC; + font-weight: 400; + color: #000000; + text-align: center; + line-height: 57rpx; + + .select { + padding: 10rpx 18rpx; + background: #ED9230; + border-radius: 10rpx; + font-size: 28rpx; + font-weight: 400; + color: #fff; + } + } + + .coupon-price { + color:#DD0000; + font-size: 30rpx; + font-weight: 500; + } +