index.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. this.setData({
  77. latitude: res.latitude,
  78. longitude: res.longitude
  79. })
  80. // console.log('0202', res)
  81. //2、根据坐标获取当前位置名称,显示在顶部:腾讯地图逆地址解析
  82. qqmapsdk.reverseGeocoder({
  83. location: {
  84. latitude: res.latitude,
  85. longitude: res.longitude
  86. },
  87. success: (res) =>{
  88. let { city:locationName } = res.result.address_component;
  89. locationName = locationName.substring(0,2);
  90. this.getList(1, locationName)
  91. // app.globalData.city = locationName;
  92. this.setData({
  93. locationName
  94. })
  95. },
  96. fail: function (res) {
  97. console.log(res)
  98. this.setData({
  99. locationName:""
  100. })
  101. },
  102. complete: function (res) {
  103. console.log(res);
  104. }
  105. });
  106. }
  107. })
  108. },
  109. getList: function (page, locationName) {
  110. let loginSessionKey = wx.getStorageSync("token");
  111. console.log(loginSessionKey)
  112. let { latitude, longitude, activeDist, activeType } = this.data;
  113. this.setData({
  114. loading: true
  115. })
  116. request["getExhibitionListOffline"]({
  117. page: page,
  118. loginSessionKey,
  119. city: locationName||"",
  120. sort:0,
  121. type:0,
  122. lng: longitude,
  123. lat: latitude,
  124. }, '', res => {
  125. let { totalElements: exhibitionNum } = res.data.data;
  126. console.log(res)
  127. this.setData({
  128. exhibitionNum,
  129. loading: false,
  130. });
  131. wx.stopPullDownRefresh();
  132. }, err => {
  133. }, complete => {
  134. })
  135. },
  136. getInternationalCity(){
  137. request["getInternationalCity"]({}, "", res => {
  138. if (res.data.code == 0) {
  139. let { data: internationalCity } = res.data;
  140. this.setData({
  141. internationalCity
  142. })
  143. }
  144. // console.log(res)
  145. })
  146. },
  147. /**
  148. * 生命周期函数--监听页面显示
  149. */
  150. onShow: function () {
  151. },
  152. /**
  153. * 生命周期函数--监听页面隐藏
  154. */
  155. onHide: function () {
  156. },
  157. /**
  158. * 生命周期函数--监听页面卸载
  159. */
  160. onUnload: function () {
  161. },
  162. /**
  163. * 页面相关事件处理函数--监听用户下拉动作
  164. */
  165. onPullDownRefresh: function () {
  166. },
  167. /**
  168. * 页面上拉触底事件的处理函数
  169. */
  170. onReachBottom: function () {
  171. },
  172. /**
  173. * 用户点击右上角分享
  174. */
  175. onShareAppMessage: function () {
  176. }
  177. })