index.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. //index.js
  2. const {
  3. request,
  4. serverName,
  5. imgServer
  6. } = require('../../utils/services');
  7. const {
  8. Toast
  9. } = require('../../utils/util.js');
  10. const {
  11. defaultImg,
  12. noExhibitionImg,
  13. closeImg
  14. } = require('../../utils/images');
  15. const WxParse = require('../../common/component/wxParse/wxParse.js');
  16. const app = getApp();
  17. Page({
  18. data: {
  19. // navItem: [{ title: '热门', tag: 0 }, { title: '即将开始', tag: 2 }, { title: '展览中', tag: 4 }, { title: '已结束', tag: 6 }],
  20. indicatorDots: true,
  21. autoplay: true,
  22. interval: 2000,
  23. duration: 1000,
  24. activeIndex: 0,
  25. animationData: {},
  26. loading: false,
  27. isLike: true,
  28. commodityImgs: [],
  29. testImg: '../../imgs/testImg/fdkz.png',
  30. currentPage: 1,
  31. exhibitionList: [],
  32. likes: {},
  33. tag: 0,
  34. latitude: null,
  35. longitude: null,
  36. showRecommend: false
  37. },
  38. onLoad: function () {
  39. this.setData({
  40. serverName,
  41. defaultImg,
  42. noExhibitionImg,
  43. imgServer,
  44. closeImg,
  45. showRecommend: true
  46. // isLogin
  47. })
  48. this.getBanner();
  49. this.getList(1);
  50. wx.hideTabBar()
  51. },
  52. loadMore: function () {
  53. if (!this.data.lastPage) {
  54. console.log(this.data.currentPage + 1)
  55. this.getList(this.data.currentPage + 1);
  56. } else {
  57. return;
  58. }
  59. },
  60. onReachBottom: function () {
  61. if (!this.data.loading) {
  62. this.loadMore();
  63. console.log('reach Bottom');
  64. }
  65. },
  66. onShow: function () {
  67. let {
  68. collectedArr,
  69. collectedChange
  70. } = app.globalData;
  71. let {
  72. exhibitionList
  73. } = this.data
  74. let isLogin = app.globalData.isLogin;
  75. this.setData({
  76. isLogin
  77. })
  78. if (collectedChange) {
  79. for (let i = 0; i < exhibitionList.length; i++) {
  80. for (let j = 0; j < collectedArr.length; j++) {
  81. if (collectedArr[j].collectedId == exhibitionList[i].id) {
  82. exhibitionList[i].hasCollect = collectedArr[j].status
  83. if (exhibitionList[i].hasCollect) {
  84. exhibitionList[i].collectionsCount += 1;
  85. } else {
  86. exhibitionList[i].collectionsCount -= 1;
  87. }
  88. if (exhibitionList[i].collectionsCount < 0) {
  89. exhibitionList[i].collectionsCount = 0
  90. }
  91. }
  92. }
  93. // console.log(collectedArr.status, collectedArr.collectedId)
  94. }
  95. this.setData({
  96. exhibitionList,
  97. })
  98. }
  99. // app.globalData.clickToSelect = false;
  100. app.globalData.collectedChange = false;
  101. },
  102. onPullDownRefresh: function () {
  103. this.setData({
  104. exhibitionList: [],
  105. currentPage: 1
  106. });
  107. this.getBanner();
  108. this.getList(1);
  109. },
  110. hideRecommend: function () {
  111. this.setData({
  112. showRecommend: false
  113. })
  114. wx.showTabBar()
  115. },
  116. fetchData: function (page) {
  117. request["getExhibitionList"]({
  118. page: page,
  119. type: 0,
  120. lat: this.data.latitude,
  121. lng: this.data.longitude
  122. }, '', res => {
  123. let tempContent = this.data.exhibitionList ?
  124. this.data.exhibitionList : [];
  125. let {
  126. last: lastPage,
  127. totalPages,
  128. content: exhibitionList
  129. } = res.data.data;
  130. let {
  131. openTime
  132. } = exhibitionList;
  133. console.log(res)
  134. exhibitionList.forEach((currentValue) => {
  135. currentValue.distance = Math.ceil(currentValue.distance);
  136. if (currentValue.product) {
  137. currentValue.product.link = escape(currentValue.product.link);
  138. currentValue.product.imageUrl = escape(currentValue.product.imageUrl);
  139. }
  140. })
  141. this.setData({
  142. currentPage: res.data.data.number + 1,
  143. lastPage,
  144. loading: false,
  145. exhibitionList: tempContent.concat(exhibitionList),
  146. });
  147. console.log(exhibitionList)
  148. // WxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that)
  149. }, err => {
  150. }, complete => {
  151. wx.stopPullDownRefresh();
  152. })
  153. },
  154. getList: function (page) {
  155. let type = this.data.tag;
  156. this.setData({
  157. loading: true
  158. })
  159. if (this.data.latitude || this.data.longitude) {
  160. this.fetchData(page)
  161. } else {
  162. wx.getLocation({
  163. type: 'wgs84',
  164. success: (res) => {
  165. this.setData({
  166. latitude: res.latitude,
  167. longitude: res.longitude
  168. })
  169. this.fetchData(page)
  170. },
  171. fail: (res) => {
  172. this.fetchData(page)
  173. }
  174. })
  175. }
  176. },
  177. getBanner: function () {
  178. request["getBannerList"]({}, '', res => {
  179. let {
  180. content: commodityImgs
  181. } = res.data.data;
  182. // console.log("wdwdwd",commodityImgs)
  183. this.setData({
  184. commodityImgs: commodityImgs || []
  185. });
  186. console.log('banner', commodityImgs)
  187. }, err => {
  188. }, complete => {
  189. wx.stopPullDownRefresh()
  190. })
  191. },
  192. addLike: function (e) {
  193. let {
  194. type,
  195. id,
  196. idx
  197. } = e.currentTarget.dataset;
  198. console.log(idx, type, id)
  199. let likes = this.data.likes;
  200. likes[id] = !likes[id];
  201. let exhibitionList = this.data.exhibitionList;
  202. let {
  203. collectedArr,
  204. collectedChange
  205. } = app.globalData, hasItem = true;
  206. console.log('type', type)
  207. this.setData({
  208. likes: likes
  209. })
  210. Toast.showToast2('loading');
  211. let loginSessionKey = wx.getStorageSync('token') || "";
  212. // if (loginSessionKey){
  213. request['isCollect']({
  214. loginSessionKey,
  215. exhibitionId: id,
  216. type: Number(type),
  217. }, "post", res => {
  218. if (res.data.code > -1) {
  219. for (let i = 0; i < collectedArr.length; i++) {
  220. if (collectedArr[i].collectedId && id == collectedArr[i].collectedId) {
  221. console.log("true")
  222. collectedArr[i] = {
  223. collectedId: id,
  224. status: res.data.data.hasCollect,
  225. }
  226. hasItem = false;
  227. }
  228. }
  229. if (hasItem) {
  230. collectedArr.push({
  231. collectedId: id,
  232. status: res.data.data.hasCollect,
  233. })
  234. }
  235. app.globalData.collectedArr = collectedArr;
  236. app.globalData.collectedChange = true;
  237. exhibitionList[idx].hasCollect = res.data.data.hasCollect
  238. this.setData({
  239. exhibitionList: exhibitionList
  240. })
  241. }
  242. }, err => {
  243. }, complete => {
  244. Toast.hideLoading();
  245. })
  246. // }
  247. console.log(this.data.exhibitionList)
  248. },
  249. tabClick: function (e) {
  250. // console.log(e.currentTarget.dataset)
  251. // if (e.currentTarget.id == 1) {
  252. // wx.switchTab({
  253. // url: '../swkz/index',
  254. // success: function (res) { },
  255. // fail: function (res) { },
  256. // complete: function (res) { },
  257. // })
  258. // }
  259. // else {
  260. this.setData({
  261. exhibitionList: [],
  262. activeIndex: e.currentTarget.id,
  263. tag: e.currentTarget.dataset.tag,
  264. currentPage: 1
  265. });
  266. this.getList(1);
  267. // }
  268. },
  269. onShareAppMessage: function () {
  270. },
  271. to_pay: function (e) {
  272. // console.log('dwdwdw', e.currentTarget.dataset)
  273. let {
  274. url,
  275. pagetype,
  276. urltype,
  277. hasproduct,
  278. haspay,
  279. productlink,
  280. id,
  281. description,
  282. imageurl,
  283. relayUrl
  284. } = e.currentTarget.dataset;
  285. // app.globalData.currentUrl = url
  286. // console.log('dwdwdw', app.globalData.currentUrl)
  287. // console.log('dwdwdwd',wx.getStorageSync('url'))
  288. switch (urltype) {
  289. case 0:
  290. wx.navigateTo({
  291. url: `../wv_page/index`,
  292. success: function (res) {},
  293. fail: function (res) {},
  294. complete: function (res) {},
  295. })
  296. break;
  297. case 1:
  298. switch (pagetype) {
  299. case 0:
  300. wx.navigateTo({
  301. url: `../cg_detail/index?id=${url}`,
  302. success: function (res) {},
  303. fail: function (res) {},
  304. complete: function (res) {},
  305. })
  306. break;
  307. case 1:
  308. if (hasproduct) {
  309. wx.navigateTo({
  310. url: `../wv_page/index?&id=${url}`,
  311. success: function (res) {},
  312. fail: function (res) {},
  313. complete: function (res) {},
  314. })
  315. } else {
  316. wx.navigateTo({
  317. url: `../zl_detail/index?id=${url}`,
  318. success: function (res) {},
  319. fail: function (res) {},
  320. complete: function (res) {},
  321. })
  322. }
  323. break;
  324. default:
  325. break;
  326. }
  327. break;
  328. case 2:
  329. app.globalData.bannerHtml = description;
  330. wx.navigateTo({
  331. url: `./html_detail/index?id=${id}&imageUrl=${imageurl}&relayUrl=${relayUrl||''}`,
  332. success: function (res) {},
  333. fail: function (res) {},
  334. complete: function (res) {},
  335. })
  336. break;
  337. default:
  338. break;
  339. }
  340. }
  341. })