index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // pages/welfareMall/couponFitFood/index.js
  2. import activity from '../../../api/activity'
  3. import {getColor} from '../../../utils/user'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. config: {},
  10. },
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad: async function (options) {
  15. console.log(options)
  16. if (!options.couponId) {
  17. wx.reLaunch({
  18. url: '/pages/welfareMall/index/index',
  19. })
  20. }
  21. this.data.couponId = options.couponId
  22. this.setData({
  23. couponName: decodeURIComponent(options.couponName),
  24. bindGoodsType: options.bindGoodsType
  25. })
  26. this.loadData()
  27. let info = await getColor();
  28. this.setData({
  29. config:info.config
  30. })
  31. },
  32. /**
  33. * 生命周期函数--监听页面初次渲染完成
  34. */
  35. onReady: function () {
  36. },
  37. /**
  38. * 生命周期函数--监听页面显示
  39. */
  40. onShow: function () {
  41. },
  42. /**
  43. * 生命周期函数--监听页面隐藏
  44. */
  45. onHide: function () {
  46. },
  47. /**
  48. * 生命周期函数--监听页面卸载
  49. */
  50. onUnload: function () {
  51. },
  52. /**
  53. * 页面相关事件处理函数--监听用户下拉动作
  54. */
  55. onPullDownRefresh: function () {
  56. },
  57. /**
  58. * 页面上拉触底事件的处理函数
  59. */
  60. onReachBottom: function () {
  61. },
  62. /**
  63. * 用户点击右上角分享
  64. */
  65. onShareAppMessage: function () {
  66. },
  67. loadData() {
  68. activity.getFoodListByCoupon({
  69. couponId: this.data.couponId,
  70. page: 1,
  71. pageSize: 10000,
  72. }).then(data => {
  73. if (data.code == 200) {
  74. this.dataMapToView(data.data)
  75. }
  76. }).catch(_ => {
  77. console.log(_)
  78. })
  79. },
  80. dataMapToView(data) {
  81. const foodList = []
  82. data.forEach(v => {
  83. foodList.push(v.foodName)
  84. })
  85. this.setData({
  86. foodList: foodList
  87. })
  88. }
  89. })