dj-confirm.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view class="flex flex-column vh100 w100">
  3. <view class="u-flex-1 w100">
  4. <map style="width: 100%; height: 100%;position: relative;" :scale="13" :latitude="latitude" :longitude="longitude" :markers="covers"
  5. :polyline="polyline">
  6. </map>
  7. </view>
  8. <dtHujiao :price = "price" @hujiao = "hujiao" style="width: 100%;"></dtHujiao>
  9. </view>
  10. </template>
  11. <script>
  12. import {mapState} from 'vuex'
  13. import amapFile from '../../libs/amap-wx.js'
  14. import {changeTime} from "../../common/common.js"
  15. export default {
  16. data() {
  17. return {
  18. query: {},
  19. time: '',
  20. other: {},
  21. price:'',
  22. distance:'',
  23. // 地图
  24. latitude: '',
  25. longitude: '',
  26. polyline: []
  27. }
  28. },
  29. computed: {
  30. ...mapState(["start","end"]),
  31. covers() {
  32. return [{
  33. id: 1,
  34. latitude: this.latitude,
  35. longitude: this.longitude,
  36. iconPath: '../../static/now.png',
  37. title: '当前位置',
  38. width:25,
  39. height:25
  40. }, {
  41. id: 2,
  42. latitude: this.start.latitude,
  43. longitude: this.start.longitude,
  44. iconPath: '../../static/start.png',
  45. title: '起点位置',
  46. width:40,
  47. height:40
  48. }, {
  49. id: 3,
  50. latitude: this.end.latitude,
  51. longitude: this.end.longitude,
  52. iconPath: '../../static/end.png',
  53. title: '终点位置',
  54. width:40,
  55. height:40
  56. }]
  57. }
  58. },
  59. onLoad(option) {
  60. this.query = JSON.parse(decodeURIComponent(option.query))
  61. //console.log(888888, this.query);
  62. // "time": "2020-12-15 00:00",
  63. // "other": {
  64. // "tel": "16638143447",
  65. // "name": "小曲"
  66. // }
  67. // }
  68. if(this.query.time == '预约时间'){
  69. this.time = ''
  70. }else{
  71. this.time = changeTime(this.query.time)
  72. }
  73. this.other = this.query.other
  74. let _this = this
  75. uni.getLocation({
  76. type: 'gcj02',
  77. success: function(res) {
  78. _this.longitude = res.longitude
  79. _this.latitude = res.latitude
  80. _this.polyline = []
  81. _this.getLine()
  82. }
  83. });
  84. },
  85. onShow() {
  86. },
  87. methods: {
  88. getLine() {
  89. var that = this;
  90. var key = 'bb6f4ed802756f963b37c184ce4e9766';
  91. var myAmapFun = new amapFile.AMapWX({
  92. key: key
  93. });
  94. this.lineData(myAmapFun, this.start.longitude + ',' + this.start.latitude, this.end.longitude + ',' +
  95. this.end.latitude,
  96. "#28d32e")
  97. },
  98. lineData(myAmapFun, origin, destination, color) {
  99. let that = this
  100. console.log(origin)
  101. console.log(destination)
  102. myAmapFun.getDrivingRoute({
  103. origin,
  104. destination,
  105. success(data) {
  106. if (data.paths && data.paths[0] && data.paths[0].steps) {
  107. var steps = data.paths[0].steps;
  108. var points = [];
  109. for (var i = 0; i < steps.length; i++) {
  110. var poLen = steps[i].polyline.split(';');
  111. for (var j = 0; j < poLen.length; j++) {
  112. points.push({
  113. longitude: parseFloat(poLen[j].split(',')[0]),
  114. latitude: parseFloat(poLen[j].split(',')[1])
  115. })
  116. }
  117. }
  118. }
  119. that.polyline.push({
  120. points: points,
  121. color,
  122. width: 10,
  123. arrowLine: true,
  124. })
  125. if (data.paths[0] && data.paths[0].distance) {
  126. that.distance = data.paths[0].distance
  127. that.getPrice(data.paths[0].distance)
  128. }
  129. },
  130. fail(info) {
  131. console.log(444444, info);
  132. }
  133. });
  134. },
  135. getPrice(distance){
  136. this.$http('/addons/ddrive/order/amount', {
  137. distance,
  138. }, "POST").then((data) => {
  139. this.price = data
  140. })
  141. },
  142. //呼叫代驾
  143. hujiao(){
  144. this.$http('/addons/ddrive/order/create', {
  145. start:this.start.name,
  146. start_city:this.start.city,
  147. start_address:this.start.address,
  148. start_latitude:this.start.latitude,
  149. start_longitude:this.start.longitude,
  150. end:this.end.name,
  151. end_city:this.end.city,
  152. end_address:this.end.address,
  153. end_latitude:this.end.latitude,
  154. end_longitude:this.end.longitude,
  155. distance:this.distance,
  156. duration:0,
  157. mobile:this.other.tel?this.other.tel:'',
  158. appointment_time:this.time,
  159. }, "POST").then((data) => {
  160. uni.showToast({
  161. title:"呼叫成功"
  162. })
  163. setTimeout(()=>{
  164. uni.redirectTo({
  165. url:'/pages/home/detail?id=' + data.order_id
  166. })
  167. },100)
  168. })
  169. }
  170. }
  171. }
  172. </script>
  173. <style lang="scss" scoped>
  174. .navigation {
  175. position: fixed;
  176. right: 10rpx;
  177. top: 100rpx;
  178. width: 100rpx;
  179. height: 100rpx;
  180. }
  181. </style>