my_riding.js 3.8 KB

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