index.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. // navItem: [{ title: '热门', tag: 0 }, { title: '即将开始', tag: 2 }, { title: '展览中', tag: 4 }, { title: '已结束', tag: 6 }],
  10. indicatorDots: true,
  11. autoplay: true,
  12. interval: 2000,
  13. duration: 1000,
  14. activeIndex: 0,
  15. animationData: {},
  16. loading: false,
  17. isLike: true,
  18. commodityImgs: [],
  19. testImg: '../../imgs/testImg/fdkz.png',
  20. currentPage: 1,
  21. exhibitionList: [],
  22. likes: {},
  23. tag: 0
  24. },
  25. onLoad: function () {
  26. this.setData({
  27. serverName,
  28. defaultImg,
  29. noExhibitionImg,
  30. // isLogin
  31. })
  32. this.getBanner();
  33. this.getList(1);
  34. },
  35. loadMore: function () {
  36. if (!this.data.lastPage) {
  37. console.log(this.data.currentPage + 1)
  38. this.getList(this.data.currentPage + 1);
  39. } else {
  40. return;
  41. }
  42. },
  43. onReachBottom: function () {
  44. if (!this.data.loading) {
  45. this.loadMore();
  46. console.log('reach Bottom');
  47. }
  48. },
  49. onShow: function () {
  50. let { collectedArr, collectedChange } = app.globalData;
  51. let { exhibitionList } = this.data
  52. let isLogin = app.globalData.isLogin;
  53. // this.setData({
  54. // exhibitionList: []
  55. // });
  56. // this.getBanner();
  57. // this.getList(1);
  58. console.log('dwdwasda', isLogin)
  59. this.setData({
  60. isLogin
  61. })
  62. if (collectedChange) {
  63. for (let i = 0; i < exhibitionList.length; i++) {
  64. for (let j = 0; j < collectedArr.length; j++) {
  65. if (collectedArr[j].collectedId == exhibitionList[i].id) {
  66. exhibitionList[i].hasCollect = collectedArr[j].status
  67. if (exhibitionList[i].hasCollect) {
  68. exhibitionList[i].collectionsCount += 1;
  69. }
  70. else {
  71. exhibitionList[i].collectionsCount -= 1;
  72. }
  73. if (exhibitionList[i].collectionsCount < 0) {
  74. exhibitionList[i].collectionsCount = 0
  75. }
  76. }
  77. }
  78. // console.log(collectedArr.status, collectedArr.collectedId)
  79. }
  80. this.setData({
  81. exhibitionList,
  82. })
  83. }
  84. // app.globalData.clickToSelect = false;
  85. app.globalData.collectedChange = false;
  86. },
  87. onPullDownRefresh: function () {
  88. this.setData({
  89. exhibitionList: [],
  90. currentPage: 1
  91. });
  92. this.getList(1);
  93. },
  94. getList: function (page) {
  95. let type = this.data.tag;
  96. console.log(this.data.tag)
  97. this.setData({
  98. loading: true
  99. })
  100. request["getExhibitionList"]({
  101. page: page,
  102. type: type
  103. }, '', res => {
  104. let tempContent = this.data.exhibitionList
  105. ? this.data.exhibitionList
  106. : [];
  107. let { last: lastPage, totalPages, content: exhibitionList } = res.data.data;
  108. let { openTime } = exhibitionList;
  109. console.log(res)
  110. this.setData({
  111. currentPage: res.data.data.number + 1,
  112. lastPage,
  113. loading: false,
  114. exhibitionList: tempContent.concat(exhibitionList),
  115. });
  116. console.log(exhibitionList)
  117. // WxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that)
  118. }, err => {
  119. }, complete => {
  120. wx.stopPullDownRefresh();
  121. })
  122. },
  123. getBanner: function () {
  124. request["getBannerList"]({
  125. }, '', res => {
  126. let { content: commodityImgs } = res.data.data;
  127. // console.log("wdwdwd",commodityImgs)
  128. this.setData({
  129. commodityImgs: commodityImgs||[]
  130. });
  131. }, err => {
  132. }, complete => {
  133. wx.stopPullDownRefresh()
  134. })
  135. },
  136. addLike: function (e) {
  137. let { type, id, idx } = e.currentTarget.dataset;
  138. console.log(idx, type, id)
  139. let likes = this.data.likes;
  140. likes[id] = !likes[id];
  141. let exhibitionList = this.data.exhibitionList;
  142. let { collectedArr, collectedChange } = app.globalData, hasItem = true;
  143. console.log('type', type)
  144. this.setData({
  145. likes: likes
  146. })
  147. Toast.showToast2('loading');
  148. let loginSessionKey = wx.getStorageSync('token') || "";
  149. // if (loginSessionKey){
  150. request['isCollect']({
  151. loginSessionKey,
  152. exhibitionId: id,
  153. type: Number(type),
  154. }, "post", res => {
  155. if (res.data.code > -1) {
  156. for (let i = 0; i < collectedArr.length; i++) {
  157. if (collectedArr[i].collectedId && id == collectedArr[i].collectedId) {
  158. console.log("true")
  159. collectedArr[i] = {
  160. collectedId: id,
  161. status: res.data.data.hasCollect,
  162. }
  163. hasItem = false;
  164. }
  165. }
  166. if (hasItem) {
  167. collectedArr.push({
  168. collectedId: id,
  169. status: res.data.data.hasCollect,
  170. })
  171. }
  172. app.globalData.collectedArr = collectedArr;
  173. app.globalData.collectedChange = true;
  174. exhibitionList[idx].hasCollect = res.data.data.hasCollect
  175. this.setData({
  176. exhibitionList: exhibitionList
  177. })
  178. }
  179. }, err => {
  180. }, complete => {
  181. Toast.hideLoading();
  182. })
  183. // }
  184. console.log(this.data.exhibitionList)
  185. },
  186. tabClick: function (e) {
  187. // console.log(e.currentTarget.dataset)
  188. // if (e.currentTarget.id == 1) {
  189. // wx.switchTab({
  190. // url: '../swkz/index',
  191. // success: function (res) { },
  192. // fail: function (res) { },
  193. // complete: function (res) { },
  194. // })
  195. // }
  196. // else {
  197. this.setData({
  198. exhibitionList: [],
  199. activeIndex: e.currentTarget.id,
  200. tag: e.currentTarget.dataset.tag,
  201. currentPage: 1
  202. });
  203. this.getList(1);
  204. // }
  205. },
  206. onShareAppMessage: function () {
  207. },
  208. to_pay: function (e) {
  209. // console.log('dwdwdw', e.currentTarget.dataset)
  210. let { url, pagetype, urltype, hasproduct, haspay } = e.currentTarget.dataset;
  211. app.globalData.currentUrl = url
  212. console.log('dwdwdw', app.globalData.currentUrl)
  213. // console.log('dwdwdwd',wx.getStorageSync('url'))
  214. switch (urltype) {
  215. case 0:
  216. wx.navigateTo({
  217. url: `../wv_page/index`,
  218. success: function (res) { },
  219. fail: function (res) { },
  220. complete: function (res) { },
  221. })
  222. break;
  223. case 1:
  224. switch (pagetype) {
  225. case 0:
  226. wx.navigateTo({
  227. url: `../cg_detail/index?id=${url}`,
  228. success: function (res) { },
  229. fail: function (res) { },
  230. complete: function (res) { },
  231. })
  232. break;
  233. case 1:
  234. if (hasproduct) {
  235. wx.navigateTo({
  236. url: `./pay_page/index?id=${url}`,
  237. success: function (res) { },
  238. fail: function (res) { },
  239. complete: function (res) { },
  240. })
  241. } else {
  242. wx.navigateTo({
  243. url: `../zl_detail/index?id=${url}`,
  244. success: function (res) { },
  245. fail: function (res) { },
  246. complete: function (res) { },
  247. })
  248. }
  249. break;
  250. default:
  251. break;
  252. }
  253. break;
  254. default:
  255. break;
  256. }
  257. // let { url } = e.currentTarget.dataset;
  258. // app.globalData.currentUrl = url
  259. // console.log('dwdwdw', app.globalData.currentUrl)
  260. // // console.log('dwdwdwd',wx.getStorageSync('url'))
  261. // if (String(url).indexOf('http')>-1){
  262. // wx.navigateTo({
  263. // url: `../wv_page/index`,
  264. // success: function (res) { },
  265. // fail: function (res) { },
  266. // complete: function (res) { },
  267. // })
  268. // }else{
  269. // wx.navigateTo({
  270. // url: `../zl_detail/index?id=${url}`,
  271. // success: function (res) { },
  272. // fail: function (res) { },
  273. // complete: function (res) { },
  274. // })
  275. // }
  276. }
  277. })