|
|
@ -34,6 +34,7 @@ const store = new Vuex.Store({ |
|
|
|
], |
|
|
|
banner : {}, |
|
|
|
cartCheckboxValue : [],//选中的购物车
|
|
|
|
spotList : [], |
|
|
|
}, |
|
|
|
getters: { |
|
|
|
// 角色 true为水洗店 false为酒店
|
|
|
@ -74,6 +75,51 @@ const store = new Vuex.Store({ |
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
getSpotList(state){ |
|
|
|
api('querySpotList', { |
|
|
|
pageNo : 1, |
|
|
|
pageSize : 999999999, |
|
|
|
}, res => { |
|
|
|
if(res.code == 200){ |
|
|
|
|
|
|
|
let spot = [] |
|
|
|
|
|
|
|
res.result.records.forEach(n => { |
|
|
|
if(n.spotLatitude && n.spotLongitude){ |
|
|
|
spot.push(n) |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
Position.calculateDistance() |
|
|
|
|
|
|
|
state.spotList = spot |
|
|
|
|
|
|
|
this.commit('calculateDistance') |
|
|
|
} |
|
|
|
}) |
|
|
|
}, |
|
|
|
// 计算地点与自己的距离
|
|
|
|
calculateDistance(state){ |
|
|
|
if(state.spotList.length && state.position.latitude){ |
|
|
|
|
|
|
|
state.spotList.forEach(n => { |
|
|
|
n.distance = parseFloat(Position.calculateDistance( |
|
|
|
state.position.latitude, |
|
|
|
state.position.longitude, |
|
|
|
n.spotLatitude, |
|
|
|
n.spotLongitude, |
|
|
|
3 |
|
|
|
)) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
// 排序,最近的在前面
|
|
|
|
state.spotList.sort((a, b) => a.distance - b.distance) |
|
|
|
|
|
|
|
console.log(state.spotList); |
|
|
|
|
|
|
|
} |
|
|
|
}, |
|
|
|
login(state){ |
|
|
|
uni.showLoading({ |
|
|
|
title: '登录中...' |
|
|
@ -120,10 +166,11 @@ const store = new Vuex.Store({ |
|
|
|
}, |
|
|
|
getPosition(state){ |
|
|
|
Position.getLocation(res => { |
|
|
|
console.log(res); |
|
|
|
state.position = res |
|
|
|
this.commit('calculateDistance') |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
actions: {}, |
|
|
|
}) |
|
|
|