index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import * as API from '@/apis/route.js'
  2. import * as WxJsApi from '@/utils/wxJsApi.js'
  3. import Carmap from '@/components/Carmap.vue'
  4. export default {
  5. data() {
  6. return {
  7. initBl: false,
  8. title: '乘车人',
  9. show: false,
  10. id: 0, // 使用 marker点击事件 需要填写id
  11. //地图居中后的位置
  12. longitude: 112.276527,
  13. latitude: 30.306427,
  14. shiftInfo: {
  15. },
  16. list: [{}, {}],
  17. stationList: [],
  18. //个人
  19. info: {
  20. obj: null,
  21. init: false,
  22. longitude: '',
  23. latitude: '',
  24. },
  25. myinterval: '',
  26. routeInfo:{}
  27. }
  28. },
  29. components: {
  30. Carmap
  31. },
  32. methods: {
  33. downBtn(item) {
  34. this.$refs.amap.setCenter(item);
  35. },
  36. drawing(point, startend) {
  37. if (this.$refs.amap) {
  38. this.$refs.amap.initMap(point, this.stationList,startend);
  39. }
  40. },
  41. reverse(){
  42. this.stationList.reverse();
  43. this.$refs.amap.setStartend(this.stationList);
  44. },
  45. getPassengerInfo() {
  46. this.$refs.common.showLoading()
  47. API.routeDetail(this.id).then((response) => {
  48. this.stationList=response.data.stationInfoList;
  49. this.$refs.common.showLoading(false)
  50. var point = [];
  51. this.routeInfo=response.data.routeInfo;
  52. this.title=this.routeInfo.name;
  53. response.data.routeInfo.mapPath.split("|").forEach((item) => {
  54. var sz = item.split(",");
  55. point.push({
  56. longitude: sz[0],
  57. latitude: sz[1],
  58. })
  59. })
  60. var startend = [{
  61. longitude: this.stationList[0].longitude,
  62. latitude: this.stationList[0].latitude,
  63. name: this.stationList[0].name
  64. }, {
  65. longitude: this.stationList[this.stationList.length-1].longitude,
  66. latitude: this.stationList[this.stationList.length-1].latitude,
  67. name: this.stationList[this.stationList.length-1].name
  68. }];
  69. this.drawing(point,startend);
  70. this.$refs.common.showLoading(false)
  71. this.getPoint()
  72. }).catch(error => {
  73. this.$refs.common.showLoading(false,error)
  74. })
  75. },
  76. getPoint() {
  77. if (!this.info.init) {
  78. WxJsApi.getWxConfig(['getLocation']).then(() => {
  79. // this.$refs.common.showLoading(false)
  80. this.getLocation()
  81. });
  82. }else{
  83. this.getLocation()
  84. }
  85. var pages = getCurrentPages();
  86. var page = (pages[pages.length - 1]).route;
  87. if (page == "pages/route/index") {
  88. setTimeout(this.getPoint, 10000);
  89. }
  90. },
  91. getLocation(){
  92. WxJsApi.getLocation().then((res) => {
  93. console.log("----getLocation ok-----")
  94. var latitude = parseFloat(res.latitude);
  95. var longitude = parseFloat(res.longitude);
  96. if (!this.info.init) {
  97. this.latitude = latitude;
  98. this.longitude = longitude;
  99. }
  100. this.info.init = true
  101. this.info.latitude = latitude;
  102. this.info.longitude = longitude;
  103. this.$refs.amap.setPerson(this.info);
  104. }).catch(error => {
  105. console.log(error)
  106. })
  107. }
  108. },
  109. onLoad(op) {
  110. this.id = op.id
  111. },
  112. onUnload() {
  113. if (this.myinterval) {
  114. clearInterval(this.myinterval)
  115. }
  116. },
  117. onReady() {
  118. this.getPassengerInfo()
  119. }
  120. }