|
|
@@ -16,7 +16,12 @@ Page({ |
|
|
|
mallTenantId: '', |
|
|
|
imId: "", |
|
|
|
goodId: "", |
|
|
|
IMorderId: "" |
|
|
|
IMorderId: "", |
|
|
|
merchantId: "", |
|
|
|
currentIndex: "", |
|
|
|
mallList: [], |
|
|
|
latitude: "", |
|
|
|
longitude: "" |
|
|
|
}, |
|
|
|
onLoad: function (options) { |
|
|
|
console.log(options, 'options!!!!!!!'); |
|
|
@@ -32,6 +37,8 @@ Page({ |
|
|
|
} |
|
|
|
console.log(this.data.mallTenantId, 'mallTenantId'); |
|
|
|
|
|
|
|
this.getCouponMerchant(options.merOrderId) |
|
|
|
|
|
|
|
tt.showLoading({ |
|
|
|
title: "加载中..." |
|
|
|
}); |
|
|
@@ -54,12 +61,22 @@ Page({ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
imCallback(e) { |
|
|
|
console.log("跳转IM客服成功", e); |
|
|
|
}, |
|
|
|
|
|
|
|
setMerchant(e) { |
|
|
|
console.log(e.detail.value, 'e'); |
|
|
|
const index = e.detail.value |
|
|
|
this.setData({ |
|
|
|
currentIndex: index, |
|
|
|
merchantId: this.data.mallList[index].id |
|
|
|
}) |
|
|
|
console.log(this.data.currentIndex, this.data.merchantId); |
|
|
|
}, |
|
|
|
|
|
|
|
onimError(e) { |
|
|
|
console.log("拉起IM客服失败", e.detail); |
|
|
|
}, |
|
|
@@ -85,7 +102,7 @@ Page({ |
|
|
|
} |
|
|
|
}).then(res => { |
|
|
|
console.log(res, 'getIm'); |
|
|
|
const imId = res.data.imId || '' |
|
|
|
const imId = res.data.imId ? res.data.imId : "" |
|
|
|
that.setData({ |
|
|
|
imId: imId |
|
|
|
}) |
|
|
@@ -94,6 +111,167 @@ Page({ |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
getCouponMerchant(couponChannelId) { //获取适用门店 |
|
|
|
const that = this |
|
|
|
Http.get({ |
|
|
|
url: config.api.couponMerchant, |
|
|
|
data: { |
|
|
|
couponChannelId, |
|
|
|
mallTenantId: that.data.mallTenantId || '' |
|
|
|
} |
|
|
|
}).then(res => { |
|
|
|
const keys = Object.keys(res.data) |
|
|
|
const mallList = [] |
|
|
|
let i = 0 |
|
|
|
keys.forEach(item => { |
|
|
|
const arr = item.split('|') |
|
|
|
const obj = { |
|
|
|
tenantId: arr[0], |
|
|
|
mallName: arr[1], |
|
|
|
merchantVoList: res.data[item], |
|
|
|
expand: false |
|
|
|
} |
|
|
|
if (i == 0) { |
|
|
|
obj.expand = true |
|
|
|
} |
|
|
|
mallList.push(obj) |
|
|
|
i++ |
|
|
|
}) |
|
|
|
that.setData({ |
|
|
|
mallList: mallList[0].merchantVoList |
|
|
|
}) |
|
|
|
console.log(that.data.mallList, 'mallList'); |
|
|
|
that.getLocation() |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 获得经纬度 |
|
|
|
*/ |
|
|
|
getLocation() { |
|
|
|
console.log('getLocation'); |
|
|
|
let that = this; |
|
|
|
tt.getLocation({ |
|
|
|
type: "wgs84", |
|
|
|
// isHighAccuracy: true, |
|
|
|
success: function (res) { |
|
|
|
console.log(res, 'getLocation') |
|
|
|
that.setData({ |
|
|
|
latitude: res.latitude, |
|
|
|
longitude: res.longitude, |
|
|
|
}) |
|
|
|
const latitudeNow = res.latitude |
|
|
|
const longitudeNow = res.longitude |
|
|
|
|
|
|
|
const mallLocationArr = [] |
|
|
|
const mallList = that.data.mallList |
|
|
|
mallList.forEach((item, index) => { |
|
|
|
const obj = { |
|
|
|
latitude: item.latitude || false, |
|
|
|
longitude: item.longitude || false, |
|
|
|
id: item.id, |
|
|
|
index: index |
|
|
|
} |
|
|
|
mallLocationArr.push(obj) |
|
|
|
}) |
|
|
|
console.log(mallLocationArr, 'mallLocationArr'); |
|
|
|
|
|
|
|
const tempArr = mallList |
|
|
|
const bloobArr = [] |
|
|
|
|
|
|
|
mallLocationArr.forEach((item, index) => { |
|
|
|
const distanceData = that.getDistances(latitudeNow, longitudeNow, item.latitude, item.longitude) |
|
|
|
tempArr[index].distance_str = distanceData.distance_str |
|
|
|
tempArr[index].distanceName = tempArr[index].merchantName + ' ' + distanceData.distance_str |
|
|
|
tempArr[index].distance = distanceData.distance |
|
|
|
bloobArr.push(tempArr[index]) |
|
|
|
}) |
|
|
|
|
|
|
|
const finalSortMallList = that.bloob(bloobArr) |
|
|
|
console.log(finalSortMallList, 'finalSortMallList'); |
|
|
|
that.setData({ |
|
|
|
mallList: finalSortMallList |
|
|
|
}) |
|
|
|
}, |
|
|
|
// 拒绝提供定位权限 |
|
|
|
fail: error => { |
|
|
|
console.log(error, 'error'); |
|
|
|
const mallList = that.data.mallList |
|
|
|
mallList.forEach(item => { |
|
|
|
item.distanceName = item.merchantName |
|
|
|
}) |
|
|
|
|
|
|
|
that.setData({ |
|
|
|
mallList |
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
complete: finish => { |
|
|
|
|
|
|
|
} |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* @description:根据经纬度计算距离 |
|
|
|
* @param {*} locationInfo (lat1, lng1, lat2, lng2) |
|
|
|
* @return: distanceObj: { distance , distance_str } |
|
|
|
*/ |
|
|
|
getDistances(lat1, lng1, lat2, lng2) { |
|
|
|
|
|
|
|
if (lat2 || lng2) { |
|
|
|
function rad(num) { |
|
|
|
return num * Math.PI / 180.0; |
|
|
|
} |
|
|
|
var radLat1 = rad(lat1); |
|
|
|
var radLat2 = rad(lat2); |
|
|
|
var a = radLat1 - radLat2; |
|
|
|
var b = rad(lng1) - rad(lng2); |
|
|
|
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; |
|
|
|
|
|
|
|
var distance = s; |
|
|
|
var distance_str = ""; |
|
|
|
|
|
|
|
if (parseInt(distance) >= 1) { |
|
|
|
distance_str = distance.toFixed(2) + "km"; |
|
|
|
} else if (!arseInt(distance)) { |
|
|
|
return false |
|
|
|
} else { |
|
|
|
distance_str = (distance * 1000).toFixed(2) + "m"; |
|
|
|
} |
|
|
|
|
|
|
|
let objData = { |
|
|
|
distance: distance, |
|
|
|
distance_str: distance_str |
|
|
|
} |
|
|
|
return objData |
|
|
|
} else { |
|
|
|
let objData = { |
|
|
|
distance: Infinity, |
|
|
|
distance_str: '' |
|
|
|
} |
|
|
|
return objData |
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
bloob(arr) { |
|
|
|
const tempArr = arr |
|
|
|
for (let i = 0; i < tempArr.length - 1; i++) { |
|
|
|
for (let j = 0; j < tempArr.length - 1 - i; j++) { |
|
|
|
if (tempArr[j].distance > tempArr[j + 1].distance) { |
|
|
|
let temp = tempArr[j]; |
|
|
|
tempArr[j] = tempArr[j + 1]; |
|
|
|
tempArr[j + 1] = temp; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return tempArr |
|
|
|
}, |
|
|
|
|
|
|
|
getSupId(id) { |
|
|
|
Http.get({ |
|
|
|
url: config.api.getSpuid, |
|
|
@@ -461,6 +639,13 @@ Page({ |
|
|
|
*/ |
|
|
|
orderFunc(discount) { |
|
|
|
if (this.data.showbutton) return; |
|
|
|
if (!this.data.merchantId) { |
|
|
|
tt.showToast({ |
|
|
|
title: '请选择可用商户!', |
|
|
|
icon: 'fail' |
|
|
|
}); |
|
|
|
return |
|
|
|
}; |
|
|
|
|
|
|
|
let that = this; |
|
|
|
tt.showLoading({ |
|
|
@@ -527,6 +712,9 @@ Page({ |
|
|
|
} else { |
|
|
|
url = config.api.orderSave |
|
|
|
data.mallTenantId = that.data.mallTenantId || '' |
|
|
|
if (that.data.data.type == 69) { |
|
|
|
data.fixMerchantId = that.data.merchantId |
|
|
|
} |
|
|
|
} |
|
|
|
/** |
|
|
|
* orderSave 下单 |
|
|
|