exchange.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. list: [],
  9. tab_index: 1,
  10. virtcard_publish: ''
  11. },
  12. listPage: 1,
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. this.getData();
  18. },
  19. getData: function () {
  20. app.util.ProReq('virtualcard.index', {}).then(res => {
  21. let { virtcard_publish } = res.data;
  22. this.setData({
  23. virtcard_publish
  24. })
  25. })
  26. },
  27. preFormSubmit: function(e) {
  28. wx.showLoading();
  29. this.formSubmit(e);
  30. },
  31. formSubmit: util.debounce(function(e) {
  32. console.log('form发生了submit事件,携带数据为:', e[0].detail.value)
  33. let token = wx.getStorageSync('token');
  34. let code_sn = e[0].detail.value.code;
  35. app.util.ProReq('virtualcard.subCodeSn', { token, code_sn }).then(res => {
  36. app.util.message(res.message || '兑换成功', '', 'error');
  37. }).catch(err => {
  38. console.log(err)
  39. err.code==1&&app.util.message(err.message || '请先登录', 'switchTo:/lionfish_comshop/pages/user/me', 'error');
  40. err.code==2&&app.util.message(err.message || '兑换失败,请重试', '', 'error');
  41. })
  42. }),
  43. tabchange: function (e) {
  44. var index = e.currentTarget.dataset.index;
  45. this.listPage = 1;
  46. this.setData({
  47. list: [],
  48. tab_index: index
  49. })
  50. if(index==2) {
  51. this.getList();
  52. }
  53. },
  54. getList() {
  55. let _this = this;
  56. let token = wx.getStorageSync('token');
  57. let data = {
  58. token,
  59. pageNum: _this.listPage
  60. };
  61. wx.showLoading();
  62. app.util.ProReq('virtualcard.loadUseRecord', data)
  63. .then(res => {
  64. _this.listLoading = false;
  65. wx.stopPullDownRefresh();
  66. let h = {};
  67. if (_this.listPage == 1) {
  68. h.list = res.data;
  69. res.data.length==0?(h.noData=true):'';
  70. } else {
  71. h.list = [..._this.data.list, ...res.data];
  72. }
  73. if (res.data.length > 0) {
  74. _this.listPage += 1;
  75. } else {
  76. _this.listPage = 0;
  77. }
  78. if(res.data.length < 10) {
  79. h.noMore = true;
  80. }
  81. this.setData(h);
  82. wx.hideLoading();
  83. })
  84. .catch(err => {
  85. wx.hideLoading();
  86. if(err.code==1) {
  87. app.util.message(err.message || '请先登录', 'switchTo:/lionfish_comshop/pages/user/me', 'error');
  88. } else {
  89. let h = {};
  90. _this.listPage==1?(h.noData=true):'';
  91. this.setData({
  92. listLoading: false,
  93. noMore: true,
  94. ...h,
  95. })
  96. }
  97. wx.stopPullDownRefresh();
  98. });
  99. },
  100. /**
  101. * 页面相关事件处理函数--监听用户下拉动作
  102. */
  103. onPullDownRefresh: function () {
  104. },
  105. /**
  106. * 页面上拉触底事件的处理函数
  107. */
  108. onReachBottom: function () {
  109. if(!this.data.noData&&!this.data.noMore) {
  110. this.getList();
  111. }
  112. },
  113. handleRuleModal() {
  114. this.setData({
  115. showRulesPopup: !this.data.showRulesPopup
  116. })
  117. }
  118. })