index.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. //index.js
  2. const { request, serverName, imgServer } = require('../../utils/services');
  3. const { Toast } = require('../../utils/util.js');
  4. const { defaultImg, noExhibitionImg } = require('../../utils/images');
  5. const WxParse = require('../../common/component/wxParse/wxParse.js');
  6. const app = getApp();
  7. Page({
  8. data: {
  9. animationData: {},
  10. loading: false,
  11. isLike: true,
  12. imgServer,
  13. commodityImgs: [],
  14. testImg: '../../imgs/testImg/fdkz.png',
  15. currentPage: 1,
  16. exhibitionList: [],
  17. likes: {},
  18. tag: 1
  19. },
  20. onLoad: function () {
  21. this.setData({
  22. serverName,
  23. defaultImg,
  24. noExhibitionImg,
  25. })
  26. this.getList(1);
  27. },
  28. loadMore: function () {
  29. if (!this.data.lastPage) {
  30. this.getList(this.data.currentPage + 1);
  31. } else {
  32. return;
  33. }
  34. },
  35. onReachBottom: function () {
  36. if (!this.data.loading) {
  37. this.loadMore();
  38. }
  39. },
  40. onShareAppMessage: function () {
  41. },
  42. onShow: function () {
  43. let { collectedArr, collectedChange } = app.globalData;
  44. let { exhibitionList } = this.data
  45. // this.setData({
  46. // exhibitionList: []
  47. // });
  48. // this.getBanner();
  49. // this.getList(1);
  50. if (collectedChange) {
  51. for (let i = 0; i < exhibitionList.length; i++) {
  52. for (let j = 0; j < collectedArr.length; j++) {
  53. if (collectedArr[j].collectedId == exhibitionList[i].id) {
  54. exhibitionList[i].hasCollect = collectedArr[j].status
  55. if (exhibitionList[i].hasCollect) {
  56. exhibitionList[i].collectionsCount += 1;
  57. }
  58. else {
  59. exhibitionList[i].collectionsCount -= 1;
  60. }
  61. if (exhibitionList[i].collectionsCount < 0) {
  62. exhibitionList[i].collectionsCount = 0
  63. }
  64. }
  65. }
  66. }
  67. this.setData({
  68. exhibitionList
  69. })
  70. }
  71. app.globalData.clickToSelect = false;
  72. app.globalData.collectedChange = false;
  73. },
  74. enablePullDownRefresh: function () {
  75. this.setData({
  76. exhibitionList: [],
  77. currentPage: 1
  78. });
  79. this.getList(1);
  80. this.getBanner();
  81. },
  82. onPullDownRefresh: function () {
  83. this.setData({
  84. exhibitionList: [],
  85. currentPage: 1
  86. });
  87. this.getList(1);
  88. },
  89. getList: function (page) {
  90. let type = this.data.tag;
  91. this.setData({
  92. loading: true
  93. })
  94. request["getExhibitionList"]({
  95. page: page,
  96. type: type
  97. }, '', res => {
  98. let tempContent = this.data.exhibitionList
  99. ? this.data.exhibitionList
  100. : [];
  101. let { last: lastPage, totalPages, content: exhibitionList } = res.data.data;
  102. let { openTime } = exhibitionList;
  103. exhibitionList.forEach((currentValue) => {
  104. currentValue.product ? currentValue.product.link = escape(currentValue.product.link) : '';
  105. currentValue.product ? currentValue.product.imageUrl = escape(currentValue.product.imageUrl) : '';
  106. })
  107. this.setData({
  108. currentPage: res.data.data.number + 1,
  109. lastPage,
  110. loading: false,
  111. exhibitionList: tempContent.concat(exhibitionList),
  112. });
  113. wx.stopPullDownRefresh();
  114. // WxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that)
  115. }, err => {
  116. }, complete => {
  117. })
  118. },
  119. addLike: function (e) {
  120. let { type, id, idx } = e.currentTarget.dataset;
  121. let likes = this.data.likes;
  122. likes[id] = !likes[id];
  123. let exhibitionList = this.data.exhibitionList;
  124. let { collectedArr, collectedChange } = app.globalData, hasItem = true;
  125. this.setData({
  126. likes: likes
  127. })
  128. Toast.showToast2('loading');
  129. let loginSessionKey = wx.getStorageSync('token') || "";
  130. // if (loginSessionKey){
  131. request['isCollect']({
  132. loginSessionKey,
  133. exhibitionId: id,
  134. type: Number(type),
  135. }, "post", res => {
  136. if (res.data.code > -1) {
  137. for (let i = 0; i < collectedArr.length; i++) {
  138. if (collectedArr[i].collectedId && id == collectedArr[i].collectedId) {
  139. collectedArr[i] = {
  140. collectedId: id,
  141. status: res.data.data.hasCollect,
  142. }
  143. hasItem = false;
  144. }
  145. }
  146. if (hasItem) {
  147. collectedArr.push({
  148. collectedId: id,
  149. status: res.data.data.hasCollect,
  150. })
  151. }
  152. app.globalData.collectedArr = collectedArr;
  153. app.globalData.collectedChange = true;
  154. exhibitionList[idx].hasCollect = res.data.data.hasCollect
  155. this.setData({
  156. exhibitionList: exhibitionList
  157. })
  158. }
  159. }, err => {
  160. }, complete => {
  161. Toast.hideLoading();
  162. })
  163. // }
  164. },
  165. to_search: function () {
  166. wx.navigateTo({
  167. url: './search/index',
  168. success: function (res) { },
  169. fail: function (res) { },
  170. complete: function (res) { },
  171. })
  172. },
  173. })