index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // index.js
  2. let myPro = require("../../../utils/wxRequest.js");
  3. let util = require("../../../utils/util.js");
  4. Page({
  5. data: {
  6. couponBg: "/statics/img/quan_bg_tu.png",
  7. couponUnBg: "/statics/img/quan_un_bg_tu.png",
  8. status: -1,
  9. page: 1,
  10. size: 10,
  11. dataList: [],
  12. finished: false,
  13. loading: false
  14. },
  15. onLoad: function (options) {
  16. // Do some initialize when page load.
  17. let that = this;
  18. that.setData({
  19. couponBg: "data:image/png;base64," + wx.getFileSystemManager().readFileSync(that.data.couponBg, "base64"),
  20. couponUnBg: "data:image/png;base64," + wx.getFileSystemManager().readFileSync(that.data.couponUnBg, "base64"),
  21. });
  22. // 获取列表
  23. that.getDataList();
  24. },
  25. onShow: function () {
  26. // Do something when page show.
  27. let that = this;
  28. },
  29. onReady: function () {
  30. // Do something when page ready.
  31. },
  32. onHide: function () {
  33. // Do something when page hide.
  34. },
  35. onUnload: function () {
  36. // Do something when page close.
  37. },
  38. onPullDownRefresh: function () {
  39. // Do something when pull down.
  40. },
  41. onReachBottom: function () {
  42. // Do something when page reach bottom.
  43. let that = this;
  44. if(!that.data.finished){
  45. that.getDataList();
  46. };
  47. },
  48. onPageScroll: function () {
  49. // Do something when page scroll
  50. },
  51. onResize: function () {
  52. // Do something when page resize
  53. },
  54. // 切换tab
  55. onChange(event){
  56. let that = this;
  57. that.setData({
  58. status: event.detail.name,
  59. page: 1,
  60. dataList: [],
  61. finished: false
  62. });
  63. that.getDataList();
  64. },
  65. // 获取列表
  66. getDataList(){
  67. let that = this;
  68. let data = {
  69. status: that.data.status,
  70. page: that.data.page,
  71. size: that.data.size
  72. };
  73. myPro.wxRequest("user/v2/usercoupon/list","GET",data).then(res=>{
  74. let list = res.result;
  75. // 无数据
  76. if(list.length == 0){
  77. wx.showToast({
  78. title: "暂无更多数据",
  79. icon: "none",
  80. });
  81. that.setData({
  82. finished: true
  83. });
  84. }else{
  85. // 判断可用状态的券是否过期(在争取后台返回,尚未同意)
  86. for(let i in list){
  87. if(list[i].status == 1){
  88. let due_time = list[i].due_time;
  89. if(new Date().getTime() > new Date(due_time.replace(/-/g, "/")+" 24:00:00").getTime()){
  90. list[i].status = 0;
  91. }
  92. }
  93. };
  94. that.setData({
  95. dataList: that.data.dataList.concat(list),
  96. page: that.data.page + 1
  97. });
  98. }
  99. }).catch(err=>{
  100. console.log('错误信息',err)
  101. wx.showToast({
  102. title: err,
  103. icon: "none",
  104. });
  105. })
  106. },
  107. // 去买商品
  108. goGoodsIndex(){
  109. let that = this;
  110. wx.reLaunch({
  111. url: "/pages/goods/index"
  112. });
  113. }
  114. });