grouponPreList.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. code: '',
  8. status: 0,
  9. page: 1,
  10. limit: 20,
  11. count: 0,
  12. scrollTop: 0,
  13. showPage: false,
  14. currentType: 0,
  15. totalList: []
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. },
  22. /**
  23. * 生命周期函数--监听页面显示
  24. */
  25. onShow: function () {
  26. if (app.globalData.hasLogin) {
  27. this.getCouponList(false);
  28. }
  29. },
  30. /**
  31. * 生命周期函数--监听页面初次渲染完成
  32. */
  33. onReady: function () {
  34. },
  35. /**
  36. * 生命周期函数--监听页面隐藏
  37. */
  38. onHide: function () {
  39. },
  40. /**
  41. * 生命周期函数--监听页面卸载
  42. */
  43. onUnload: function () {
  44. },
  45. goCouponList(e){
  46. let id = e.currentTarget.dataset.id;
  47. if (!app.globalData.hasLogin) {
  48. wx.navigateTo({
  49. url: "/pages/auth/login/login",
  50. })
  51. return;
  52. }
  53. wx.navigateTo({
  54. url: '/pages/ucenter/couponList/couponList',
  55. })
  56. },
  57. goService(e) {
  58. let id = e.currentTarget.dataset.id;
  59. if (!app.globalData.hasLogin) {
  60. wx.navigateTo({
  61. url: "/pages/auth/login/login",
  62. })
  63. return;
  64. }
  65. wx.navigateTo({
  66. url: '/pages/ucenter/couponList/couponList?type=1&coupon='+id,
  67. })
  68. },
  69. /**
  70. * 页面相关事件处理函数--监听用户下拉动作
  71. */
  72. onPullDownRefresh() {
  73. wx.showNavigationBarLoading() //在标题栏中显示加载
  74. this.getCouponList();
  75. wx.hideNavigationBarLoading() //完成停止加载
  76. wx.stopPullDownRefresh() //停止下拉刷新
  77. },
  78. /**
  79. * 页面上拉触底事件的处理函数
  80. */
  81. onReachBottom: function () {
  82. },
  83. /**
  84. * 用户点击右上角分享
  85. */
  86. onShareAppMessage: function () {
  87. },
  88. getCouponList: function (hasMobile) {
  89. if (hasMobile!=false&&this.data.code.length != 11) {
  90. util.showErrorToast("请输入正确手机号");
  91. return;
  92. }
  93. let that = this;
  94. that.setData({
  95. scrollTop: 0,
  96. showPage: false,
  97. couponList: []
  98. });
  99. util.request(api.CouponPre, {
  100. mobile: that.data.code
  101. }).then(function (res) {
  102. if (res.errno === 0) {
  103. that.setData({
  104. scrollTop: 0,
  105. couponList: res.data
  106. });
  107. wx.showToast({
  108. title: "查询成功",
  109. duration: 2000
  110. })
  111. }
  112. });
  113. },
  114. bindExchange: function (e) {
  115. this.setData({
  116. code: e.detail.value
  117. });
  118. },
  119. clearExchange: function () {
  120. this.setData({
  121. code: ''
  122. });
  123. },
  124. nextPage: function (event) {
  125. var that = this;
  126. if (this.data.page > that.data.count / that.data.limit) {
  127. return true;
  128. }
  129. that.setData({
  130. page: that.data.page + 1,
  131. currentType: 0
  132. });
  133. this.getCouponList();
  134. },
  135. prevPage: function (event) {
  136. if (this.data.page <= 1) {
  137. return false;
  138. }
  139. var that = this;
  140. that.setData({
  141. page: that.data.page - 1,
  142. currentType: 0
  143. });
  144. this.getCouponList();
  145. },
  146. })