index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. //index.js
  2. //获取应用实例
  3. const { request, serverName } = 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. })
  89. },
  90. onShareAppMessage: function () {
  91. },
  92. onShow: function () {
  93. let { city, clickToSelect, collectedArr, collectedChange } = app.globalData;
  94. let { activeIndex, exhibitionList } = this.data
  95. if (clickToSelect) {
  96. // console.log(city)
  97. this.setData({
  98. locationName: city || "珠海",
  99. exhibitionList: [],
  100. activeIndex: 0,
  101. type: 5
  102. });
  103. if (activeIndex == 1) {
  104. this.getNearByList(1);
  105. }
  106. else {
  107. this.getList(1);
  108. }
  109. }
  110. if (collectedChange) {
  111. for (let i = 0; i < exhibitionList.length; i++) {
  112. for (let j = 0; j < collectedArr.length; j++) {
  113. if (collectedArr[j].collectedId == exhibitionList[i].id) {
  114. exhibitionList[i].hasCollect = collectedArr[j].status
  115. if (exhibitionList[i].hasCollect) {
  116. exhibitionList[i].collectionsCount += 1;
  117. }
  118. else {
  119. exhibitionList[i].collectionsCount -= 1;
  120. }
  121. if (exhibitionList[i].collectionsCount < 0) {
  122. exhibitionList[i].collectionsCount = 0
  123. }
  124. }
  125. }
  126. // console.log(collectedArr.status, collectedArr.collectedId)
  127. }
  128. this.setData({
  129. exhibitionList
  130. })
  131. }
  132. app.globalData.clickToSelect = false;
  133. // app.globalData.collectedChange = false;
  134. },
  135. addLike: function (e) {
  136. let { type, id, idx } = e.currentTarget.dataset;
  137. console.log(idx, type, id)
  138. let exhibitionList = this.data.exhibitionList;
  139. let { collectedArr, collectedChange } = app.globalData, hasItem = true;
  140. console.log('type', type)
  141. Toast.showToast2('loading');
  142. let loginSessionKey = wx.getStorageSync('token') || "";
  143. // if (loginSessionKey){
  144. request['isCollect']({
  145. loginSessionKey,
  146. exhibitionId: id,
  147. type: Number(type),
  148. }, "post", res => {
  149. if (res.data.code > -1) {
  150. for (let i = 0; i < collectedArr.length; i++) {
  151. if (collectedArr[i].collectedId && id == collectedArr[i].collectedId) {
  152. console.log("true")
  153. collectedArr[i] = {
  154. collectedId: id,
  155. status: res.data.data.hasCollect,
  156. }
  157. hasItem = false;
  158. }
  159. }
  160. if (hasItem) {
  161. collectedArr.push({
  162. collectedId: id,
  163. status: res.data.data.hasCollect,
  164. })
  165. }
  166. app.globalData.collectedArr = collectedArr;
  167. app.globalData.collectedChange = true;
  168. exhibitionList[idx].hasCollect = res.data.data.hasCollect
  169. this.setData({
  170. exhibitionList: exhibitionList
  171. })
  172. }
  173. }, err => {
  174. }, complete => {
  175. Toast.hideLoading();
  176. })
  177. // }
  178. console.log(this.data.exhibitionList)
  179. },
  180. showDrop: function (e) {
  181. let tag = e.target.dataset.id
  182. let name = e._relatedInfo.anchorTargetText
  183. console.log(tag)
  184. if (tag==='type'){
  185. this.setData({
  186. navItem: {
  187. type: tag,
  188. name: name,
  189. arr: typeItems
  190. },
  191. isShow: !this.data.isShow
  192. })
  193. }
  194. else{
  195. this.setData({
  196. navItem: {
  197. type: tag,
  198. name: name,
  199. arr: distItems
  200. },
  201. isShow: !this.data.isShow
  202. })
  203. }
  204. },
  205. getLocationName: function () {
  206. // 调用接口
  207. wx.getLocation({
  208. type: 'wgs84',
  209. success: (res) => {
  210. this.setData({
  211. latitude: res.latitude,
  212. longitude: res.longitude
  213. })
  214. //2、根据坐标获取当前位置名称,显示在顶部:腾讯地图逆地址解析
  215. qqmapsdk.reverseGeocoder({
  216. location: {
  217. latitude: res.latitude,
  218. longitude: res.longitude
  219. },
  220. success: (res) => {
  221. let { city: locationName } = res.result.address_component;
  222. locationName = locationName.substring(0, 2);
  223. console.log(locationName);
  224. app.globalData.city = locationName;
  225. this.setData({
  226. locationName
  227. })
  228. this.getList(1)
  229. },
  230. fail: function (res) {
  231. console.log(res)
  232. this.setData({
  233. locationName: ""
  234. })
  235. },
  236. complete: function (res) {
  237. console.log(res);
  238. }
  239. });
  240. }
  241. })
  242. },
  243. getList: function (page) {
  244. let { locationName, latitude, longitude, activeDist, activeType } = this.data;
  245. let loginSessionKey = wx.getStorageSync("token");
  246. let sort = distItems.find(item => item.id === activeDist).idx
  247. let type = typeItems.find(item => item.id === activeType).idx
  248. console.log(sort, type)
  249. console.log(type, locationName, latitude, longitude);
  250. this.setData({
  251. loading: true
  252. })
  253. request["getExhibitionListOffline"]({
  254. page: page,
  255. type: type,
  256. loginSessionKey,
  257. city: locationName,
  258. sort,
  259. type,
  260. lng: longitude,
  261. lat: latitude
  262. }, '', res => {
  263. let tempContent = this.data.exhibitionList
  264. ? this.data.exhibitionList
  265. : [];
  266. let { last: lastPage, totalPages, totalElements, content: exhibitionList } = res.data.data;
  267. let { openTime } = exhibitionList;
  268. this.setData({
  269. currentPage: res.data.data.number + 1,
  270. lastPage,
  271. loading: false,
  272. exhibitionList: tempContent.concat(exhibitionList),
  273. exhiNum: totalElements
  274. });
  275. console.log(this.data.exhibitionList)
  276. wx.stopPullDownRefresh();
  277. // WxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that)
  278. }, err => {
  279. }, complete => {
  280. })
  281. },
  282. getNearByList: function (page) {
  283. let { type, locationName, latitude, longitude } = this.data;
  284. let loginSessionKey = wx.getStorageSync("token");
  285. wx.getSetting({
  286. success: res => {
  287. if (!res.authSetting['scope.userLocation']) {
  288. Toast.showToast('tip', "无法获取用户位置", () => {
  289. return;
  290. })
  291. this.setData({
  292. getLocationBtn: true
  293. })
  294. }
  295. else {
  296. this.setData({
  297. loading: true,
  298. getLocationBtn: false
  299. })
  300. if (!longitude && !latitude) {
  301. wx.getLocation({
  302. success: res => {
  303. let longitude = (this.longitude = res.longitude);
  304. let latitude = (this.latitude = res.latitude);
  305. request["getNearByList"]({
  306. page: page,
  307. loginSessionKey,
  308. city: locationName,
  309. lng: longitude,
  310. lat: latitude
  311. }, '', res => {
  312. let tempContent = this.data.exhibitionList
  313. ? this.data.exhibitionList
  314. : [];
  315. let { last: lastPage, totalPages, content: exhibitionList } = res.data.data;
  316. let { openTime } = exhibitionList;
  317. console.log(res)
  318. this.setData({
  319. currentPage: res.data.data.number + 1,
  320. lastPage,
  321. loading: false,
  322. longitude,
  323. latitude,
  324. exhibitionList: tempContent.concat(exhibitionList),
  325. });
  326. console.log(exhibitionList)
  327. wx.stopPullDownRefresh();
  328. // WxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that)
  329. }, err => {
  330. }, complete => {
  331. })
  332. },
  333. })
  334. } else {
  335. request["getNearByList"]({
  336. page: page,
  337. loginSessionKey,
  338. city: locationName,
  339. lng: longitude,
  340. lat: latitude
  341. }, '', res => {
  342. let tempContent = this.data.exhibitionList
  343. ? this.data.exhibitionList
  344. : [];
  345. let { last: lastPage, totalPages, content: exhibitionList } = res.data.data;
  346. let { openTime } = exhibitionList;
  347. console.log(res)
  348. this.setData({
  349. currentPage: res.data.data.number + 1,
  350. lastPage,
  351. loading: false,
  352. exhibitionList: tempContent.concat(exhibitionList),
  353. });
  354. console.log(exhibitionList)
  355. wx.stopPullDownRefresh();
  356. }, err => {
  357. }, complete => {
  358. })
  359. }
  360. }
  361. }
  362. })
  363. },
  364. closeDialog: function () {
  365. this.setData({
  366. showConfirm: false
  367. })
  368. },
  369. loadMore: function () {
  370. let { activeIndex } = this.data
  371. if (!this.data.lastPage) {
  372. console.log(this.data.currentPage + 1)
  373. if (activeIndex == 1) {
  374. this.getNearByList(this.data.currentPage + 1);
  375. }
  376. else {
  377. this.getList(this.data.currentPage + 1);
  378. }
  379. } else {
  380. return;
  381. }
  382. },
  383. onReachBottom: function () {
  384. if (!this.data.loading) {
  385. this.loadMore();
  386. console.log('reach Bottom');
  387. }
  388. },
  389. tabClick: function (e) {
  390. // console.log(e.currentTarget.dataset)
  391. this.setData({
  392. exhibitionList: [],
  393. activeIndex: e.currentTarget.id,
  394. type: e.currentTarget.dataset.tag,
  395. currentPage: 1
  396. });
  397. if (e.currentTarget.id == 1) {
  398. this.getNearByList(1);
  399. }
  400. else {
  401. this.getList(1);
  402. }
  403. },
  404. onIsclose: function (e) {
  405. this.setData({
  406. isShow: e.detail
  407. })
  408. },
  409. getActiveItem:function(e){
  410. console.log(e)
  411. let { activeDist, activeType} = e.detail
  412. this.setData({
  413. activeDist,
  414. activeType,
  415. exhibitionList:[]
  416. })
  417. this.getList(1)
  418. },
  419. to_search: function () {
  420. wx.navigateTo({
  421. url: './search/index',
  422. success: function (res) { },
  423. fail: function (res) { },
  424. complete: function (res) { },
  425. })
  426. }
  427. })