community.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. },
  52. toCommunityMessage() {
  53. if (this.data.info.count == 0) {
  54. toast('没有更多消息哦')
  55. return;
  56. }
  57. Route.toCommunityMessage();
  58. },
  59. async requestData() {
  60. let res = await Api.getTrainList({
  61. pageNum: this.pageNum,
  62. pageSize: this.pageSize
  63. });
  64. res.data.rows.forEach(item => {
  65. if (item.attachmentUrlList && item.attachmentType == uploadResTypes.IMAGE) {
  66. let attachmentUrlList = item.attachmentUrlList || [];
  67. item.attachmentUrlList = attachmentUrlList.map(item => {
  68. return {
  69. url: item,
  70. isImage: true
  71. }
  72. })
  73. item.createTime = formatTime(item.createTime);
  74. }
  75. })
  76. return res;
  77. }
  78. })