index.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. //index.js
  2. const { request, serverName } = 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. commodityImgs: [],
  13. testImg: '../../imgs/testImg/fdkz.png',
  14. currentPage: 1,
  15. exhibitionList: [],
  16. likes: {},
  17. tag: 1
  18. },
  19. onLoad: function () {
  20. this.setData({
  21. serverName,
  22. defaultImg,
  23. noExhibitionImg,
  24. })
  25. this.getList(1);
  26. },
  27. loadMore: function () {
  28. if (!this.data.lastPage) {
  29. console.log(this.data.currentPage + 1)
  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. console.log('reach Bottom');
  39. }
  40. },
  41. onShareAppMessage: function () {
  42. },
  43. onShow: function () {
  44. let { collectedArr, collectedChange } = app.globalData;
  45. let { exhibitionList } = this.data
  46. // this.setData({
  47. // exhibitionList: []
  48. // });
  49. // this.getBanner();
  50. // this.getList(1);
  51. console.log('dwdwasda',collectedChange)
  52. if (collectedChange) {
  53. for (let i = 0; i < exhibitionList.length; i++) {
  54. for (let j = 0; j < collectedArr.length; j++) {
  55. if (collectedArr[j].collectedId == exhibitionList[i].id) {
  56. exhibitionList[i].hasCollect = collectedArr[j].status
  57. if (exhibitionList[i].hasCollect) {
  58. exhibitionList[i].collectionsCount += 1;
  59. }
  60. else {
  61. exhibitionList[i].collectionsCount -= 1;
  62. }
  63. if (exhibitionList[i].collectionsCount < 0) {
  64. exhibitionList[i].collectionsCount = 0
  65. }
  66. }
  67. }
  68. // console.log(collectedArr.status, collectedArr.collectedId)
  69. }
  70. this.setData({
  71. exhibitionList
  72. })
  73. }
  74. app.globalData.clickToSelect = false;
  75. app.globalData.collectedChange = false;
  76. },
  77. enablePullDownRefresh: function () {
  78. this.setData({
  79. exhibitionList: [],
  80. currentPage: 1
  81. });
  82. this.getList(1);
  83. this.getBanner();
  84. },
  85. onPullDownRefresh: function () {
  86. this.setData({
  87. exhibitionList: [],
  88. currentPage: 1
  89. });
  90. this.getList(1);
  91. },
  92. getList: function (page) {
  93. let type = this.data.tag;
  94. console.log(this.data.tag)
  95. this.setData({
  96. loading: true
  97. })
  98. request["getExhibitionList"]({
  99. page: page,
  100. type: type
  101. }, '', res => {
  102. let tempContent = this.data.exhibitionList
  103. ? this.data.exhibitionList
  104. : [];
  105. let { last: lastPage, totalPages, content: exhibitionList } = res.data.data;
  106. let { openTime } = exhibitionList;
  107. console.log(res)
  108. this.setData({
  109. currentPage: res.data.data.number + 1,
  110. lastPage,
  111. loading: false,
  112. exhibitionList: tempContent.concat(exhibitionList),
  113. });
  114. console.log(exhibitionList)
  115. wx.stopPullDownRefresh();
  116. // WxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that)
  117. }, err => {
  118. }, complete => {
  119. })
  120. },
  121. addLike: function (e) {
  122. let { type, id, idx } = e.currentTarget.dataset;
  123. console.log(idx, type, id)
  124. let likes = this.data.likes;
  125. likes[id] = !likes[id];
  126. let exhibitionList = this.data.exhibitionList;
  127. let { collectedArr, collectedChange } = app.globalData, hasItem = true;
  128. console.log('type', type)
  129. this.setData({
  130. likes: likes
  131. })
  132. Toast.showToast2('loading');
  133. let loginSessionKey = wx.getStorageSync('token') || "";
  134. // if (loginSessionKey){
  135. request['isCollect']({
  136. loginSessionKey,
  137. exhibitionId: id,
  138. type: Number(type),
  139. }, "post", res => {
  140. if (res.data.code > -1) {
  141. for (let i = 0; i < collectedArr.length; i++) {
  142. if (collectedArr[i].collectedId && id == collectedArr[i].collectedId) {
  143. console.log("true")
  144. collectedArr[i] = {
  145. collectedId: id,
  146. status: res.data.data.hasCollect,
  147. }
  148. hasItem = false;
  149. }
  150. }
  151. if (hasItem) {
  152. collectedArr.push({
  153. collectedId: id,
  154. status: res.data.data.hasCollect,
  155. })
  156. }
  157. app.globalData.collectedArr = collectedArr;
  158. app.globalData.collectedChange = true;
  159. exhibitionList[idx].hasCollect = res.data.data.hasCollect
  160. this.setData({
  161. exhibitionList: exhibitionList
  162. })
  163. }
  164. }, err => {
  165. }, complete => {
  166. Toast.hideLoading();
  167. })
  168. // }
  169. console.log(this.data.exhibitionList)
  170. },
  171. to_search: function () {
  172. wx.navigateTo({
  173. url: './search/index',
  174. success: function (res) { },
  175. fail: function (res) { },
  176. complete: function (res) { },
  177. })
  178. },
  179. to_pay: function (e) {
  180. console.log(e)
  181. let url = e.currentTarget.dataset.url
  182. wx.navigateTo({
  183. url: `../wv_page/index?url=${url}`,
  184. success: function (res) { },
  185. fail: function (res) { },
  186. complete: function (res) { },
  187. })
  188. }
  189. })