replyDetail.js 3.8 KB

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