Browse Source

目的地出发地/计算到店距离

master
石可 4 years ago
parent
commit
44100d7a97
  1. 2
      common/api.js
  2. 15
      package-lock.json
  3. 86
      pages/goodsDetail/index.vue

2
common/api.js

@ -1,5 +1,5 @@
// appId: 正式 null | 测试 wxeb58570b5e04d147
export const DEV = "prod"; // dev 测试 | prod 正式
export const DEV = "dev"; // dev 测试 | prod 正式
export const VERSION = '1.0.0'; // 版本号
export const DEVURL = 'https://yytx.eugyl.com'; // 测试服请求地址
// export const DEVURL = 'http://hainan.com'; // 测试服请求地址

15
package-lock.json

@ -1,6 +1,19 @@
{
"name": "uniapp-hainan",
"lockfileVersion": 2,
"requires": true,
"lockfileVersion": 1,
"packages": {
"": {
"dependencies": {
"tki-qrcode": "^0.1.6"
}
},
"node_modules/tki-qrcode": {
"version": "0.1.6",
"resolved": "https://registry.npmjs.org/tki-qrcode/-/tki-qrcode-0.1.6.tgz",
"integrity": "sha512-EnnlS8psowC7PsW3MDYcxvJYkuklX3WAZ/BYanR4TdBHTu74GfjTBX8Y16REP+AeDENiVtBPh4jtTRL2P736hQ=="
}
},
"dependencies": {
"tki-qrcode": {
"version": "0.1.6",

86
pages/goodsDetail/index.vue

@ -40,6 +40,20 @@
<text class="lf-iconfont lf-icon-xiangyou lf-text-vertical"></text>
</view>
</view>
<view v-if="goods_detail.product.type == 0">
<view class="lf-row-between list-item lf-m-t-20">
<view class="lf-row-center">
<text class="lf-font-28 lf-color-gray">出发地</text>
<text class="lf-text-vertical lf-m-l-40 lf-font-28 lf-color-black">{{goods_detail.product.extends.field_0_departure_place}}</text>
</view>
</view>
<view class="lf-row-between list-item">
<view class="lf-row-center">
<text class="lf-font-28 lf-color-gray">目的地</text>
<text class="lf-text-vertical lf-m-l-40 lf-font-28 lf-color-black">{{goods_detail.product.extends.field_0_destination}}</text>
</view>
</view>
</view>
<!-- 景区类型 -->
<view v-if="goods_detail.product.extends && goods_detail.product && goods_detail.product.type == 2">
<view class="goods-detail"
@ -50,7 +64,10 @@
<view class="lf-row-between">
<view class="lf-line-2 lf-font-28 lf-color-333">
{{goods_detail.product.extends.field_2_address}}</view>
<view class="lf-iconfont lf-icon-dizhi lf-color-blue"></view>
<view class="lf-flex-column lf-row-center">
<view class="lf-iconfont lf-icon-dizhi lf-color-blue"></view>
<view class="lf-font-24 lf-color-222 lf-m-t-10" v-if="$isRight(shop_distance)">距您{{shop_distance}}</view>
</view>
</view>
</view>
<view class="goods-detail" v-if="goods_detail.product.extends.field_2_open_time">
@ -514,7 +531,8 @@
//uview picker
show: false,
hotel_show_range: false,
hotel_show_single: false
hotel_show_single: false,
shop_distance: 0
}
},
onLoad(options) {
@ -531,6 +549,56 @@
}
},
methods: {
getGoodsDetail() {
this.$http(this.API.API_ADVICEDETAILS, {
id: this.goods_id
}).then(res => {
this.skeletonLoading = false;
this.goods_detail = res.data;
if(this.goods_detail) {
this.getShopDistance();
}
this.is_collect = Boolean(res.data.is_collect) || false;
}).catch(err => {
this.skeletonLoading = false;
setTimeout(() => {
this.$toBack();
}, 1000);
})
},
//
getShopDistance() {
let that = this;
wx.getLocation({
type: 'wgs84',
isHighAccuracy: true,
success (res) {
const self_latitude = res.latitude
const self_longitude = res.longitude
console.log('当前经纬度',self_latitude,self_longitude,res);
if(that.$isRight(that.goods_detail.product.extends)) {
const shop_latitude = that.goods_detail.product.extends.field_2_latitude;
const shop_longitude = that.goods_detail.product.extends.field_2_longitude;
console.log('商家经纬度',shop_latitude,shop_longitude);
//
var radLat1 = self_latitude* Math.PI / 180.0;
var radLat2 = shop_latitude* Math.PI / 180.0;
var a = radLat1 - radLat2;
var b = (self_longitude* Math.PI / 180.0) - (shop_longitude* Math.PI / 180.0);
var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
s = s * 6378.137;//
s = Math.round(s * 10000) / 10000;
s = s.toFixed(2) + 'km' //
that.shop_distance = s
console.log('经纬度计算的距离:' + s)
}
},
fail(err) {
console.log(err)
}
})
},
valChange(e) {
this.buy_num = e.value;
},
@ -667,20 +735,6 @@
name: address
});
},
getGoodsDetail() {
this.$http(this.API.API_ADVICEDETAILS, {
id: this.goods_id
}).then(res => {
this.skeletonLoading = false;
this.goods_detail = res.data;
this.is_collect = Boolean(res.data.is_collect) || false;
}).catch(err => {
this.skeletonLoading = false;
setTimeout(() => {
this.$toBack();
}, 1000);
})
},
//
switchCollect() {
let userInfo = uni.getStorageSync('userinfo') || {};

Loading…
Cancel
Save