communityDetail.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import Api from "../../model/api";
  2. import {formatTime, getEventParam, throttle, toast} from "../../utils/utils";
  3. import {communityDetailTypes, logicStatus, uploadResTypes} from "../../model/enum";
  4. const app = getApp();
  5. app.Base({
  6. data: {
  7. newData: {},
  8. item: {},
  9. uploadResTypesEnum: uploadResTypes,
  10. logicStatusEnum: logicStatus,
  11. trainType: '',
  12. type: '',
  13. id: '',
  14. title: '',
  15. isPre: 0,
  16. },
  17. async onLoad(options) {
  18. let {title, type, id, trainType, isPre, detail, item} = options;
  19. this.data.type = type;
  20. if (type == communityDetailTypes.COMMUNITY) {
  21. await this.handleCommunity(id, trainType)
  22. } else if (type == communityDetailTypes.CLASS) {
  23. let newData = JSON.parse(detail)
  24. item = JSON.parse(item)
  25. this.setData({
  26. id: newData.id, title, type,
  27. newData, isPre, item
  28. })
  29. }
  30. wx.setNavigationBarTitle({title})
  31. },
  32. reply: throttle(async function (e) {
  33. const messagDes = getEventParam(e, "msg");
  34. if (!messagDes.trim()) {
  35. toast("请输入评论")
  36. return
  37. }
  38. if (this.data.type == communityDetailTypes.COMMUNITY) {
  39. await Api.ReleaseComment({
  40. content: messagDes,
  41. trainType: this.data.trainType,
  42. parentId: this.data.id
  43. }, true)
  44. } else if (this.data.type == communityDetailTypes.CLASS) {
  45. await Api.addInteractionComment({
  46. parentId: this.data.id,
  47. content: messagDes,
  48. stuId: this.data.item.eduStuId,
  49. stuName: this.data.item.eduStuName,
  50. }, true);
  51. }
  52. const eventChannel = this.getOpenerEventChannel()
  53. eventChannel.emit('comment');
  54. this.selectComponent('.bottom-reply').clear();
  55. await this.resetData(this);
  56. // this.pageScrollToBottom();
  57. }),
  58. async requestData() {
  59. let res;
  60. if (this.data.type == communityDetailTypes.COMMUNITY) {
  61. res = await Api.getMyComment({
  62. trainType: this.data.trainType,
  63. parentId: this.data.id,
  64. pageNum: this.pageNum,
  65. pageSize: this.pageSize
  66. });
  67. } else if (this.data.type == communityDetailTypes.CLASS) {
  68. res = await Api.getinteractionCommentList({
  69. parentId: this.data.id,
  70. pageNum: this.pageNum,
  71. pageSize: this.pageSize
  72. });
  73. }
  74. res.data.rows = res.data.rows.map(item => {
  75. if (item.cAttachmentUrlList && item.cAttachmentType == uploadResTypes.IMAGE) {
  76. item.cAttachmentUrlList = item.cAttachmentUrlList || [];
  77. item.cAttachmentUrlList = item.cAttachmentUrlList.map(item => {
  78. return {
  79. url: item,
  80. isImage: true
  81. }
  82. });
  83. }
  84. return {
  85. coverImg: item.stuPic || item.picUrl || item.managePic,
  86. messageName: item.stuName || item.manageName,
  87. time: formatTime(item.createTime),
  88. messagDes: item.content,
  89. cAttachmentUrlList: item.cAttachmentUrlList,
  90. cAttachmentType: item.cAttachmentType
  91. }
  92. })
  93. return res;
  94. },
  95. play(e) {
  96. wx.createVideoContext("myVideo").pause()
  97. },
  98. pageScrollToBottom() {
  99. wx.createSelectorQuery().select('.content').boundingClientRect(function (rect) {
  100. wx.pageScrollTo({
  101. scrollTop: rect.bottom
  102. })
  103. }).exec()
  104. },
  105. async handleCommunity(id, trainType) {
  106. const res = await Api.getTrainListDetail({
  107. id,
  108. trainType
  109. }, true);
  110. if (res.data.attachmentUrlList && res.data.attachmentType == uploadResTypes.IMAGE) {
  111. res.data.attachmentUrlList = res.data.attachmentUrlList || [];
  112. res.data.attachmentUrlList = res.data.attachmentUrlList.map(item => {
  113. return {
  114. url: item,
  115. isImage: true
  116. }
  117. });
  118. }
  119. this.data.trainType = trainType;
  120. this.data.id = id;
  121. this.setData({
  122. trainType: trainType,
  123. id: id,
  124. newData: res.data
  125. })
  126. },
  127. })