index.js 5.2 KB

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