liujd 6 سال پیش
والد
کامیت
aad96c996a
3فایلهای تغییر یافته به همراه55 افزوده شده و 24 حذف شده
  1. 1 0
      mobile-code/src/components/app-delivery.vue
  2. 25 12
      mobile-code/src/pages/order/buy.vue
  3. 29 12
      mobile-code/src/utils/common.js

+ 1 - 0
mobile-code/src/components/app-delivery.vue

@@ -191,6 +191,7 @@
 				this.form.receiveFullAddress = e.address
 				this.region.latitude = e.location.lat
 				this.region.longitude = e.location.lng
+				this.$emit('changeAddress', e)
 			},
 			// -----
 			timeTodaySelFn(index) {

+ 25 - 12
mobile-code/src/pages/order/buy.vue

@@ -5,7 +5,7 @@
 		<!-- 配送 -->
 		<form @submit="formSubmit">
 			<block v-if="tabIndex == 0">
-				<app-delivery-module ref="appDelivery" />
+				<app-delivery-module ref="appDelivery" @changeAddress="changeAddress" />
 			</block>
 			<!-- 自取 -->
 			<block v-else>
@@ -24,15 +24,15 @@
 
 			<!-- 商品金额 -->
 			<div class="module-com shop-price-wrap">
-				<div class="module-tit">商品金额</div>
+				<div class="module-tit">商品信息</div>
 				<div class="module-det">
 					<app-list-module v-if="!$util.isEmpty(goodsInfo)" :info="goodsInfo" />
-					<div class="shop-prompt">
+					<div class="shop-prompt" v-if="!$util.isEmpty(this.orderShop)" @click="showAlert = true">
 						<div>
-							<span>运费(6公里)</span>
+							<span>{{ `运费(${this.orderShop.freight.first}公里)` }}</span>
 							<i class="iconfont iconchangjianwentixiangguanwenti2"></i>
 						</div>
-						<div>¥{{ goodsInfo.price }}</div>
+						<div>¥{{ freightPrice }}</div>
 					</div>
 					<div class="shop-prompt">
 						<div>总计</div>
@@ -70,13 +70,13 @@
 		</form>
 		<!-- 弹窗 -->
 		<alert-module :show="showAlert" @click="hideAlert" @cancel="hideAlert">
-			<div class="alt-content">
-				<div>5公里内免运费</div>
+			<div class="alt-content" v-if="!$util.isEmpty(this.orderShop)">
+				<div>{{ `${this.orderShop.freight.first}公里内免运费` }}</div>
 				<div>
 					<span>超过</span>
-					<span class="app-price">5公里</span>
+					<span class="app-price">{{ `${this.orderShop.freight.first}公里` }}</span>
 					<span>每增加1公里</span>
-					<span class="app-price">+2元</span>
+					<span class="app-price">{{ `+${this.orderShop.freight.add}元` }}</span>
 				</div>
 			</div>
 		</alert-module>
@@ -93,6 +93,7 @@
 	import AppCouponSel from '@/components/app-coupon-sel'
 	import AlertModule from '@/components/plugin/alert'
 	const form = require('@/utils/formValidation.js')
+	import { calcDistance } from '@/utils/common'
 	// api
 	import { getShopUser } from '@/utils/auth'
 	import { getOrderShop } from '@/utils/config'
@@ -137,7 +138,9 @@
 				mentionForm: {
 					bookMobile: ''
 				},
-				discountArr: false
+				discountArr: false,
+				// 运费
+				freightPrice: 0
 			}
 		},
 		computed: {
@@ -145,13 +148,13 @@
 			...mapGetters({ shopUser: 'getShopUser' }),
 			// 计算总金额
 			totalPrice() {
-				let totalPrice = this.goodsInfo.price * this.option.goodsNum
+				let totalPrice = this.goodsInfo.price * this.option.goodsNum - freightPrice
 				console.log('this.shopUser', this.shopUser)
 				// let discountMember = this.$util.isEmpty(this.shopUser) ? this.shopUser.userAsset.discount * totalPrice : 1 * totalPrice
 				// discountMember = discountMember / 10
 				// return discountMember.toFixed(2)
 				return totalPrice.toFixed(2)
-			}
+			},
 		},
 		onLoad(option) {
 			// this.init()
@@ -173,6 +176,11 @@
 					this.$refs.couponSel._getUserDiscount().then(status => {
 						this.discountArr = status
 					})
+					
+					if (!this.$util.isEmpty(this.$refs.appDelivery.region) && this.$refs.appDelivery.region.latitude) {
+						// 计算距离价格
+						this.freightPrice = calcDistance(this.orderShop.shop, this.$refs.appDelivery.region, this.orderShop.freight)
+					}
 				})
 				getShopUser()
 				goodsInfo.buyNum = this.option.goodsNum
@@ -222,6 +230,11 @@
 			anonymityChange(e) {
 				this.form.anonymity = this.form.anonymity == 1 ? 0 : 1
 			},
+			// 选择地址
+			changeAddress() {
+				// 计算距离价格
+				this.freightPrice = calcDistance(this.orderShop.shop, this.$refs.appDelivery.region, this.orderShop.freight)
+			},
 			// 表单验证
 			formSubmit(e) {
 				console.log(e)

+ 29 - 12
mobile-code/src/utils/common.js

@@ -279,22 +279,39 @@ export function verifiPhone(phone) {
 
 /** *
  * 获取位置距离
- * data 经纬度数据信息
+ * form 开始经纬度数据信息
+ * to 结束经纬度数据信息
+ * rule 运费规则
+ * onlyDistance 是否只需要距离值
  */
-export function calcDistance(data) {
-	let userRegions = uni.getStorageSync('userRegion')
-	if (!userRegions || !data) {
+export function calcDistance(form = null, to = null, rule = {}, onlyDistance = false) {
+	console.log('我开始计算运费了', freight)
+	console.log('form', form)
+	console.log('to', to)
+	console.log('rule', rule)
+	if (!form || !to) {
 		return
 	}
-	userRegions = JSON.parse(userRegions)
-	if (userRegions && data.lat && data.lng) {
+	if (form && to.lat && to.lng) {
 		// eslint-disable-next-line one-var
-		const lat1 = data.lat * 1,
-			lng1 = data.lng * 1,
-			lat2 = parseFloat(userRegions.postion.lat),
-			lng2 = parseFloat(userRegions.postion.lng)
-
-		return parseInt(calcDistanceFn(lat1, lng1, lat2, lng2))
+		let lat1 = to.lat || to.latitude,
+			lng1 = to.lng || to.longitude,
+			lat2 = form.lat || form.latitude,
+			lng2 = form.lng || form.longitude
+
+		lat1 = lat1 * 1
+		lng1 = lng1 * 1
+		lat2 = parseFloat(lat2)
+		lng2 = parseFloat(lng2)
+
+		let distance = parseInt(calcDistanceFn(lat1, lng1, lat2, lng2))
+		// 只需要返回距离的时候
+		if (onlyDistance) {
+			return distance
+		}
+		// 需要返回具体金额
+		let freight = (distance - rule.first) * rule.add
+		return freight
 	}
 }
 // 计算距离 公用方法