You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
4.2 KiB
JavaScript

import {
defineStore
} from 'pinia'
import {
ref
} from 'vue'
//自己写的假数据待删除
// import preferential from '/static/jiashuju/one.json'
import {
getRecharge,
getSecond,
getNetwork,
getBranchInformation
} from '../../api/api.js'
export const youhui = defineStore('youhui', () => {
//自己写的假数据待删除
// const preferentials = ref({})
//用来存储获取的余额选项的索引
const showactive = ref(0)
//用来存储获取的次卡选项的索引
const showactives = ref(10000)
//存储余额选项优惠
const recharges = ref([])
//存储次卡选项优惠
const seconds = ref([])
//存储选择后的套餐价格
const activeRecharges = ref('请选择')
//存储网点列表
const netWorkList = ref([])
// 网点详细信息
const BranchInformationList = ref([])
//存储选择的网点名称信息
const wangdianName = ref('请选择网点')
// const getpreferentials = () => {
// //假数据测试待删除
// preferentials.value = preferential
// }
//获取当前选择的余额优惠选项卡添加样式并避免与次卡选项的样式冲突
const getactive = (index) => {
showactives.value = 10000
showactive.value = index
// console.log(showactive.value);
console.log(recharges.value[showactive.value]);
activeRecharges.value = recharges.value[index]
}
//获取当前选择的次卡优惠选项卡添加样式并避免与余额选项的样式冲突
const getactives = (index) => {
showactive.value = 10000
showactives.value = index
console.log(seconds.value[index]);
activeRecharges.value = seconds.value[index]
}
//获取所有余额优惠选项卡
const getRecharges = (data) => {
getRecharge({
networkId: data
}).then((res => {
recharges.value = res.data
/*根据权重weight排序*/
recharges.value.sort((a,b)=>(a.weight-b.weight))
console.log(recharges.value);
// setShowactive()
showactive.value=0
showactives.value=10000
}))
}
//获取所有次卡选项卡
const getSeconds = (data) => {
getSecond({
networkId: data
}).then((res) => {
seconds.value = res.data
/*根据权重weight排序*/
seconds.value.sort((a,b)=>(a.weight-b.weight))
console.log(seconds.value);
showactive.value=0
showactives.value=10000
})
}
//获取选择的网点名称为避免报错延迟1秒获取选择的优惠卡选项
const setShowactive = (name) => {
wangdianName.value =name
setTimeout(() => {
activeRecharges.value = recharges.value[0]
console.log(activeRecharges.value);
}, 1000)
}
//获取网点列表
const getNetworks = () => {
getNetwork().then((res) => {
netWorkList.value = res
if(uni.getStorageSync('longitude')&&uni.getStorageSync('latitude')){
getlist()
}
})
}
//获取网点详情
const getBranchInformations = (data) => {
getBranchInformation(data).then((res) => {
BranchInformationList.value = res
console.log(res);
})
}
const getDistanceFromLatLonInKm = (lat1, lon1, lat2, lon2) => {
var R = 6374
var dLat = deg2rad(lat2 - lat1);
var dLon = deg2rad(lon2 - lon1);
var a =
Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
Math.sin(dLon / 2) * Math.sin(dLon / 2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
var distance = R * c; // 距离,单位为千米
return distance;
}
const deg2rad = (deg) => {
return deg * (Math.PI / 180);
}
//获取目的地距离自己的位置有多远单位km
const getlist = () => {
// listdata.value = two.xichedian
if (uni.getStorageSync('longitude') && uni.getStorageSync('latitude')) {
console.log(1);
netWorkList.value.forEach((e, index) => {
console.log(1);
return e.gongli = getDistanceFromLatLonInKm(e.latitude, e.longitude, uni
.getStorageSync('latitude'), uni.getStorageSync('longitude'))
.toFixed(2)
})
netWorkList.value.sort((a, b) => {
return a.gongli - b.gongli
})
}
}
return {
// preferentials,
// getpreferentials,
getactive,
getactives,
showactive,
showactives,
recharges,
getRecharges,
seconds,
getSeconds,
activeRecharges,
setShowactive,
getBranchInformations,
getNetworks,
BranchInformationList,
netWorkList,
wangdianName
}
})