coupon.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. var app = getApp();
  4. Page({
  5. data: {
  6. couponList: []
  7. },
  8. onLoad: function (options) {
  9. // 页面初始化 options为页面跳转所带来的参数
  10. this.getCouponList();
  11. },
  12. onReady: function () {
  13. // 页面渲染完成
  14. },
  15. onShow: function () {
  16. // 页面显示
  17. },
  18. getCouponList() {
  19. let that = this;
  20. util.request(api.CartCouponList).then(function (res) {
  21. if (res.errno === 0) {
  22. that.setData({
  23. couponList: res.data
  24. });
  25. }
  26. });
  27. },
  28. selectCoupon(event) {
  29. let that = this;
  30. let userCouponId = event.currentTarget.dataset.userCouponId;
  31. //
  32. let couponItem;
  33. for(var i=0;i< that.data.couponList.length;i++){
  34. if (that.data.couponList[i].id == userCouponId){
  35. couponItem = that.data.couponList[i];
  36. }
  37. }
  38. if(couponItem.enabled==0){
  39. wx.showModal({
  40. title: '提示',
  41. showCancel:false,
  42. content: '此优惠券不可用',
  43. success: function(res) {
  44. }
  45. })
  46. return false;
  47. }
  48. //
  49. var pages = getCurrentPages();
  50. var prevPage = pages[pages.length - 2]; //上一个页面
  51. //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
  52. prevPage.setData({
  53. checkedCoupon: couponItem,
  54. userCouponId: userCouponId
  55. })
  56. wx.navigateBack();
  57. },
  58. onHide: function () {
  59. // 页面隐藏
  60. },
  61. onUnload: function () {
  62. // 页面关闭
  63. }
  64. })