replyDetail.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import httpRequestApi from '../../../utils/APIClient';
  2. import {
  3. formatDate
  4. } from '../../../utils/util';
  5. Page({
  6. data: {
  7. class1: 'commentItem commentItemFirst',
  8. classNormal: 'commentItem',
  9. postId: '',
  10. comment: [],
  11. replyInfo: '',
  12. count: ''
  13. },
  14. onLoad: function (option) {
  15. console.log(option)
  16. this.setData({
  17. postId: option.id,
  18. // count: option.count === 'undefined' ? 0 : option.count
  19. })
  20. wx.setNavigationBarTitle({
  21. // title: option.count + '条回复' //页面标题为路由参数
  22. title: '回复详情' //页面标题为路由参数
  23. })
  24. this.uid = wx.getStorageSync('uid');
  25. this.getReplyDetail();
  26. },
  27. // 保存 回复的内容
  28. saveValue: function(e){
  29. this.setData({
  30. replyInfo: e.detail.value
  31. });
  32. },
  33. replyDone:function(){
  34. const data = {
  35. postsId: this.data.postId,
  36. content: encodeURI(this.data.replyInfo)
  37. }
  38. if(this.data.replyInfo){
  39. httpRequestApi.postReplyComment(this.uid, data).success(res => {
  40. this.setData({
  41. replyModal: false,
  42. replyInfo: ''
  43. });
  44. this.getReplyDetail();//更新 变化后的 replyTemp。
  45. });
  46. }
  47. },
  48. // 查询回复详情
  49. getReplyDetail: function () {
  50. // let uid = wx.getStorageSync('uid');
  51. httpRequestApi.getReplyComment(this.uid, this.data.postId).success((res) => {
  52. console.log(res);
  53. const replyList = res.data.data.replyVOList;
  54. const replied = res.data.data;
  55. const replyTemp = [];
  56. const authorDetail = {};
  57. authorDetail.name = replied.user.wechatName;
  58. authorDetail.text = decodeURI(replied.detailDesc);
  59. authorDetail.time = formatDate(replied.gmtModified,3);
  60. authorDetail.likes = replied.postsAttributeInfo.favors;
  61. authorDetail.avatar = replied.user.avatar;
  62. replyTemp.push(authorDetail);
  63. replyList.forEach(item => {
  64. const temp = {};
  65. temp.name = item.user.wechatName;
  66. temp.text = decodeURI(item.content);
  67. temp.time = formatDate(item.gmtModified,3);
  68. temp.likes = 0;
  69. temp.id = item.postId;
  70. temp.avatar = item.user.avatar;
  71. replyTemp.push(temp);
  72. console.log(replyTemp);
  73. });
  74. this.setData({
  75. comment: replyTemp,
  76. count: replied.replyCount
  77. })
  78. });
  79. },
  80. // 点赞评论
  81. likeCommend: function (e) {
  82. console.log(e);
  83. // let uid = wx.getStorageSync('uid');
  84. let followUid = e.currentTarget.dataset.id;
  85. let index = e.currentTarget.dataset.index;
  86. httpRequestApi.likeCommend(this.uid, followUid).success(res => {
  87. console.log(res);
  88. const str = `comment[${index}].likes`;
  89. this.setData({
  90. [str]: res.data.data.favors
  91. })
  92. });
  93. },
  94. // 设置点击时的id
  95. setSBId: function (e) {
  96. console.log(e)
  97. this.setData({
  98. // replySBId: e.currentTarget.dataset.id,
  99. replyModal: true
  100. })
  101. },
  102. // 回复某个评论
  103. replySB: function () {
  104. const data = {
  105. postsId: this.data.postId,
  106. content: this.data.inputSBValue
  107. }
  108. httpRequestApi.postReplyComment(this.uid, data).success(res => {
  109. this.setData({
  110. replyModal: false
  111. },()=>{
  112. this.getReplyDetail();
  113. })
  114. });
  115. },
  116. // 获取回复楼中楼的内容
  117. inputSBValue: function (e) {
  118. this.setData({
  119. inputSBValue: e.detail.value
  120. });
  121. },
  122. })