index.js 5.5 KB

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