parking.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. var QQMapWX = require('../../utils/qqmap-wx-jssdk.min.js');
  2. var app = getApp();
  3. var qqmapsdk = new QQMapWX({
  4. key: app.globalData.mapKey // 必填
  5. });
  6. Page({
  7. data: {
  8. longitude: '',
  9. latitude: '',
  10. suggestion:[],
  11. show:false,
  12. value:'',
  13. parking:false,
  14. controls:[],
  15. animationData:{},
  16. address:'',
  17. area:[],
  18. polygons:[],
  19. areaTop:[],
  20. home_polygons: [],
  21. markers:[],
  22. img:app.globalData.imgUrl
  23. },
  24. onLoad: function(options) {
  25. var that = this;
  26. my.getLocation({
  27. type: 'gcj02',
  28. success: (res) => {
  29. console.log('经纬度为:+++++++++++++++++++++' + res.latitude + '++++++++' + res.longitude)
  30. var latitude = res.latitude
  31. var longitude = res.longitude
  32. that.setData({
  33. longitude: longitude,
  34. latitude: latitude
  35. })
  36. },
  37. fail: function(err) {
  38. console.log(err)
  39. }
  40. })
  41. if(!my.getStorageSync({'key':'home'}).data){
  42. my.showToast({
  43. content: '附近暂无运营区',
  44. icon: 'none'
  45. })
  46. }else{
  47. that.setData({ home_polygons: my.getStorageSync({'key':'home'}).data, polygons: that.data.polygons.concat(my.getStorageSync({'key':'home'}).data)})
  48. var data = {
  49. 'area_id': my.getStorageSync({'key':'home'}).data.id
  50. }
  51. app.request('/parking/stop-sites', data, 'GET').then(res => {
  52. // console.log(res)
  53. if (res.status == 200) {
  54. var data = res.data
  55. that.setData({
  56. polygons: that.data.polygons.concat(data.polygons),
  57. markers: data.centres
  58. })
  59. console.log(that.data.polygons)
  60. }
  61. })
  62. }
  63. },
  64. parkingArea:function(){
  65. var that = this;
  66. my.getLocation({
  67. type: 'gcj02',
  68. success: function(resp) {
  69. var data = {
  70. 'lat': that.data.latitude,
  71. 'lng': that.data.longitude,
  72. 'area_id': my.getStorageSync({'key':'home'}).data.id,
  73. 'location_lat':resp.latitude,
  74. 'location_lng':resp.longitude
  75. }
  76. var markers = that.data.markers;
  77. app.request('/parking/nearby', data, 'GET').then(res => {
  78. console.log(res)
  79. if(res.data.points!=''){
  80. that.setData({area:res.data.points,areaTop:res.data.points[0]})
  81. }
  82. if (res.status == 200) {
  83. var data1 = res.data
  84. if(data1.polygons.length>0){
  85. var array = data1.points;
  86. var marker = {};
  87. marker.latitude = that.data.latitude;
  88. marker.longitude = that.data.longitude;
  89. marker.zIndex = 1111;
  90. marker.width = 15;
  91. marker.height = 27;
  92. marker.type = 3;
  93. marker.iconPath = '/img/map.png';
  94. array = array.concat(marker)
  95. that.setData({ polygons: that.data.polygons.concat(data1.polygons), markers: markers.concat(array), parking:true})
  96. console.log(that.data.polygons)
  97. console.log(that.data.markers)
  98. }else{
  99. my.showToast({
  100. content: '当前目的地附近暂无还车点',
  101. icon:'none'
  102. })
  103. that.setData({ parking:false})
  104. var marker = {};
  105. marker.latitude = that.data.latitude;
  106. marker.longitude = that.data.longitude;
  107. marker.zIndex = 1111;
  108. marker.width = 15;
  109. marker.height = 27;
  110. marker.type = 3;
  111. marker.iconPath = '/img/map.png';
  112. that.setData({ markers: markers.concat(marker) })
  113. }
  114. }else{
  115. var marker = {};
  116. marker.latitude = that.data.latitude;
  117. marker.longitude = that.data.longitude;
  118. marker.zIndex = 1111;
  119. marker.width = 15;
  120. marker.height = 27;
  121. marker.type = 3;
  122. marker.iconPath = '/img/map.png';
  123. that.setData({ markers: markers.concat(marker) })
  124. }
  125. })
  126. },
  127. })
  128. },
  129. stop(e){
  130. var that = this;
  131. var area = this.data.area;
  132. var markers = that.data.markers;
  133. for (let item of markers) {
  134. // console.log(item)
  135. if (item.id == e.markerId) {
  136. if(item.type==2){
  137. item.iconPath = 'http://resource.bike.hanyiyun.com/weapp/orange-stop.png'
  138. }
  139. if (item.type == 1) {
  140. item.iconPath = 'http://resource.bike.hanyiyun.com/weapp/ban-stop.png'
  141. }
  142. } else {
  143. if(item.type==2){
  144. if (item.iconPath == '/img/map.png') {
  145. } else {
  146. item.iconPath = 'http://resource.bike.hanyiyun.com/weapp/stop1.png'
  147. }
  148. }
  149. if (item.type == 1) {
  150. item.iconPath = 'http://resource.bike.hanyiyun.com/weapp/ban-stop.png'
  151. }
  152. }
  153. }
  154. that.setData({ markers })
  155. for (let item of area) {
  156. if (item.id == e.markerId) {
  157. if(item.type==2){
  158. that.setData({ areaTop: item })
  159. }
  160. }
  161. }
  162. },
  163. selected(e){
  164. var that = this;
  165. var city = that.data.suggestion;
  166. var index = e.currentTarget.dataset.index;
  167. that.setData({
  168. value:city[index].title,
  169. latitude: city[index].latitude,
  170. longitude:city[index].longitude,
  171. show:false,
  172. address: city[index].addr
  173. })
  174. // this.pointer();
  175. that.parkingArea()
  176. var animation = my.createAnimation({
  177. duration: 1000,//动画的持续时间
  178. })
  179. this.animation = animation; //将animation变量赋值给当前动画
  180. var time1 = setTimeout(function () {
  181. that.slideIn();//调用动画--滑入
  182. clearTimeout(time1);
  183. time1 = null;
  184. }, 100)
  185. },
  186. slideIn: function () {
  187. this.animation.translateY(0).step() // 在y轴偏移,然后用step()完成一个动画
  188. this.setData({
  189. //动画实例的export方法导出动画数据传递给组件的animation属性
  190. animationData: this.animation.export()
  191. })
  192. },
  193. slideDown: function () {
  194. this.animation.translateY(300).step()
  195. this.setData({
  196. animationData: this.animation.export(),
  197. })
  198. },
  199. bindregionchange() {
  200. },
  201. location:function(e){
  202. console.log(this.data.areaTop)
  203. var latitude = this.data.areaTop.latitude;
  204. var longitude = this.data.areaTop.longitude;
  205. var address = this.data.areaTop.description;
  206. var name = this.data.areaTop.name;
  207. my.openLocation({//​使用支付宝内置地图查看位置。
  208. latitude: latitude,//要去的纬度-地址
  209. longitude: longitude,//要去的经度-地址
  210. name: name,
  211. address: address
  212. })
  213. },
  214. input(e) {
  215. var _this = this;
  216. //调用关键词提示接口
  217. if (e.detail.value == '') {
  218. _this.setData({ //设置suggestion属性,将关键词搜索结果以列表形式展示
  219. suggestion: [],
  220. show:false,
  221. parking:false
  222. });
  223. return;
  224. }
  225. if (this.data.value != e.detail.value && e.detail.value!='') {
  226. // _this.setData({:false})
  227. var animation = my.createAnimation({
  228. duration: 1000,//动画的持续时间
  229. })
  230. this.animation = animation; //将animation变量赋值给当前动画
  231. var time1 = setTimeout(function () {
  232. _this.slideDown();//调用动画--滑入
  233. clearTimeout(time1);
  234. time1 = null;
  235. }, 100)
  236. }
  237. _this.setData({ value: e.detail.value })
  238. var location=_this.data.latitude+','+_this.data.longitude
  239. qqmapsdk.getSuggestion({
  240. //获取输入框值并设置keyword参数
  241. keyword: e.detail.value, //用户输入的关键词,可设置固定值,如keyword:'KFC'
  242. page_size:20,
  243. //region:'北京', //设置城市名,限制关键词所示的地域范围,非必填参数
  244. location:location,
  245. region_fix:1,
  246. success: function(res) { //搜索成功后的回调
  247. var sug = [];
  248. for (var i = 0; i < res.data.length; i++) {
  249. sug.push({ // 获取返回结果,放到sug数组中
  250. title: res.data[i].title,
  251. id: res.data[i].id,
  252. addr: res.data[i].address,
  253. city: res.data[i].city,
  254. district: res.data[i].district,
  255. latitude: res.data[i].location.lat,
  256. longitude: res.data[i].location.lng
  257. });
  258. }
  259. _this.setData({ //设置suggestion属性,将关键词搜索结果以列表形式展示
  260. suggestion: sug,
  261. show:true
  262. });
  263. }
  264. });
  265. },
  266. onReady: function() {
  267. },
  268. onShow: function() {
  269. },
  270. onHide: function() {
  271. },
  272. onUnload: function() {
  273. },
  274. onPullDownRefresh: function() {
  275. },
  276. onReachBottom: function() {
  277. },
  278. onShareAppMessage: function() {
  279. }
  280. })