index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. },
  31. tabClick: function (e) {
  32. this.setData({
  33. loading: true,
  34. activeIndex: e.currentTarget.id,
  35. domesticCityList: [],
  36. internationalCity: []
  37. });
  38. if (this.data.activeIndex==0){
  39. this.getDomesticCity();
  40. }
  41. else{
  42. this.getInternationalCity();
  43. }
  44. },
  45. clickItem:function(e){
  46. console.log(e.currentTarget)
  47. let { name } = e.currentTarget.dataset;
  48. console.log(name);
  49. app.globalData.city = name;
  50. app.globalData.clickToSelect = true;
  51. wx.navigateBack({
  52. delta: 1,
  53. })
  54. },
  55. /**
  56. * 生命周期函数--监听页面初次渲染完成
  57. */
  58. onReady: function () {
  59. },
  60. getDomesticCity:function(){
  61. request["getDomesticCity"]({},"",res=>{
  62. if(res.data.code==0){
  63. let { data: domesticCityList} = res.data;
  64. this.setData({
  65. domesticCityList
  66. })
  67. }
  68. // console.log(domesticCityList)
  69. })
  70. },
  71. getLocationName:function(){
  72. // 调用接口
  73. wx.getLocation({
  74. type: 'wgs84',
  75. success: (res) => {
  76. // console.log('0202', res)
  77. //2、根据坐标获取当前位置名称,显示在顶部:腾讯地图逆地址解析
  78. qqmapsdk.reverseGeocoder({
  79. location: {
  80. latitude: res.latitude,
  81. longitude: res.longitude
  82. },
  83. success: (res) =>{
  84. let { city:locationName } = res.result.address_component;
  85. locationName = locationName.substring(0,2);
  86. this.getList(1, locationName)
  87. // app.globalData.city = locationName;
  88. this.setData({
  89. locationName
  90. })
  91. },
  92. fail: function (res) {
  93. console.log(res)
  94. this.setData({
  95. locationName:""
  96. })
  97. },
  98. complete: function (res) {
  99. console.log(res);
  100. }
  101. });
  102. }
  103. })
  104. },
  105. getList: function (page, locationName) {
  106. let loginSessionKey = wx.getStorageSync("token");
  107. console.log(loginSessionKey)
  108. this.setData({
  109. loading: true
  110. })
  111. request["getExhibitionList"]({
  112. page: page,
  113. type: 5,
  114. loginSessionKey,
  115. city: locationName||""
  116. }, '', res => {
  117. let { totalElements: exhibitionNum } = res.data.data;
  118. console.log(res)
  119. this.setData({
  120. exhibitionNum,
  121. loading: false,
  122. });
  123. wx.stopPullDownRefresh();
  124. }, err => {
  125. }, complete => {
  126. })
  127. },
  128. getInternationalCity(){
  129. request["getInternationalCity"]({}, "", res => {
  130. if (res.data.code == 0) {
  131. let { data: internationalCity } = res.data;
  132. this.setData({
  133. internationalCity
  134. })
  135. }
  136. // console.log(res)
  137. })
  138. },
  139. /**
  140. * 生命周期函数--监听页面显示
  141. */
  142. onShow: function () {
  143. },
  144. /**
  145. * 生命周期函数--监听页面隐藏
  146. */
  147. onHide: function () {
  148. },
  149. /**
  150. * 生命周期函数--监听页面卸载
  151. */
  152. onUnload: function () {
  153. },
  154. /**
  155. * 页面相关事件处理函数--监听用户下拉动作
  156. */
  157. onPullDownRefresh: function () {
  158. },
  159. /**
  160. * 页面上拉触底事件的处理函数
  161. */
  162. onReachBottom: function () {
  163. },
  164. /**
  165. * 用户点击右上角分享
  166. */
  167. onShareAppMessage: function () {
  168. }
  169. })