book.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import Api from "../../model/api";
  2. import {getDataSet, getEventParam} from "../../utils/utils";
  3. import Route from "../../model/route";
  4. const app = getApp();
  5. app.Base({
  6. data: {
  7. tabsList: [],
  8. active: 0,
  9. textbookClassify: 0,
  10. },
  11. async onLoad() {
  12. const res = await Api.getTextBookDict(true);
  13. let textbookClassify = 0;
  14. if (res.data[0]) {
  15. textbookClassify = res.data[0].dict_value;
  16. }
  17. this.data.textbookClassify = textbookClassify
  18. this.setData({
  19. tabsList: res.data,
  20. textbookClassify
  21. })
  22. this.selectComponent('#tabs').resize();
  23. },
  24. async onChange(e) {
  25. const index = getEventParam(e, 'index');
  26. const name = getEventParam(e, 'name');
  27. this.setData({active: index, textbookClassify: name}, async () => {
  28. this.changeResetData(this);
  29. })
  30. },
  31. toBookDetail(e) {
  32. const id = getDataSet(e, "id");
  33. Route.toBookDetail(id, this.data.tabsList[this.data.active].dict_label)
  34. },
  35. async requestData() {
  36. const res = await Api.getTextBookList(this.data.textbookClassify, {
  37. pageNum: this.pageNum,
  38. pageSize: this.pageSize
  39. });
  40. res.data.rows = res.data.rows.map(item => {
  41. return {
  42. ...item,
  43. cover: JSON.parse(item.textbook_pictures)[0],
  44. }
  45. });
  46. return res;
  47. },
  48. })