HolyKnightIX 1 рік тому
джерело
коміт
af9f736da3
3 змінених файлів з 167 додано та 10 видалено
  1. +146
    -1
      package2/pages/appointment/appointment.js
  2. +13
    -9
      package2/pages/appointment/appointment.ttml
  3. +8
    -0
      package2/pages/appointment/appointment.ttss

+ 146
- 1
package2/pages/appointment/appointment.js Переглянути файл

@@ -21,7 +21,9 @@ Page({
merchantId: "",
currentIndex: "",
status: "",
isShowBtns: false
isShowBtns: false,
latitude: "",
longitude: ""
},
onLoad(options) {
console.log(options, 'options')
@@ -36,12 +38,33 @@ Page({

console.log(finalStartTime, 'finalStartTime');

// const mallList = [{
// merchantName: "1家帮汇家政保洁(河池市庆远镇)",
// latitude: 50.277748,
// longitude: 119.996078,
// id: 1
// }, {
// merchantName: "2家帮汇家政保洁(河池市庆远镇)",
// latitude: 35.277748,
// longitude: 119.996078,
// id: 2
// }, {
// merchantName: "3家帮汇家政保洁(河池市庆远镇)",
// id: 3
// }, {
// merchantName: "4家帮汇家政保洁(河池市庆远镇)",
// latitude: 45.277748,
// longitude: 119.996078,
// id: 4
// }]

this.setData({
id: options.id || '',
orderId: options.orderId || '',
startTime: finalStartTime,
endTime: options.endTime || '',
mallList: JSON.parse(options.mallList)[0].merchantVoList || '',
// mallList
})

console.log(this.data.mallList, 'mallList');
@@ -72,6 +95,64 @@ Page({
console.log(this.data.currentIndex, this.data.merchantId);
},

/**
* 获得经纬度
*/
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 => {

},
complete: finish => {

}
})
},

chooseAddress() {
if (!this.data.isShowBtns) return
let that = this;
@@ -280,5 +361,69 @@ Page({
}).catch(err => {
console.log(err, 'getOrderReservationDetail');
})
},

/**
* @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
},

onShow() {
this.getLocation()
}
})

+ 13
- 9
package2/pages/appointment/appointment.ttml Переглянути файл

@@ -32,20 +32,24 @@
</picker>
</view>

<view class="datePickerFlex">
<view>选择可用商户:</view>
<picker mode="selector" value="{{index}}" range="{{mallList}}" range-key="merchantName" disabled="{{false}}"
bindchange="setMerchant">
<view tt:if="{{ !merchantId }}" class="picker">
<view tt:if="{{ !merchantId }}" class="addressPickerFlex">
<text>选择可用商户:</text>
<picker style="display: inline-block;" mode="selector" value="{{index}}" range="{{mallList}}"
range-key="distanceName" disabled="{{false}}" bindchange="setMerchant">
<view class="pickerInside">
请选择
</view>

<view tt:if="{{ merchantId }}" class="picker">
{{ mallList[currentIndex].merchantName }}
</view>
</picker>
</view>

<view tt:if="{{ merchantId }}" class="addressPicker">
<picker style="display: inline;" mode="selector" value="{{index}}" range="{{mallList}}" range-key="distanceName"
disabled="{{false}}" bindchange="setMerchant">
<text> 选择可用商户:<text class="pickerInside">{{ mallList[currentIndex].merchantName }} <text
class="distanceFoot">{{ mallList[currentIndex].distance_str }}</text></text></text>
</picker><!-- -->
</view>

<view class="textarea">
<textarea class="describe" placeholder="备注:说点什么吧" disabled="{{ !isShowBtns }}" bindinput="describing"
value="{{ describeStr }}"></textarea>


+ 8
- 0
package2/pages/appointment/appointment.ttss Переглянути файл

@@ -30,6 +30,14 @@ page {
margin: 35rpx auto;
}

.pickerInside {
color: #8a8a8a;
}

.distanceFoot {
font-size: 25rpx;
color: #3c89ff;
}

.datePicker {
background-color: #fff;


Завантаження…
Відмінити
Зберегти