community.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import Api from "../../model/api";
  2. import {formatTime, getEventParam, toast} from "../../utils/utils";
  3. import {communityDetailTypes, logicStatus, uploadResTypes} from "../../model/enum";
  4. import Route from "../../model/route";
  5. const app = getApp();
  6. app.Base({
  7. data: {
  8. blur: '',
  9. info: {
  10. trains: 0,
  11. focus: 0,
  12. examples: 0,
  13. count: 0,
  14. },
  15. show: false,
  16. },
  17. async onLoad() {
  18. const data = await Api.getTrainIndex(true);
  19. this.setData({
  20. info: data.data
  21. })
  22. },
  23. async onPullDownRefresh() {
  24. const data = await Api.getTrainIndex(true);
  25. this.setData({
  26. info: data.data
  27. })
  28. },
  29. publishInfo() {
  30. this.setData({
  31. show: true,
  32. blur: 'community-content',
  33. })
  34. },
  35. onClickHide() {
  36. this.setData({
  37. show: false,
  38. blur: '',
  39. })
  40. },
  41. onHandlePublish(e) {
  42. const isSuccess = getEventParam(e, "isSuccess");
  43. if (isSuccess) {
  44. this.onPullDownRefresh();
  45. }
  46. },
  47. toDetail(e) {
  48. const res = getEventParam(e, "res");
  49. Route.tocCommunityDetail(communityDetailTypes.COMMUNITY, "详细", res.id, res.trainType,
  50. "", "", logicStatus.NO, {
  51. comment: () => {
  52. this.onPullDownRefresh();
  53. }
  54. });
  55. },
  56. toCommunityMessage() {
  57. if (this.data.info.count == 0) {
  58. toast('没有更多消息哦')
  59. return;
  60. }
  61. Route.toCommunityMessage();
  62. },
  63. async requestData() {
  64. let res = await Api.getTrainList({
  65. pageNum: this.pageNum,
  66. pageSize: this.pageSize
  67. });
  68. res.data.rows.forEach(item => {
  69. if (item.attachmentUrlList && item.attachmentType == uploadResTypes.IMAGE) {
  70. let attachmentUrlList = item.attachmentUrlList || [];
  71. item.attachmentUrlList = attachmentUrlList.map(item => {
  72. return {
  73. url: item,
  74. isImage: true
  75. }
  76. })
  77. item.createTime = formatTime(item.createTime);
  78. }
  79. })
  80. return res;
  81. }
  82. })