index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. //index.js
  2. //获取应用实例
  3. const { request, serverName,imgServer } = require('../../utils/services');
  4. const { Toast, qqmapsdk } = require('../../utils/util.js');
  5. const { defaultImg, noExhibitionImg } = require('../../utils/images');
  6. const WxParse = require('../../common/component/wxParse/wxParse.js');
  7. // const QQMapWX = require('../../common/component/mapSDK/qqmap-wx-jssdk.min.js');
  8. const app = getApp();
  9. const distItems = [
  10. {
  11. name: '综合排序',
  12. id: '综合排序',
  13. idx:0
  14. },
  15. {
  16. name: '按距离排序',
  17. id: '距离排序',
  18. idx: 1
  19. },
  20. {
  21. name: '按热度排序',
  22. id: '热度排序',
  23. idx: 2
  24. }
  25. ]
  26. const typeItems = [
  27. {
  28. name: '展览中',
  29. id: '展览中',
  30. idx: 1
  31. },
  32. {
  33. name: '即将开始',
  34. id: '即将开始',
  35. idx: 2
  36. },
  37. {
  38. name: '已结束',
  39. id: '已结束',
  40. idx: 3
  41. },
  42. {
  43. name: '全部状态',
  44. id: '全部状态',
  45. idx: 0
  46. }
  47. ]
  48. Page({
  49. data: {
  50. navItem: distItems,
  51. indicatorDots: true,
  52. autoplay: true,
  53. interval: 5000,
  54. duration: 1000,
  55. activeIndex: 0,
  56. locationName: "珠海",
  57. isLike: false,
  58. showConfirm: false,
  59. tag: "",
  60. exhibitionList: [],
  61. commodityImgs: [
  62. '../../imgs/testImg/thumbSmallImg.jpg',
  63. '../../imgs/testImg/thumbSmallImg.jpg',
  64. ],
  65. type: 5,
  66. testImg: '../../imgs/testImg/fdkz.png',
  67. getLocationBtn: false,
  68. isShow: false,
  69. exhiNum:0,
  70. activeDist:'综合排序',
  71. activeType:'全部状态'
  72. },
  73. to_search_exhibition: function () {
  74. wx.navigateTo({
  75. url: '../yuezhan/search/index',
  76. success: function (res) { },
  77. fail: function (res) { },
  78. complete: function (res) { },
  79. })
  80. },
  81. onLoad: function () {
  82. this.getLocationName();
  83. // this.getList(1)
  84. this.setData({
  85. serverName,
  86. noExhibitionImg,
  87. defaultImg,
  88. imgServer
  89. })
  90. },
  91. onShareAppMessage: function () {
  92. },
  93. onShow: function () {
  94. let { city, clickToSelect, collectedArr, collectedChange } = app.globalData;
  95. let { activeIndex, exhibitionList } = this.data
  96. if (clickToSelect) {
  97. // console.log(city)
  98. this.setData({
  99. locationName: city || "珠海",
  100. exhibitionList: [],
  101. activeIndex: 0,
  102. type: 5
  103. });
  104. if (activeIndex == 1) {
  105. this.getNearByList(1);
  106. }
  107. else {
  108. this.getList(1);
  109. }
  110. }
  111. if (collectedChange) {
  112. for (let i = 0; i < exhibitionList.length; i++) {
  113. for (let j = 0; j < collectedArr.length; j++) {
  114. if (collectedArr[j].collectedId == exhibitionList[i].id) {
  115. exhibitionList[i].hasCollect = collectedArr[j].status
  116. if (exhibitionList[i].hasCollect) {
  117. exhibitionList[i].collectionsCount += 1;
  118. }
  119. else {
  120. exhibitionList[i].collectionsCount -= 1;
  121. }
  122. if (exhibitionList[i].collectionsCount < 0) {
  123. exhibitionList[i].collectionsCount = 0
  124. }
  125. }
  126. }
  127. // console.log(collectedArr.status, collectedArr.collectedId)
  128. }
  129. this.setData({
  130. exhibitionList
  131. })
  132. }
  133. app.globalData.clickToSelect = false;
  134. // app.globalData.collectedChange = false;
  135. },
  136. addLike: function (e) {
  137. let { type, id, idx } = e.currentTarget.dataset;
  138. console.log(idx, type, id)
  139. let exhibitionList = this.data.exhibitionList;
  140. let { collectedArr, collectedChange } = app.globalData, hasItem = true;
  141. console.log('type', type)
  142. Toast.showToast2('loading');
  143. let loginSessionKey = wx.getStorageSync('token') || "";
  144. // if (loginSessionKey){
  145. request['isCollect']({
  146. loginSessionKey,
  147. exhibitionId: id,
  148. type: Number(type),
  149. }, "post", res => {
  150. if (res.data.code > -1) {
  151. for (let i = 0; i < collectedArr.length; i++) {
  152. if (collectedArr[i].collectedId && id == collectedArr[i].collectedId) {
  153. console.log("true")
  154. collectedArr[i] = {
  155. collectedId: id,
  156. status: res.data.data.hasCollect,
  157. }
  158. hasItem = false;
  159. }
  160. }
  161. if (hasItem) {
  162. collectedArr.push({
  163. collectedId: id,
  164. status: res.data.data.hasCollect,
  165. })
  166. }
  167. app.globalData.collectedArr = collectedArr;
  168. app.globalData.collectedChange = true;
  169. exhibitionList[idx].hasCollect = res.data.data.hasCollect
  170. this.setData({
  171. exhibitionList: exhibitionList
  172. })
  173. }
  174. }, err => {
  175. }, complete => {
  176. Toast.hideLoading();
  177. })
  178. // }
  179. console.log(this.data.exhibitionList)
  180. },
  181. showDrop: function (e) {
  182. let tag = e.target.dataset.id
  183. console.log(e)
  184. let name = e.target.dataset.test
  185. console.log(tag)
  186. if (tag==='type'){
  187. this.setData({
  188. navItem: {
  189. type: tag,
  190. name: name,
  191. arr: typeItems
  192. },
  193. isShow: !this.data.isShow
  194. })
  195. }
  196. else{
  197. this.setData({
  198. navItem: {
  199. type: tag,
  200. name: name,
  201. arr: distItems
  202. },
  203. isShow: !this.data.isShow
  204. })
  205. }
  206. },
  207. getLocationName: function () {
  208. // 调用接口
  209. wx.getLocation({
  210. type: 'wgs84',
  211. success: (res) => {
  212. this.setData({
  213. latitude: res.latitude,
  214. longitude: res.longitude
  215. })
  216. //2、根据坐标获取当前位置名称,显示在顶部:腾讯地图逆地址解析
  217. qqmapsdk.reverseGeocoder({
  218. location: {
  219. latitude: res.latitude,
  220. longitude: res.longitude
  221. },
  222. success: (res) => {
  223. let { city: locationName } = res.result.address_component;
  224. locationName = locationName.substring(0, 2);
  225. console.log(locationName);
  226. app.globalData.city = locationName;
  227. this.setData({
  228. locationName
  229. })
  230. this.getList(1)
  231. },
  232. fail: function (res) {
  233. console.log(res)
  234. this.setData({
  235. locationName: ""
  236. })
  237. },
  238. complete: function (res) {
  239. console.log(res);
  240. }
  241. });
  242. }
  243. })
  244. },
  245. getList: function (page) {
  246. let { locationName, latitude, longitude, activeDist, activeType } = this.data;
  247. let loginSessionKey = wx.getStorageSync("token");
  248. let sort = distItems.find(item => item.id === activeDist).idx
  249. let type = typeItems.find(item => item.id === activeType).idx
  250. console.log(sort, type)
  251. console.log(page)
  252. console.log(type, locationName, latitude, longitude);
  253. this.setData({
  254. loading: true
  255. })
  256. request["getExhibitionListOffline"]({
  257. page: page,
  258. type: type,
  259. loginSessionKey,
  260. city: locationName,
  261. sort,
  262. type,
  263. lng: longitude,
  264. lat: latitude
  265. }, '', res => {
  266. let tempContent = this.data.exhibitionList
  267. ? this.data.exhibitionList
  268. : [];
  269. let { last: lastPage, totalPages, totalElements, content: exhibitionList } = res.data.data;
  270. let { openTime } = exhibitionList;
  271. this.setData({
  272. currentPage: res.data.data.number + 1,
  273. lastPage,
  274. loading: false,
  275. exhibitionList: tempContent.concat(exhibitionList),
  276. exhiNum: totalElements
  277. });
  278. console.log(this.data.exhibitionList)
  279. wx.stopPullDownRefresh();
  280. // WxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that)
  281. }, err => {
  282. }, complete => {
  283. })
  284. },
  285. getNearByList: function (page) {
  286. let { type, locationName, latitude, longitude } = this.data;
  287. let loginSessionKey = wx.getStorageSync("token");
  288. wx.getSetting({
  289. success: res => {
  290. if (!res.authSetting['scope.userLocation']) {
  291. Toast.showToast('tip', "无法获取用户位置", () => {
  292. return;
  293. })
  294. this.setData({
  295. getLocationBtn: true
  296. })
  297. }
  298. else {
  299. this.setData({
  300. loading: true,
  301. getLocationBtn: false
  302. })
  303. if (!longitude && !latitude) {
  304. wx.getLocation({
  305. success: res => {
  306. let longitude = (this.longitude = res.longitude);
  307. let latitude = (this.latitude = res.latitude);
  308. request["getNearByList"]({
  309. page: page,
  310. loginSessionKey,
  311. city: locationName,
  312. lng: longitude,
  313. lat: latitude
  314. }, '', res => {
  315. let tempContent = this.data.exhibitionList
  316. ? this.data.exhibitionList
  317. : [];
  318. let { last: lastPage, totalPages, content: exhibitionList } = res.data.data;
  319. let { openTime } = exhibitionList;
  320. console.log(res)
  321. this.setData({
  322. currentPage: res.data.data.number + 1,
  323. lastPage,
  324. loading: false,
  325. longitude,
  326. latitude,
  327. exhibitionList: tempContent.concat(exhibitionList),
  328. });
  329. console.log(exhibitionList)
  330. wx.stopPullDownRefresh();
  331. // WxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that)
  332. }, err => {
  333. }, complete => {
  334. })
  335. },
  336. })
  337. } else {
  338. request["getNearByList"]({
  339. page: page,
  340. loginSessionKey,
  341. city: locationName,
  342. lng: longitude,
  343. lat: latitude
  344. }, '', res => {
  345. let tempContent = this.data.exhibitionList
  346. ? this.data.exhibitionList
  347. : [];
  348. let { last: lastPage, totalPages, content: exhibitionList } = res.data.data;
  349. let { openTime } = exhibitionList;
  350. console.log(res)
  351. this.setData({
  352. currentPage: res.data.data.number + 1,
  353. lastPage,
  354. loading: false,
  355. exhibitionList: tempContent.concat(exhibitionList),
  356. });
  357. console.log(exhibitionList)
  358. wx.stopPullDownRefresh();
  359. }, err => {
  360. }, complete => {
  361. })
  362. }
  363. }
  364. }
  365. })
  366. },
  367. closeDialog: function () {
  368. this.setData({
  369. showConfirm: false
  370. })
  371. },
  372. loadMore: function () {
  373. let { activeIndex } = this.data
  374. if (!this.data.lastPage) {
  375. console.log(this.data.currentPage + 1)
  376. if (activeIndex == 1) {
  377. this.getNearByList(this.data.currentPage + 1);
  378. }
  379. else {
  380. this.getList(this.data.currentPage + 1);
  381. }
  382. } else {
  383. return;
  384. }
  385. },
  386. onReachBottom: function () {
  387. if (!this.data.loading) {
  388. this.loadMore();
  389. console.log('reach Bottom');
  390. }
  391. },
  392. tabClick: function (e) {
  393. // console.log(e.currentTarget.dataset)
  394. this.setData({
  395. exhibitionList: [],
  396. activeIndex: e.currentTarget.id,
  397. type: e.currentTarget.dataset.tag,
  398. currentPage: 1
  399. });
  400. if (e.currentTarget.id == 1) {
  401. this.getNearByList(1);
  402. }
  403. else {
  404. this.getList(1);
  405. }
  406. },
  407. onIsclose: function (e) {
  408. this.setData({
  409. isShow: e.detail
  410. })
  411. },
  412. getActiveItem:function(e){
  413. console.log(e)
  414. let { activeDist, activeType} = e.detail
  415. this.setData({
  416. activeDist,
  417. activeType,
  418. exhibitionList:[]
  419. })
  420. this.getList(1)
  421. },
  422. to_search: function () {
  423. wx.navigateTo({
  424. url: './search/index',
  425. success: function (res) { },
  426. fail: function (res) { },
  427. complete: function (res) { },
  428. })
  429. }
  430. })