couponGoods.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. coupon: '',
  9. goodsList: [],
  10. couponId: 0,
  11. addressInfo: {}
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. if (options.id) {
  18. this.setData({
  19. couponId: options.id
  20. })
  21. }
  22. var addressInfo = wx.getStorageSync("addressInfo");
  23. if (addressInfo) {
  24. this.setData({
  25. addressInfo: addressInfo
  26. })
  27. this.getGoodsList();
  28. }
  29. },
  30. getGoodsList: function () {
  31. var that = this;
  32. util.request(api.GoodsCoupon, {
  33. id: that.data.couponId,
  34. // shopId: that.data.addressInfo.shopId,
  35. city: that.data.addressInfo.city
  36. })
  37. .then(function (res) {
  38. if (res.errno === 0) {
  39. that.setData({
  40. goodsList: res.data.list,
  41. coupon: res.data.coupon
  42. });
  43. if (res.data.list.length == 0)
  44. wx.navigateTo({
  45. url: '/pages/goods/goods?id=' + res.data.list[0].id,
  46. })
  47. }
  48. });
  49. },
  50. /**
  51. * 生命周期函数--监听页面初次渲染完成
  52. */
  53. onReady: function () {
  54. },
  55. /**
  56. * 生命周期函数--监听页面显示
  57. */
  58. onShow: function () {
  59. },
  60. /**
  61. * 生命周期函数--监听页面隐藏
  62. */
  63. onHide: function () {
  64. },
  65. /**
  66. * 生命周期函数--监听页面卸载
  67. */
  68. onUnload: function () {
  69. },
  70. /**
  71. * 页面相关事件处理函数--监听用户下拉动作
  72. */
  73. onPullDownRefresh: function () {
  74. },
  75. /**
  76. * 页面上拉触底事件的处理函数
  77. */
  78. onReachBottom: function () {
  79. },
  80. /**
  81. * 用户点击右上角分享
  82. */
  83. onShareAppMessage: function () {
  84. }
  85. })