index.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. // pages/yuezhan/search/index.js
  2. const { request, serverName } = require('../../../utils/services');
  3. const { Toast } = require('../../../utils/util.js');
  4. const QQMapWX = require('../../../common/component/mapSDK/qqmap-wx-jssdk.min.js');
  5. var qqmapsdk = "";
  6. const app = getApp();
  7. const WxParse = require('../../../common/component/wxParse/wxParse.js');
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. tabs: ['国内', '国际'],
  14. testImg: '../../../imgs/testImg/thumbSmallImg2.jpg',
  15. avatar: '../../../imgs/testImg/1.jpg',
  16. activeIndex:0,
  17. domesticCityList:[],
  18. internationalCity:[]
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function (options) {
  24. qqmapsdk = new QQMapWX({
  25. key: '2Z3BZ-H7EWO-F4YWX-SG5JF-2VOK2-S2FUB'
  26. });
  27. this.getLocationName();
  28. this.getDomesticCity();
  29. console.log(app.globalData.city);
  30. this.setData({
  31. cityAction: app.globalData.city
  32. })
  33. },
  34. tabClick: function (e) {
  35. this.setData({
  36. loading: true,
  37. activeIndex: e.currentTarget.id,
  38. domesticCityList: [],
  39. internationalCity: []
  40. });
  41. if (this.data.activeIndex==0){
  42. this.getDomesticCity();
  43. }
  44. else{
  45. this.getInternationalCity();
  46. }
  47. },
  48. clickItem:function(e){
  49. console.log(e.currentTarget)
  50. let { name } = e.currentTarget.dataset;
  51. console.log(name);
  52. app.globalData.city = name;
  53. app.globalData.clickToSelect = true;
  54. wx.navigateBack({
  55. delta: 1,
  56. })
  57. },
  58. /**
  59. * 生命周期函数--监听页面初次渲染完成
  60. */
  61. onReady: function () {
  62. },
  63. getDomesticCity:function(){
  64. request["getDomesticCity"]({},"",res=>{
  65. if(res.data.code==0){
  66. let { data: domesticCityList} = res.data;
  67. this.setData({
  68. domesticCityList
  69. })
  70. }
  71. // console.log(domesticCityList)
  72. })
  73. },
  74. getLocationName:function(){
  75. // 调用接口
  76. wx.getLocation({
  77. type: 'wgs84',
  78. success: (res) => {
  79. this.setData({
  80. latitude: res.latitude,
  81. longitude: res.longitude
  82. })
  83. // console.log('0202', res)
  84. //2、根据坐标获取当前位置名称,显示在顶部:腾讯地图逆地址解析
  85. qqmapsdk.reverseGeocoder({
  86. location: {
  87. latitude: res.latitude,
  88. longitude: res.longitude
  89. },
  90. success: (res) =>{
  91. let { city:locationName } = res.result.address_component;
  92. locationName = locationName.substring(0,2);
  93. this.getList(1, locationName)
  94. // app.globalData.city = locationName;
  95. this.setData({
  96. locationName
  97. })
  98. },
  99. fail: function (res) {
  100. console.log(res)
  101. this.setData({
  102. locationName:""
  103. })
  104. },
  105. complete: function (res) {
  106. console.log(res);
  107. }
  108. });
  109. }
  110. })
  111. },
  112. getList: function (page, locationName) {
  113. let loginSessionKey = wx.getStorageSync("token");
  114. console.log(loginSessionKey)
  115. let { latitude, longitude, activeDist, activeType } = this.data;
  116. this.setData({
  117. loading: true
  118. })
  119. request["getExhibitionListOffline"]({
  120. page: page,
  121. loginSessionKey,
  122. city: locationName||"",
  123. sort:0,
  124. type:0,
  125. lng: longitude,
  126. lat: latitude,
  127. }, '', res => {
  128. let { totalElements: exhibitionNum } = res.data.data;
  129. console.log(res)
  130. this.setData({
  131. exhibitionNum,
  132. loading: false,
  133. });
  134. wx.stopPullDownRefresh();
  135. }, err => {
  136. }, complete => {
  137. })
  138. },
  139. getInternationalCity(){
  140. request["getInternationalCity"]({}, "", res => {
  141. if (res.data.code == 0) {
  142. let { data: internationalCity } = res.data;
  143. this.setData({
  144. internationalCity
  145. })
  146. }
  147. // console.log(res)
  148. })
  149. },
  150. /**
  151. * 生命周期函数--监听页面显示
  152. */
  153. onShow: function () {
  154. },
  155. /**
  156. * 生命周期函数--监听页面隐藏
  157. */
  158. onHide: function () {
  159. },
  160. /**
  161. * 生命周期函数--监听页面卸载
  162. */
  163. onUnload: function () {
  164. },
  165. /**
  166. * 页面相关事件处理函数--监听用户下拉动作
  167. */
  168. onPullDownRefresh: function () {
  169. },
  170. /**
  171. * 页面上拉触底事件的处理函数
  172. */
  173. onReachBottom: function () {
  174. },
  175. /**
  176. * 用户点击右上角分享
  177. */
  178. onShareAppMessage: function () {
  179. }
  180. })