index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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.templateList.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.templateList[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. })