giftBag.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import {get} from '../../../utils/http'
  2. Page({
  3. data: {
  4. moveBottom: {}, //打开盒子动画
  5. moveBack: {}, //关闭盒子动画
  6. animationIndex: 5, //活动动画下标
  7. animationStatus: [false, false, false, false], //盒子状态
  8. giftBagList: [], //礼包商品列表
  9. },
  10. onLoad() {
  11. // 获取礼包列表
  12. this.getGiftBagList()
  13. },
  14. // 打开盒子
  15. moveBottomFun() {
  16. var moveBottom = wx.createAnimation({
  17. transformOrigin: "50% 50%",
  18. duration: 1000,
  19. timingFunction: "ease",
  20. delay: 0
  21. })
  22. moveBottom.translateY(-120).step()
  23. this.setData({
  24. moveBottom: moveBottom.export(),
  25. })
  26. },
  27. // 关闭盒子
  28. moveBackFun() {
  29. var moveBack = wx.createAnimation({
  30. transformOrigin: "50% 50%",
  31. duration: 1000,
  32. timingFunction: "ease",
  33. delay: 0
  34. })
  35. moveBack.translateY(0).step()
  36. this.setData({
  37. moveBack: moveBack.export(),
  38. })
  39. },
  40. // 执行盒子动画
  41. openAnimations(e) {
  42. let index = e.currentTarget.dataset.index
  43. this.setData({
  44. animationIndex: index
  45. })
  46. if (this.data.animationStatus[index]) {
  47. this.moveBackFun()
  48. } else {
  49. this.moveBottomFun()
  50. }
  51. },
  52. // 动画结束时执行
  53. transitionend(e) {
  54. let index = e.currentTarget.dataset.index
  55. let animationStatus = `animationStatus[${index}]`
  56. this.setData({
  57. [animationStatus]: this.data.animationStatus[index] ? false : true,
  58. moveBack: {},
  59. moveBottom: {}
  60. })
  61. },
  62. // 获取圣诞礼包列表
  63. getGiftBagList() {
  64. get('v2/api/package/list', {}, (res => {
  65. if (res.code == 200) {
  66. this.setData({
  67. giftBagList: res.data.list
  68. })
  69. }
  70. }))
  71. },
  72. // 获取礼包详情
  73. getGiftBagDetail(id) {
  74. get('v2/api/package/info', {
  75. id
  76. }, (res => {
  77. let falg = false
  78. res.data.items.forEach(item => {
  79. if (item.type == 2) {
  80. falg = true
  81. }
  82. })
  83. // 判断是否有需要选规格的产品
  84. if (falg) {
  85. wx.navigateTo({
  86. url: `/subPackagesE/pages/giftBagSize/giftBagSize?id=${id}`,
  87. })
  88. } else {
  89. let selectGiftList = []
  90. res.data.items.forEach(item => {
  91. item.goods_list.forEach(itemA => {
  92. let list = {}
  93. list.item_id = item.id
  94. list.goods_id = itemA.id
  95. list.num = 1
  96. list.goods_name = itemA.goods_name
  97. list.cover_url = itemA.cover_url
  98. selectGiftList.push(list)
  99. })
  100. })
  101. wx.navigateTo({
  102. url: `/subPackagesE/pages/giftBagOrder/giftBagOrder?giftID=${id}&&productList=${JSON.stringify(selectGiftList)}`,
  103. })
  104. }
  105. console.log(res);
  106. }))
  107. },
  108. // 去购买
  109. goShopping(e) {
  110. let index = e.currentTarget.dataset.index
  111. let id = this.data.giftBagList[index].id
  112. this.getGiftBagDetail(id)
  113. }
  114. })