communityDetail.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 = options.title;
  19. let type = options.type;
  20. this.data.type = type;
  21. if (type == communityDetailTypes.COMMUNITY) {
  22. await this.handleCommunity(options.id, options.trainType)
  23. } else if (type == communityDetailTypes.CLASS) {
  24. let isPre = options.isPre;
  25. let newData = JSON.parse(options.detail)
  26. let item = JSON.parse(options.item)
  27. this.setData({
  28. id: newData.id, title, type,
  29. newData, isPre, item
  30. })
  31. }
  32. wx.setNavigationBarTitle({title: options.title})
  33. },
  34. reply: throttle(async function (e) {
  35. const messagDes = getEventParam(e, "msg");
  36. if (!messagDes.trim()) {
  37. toast("请输入评论")
  38. return
  39. }
  40. if (this.data.type == communityDetailTypes.COMMUNITY) {
  41. await Api.ReleaseComment({
  42. content: messagDes,
  43. trainType: this.data.trainType,
  44. parentId: this.data.id
  45. }, true)
  46. } else if (this.data.type == communityDetailTypes.CLASS) {
  47. await Api.addInteractionComment({
  48. parentId: this.data.id,
  49. content: messagDes,
  50. stuId: this.data.item.eduStuId,
  51. stuName: this.data.item.eduStuName,
  52. }, true);
  53. }
  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. const id = getEventParam(e, "id");
  97. if (id) {
  98. let videoId = id.replace('myVideo', '');
  99. for (let i = 0; i < this.data.rows.length; i++) {
  100. if (videoId != i) {
  101. this.selectComponent(`#list${i}`).pauseVideo(i)
  102. }
  103. }
  104. wx.createVideoContext("myVideo").pause()
  105. } else {
  106. for (let i = 0; i < this.data.rows.length; i++) {
  107. this.selectComponent(`#list${i}`).pauseVideo(i)
  108. }
  109. }
  110. },
  111. pageScrollToBottom() {
  112. wx.createSelectorQuery().select('.content').boundingClientRect(function (rect) {
  113. wx.pageScrollTo({
  114. scrollTop: rect.bottom
  115. })
  116. }).exec()
  117. },
  118. async handleCommunity(id, trainType) {
  119. const res = await Api.getTrainListDetail({
  120. id,
  121. trainType
  122. }, true);
  123. if (res.data.attachmentUrlList && res.data.attachmentType == uploadResTypes.IMAGE) {
  124. res.data.attachmentUrlList = res.data.attachmentUrlList || [];
  125. res.data.attachmentUrlList = res.data.attachmentUrlList.map(item => {
  126. return {
  127. url: item,
  128. isImage: true
  129. }
  130. });
  131. }
  132. this.data.trainType = trainType;
  133. this.data.id = id;
  134. this.setData({
  135. trainType: trainType,
  136. id: id,
  137. newData: res.data
  138. })
  139. },
  140. })