index.js 4.5 KB

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