1
0

coupon.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. couponNumber: '',
  8. },
  9. bindCouponNumberInput: function (e) {
  10. this.setData({
  11. couponNumber: e.detail.value
  12. });
  13. },
  14. onLoad: function (options) {
  15. // 页面初始化 options为页面跳转所带来的参数
  16. this.getCouponList();
  17. },
  18. onReady: function () {
  19. },
  20. onShow: function () {
  21. },
  22. onHide: function () {
  23. // 页面隐藏
  24. },
  25. onUnload: function () {
  26. // 页面关闭
  27. },
  28. getCouponList () {
  29. let that = this;
  30. util.request(api.CouponList, { coupon_number: that.data.couponNumber}).then(function (res) {
  31. if (res.errno === 0) {
  32. that.setData({
  33. couponList: res.data
  34. });
  35. }
  36. });
  37. },
  38. exchangeCoupon() {
  39. var that = this;
  40. if (that.data.couponNumber.length == 0
  41. && that.data.couponNumber == '0') {
  42. wx.showModal({
  43. title: '错误信息',
  44. content: '优惠码不能为空',
  45. showCancel: false
  46. });
  47. return false;
  48. }
  49. util.request(api.CouponExchange, {
  50. coupon_number: that.data.couponNumber
  51. }, 'POST').then(function (res) {
  52. if (res.errno === 0) {
  53. wx.showToast({
  54. title: '兑换成功'
  55. });
  56. that.getCouponList();
  57. } else if (res.errno === 1) {
  58. util.showErrorToast(res.errmsg);
  59. }
  60. });
  61. },
  62. linkCoupon(event){
  63. let url = event.currentTarget.dataset.couponUrl;
  64. wx.switchTab({
  65. url: url,
  66. });
  67. }
  68. })