index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. exhibitionList.forEach((currentValue) => {
  109. currentValue.product ? currentValue.product.link = escape(currentValue.product.link) : '';
  110. })
  111. console.log(res)
  112. this.setData({
  113. currentPage: res.data.data.number + 1,
  114. lastPage,
  115. loading: false,
  116. exhibitionList: tempContent.concat(exhibitionList),
  117. });
  118. console.log(exhibitionList)
  119. wx.stopPullDownRefresh();
  120. // WxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that)
  121. }, err => {
  122. }, complete => {
  123. })
  124. },
  125. addLike: function (e) {
  126. let { type, id, idx } = e.currentTarget.dataset;
  127. console.log(idx, type, id)
  128. let likes = this.data.likes;
  129. likes[id] = !likes[id];
  130. let exhibitionList = this.data.exhibitionList;
  131. let { collectedArr, collectedChange } = app.globalData, hasItem = true;
  132. console.log('type', type)
  133. this.setData({
  134. likes: likes
  135. })
  136. Toast.showToast2('loading');
  137. let loginSessionKey = wx.getStorageSync('token') || "";
  138. // if (loginSessionKey){
  139. request['isCollect']({
  140. loginSessionKey,
  141. exhibitionId: id,
  142. type: Number(type),
  143. }, "post", res => {
  144. if (res.data.code > -1) {
  145. for (let i = 0; i < collectedArr.length; i++) {
  146. if (collectedArr[i].collectedId && id == collectedArr[i].collectedId) {
  147. console.log("true")
  148. collectedArr[i] = {
  149. collectedId: id,
  150. status: res.data.data.hasCollect,
  151. }
  152. hasItem = false;
  153. }
  154. }
  155. if (hasItem) {
  156. collectedArr.push({
  157. collectedId: id,
  158. status: res.data.data.hasCollect,
  159. })
  160. }
  161. app.globalData.collectedArr = collectedArr;
  162. app.globalData.collectedChange = true;
  163. exhibitionList[idx].hasCollect = res.data.data.hasCollect
  164. this.setData({
  165. exhibitionList: exhibitionList
  166. })
  167. }
  168. }, err => {
  169. }, complete => {
  170. Toast.hideLoading();
  171. })
  172. // }
  173. console.log(this.data.exhibitionList)
  174. },
  175. to_search: function () {
  176. wx.navigateTo({
  177. url: './search/index',
  178. success: function (res) { },
  179. fail: function (res) { },
  180. complete: function (res) { },
  181. })
  182. },
  183. to_pay: function (e) {
  184. console.log(e)
  185. let url = e.currentTarget.dataset.url
  186. wx.navigateTo({
  187. url: `../wv_page/index?url=${url}`,
  188. success: function (res) { },
  189. fail: function (res) { },
  190. complete: function (res) { },
  191. })
  192. }
  193. })