index.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import {
  2. getActivityList
  3. } from '~/api/activity'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. banner: '',
  10. cardActivityList: [],
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad(options) {
  16. this.getActivityList()
  17. },
  18. async getActivityList() {
  19. let {
  20. banner,
  21. cardActivityList
  22. } = await getActivityList()
  23. cardActivityList.forEach(item => {
  24. item.currentIndex = 0
  25. })
  26. console.log(cardActivityList);
  27. this.setData({
  28. cardActivityList,
  29. banner
  30. })
  31. },
  32. // 换一换
  33. changeTemplate({
  34. currentTarget
  35. }) {
  36. let index = currentTarget.dataset.index
  37. let item = currentTarget.dataset.item
  38. let nextIndex = item.currentIndex
  39. if (item.currentIndex < item.templateTypeList.length - 1) {
  40. nextIndex = ++item.currentIndex
  41. } else {
  42. nextIndex = 0
  43. }
  44. this.setData({
  45. [`cardActivityList[${index}].currentIndex`]: nextIndex
  46. })
  47. },
  48. toRecording({
  49. currentTarget
  50. }) {
  51. let index = currentTarget.dataset.index
  52. let target = this.data.cardActivityList[index]
  53. let id = target.templateTypeList[target.currentIndex].id
  54. wx.navigateTo({
  55. url: `/pages/activityDet/index?id=${id}`,
  56. })
  57. },
  58. jumpMyGreeing() {
  59. wx.navigateTo({
  60. url: '/pages/greeting/index',
  61. })
  62. },
  63. })