my_riding.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. var app = getApp();
  2. const util = require('../../utils/utils.js');
  3. Page({
  4. data: {
  5. windowHeight:'',
  6. height:'',
  7. order:'',
  8. date:[],
  9. markers:[],
  10. polyline:[],
  11. latitude:'',
  12. longitude:'',
  13. url:'',
  14. index:''
  15. },
  16. onLoad: function (options) {
  17. var that = this;
  18. console.log(options)
  19. wx.getSystemInfo({
  20. success: function (res) {
  21. console.log(res.windowHeight);
  22. that.setData({ windowHeight: res.windowHeight})
  23. }
  24. })
  25. this.setData({order:options.order})
  26. if(options.index){
  27. if (options.index == 0) {
  28. that.setData({
  29. url : '/order?order_no='
  30. })
  31. }
  32. if (options.index == 1) {
  33. that.setData({
  34. url : '/rent/order?no='
  35. })
  36. }
  37. this.setData({index:options.index})
  38. }
  39. if(options.index){
  40. if (options.index == 'true') {
  41. that.setData({
  42. url : '/order?order_no='
  43. })
  44. this.setData({index:0})
  45. }
  46. if (options.index == 'false') {
  47. that.setData({
  48. url : '/rent/order?no='
  49. })
  50. this.setData({index:1})
  51. }
  52. }
  53. var query = wx.createSelectorQuery();
  54. query.select('.box').boundingClientRect();
  55. query.exec(function (res) {
  56. console.log(res)
  57. console.log(res[0].height)
  58. that.setData({ height: res[0].height });
  59. })
  60. wx.getLocation({
  61. type:'gcj02',
  62. success: function(res) {
  63. var latitude = res.latitude
  64. var longitude = res.longitude
  65. that.setData({ longitude: longitude, latitude: latitude })
  66. },
  67. })
  68. // this.load();
  69. this.getTrack(); //获取行车轨迹及订单信息
  70. },
  71. // 获取行车轨迹及订单信息
  72. getTrack(){
  73. var that = this;
  74. wx.showLoading({
  75. title: '加载中...',
  76. })
  77. console.log(that.data.url)
  78. app.request(that.data.url + that.data.order+'&include=locations','','GET').then(res=>{
  79. console.log(res)
  80. if(res.statusCode == 200){
  81. wx.hideLoading()
  82. that.setData({ date: res.data });
  83. let points = res.data.locations.data;
  84. var center = parseInt(points.length/2)
  85. var obj = {};
  86. obj.points = points;
  87. obj.width = 4;
  88. obj.color = '#18D5B9';
  89. obj.borderWidth = 3;
  90. obj.borderColor = '#18D5B9';
  91. that.setData({ polyline: that.data.polyline.concat(obj) })
  92. if (points.length>0){
  93. var maker = [];
  94. maker = maker.concat(points[0]);
  95. maker = maker.concat(points[points.length - 1])
  96. for (var i = 0; i < maker.length; i++) {
  97. maker[i].width = 32;
  98. maker[i].height = 32;
  99. maker[i].zIndex = 1111;
  100. }
  101. //在地图上显示两个坐标
  102. maker[0].iconPath = 'http://resource.weilaigo.l4j.cn/start1.png'
  103. maker[1].iconPath = 'http://resource.weilaigo.l4j.cn/end1.png'
  104. that.setData({ markers: maker, longitude: points[center].longitude, latitude: points[center].latitude })
  105. } else {
  106. wx.getLocation({
  107. type: 'gcj02',
  108. success: function (res) {
  109. var latitude = res.latitude
  110. var longitude = res.longitude
  111. that.setData({ longitude: longitude, latitude: latitude })
  112. },
  113. })
  114. }
  115. }
  116. })
  117. },
  118. onReady: function () {
  119. },
  120. payment: util.throttle(function(){
  121. //点击去支付
  122. var url = ''
  123. if(this.data.index==1){
  124. url = '&rent=rent'
  125. }
  126. wx.navigateTo({
  127. url: '../payment/payment?order='+this.data.order+url,
  128. })
  129. },1000),
  130. onShow: function () {
  131. },
  132. onHide: function () {
  133. },
  134. onUnload: function () {
  135. },
  136. onPullDownRefresh: function () {
  137. },
  138. onReachBottom: function () {
  139. },
  140. onShareAppMessage: function () {
  141. }
  142. })