score.js 1.9 KB

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