|
|
<template> <view> <lf-nav title="确认订单" :showIcon="true"></lf-nav> <block v-if="$isRight(order_detail)"> <view class="card head"> <view class="lf-font-32 lf-color-222">选择收货方式</view> <view class="capsule"> <view class="item" :class="{'capsule-active': mode == 0}" @click="switchMode(0)">邮寄</view> <view class="item" :class="{'capsule-active': mode == 1}" @click="switchMode(1)">自提</view> </view> </view> <view class="card address" v-if="mode == 0"> <view @click="$url('/pages/address/list/list?is_select=1')"> <text class="lf-font-28 lf-color-primary lf-m-r-10">更换收获地址</text> <text class="lf-iconfont icon-xiangyou lf-font-24 lf-color-777"></text> </view> <view v-if="address"> <view class="lf-m-t-20"> <text class="lf-font-28 lf-color-222 lf-font-bold">{{ address.accept_name }}</text> <text class="lf-font-28 lf-color-777 lf-m-l-20">{{ address.mobile }}</text> </view> <view class="lf-font-28 lf-color-333 lf-m-t-10"> <text>{{ address.address_name }}{{ address.address }}</text> </view> </view> <view v-else class="lf-font-28 lf-color-777"> 暂无收货地址,请前往添加 </view> </view> <view class="card address" v-else> <view> <text class="lf-font-28 lf-color-primary lf-m-r-10">店铺地址</text> </view> <view v-if="address"> <view class="lf-m-t-20"> <text class="lf-font-28 lf-color-222 lf-font-bold">{{ order_detail.order.brand.name }}</text> <text class="lf-font-28 lf-color-777 lf-m-l-20">{{ order_detail.order.brand.tel }}</text> </view> <view class="lf-font-28 lf-color-333 lf-m-t-10"> <text>{{ order_detail.order.brand.floor }}</text> </view> </view> <view v-else class="lf-font-28 lf-color-777"> 暂无收货地址,请前往添加 </view> </view> <view class="card goods" v-if="$isRight(order_detail.order) && $isRight(order_detail.order.items)"> <view @click="$url('/pages/shop/shopdetail?id='+ order_detail.order.brand.id)"> <text class="lf-iconfont icon-Group- lf-font-30"></text> <text class="shop-name">{{ order_detail.order.brand.name }}</text> <text class="lf-iconfont icon-xiangyou lf-font-24"></text> </view> <view class="lf-flex lf-m-t-20" v-for="(item, index) in order_detail.order.items" :key="index"> <image class="goods-img" :src="item.item_meta.image"></image> <view class="info"> <view class="lf-font-26 lf-color-333 lf-line-1">{{ item.item_name }}</view> <view class="lf-font-24 lf-color-777">{{ item.item_meta.specs_text }}</view> <view class="lf-row-between" style="line-height: 1;"> <text class="price"><text v-if="goods_type==1">¥</text>{{ unitConversion(item.unit_price) }}<text class="lf-font-24" v-if="goods_type==0">积分</text></text> <text class="lf-font-28 lf-color-777">x {{ item.quantity }}</text> </view> </view> </view> <!-- <view class="tips">支付成功后15天内柜台提货</view> --> <view class="lf-flex lf-m-t-20"> <view class="lf-font-28 lf-color-777">留言</view> <input v-model="value" class="input" placeholder="有什么要求,请备注留言" /> </view> </view> <view class="card lf-m-t-20"> <view class="lf-row-between" @click="openCheckCoupon"> <view class="lf-font-28 lf-color-777">优惠券</view> <view> <text class="lf-font-26 lf-color-999 lf-m-r-10">{{ showCouponTitle }}</text> <text class="lf-iconfont icon-xiangyou lf-font-24"></text> </view> </view> <view class="lf-row-between lf-m-t-20"> <view class="lf-font-28 lf-color-777">商品金额</view> <view class="lf-font-26 lf-color-222"><text v-if="goods_type==1">¥</text>{{ itemsPrice }}<text v-if="goods_type==0">积分</text></view> </view> <view class="lf-row-between lf-m-t-20" v-if="mode == 0"> <view class="lf-font-28 lf-color-777">运费</view> <view class="lf-font-26" style="color: #F63434;">+¥{{ order_detail.order.payable_freight_yuan || 0 }}</view> </view> <view class="lf-row-between lf-m-t-20"> <view class="lf-font-28 lf-color-777">优惠</view> <view class="lf-font-26" style="color: #F63434;">-¥{{ fullMinus(order_detail.discounts) }}</view> </view> </view> <view class="spread-out"></view> <view class="fixed-bottom"> <view class="fixed-content"> <view class="lf-font-24 lf-color-777">共{{ order_detail.order.count }}件</view> <view class="lf-flex"> <!-- <view class="lf-font-32 lf-color-primary" style="max-width: 400rpx;">合计 ¥{{ order_detail.order.total_yuan }}</view> --> <view class="lf-font-32 lf-color-primary" style="max-width: 400rpx;"> <text>合计</text> <text v-if="goods_type==1">¥</text> <text>{{ totalPrice }}</text> <text v-if="goods_type==0">积分</text> </view> <view class="confirm-btn" hover-class="lf-opacity" @click="confirm">提交订单</view> </view> </view> </view> <!-- 选择优惠券弹出层 --> <u-popup v-model="show_coupon" mode="bottom" :round="true" borderRadius="20"> <view class="popup-content"> <view class="lf-row-between" v-for="(item, index) in order_detail.coupons" :key="index"> <radio-group @change="couponChange"> <radio :value="index" :checked="coupon_index == index"></radio> </radio-group> <view class="coupon-card lf-m-b-30" :class="{'invalid-bg': item.ifpast == true}"> <view class="coupon-circle-top"> <view class="coupon-circle1"></view> </view> <view class="coupon-circle-bottom"> <view class="coupon-circle1"></view> </view> <view class="coupon-radius"> <view class="coupon-left"> <view class="lf-font-36 lf-color-white" style="line-height: 1;" v-if="item.discount.action_type.type == 'cash'"> <text v-if="goods_type==1">¥</text> <text class="lf-font-70 lf-font-bold">{{item.discount.action_type.value}}</text> <text v-if="goods_type==0">积分</text> </view> <view class="lf-font-36 lf-color-white" style="line-height: 1;" v-if="item.discount.action_type.type == 'discount'"> <text class="lf-font-70 lf-font-bold">{{item.discount.action_type.value}}</text> <text>%</text> </view> <view class="coupon-tag" v-if="item.used_at != ''"> 已使用 </view> <view class="coupon-tag" v-if="item.ifpast"> 已过期 </view> <view class="coupon-tag" v-if="!item.ifpast && item.used_at == ''"> 待使用 </view> </view> <view class="coupon-right"> <view class="lf-font-32 lf-font-bold lf-color-white">{{item.discount.title}}</view> <view class="lf-font-24 lf-color-white">有效期{{item.discount.starts_at}}~{{item.discount.ends_at}}</view> </view> </view> </view> </view> <!-- 不使用优惠券 --> <view class="lf-flex"> <radio-group @change="couponChange"> <radio value="null" :checked="coupon_index == null"></radio> </radio-group> <view>不使用优惠券</view> </view> </view> </u-popup> </block> </view></template>
<script> import Bigc from '@/common/js/bigc.js'; export default { data(){ return { mode: 0, // 0邮寄,1自提
value: '', // 备注
token: '', address: {}, address_id: null, order_detail: {}, show_coupon: false, coupon_index: null, goods_type: 1, itemsPrice: 0, // 商品金额(所有商品之和,但不包括额外费用及优惠)
totalPrice: 0 ,// 合计价格
clickContinue: true } }, computed: { showCouponTitle(){ let order_detail = this.order_detail; if(typeof order_detail.coupons == 'undefined'){ order_detail.coupons = []; } if(this.coupon_index != null){ return order_detail.coupons[this.coupon_index].discount.title; }else{ if(order_detail.coupons.length){ return '不使用优惠券'; }else{ return '暂无可用优惠券'; } } }, fullMinus(){ return function(arr){ if(this.$isRight(arr)){ let price = arr[0].adjustmentTotal; let adjustmentTotal = new Bigc(price).div(100); return Math.abs(adjustmentTotal); }else{ return 0 } } } }, onLoad(e){ this.token = this.$cookieStorage.get('user_token'); this.goods_type = e.goods_type; console.log('积分类型',e) let options = this.$cookieStorage.get('order_confirm'); if(this.$isRight(options)){ this.orderCheckout(options); } }, onUnload(){ this.$cookieStorage.clear('order_confirm'); }, onShow(){ if(this.address_id){ this.getSelectAddress(); } }, methods: { // 生成临时订单
orderCheckout(options){ uni.showLoading({ title: '正在生成订单' }) this.$http.post({ api: 'api/shopping/order/checkout', data: options, header: { Authorization: this.token } }).then(res => { if(res.data.code == 200){ let detail = res.data.data; this.order_detail = detail; this.address = res.data.data.address; if(this.$isRight(detail.coupons)){ this.coupon_index = 0; } this.calcAmount(); }else{ this.$msg(res.data.message || '生成订单失败').then(() => { this.$toBack(); }) } uni.hideLoading() }).catch(err => uni.hideLoading()) }, // 单位转换金额
unitConversion(price){ let newPrice = new Bigc(price).div(100); return Math.abs(newPrice); }, // 计算金额
calcAmount(){ let detail = this.order_detail; let items = detail.order.items || []; let itemsPrice = new Bigc(0); // 所有商品总计
items.map(item => { let price = new Bigc(item.unit_price).div(100); let itemP = price.times(item.quantity); itemsPrice = itemsPrice.plus(itemP); }) this.itemsPrice = itemsPrice; // 减去优惠券的价格
if(this.coupon_index != null){ let coupon = detail.coupons[this.coupon_index]; let adjustmentTotal = new Bigc(coupon.adjustmentTotal).div(100); // 得到负数
itemsPrice = itemsPrice.plus(adjustmentTotal); // 加一个负数等于减去的优惠
} // 减去满减优惠
if(this.$isRight(detail.discounts)){ let discount = detail.discounts[0]; let adjustmentTotal = new Bigc(discount.adjustmentTotal).div(100); // 得到负数
itemsPrice = itemsPrice.plus(adjustmentTotal); // 加一个负数等于减去的优惠
} // 如果为邮寄订单时,加上运费
if(this.mode == 0){ let payable_freight = new Bigc(detail.order.payable_freight).div(100); itemsPrice = itemsPrice.plus(payable_freight); } this.totalPrice = itemsPrice; // 合计价格
}, // 切换订单是邮寄还是自提
switchMode(mode){ this.mode = mode; this.calcAmount(); }, // 获取默认地址
getDefaultAddress(){ this.$http.get({ api: 'api/address/default', header: { Authorization: this.token } }).then(res => { this.address = res.data.data || {}; }) }, // 获取用户自己选择的地址
getSelectAddress(){ this.$http.get({ api: 'api/address/'+ this.address_id, header: { Authorization: this.token } }).then(res => { this.address = res.data.data || {}; }) }, // 打开选择优惠券
openCheckCoupon(){ if(this.order_detail.coupons.length){ this.show_coupon = true; }else{ this.$msg('您没有可用的优惠券哦'); } }, // 提交订单
confirm(){ console.log(this.address) if(this.clickContinue == true) { this.clickContinue = false; if(this.address == null) { this.$msg('请先添加收货地址!'); return } let par = { order_no: this.order_detail.order.order_no, pick_self: this.mode, // 0 配送,1自提
address_id: this.address.id, note: this.value } // 是否选择了优惠券 TODO 优惠券id是否传对?
if(this.coupon_index != null){ par.coupon_id = this.order_detail.coupons[this.coupon_index].id; } this.$http.post({ api: 'api/shopping/order/confirm', data: par, header: { Authorization: this.token } }).then(res => { if(res.data.code == 200 || res.data.code == true){ let order = res.data.data.order; let url = '/pages/order/cashier/cashier'; url += '?amount='+ this.totalPrice; url += '&order_no='+ order.order_no; this.$url(url, {type: 'redirect'}); this.clickContinue = true; }else{ this.$msg(res.data.message); this.clickContinue = true; } }) } }, // 选择优惠券
couponChange(event){ if(event.detail.value == 'null'){ this.coupon_index = null; }else{ this.coupon_index = Number(event.detail.value); } this.show_coupon = false; this.calcAmount(); } } }</script>
<style> page{ background-color: #F8F8F8; }</style><style lang="scss" scoped="scoped"> .card{ height: max-content; width: 750rpx; padding: 30rpx 32rpx; background-color: #FFFFFF; } .head{ .capsule{ width: 614rpx; height: 100rpx; margin: 30rpx auto 0; border-radius: 100px; border: 2rpx solid #15716E; display: flex; overflow: hidden; .item{ width: 50%; display: flex; justify-content: center; align-items: center; font-size: 32rpx; font-weight: bold; color: #15716E; } .capsule-active{ background-color: #15716E; color: #FFFFFF; } } } .address{ margin-top: 20rpx; } .goods{ margin-top: 20rpx; .shop-name{ font-size: 28rpx; color: #222222; font-weight: bold; margin: 0 15rpx; } .goods-img{ width: 130rpx; height: 130rpx; border-radius: 4rpx; margin-right: 15rpx; background-color: #EEEEEE; } .info{ width: 540rpx; height: 130rpx; display: flex; flex-direction: column; justify-content: space-around; .price{ font-size: 32rpx; color: #F63434; font-weight: bold; } } .tips{ font-size: 22rpx; margin-top: 30rpx; color: #15716E; } .input{ margin-left: 30rpx; font-size: 28rpx; width: 596rpx; } } .spread-out{ height: 138rpx; padding-bottom: constant(safe-area-inset-bottom); padding-bottom: env(safe-area-inset-bottom); box-sizing: content-box; } .fixed-bottom{ position: fixed; left: 0; bottom: 0; width: 750rpx; height: max-content; background-color: #FFFFFF; border-top: 1rpx solid #e5e5e5; padding-bottom: constant(safe-area-inset-bottom); padding-bottom: env(safe-area-inset-bottom); .fixed-content{ width: 100%; height: 118rpx; padding: 0 32rpx; display: flex; align-items: center; justify-content: space-between; .confirm-btn{ width: 167rpx; height: 80rpx; background: #15716E; border-radius: 40rpx; color: #FFFFFF; display: flex; justify-content: center; align-items: center; margin-left: 30rpx; font-size: 26rpx; } } } .popup-content{ width: 750rpx; height: max-content; max-height: 70vh; overflow-y: scroll; padding: 40rpx 32rpx; background: #FFFFFF; } .coupon-circle1 { width: 40rpx; height: 40rpx; background-color: white; border-radius: 50%; } .coupon-circle-top { width: 50rpx; height: 50rpx; border-radius: 50%; // background-color: red;
position: absolute; border: 1px dashed #ccc; left: 190rpx; top: -20rpx; display: flex; align-items: center; text-align: center; justify-content: center; } .coupon-circle-bottom { width: 50rpx; height: 50rpx; border-radius: 50%; // background-color: red;
position: absolute; border: 1px dashed #ccc; left: 190rpx; bottom: -20rpx; display: flex; align-items: center; text-align: center; justify-content: center; } .coupon-right { text-align: left; justify-content: center; align-items: flex-start; display: flex; flex-direction: column; margin-left: 90rpx; } .coupon-left { margin-left: 30rpx; display: flex; flex-direction: column; justify-content: center; align-items: center; } .coupon-tag { width: max-content; margin-top: 10rpx; padding: 0 24rpx; height: 43rpx; border-radius: 22rpx; border: 2rpx solid #FFFFFF; font-size: 24rpx; color: white; } .coupon-wrap { display: flex; justify-content: center; margin-top: 30rpx; flex-direction: column; align-content: center; align-items: center; } .coupon-card { overflow: hidden; position: relative; display: flex; align-items: center; justify-content: center; // width: 674rpx;
width: 626rpx; height: 171rpx; background: #15716E; border-radius: 20rpx; } .invalid-bg{ background-color: #999999; } .coupon-radius { // width: 664rpx;
width: 616rpx; display: flex; height: 161rpx; border: 1rpx dashed #ccc; // background: #15716E;
border-radius: 20rpx; } /deep/.u-scroll-box { display: flex; justify-content: center; align-items: center; border-bottom: 1rpx solid rgba(0, 0, 0, 0.1); } /deep/.special_tab .u-tabs .u-scroll-box .u-tab-bar { background-color: #15716E!important; width: 80rpx!important; position: absolute; height: 10rpx; left: 0; border-radius: 8rpx 8rpx 0px 0px!important; bottom: -12rpx; } /deep/ .u-tab-item { font-size: 28rpx!important; }</style>
|