index.js 12 KB

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