apply.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. value: '',
  12. value1: '',
  13. height: 490,
  14. touchS: [0],
  15. touchE: [0],
  16. animatheightadd: null,
  17. mapHeight: 245,
  18. iconHeight:58,
  19. animatMap: null,
  20. windowHeight: null,
  21. page: 1,
  22. animaticon:null,
  23. posiHeight:'',
  24. img:app.globalData.imgUrl
  25. },
  26. tolower: function () {
  27. var that = this;
  28. wx.showLoading({
  29. title: '加载中...',
  30. })
  31. var page = that.data.page + 1
  32. qqmapsdk.reverseGeocoder({
  33. location: {
  34. latitude: that.data.latitude,
  35. longitude: that.data.longitude
  36. }, //坐标
  37. get_poi: 1, //是否获取坐标对应附近列表
  38. poi_options: 'policy=2;radius=3000;page_size=10;page_index=' + page, //poi 参数
  39. success: function (res) {
  40. console.log(res)
  41. var poiList = res.result.pois;
  42. if (poiList.length == 0) {
  43. wx.showToast({
  44. title: '没有更多了~',
  45. icon:'none'
  46. })
  47. } else {
  48. that.setData({
  49. suggestion: that.data.suggestion.concat(poiList),
  50. page
  51. })
  52. wx.hideLoading({
  53. complete: (res) => {},
  54. })
  55. }
  56. }
  57. })
  58. },
  59. getList: function (lat, lng) {
  60. var that = this;
  61. wx.showLoading({
  62. title: '加载中...',
  63. })
  64. qqmapsdk.reverseGeocoder({
  65. location: {
  66. latitude: lat,
  67. longitude: lng
  68. }, //坐标
  69. get_poi: 1, //是否获取坐标对应附近列表
  70. poi_options: 'policy=2;radius=3000;page_size=10;page_index=1', //poi 参数
  71. success: function (res) {
  72. // console.log(res)
  73. var poiList = res.result.pois;
  74. for(var i=0;i<poiList.length;i++){
  75. poiList[i].select = false;
  76. poiList[0].select = true;
  77. }
  78. wx.hideLoading({
  79. complete: (res) => {},
  80. })
  81. that.setData({
  82. suggestion: poiList,
  83. value1:poiList[0].title
  84. })
  85. }
  86. })
  87. },
  88. onLoad: function (options) {
  89. var that = this;
  90. wx.getLocation({
  91. type: 'gcj02',
  92. success: (res) => {
  93. console.log('经纬度为:+++++++++++++++++++++' + res.latitude + '++++++++' + res.longitude)
  94. var latitude = res.latitude
  95. var longitude = res.longitude
  96. that.setData({
  97. longitude: longitude,
  98. latitude: latitude
  99. })
  100. that.getList(latitude, longitude)
  101. },
  102. fail: function (err) {
  103. console.log(err)
  104. }
  105. })
  106. wx.getSystemInfo({
  107. success: (res) => {
  108. this.setData({
  109. mapHeight: res.windowHeight - 245,
  110. windowHeight: res.windowHeight
  111. })
  112. }
  113. })
  114. },
  115. touchStart: function (e) {
  116. // console.log(e.touches[0].pageX)
  117. // console.log(e)
  118. let sy = e.touches[0].pageY;
  119. this.data.touchS = [sy]
  120. },
  121. move(e) {
  122. var that = this;
  123. let sy = e.touches[0].pageY;
  124. this.data.touchE = [sy];
  125. this.animation()
  126. },
  127. scroll: function (e) {
  128. // console.log(e)
  129. var that = this;
  130. let sy = e.detail.deltaY;
  131. this.data.touchE = [sy];
  132. this.animation()
  133. },
  134. animation: function () {
  135. var that = this;
  136. var animation = wx.createAnimation({
  137. duration: 500,
  138. timingFunction: "ease",
  139. delay: 0,
  140. transformOrigin: "50% 50%",
  141. })
  142. var animatheightadd = wx.createAnimation({
  143. duration: 500,
  144. timingFunction: 'ease-in',
  145. })
  146. var animaticon = wx.createAnimation({
  147. duration: 500,
  148. timingFunction: 'ease-in',
  149. })
  150. var animatMap = wx.createAnimation({
  151. duration: 500,
  152. timingFunction: 'ease-in',
  153. })
  154. if (this.data.touchS[0] < this.data.touchE[0]) {
  155. animation.rotate(0).step();
  156. animatheightadd.height(245).step()
  157. animaticon.height(that.data.posiHeight).step()
  158. animatMap.height(that.data.windowHeight - 245).step()
  159. that.setData({
  160. animatheightadd: animatheightadd.export(),
  161. animatMap: animatMap.export(),
  162. animaticon: animaticon.export()
  163. })
  164. } else {
  165. //上拉
  166. animation.rotate(90).step();
  167. animatheightadd.height(450).step()
  168. animaticon.height(that.data.posiHeight-200).step()
  169. animatMap.height(that.data.windowHeight - 450).step()
  170. that.setData({
  171. animatheightadd: animatheightadd.export(),
  172. animatMap: animatMap.export(),
  173. animaticon: animaticon.export()
  174. })
  175. }
  176. },
  177. selected(e) {
  178. var that = this;
  179. var city = that.data.suggestion;
  180. // console.log(city)
  181. var index = e.currentTarget.dataset.index;
  182. var lat = '';
  183. var lng = '';
  184. var arrress = '';
  185. for(var i=0;i<city.length;i++){
  186. city[i].select = false;
  187. city[index].select = true;
  188. }
  189. if (city[index].location != undefined) {
  190. lat = city[index].location.lat;
  191. lng = city[index].location.lng;
  192. } else {
  193. lat = city[index].latitude;
  194. lng = city[index].longitude;
  195. arrress = city[index].addr;
  196. }
  197. that.setData({
  198. value1: city[index].title,
  199. latitude: lat,
  200. longitude: lng,
  201. suggestion:city
  202. })
  203. },
  204. bindregionchange: function (e) {
  205. //实现大头针移动选点
  206. var that = this
  207. if (e.type == "end" && e.causedBy == 'drag') {
  208. //停止
  209. var mapCtx = wx.createMapContext("map")
  210. mapCtx.getCenterLocation({
  211. success: function (res) {
  212. // console.log(res)
  213. var latitude = res.latitude
  214. var longitude = res.longitude
  215. that.setData({
  216. latitude,
  217. longitude
  218. })
  219. that.getList(latitude, longitude)
  220. }
  221. })
  222. } else {
  223. wx.hideLoading({
  224. complete: (res) => {},
  225. })
  226. }
  227. },
  228. input(e) {
  229. var _this = this;
  230. //调用关键词提示接口
  231. if (e.detail.value == '') {
  232. _this.setData({ //设置suggestion属性,将关键词搜索结果以列表形式展示
  233. suggestion: [],
  234. });
  235. return;
  236. }
  237. _this.setData({
  238. value: e.detail.value
  239. })
  240. var location = _this.data.latitude + ',' + _this.data.longitude
  241. console.log(location)
  242. qqmapsdk.getSuggestion({
  243. //获取输入框值并设置keyword参数
  244. keyword: e.detail.value, //用户输入的关键词,可设置固定值,如keyword:'KFC'
  245. page_size: 20,
  246. location: location,
  247. region_fix: 1,
  248. success: function (res) { //搜索成功后的回调
  249. console.log(res);
  250. _this.setData({ //设置suggestion属性,将关键词搜索结果以列表形式展示
  251. suggestion: res.data,
  252. });
  253. }
  254. });
  255. },
  256. submit:function(){
  257. var that = this;
  258. var value = '';
  259. if(that.data.value==''){
  260. value = that.data.value1
  261. }else{
  262. value = that.data.value
  263. }
  264. var data = {
  265. area_id:wx.getStorageSync('home').id,
  266. location_name:value,
  267. longitude:this.data.suggestion[0].location.lng,
  268. latitude:this.data.suggestion[0].location.lat
  269. }
  270. app.request('/pages/applyAddParking', data, 'POST', app.globalData.req).then(res => {
  271. console.log(res)
  272. if(res.statusCode==200){
  273. wx.showModal({
  274. title: '提交成功',
  275. content: '感谢您提交的 p 点 (还车点) 的定点还车区域,我们会尽快评估,若您的建议被采纳,将会在地图上显示新的还车点。',
  276. showCancel: false,//是否显示取消按钮
  277. confirmText:"我知道了",//默认是“确定”
  278. confirmColor: '#18D5B9',//确定文字的颜色
  279. success:function(){
  280. wx.navigateBack()
  281. }
  282. })
  283. }
  284. })
  285. },
  286. posi: function () {
  287. //点击定位
  288. //这是一段注释
  289. var that = this;
  290. wx.getLocation({
  291. type: 'gcj02',
  292. success: (res) => {
  293. // console.log('经纬度为:+++++++++++++++++++++' + res.latitude + '++++++++' + res.longitude)
  294. var latitude = res.latitude
  295. var longitude = res.longitude
  296. that.setData({
  297. longitude: longitude,
  298. latitude: latitude
  299. })
  300. that.getList(latitude, longitude)
  301. }
  302. })
  303. },
  304. onReady: function () {
  305. var that = this;
  306. var query = wx.createSelectorQuery();
  307. query.select('.circle').boundingClientRect();
  308. query.exec(function (res) {
  309. console.log(res)
  310. that.setData({
  311. posiHeight: res[0].height
  312. })
  313. })
  314. },
  315. onShow: function () {
  316. },
  317. onHide: function () {
  318. },
  319. onUnload: function () {
  320. },
  321. onPullDownRefresh: function () {
  322. },
  323. onReachBottom: function () {
  324. },
  325. onShareAppMessage: function () {
  326. }
  327. })