import Vue from 'vue'
|
|
import Vuex from 'vuex'
|
|
|
|
Vue.use(Vuex); //vue的插件机制
|
|
|
|
import api from '@/api/api.js'
|
|
import Position from '@/utils/position.js'
|
|
|
|
//Vuex.Store 构造器选项
|
|
const store = new Vuex.Store({
|
|
state: {
|
|
configList: [], //配置列表
|
|
shop : false,
|
|
position : {//定位信息
|
|
latitude : 0,
|
|
longitude : 0,
|
|
},
|
|
userInfo : {},//用户信息
|
|
cartList : [//购物车列表
|
|
{
|
|
id : 1,
|
|
title : '桌布租赁',
|
|
num : 1,
|
|
price : 299,
|
|
unit : '120*40*75【桌子尺寸】',
|
|
},
|
|
{
|
|
id : 2,
|
|
title : '桌布租赁',
|
|
num : 1,
|
|
price : 299,
|
|
unit : '120*40*75【桌子尺寸】',
|
|
},//购物车列表
|
|
],
|
|
banner : {},
|
|
cartCheckboxValue : [],//选中的购物车
|
|
spotList : [],
|
|
},
|
|
getters: {
|
|
// 角色 true为水洗店 false为酒店
|
|
userShop(state){
|
|
return state.shop
|
|
}
|
|
},
|
|
mutations: {
|
|
// 初始化配置
|
|
initConfig(state){
|
|
// api('getConfig', res => {
|
|
// if(res.code == 200){
|
|
// state.configList = res.result
|
|
// }
|
|
// })
|
|
|
|
let config = ['getPrivacyPolicy', 'getUserAgreement']
|
|
config.forEach(k => {
|
|
api(k, res => {
|
|
if (res.code == 200) {
|
|
state.configList[k] = res.result
|
|
}
|
|
})
|
|
})
|
|
},
|
|
getBanner(state){
|
|
|
|
// 0-首页 1-遗产路径 2-我要跟拍 3-非遗体验 4-无忧服务 5申遗历程
|
|
let config = ['path', 'follow', 'experience', 'service', 'course']
|
|
config.forEach((k, i) => {
|
|
api('queryBannerList', {
|
|
bannerCategoryType : i + 1,
|
|
}, res => {
|
|
if(res.code == 200){
|
|
state.banner[k] = res.result
|
|
}
|
|
})
|
|
})
|
|
|
|
},
|
|
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: '登录中...'
|
|
})
|
|
|
|
uni.login({
|
|
success(res) {
|
|
if(res.errMsg != "login:ok"){
|
|
return
|
|
}
|
|
|
|
api('wxLogin', {
|
|
code : res.code,
|
|
latitude : state.position.latitude,
|
|
longitude : state.position.longitude,
|
|
}, res => {
|
|
|
|
uni.hideLoading()
|
|
|
|
if(res.code != 200){
|
|
return
|
|
}
|
|
|
|
state.userInfo = res.result.userInfo
|
|
uni.setStorageSync('token', res.result.token)
|
|
|
|
// if(!state.userInfo.nickName || !state.userInfo.headImage){
|
|
// uni.navigateTo({
|
|
// url: '/pages_order/auth/wxUserInfo'
|
|
// })
|
|
// }else{
|
|
uni.navigateBack(-1)
|
|
// }
|
|
})
|
|
}
|
|
})
|
|
},
|
|
getUserInfo(state){
|
|
api('infoGetInfo', res => {
|
|
if(res.code == 200){
|
|
state.userInfo = res.result
|
|
}
|
|
})
|
|
},
|
|
getPosition(state){
|
|
Position.getLocation(res => {
|
|
state.position = res
|
|
this.commit('calculateDistance')
|
|
})
|
|
},
|
|
|
|
},
|
|
actions: {},
|
|
})
|
|
|
|
export default store
|