myCoupons.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // pages/myCoupons/myCoupons.js
  2. const { default: activity } = require("../../api/activity");
  3. const util = require('../../utils/util.js');
  4. const app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. couponList:[], //我的卡券列表
  11. nextPage:1,
  12. pageSize:12,
  13. mobile:'', //我的手机号
  14. totalPage:1, //总页码
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. //获取我的卡券列表 api/supers/coupon/sn-list-member
  21. let _self = this;
  22. if(options.mobile) {
  23. _self.setData({
  24. mobile:options.mobile
  25. })
  26. }
  27. _self.getSnListMember();
  28. },
  29. //获取我的券列表
  30. async getSnListMember(step='init') {
  31. let _self = this;
  32. let nextPage = _self.data.nextPage;
  33. let pageSize = _self.data.pageSize;
  34. let mobile = _self.data.mobile;
  35. let res =await activity.getSnListMember(nextPage,pageSize,mobile);
  36. let totalPage =Math.ceil(res.count/pageSize);
  37. _self.setData({
  38. totalPage:totalPage
  39. })
  40. let list =_self.handleList(res.list);
  41. if(step=='init') {
  42. _self.setData({
  43. couponList:list
  44. })
  45. } else if(step=='pull') {
  46. _self.setData({
  47. couponList:_self.data.couponList.concat(list),
  48. })
  49. }
  50. },
  51. /**
  52. * 处理数据
  53. */
  54. handleList(list) {
  55. list.map((item,key)=>{
  56. item.beignTime = util.format(item.beginTimestamp*1000);
  57. item.endTime = util.format(item.endTimestamp*1000);
  58. item.coupon.discount = item.coupon.type.value=='D'?item.coupon.discount/10:item.coupon.discount;
  59. item.isFree = item.coupon.type.value=='D'&& item.coupon.discount==0?true:false;
  60. })
  61. return list;
  62. },
  63. /**
  64. * 生命周期函数--监听页面初次渲染完成
  65. */
  66. onReady: function () {
  67. },
  68. /**
  69. * 生命周期函数--监听页面显示
  70. */
  71. onShow: function () {
  72. },
  73. /**
  74. * 生命周期函数--监听页面隐藏
  75. */
  76. onHide: function () {
  77. },
  78. /**
  79. * 生命周期函数--监听页面卸载
  80. */
  81. onUnload: function () {
  82. },
  83. /**
  84. * 页面相关事件处理函数--监听用户下拉动作
  85. */
  86. onPullDownRefresh: function () {
  87. },
  88. /**
  89. * 页面上拉触底事件的处理函数
  90. */
  91. onReachBottom: function () {
  92. let _self = this;
  93. let nextPage = _self.data.nextPage;
  94. let totalPage = _self.data.totalPage;
  95. if(nextPage>=totalPage) {
  96. app.showToast ('亲,到底了!');
  97. return;
  98. }
  99. _self.setData({
  100. nextPage:nextPage+1
  101. })
  102. _self.getSnListMember('pull')
  103. },
  104. /**
  105. * 使用券跳转小程序
  106. */
  107. goUseCoupon() {
  108. wx.navigateToMiniProgram({
  109. appId: 'wxd92a2d29f8022f40',
  110. path: 'pages/index/index',
  111. extraData: {
  112. foo: 'bar'
  113. },
  114. envVersion: 'develop',
  115. success(res) {
  116. // 打开成功
  117. }
  118. })
  119. },
  120. /**
  121. * 用户点击右上角分享
  122. */
  123. onShareAppMessage: function () {
  124. }
  125. })