score.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import Api from "../../model/api";
  2. import {
  3. getEventParam
  4. } from "../../utils/utils";
  5. import Route from "../../model/route";
  6. import {
  7. videoTypes,
  8. htmlTypes
  9. } from "../../model/enum";
  10. const app = getApp();
  11. app.Base({
  12. dict: {
  13. "兑换课程": {
  14. method: Api.getNoScoreList,
  15. isComplete: false
  16. },
  17. "已兑换课程": {
  18. method: Api.getScoreList,
  19. isComplete: true
  20. },
  21. },
  22. title: '兑换课程',
  23. data: {
  24. scoreInfos: [],
  25. active: 0,
  26. isComplete: false,
  27. show: false,
  28. item: {},
  29. },
  30. async onLoad(options) {
  31. await this.init();
  32. },
  33. async init() {
  34. const data = await Api.getScoreInfo(true);
  35. this.setData({
  36. scoreInfos: data.data
  37. })
  38. },
  39. async onPullDownRefresh() {
  40. await this.init();
  41. },
  42. async pay(e) {
  43. await this.onPullDownRefresh();
  44. },
  45. async onChange(e) {
  46. this.title = getEventParam(e, "title");
  47. this.setData({
  48. isComplete: this.dict[this.title].isComplete
  49. }, async () => {
  50. await this.changeResetData(this);
  51. })
  52. },
  53. toDetail(e) {
  54. Route.toScoreDetail();
  55. },
  56. toRule() {
  57. Route.toIntegralRule(htmlTypes.INTEGRAL_RULE, "积分规则");
  58. },
  59. toNewsDetail(e) {
  60. let item = getEventParam(e, "item");
  61. this.setData({
  62. item: item,
  63. show: true
  64. })
  65. },
  66. async requestData() {
  67. let res = await this.dict[this.title].method({
  68. pageNum: this.pageNum,
  69. pageSize: this.pageSize
  70. });
  71. res.data.rows = res.data.rows.map(item => {
  72. let flag = this.data.scoreInfos.some(info => {
  73. return info.surplusValue >= item.score;
  74. })
  75. return {
  76. ...item,
  77. hasScore: flag,
  78. }
  79. });
  80. return res;
  81. },
  82. toVideo(e) {
  83. const item = getEventParam(e, "item");
  84. Route.toVideo(item.id, videoTypes.SCORE, "积分课")
  85. }
  86. })