wip: tiered deliver price
This commit is contained in:
1 parent
8423007350
commit
a0c13b91da
23 files changed
+426
-39
No files matched your search
@@ -13,3 +13,10 @@ export function menuGoods(data) {
|
||||
return api.get('/product/products', data, { login: false })
|
||||
}
|
||||
|
||||
/**
|
||||
* 预估配送费(根据收货地址距离匹配配送规则)
|
||||
*/
|
||||
export function getDeliveryFee(data) {
|
||||
return api.get('/store/delivery-fee', data, { login: false })
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const DEV_API_URL = 'http://localhost:48081/app-api'
|
||||
const PROD_API_URL = 'https://apidc.yixiang.co/app-api'
|
||||
const DEV_API_URL = 'http://maitre.imomoe.cn/api/app-api'
|
||||
const PROD_API_URL = 'https://maitre.imomoe.cn/api/app-api'
|
||||
|
||||
// #ifdef APP-PLUS || H5 || MP-WEIXIN
|
||||
export const VUE_APP_API_URL =
|
||||
@@ -8,7 +8,7 @@ export const VUE_APP_API_URL =
|
||||
|
||||
export const VUE_APP_RESOURCES_URL = 'https://h5.yixiang.co/static'
|
||||
export const VUE_APP_UPLOAD_URL = VUE_APP_API_URL + '/infra/file/upload'
|
||||
export const APP_ID = 'wxdbdbc123c8c30b45'
|
||||
export const APP_ID = 'wx3548436813df3f60'
|
||||
|
||||
const orderListStatus = {}
|
||||
|
||||
|
||||
@@ -431,18 +431,18 @@
|
||||
"router" : {
|
||||
"base" : "/h5/"
|
||||
},
|
||||
"sdkConfigs" : {
|
||||
// 使用地图或位置相关功能必须填写其一
|
||||
"maps" : {
|
||||
"bmap" : {
|
||||
// 百度地图秘钥(HBuilderX 3.99+)http://lbsyun.baidu.com/apiconsole/key#/home
|
||||
"key" : ""
|
||||
},
|
||||
"qqmap" : {
|
||||
"key" : "OGABZ-Y5OCF-5UWJ5-N7DHH-VFIG7-DHFEB"
|
||||
}
|
||||
}
|
||||
}
|
||||
"sdkConfigs" : {
|
||||
// 使用地图或位置相关功能必须填写其一
|
||||
"maps" : {
|
||||
"bmap" : {
|
||||
// 百度地图秘钥(HBuilderX 3.99+)http://lbsyun.baidu.com/apiconsole/key#/home
|
||||
"key" : ""
|
||||
},
|
||||
"qqmap" : {
|
||||
"key" : "OGABZ-Y5OCF-5UWJ5-N7DHH-VFIG7-DHFEB"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* 模块配置 *//* 应用发布信息 *//* android打包配置 */
|
||||
|
||||
@@ -125,7 +125,7 @@
|
||||
<view class="flex-fill d-flex justify-content-end align-items-center">
|
||||
<view>
|
||||
总计¥{{ total }}
|
||||
<text v-if="orderType == 'takeout'">,配送费¥{{ store.deliveryPrice }}</text>
|
||||
<text v-if="orderType == 'takeout'">,配送费¥{{ deliveryFee }}</text>
|
||||
<text v-if="coupon.value">,¥-{{ coupon.value }}</text>
|
||||
,实付
|
||||
</view>
|
||||
@@ -219,6 +219,7 @@
|
||||
import {
|
||||
ref,
|
||||
computed,
|
||||
watch,
|
||||
nextTick
|
||||
} from 'vue'
|
||||
import { useMainStore } from '@/store/store'
|
||||
@@ -235,12 +236,15 @@ import {
|
||||
import {
|
||||
couponCount
|
||||
} from '@/api/coupon'
|
||||
import { getDeliveryFee } from '@/api/goods'
|
||||
// #ifdef H5
|
||||
import * as jweixin from 'weixin-js-sdk'
|
||||
// #endif
|
||||
const main = useMainStore()
|
||||
const { orderType,address, store,location,isLogin,member,mycoupon } = storeToRefs(main)
|
||||
const active = ref(false)
|
||||
const deliveryFee = ref(0)
|
||||
const outOfRange = ref(false)
|
||||
const title = ref('支付')
|
||||
const jsStr = ref('')
|
||||
const cart = ref([])
|
||||
@@ -302,8 +306,8 @@ const total = computed(() =>{
|
||||
const amount = computed(() =>{
|
||||
let amount = cart.value.reduce((acc, cur) => acc + cur.number * cur.price, 0);
|
||||
// 加配送费
|
||||
if (store.value.distance > 0 && orderType.value == 'takeout') {
|
||||
amount += parseFloat(store.value.deliveryPrice);
|
||||
if (orderType.value == 'takeout') {
|
||||
amount += deliveryFee.value;
|
||||
}
|
||||
|
||||
|
||||
@@ -317,6 +321,33 @@ const amount = computed(() =>{
|
||||
return amount.toFixed(2);
|
||||
})
|
||||
|
||||
// 选地址/切换外卖后预估配送费(基于收货地址距离匹配配送规则)
|
||||
watch([address, store, orderType], async () => {
|
||||
if (orderType.value !== 'takeout' || !store.value.id) {
|
||||
deliveryFee.value = 0
|
||||
outOfRange.value = false
|
||||
return
|
||||
}
|
||||
// 未选地址时显示默认配送费
|
||||
if (!address.value || !address.value.longitude) {
|
||||
deliveryFee.value = parseFloat(store.value.deliveryPrice) || 0
|
||||
outOfRange.value = false
|
||||
return
|
||||
}
|
||||
try {
|
||||
const res = await getDeliveryFee({
|
||||
shopId: store.value.id,
|
||||
lng: address.value.longitude,
|
||||
lat: address.value.latitude
|
||||
})
|
||||
outOfRange.value = !!res.outOfRange
|
||||
deliveryFee.value = parseFloat(res.deliveryPrice) || 0
|
||||
} catch (e) {
|
||||
deliveryFee.value = parseFloat(store.value.deliveryPrice) || 0
|
||||
outOfRange.value = false
|
||||
}
|
||||
}, { immediate: true })
|
||||
|
||||
onShow(() => {
|
||||
coupon.value = main.mycoupon
|
||||
let date = new Date(new Date().getTime() + 3600000); // 一个小时后
|
||||
@@ -494,6 +525,11 @@ const submit = () => {
|
||||
}
|
||||
}
|
||||
const pay = async() => {
|
||||
// 外卖时校验收货地址是否在配送范围
|
||||
if (orderType.value == 'takeout' && outOfRange.value) {
|
||||
uToast.value.show({message:'当前收货地址不在配送范围内',type: 'error'});
|
||||
return;
|
||||
}
|
||||
let that = this;
|
||||
// // #ifdef MP-WEIXIN
|
||||
// await new Promise(function(revolve) {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<view class="shop-page__body">
|
||||
<view class="shop-page__info">
|
||||
<view>距离您 {{kmUnit(item.dis)}}</view>
|
||||
<view v-if="item.distance > 0">配送距离:{{item.distance + 'km '}} & 配送费:{{item.delivery_price}}</view>
|
||||
<view v-if="item.distance > 0">配送距离:{{item.distance + 'km '}} & 配送费:{{deliveryRuleText(item)}}</view>
|
||||
<view v-else>外卖不配送</view>
|
||||
<view>{{item.addressMap + ' ' + item.address}}</view>
|
||||
<view>营业时间 {{formatDateTime(item.startTime,'hh:mm')}} - {{formatDateTime(item.endTime,'hh:mm')}}</view>
|
||||
@@ -74,6 +74,20 @@ const getShop = async(keywork = '') => {
|
||||
}
|
||||
}
|
||||
}
|
||||
// 配送规则摘要文本
|
||||
const deliveryRuleText = (item) => {
|
||||
let rules = []
|
||||
try {
|
||||
rules = typeof item.deliveryRules === 'string' && item.deliveryRules
|
||||
? JSON.parse(item.deliveryRules) : (item.deliveryRules || [])
|
||||
} catch (e) {
|
||||
rules = []
|
||||
}
|
||||
if (rules && rules.length) {
|
||||
return rules.map(r => r.minKm + '-' + r.maxKm + 'km ¥' + r.price).join(' / ')
|
||||
}
|
||||
return '¥' + (item.deliveryPrice || 0)
|
||||
}
|
||||
//打开定位
|
||||
const openLocation = (shop) => {
|
||||
//console.log(shop);
|
||||
|
||||
@@ -366,12 +366,12 @@ const getCartGoodsPrice = computed(() =>{ //计算购物车总价
|
||||
return parseFloat(price).toFixed(2);
|
||||
})
|
||||
const disabledPay = computed(() => { //是否达到起送价
|
||||
return orderType.value == 'takeout' && (getCartGoodsPrice < parseFloat(store.value.min_price)) ? true :
|
||||
return orderType.value == 'takeout' && (getCartGoodsPrice < parseFloat(store.value.minPrice)) ? true :
|
||||
false
|
||||
})
|
||||
const spread = computed(() => { //差多少元起送
|
||||
if (orderType.value != 'takeout') return
|
||||
return parseFloat((store.value.min_price - getCartGoodsPrice).toFixed(2))
|
||||
return parseFloat((store.value.minPrice - getCartGoodsPrice).toFixed(2))
|
||||
})
|
||||
|
||||
// 监听自定义事件
|
||||
@@ -750,8 +750,8 @@ const toPay = () => {
|
||||
uToast.value.show({message:'本店不支持外卖',type: 'error'});
|
||||
return;
|
||||
}
|
||||
// 判断当前是否在配送范围内
|
||||
if (orderType.value == 'takeout' && store.value.distance < store.value.far) {
|
||||
// 判断当前是否在配送范围内(基于用户定位距离粗略判断,最终以下单时收货地址校验为准)
|
||||
if (orderType.value == 'takeout' && store.value.dis && store.value.distance < (store.value.dis / 1000)) {
|
||||
uToast.value.show({message:'选中的地址不在配送范围',type: 'error'});
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user