replyDetail.js 3.6 KB

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