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

62 lines
1.5 KiB

  1. import { mapState } from 'vuex'
  2. import { calculateDistance } from '@/utils/position'
  3. export default {
  4. data() {
  5. return {
  6. }
  7. },
  8. computed: {
  9. ...mapState(['position']),
  10. },
  11. methods: {
  12. calculateDistance,
  13. calculateDistanceAddress(teacherAddress) {
  14. if (!teacherAddress ||
  15. teacherAddress.length == 0 ||
  16. !this.position ||
  17. !this.position.latitude ||
  18. !this.position.longitude) {
  19. return 0
  20. }
  21. let minDistance = 0
  22. teacherAddress.forEach((item, index) => {
  23. let distance = calculateDistance(
  24. this.position.latitude,
  25. this.position.longitude,
  26. item.latitude,
  27. item.longitude,
  28. )
  29. if(index == 0){
  30. minDistance = distance
  31. }
  32. minDistance = Math.min(minDistance, distance)
  33. })
  34. return minDistance
  35. },
  36. calculateDistanceAddressList(teacherAddress){
  37. if (!teacherAddress ||
  38. teacherAddress.length == 0 ||
  39. !this.position ||
  40. !this.position.latitude ||
  41. !this.position.longitude) {
  42. return 0
  43. }
  44. teacherAddress.forEach((item, index) => {
  45. item.distance = calculateDistance(
  46. this.position.latitude,
  47. this.position.longitude,
  48. item.latitude,
  49. item.longitude,
  50. )
  51. })
  52. return teacherAddress.sort((a, b) => a.distance - b.distance)
  53. },
  54. }
  55. }