index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { fetchCouponList } from '../../../services/coupon/index';
  2. Page({
  3. data: {
  4. status: 0,
  5. list: [
  6. {
  7. text: '可使用',
  8. key: 0,
  9. },
  10. {
  11. text: '已使用',
  12. key: 1,
  13. },
  14. {
  15. text: '已失效',
  16. key: 2,
  17. },
  18. ],
  19. couponList: [],
  20. },
  21. onLoad() {
  22. this.init();
  23. },
  24. init() {
  25. this.fetchList();
  26. },
  27. fetchList(status = this.data.status) {
  28. let statusInFetch = '';
  29. switch (Number(status)) {
  30. case 0: {
  31. statusInFetch = 'default';
  32. break;
  33. }
  34. case 1: {
  35. statusInFetch = 'useless';
  36. break;
  37. }
  38. case 2: {
  39. statusInFetch = 'disabled';
  40. break;
  41. }
  42. default: {
  43. throw new Error(`unknown fetchStatus: ${statusInFetch}`);
  44. }
  45. }
  46. fetchCouponList(statusInFetch).then((couponList) => {
  47. this.setData({ couponList });
  48. });
  49. },
  50. tabChange(e) {
  51. const { value } = e.detail;
  52. this.setData({ status: value });
  53. this.fetchList(value);
  54. },
  55. goCouponCenterHandle() {
  56. wx.showToast({ title: '去领券中心', icon: 'none' });
  57. },
  58. onPullDownRefresh_() {
  59. this.setData(
  60. {
  61. couponList: [],
  62. },
  63. () => {
  64. this.fetchList();
  65. },
  66. );
  67. },
  68. });