replyDetail.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. })
  25. this.uid = wx.getStorageSync('uid');
  26. this.getReplyDetail();
  27. },
  28. // 保存 回复的内容
  29. saveValue: function(e){
  30. this.setData({
  31. replyInfo: e.detail.value
  32. });
  33. },
  34. replyDone:function(){
  35. const data = {
  36. postsId: this.data.postId,
  37. content: this.data.replyInfo
  38. }
  39. if(this.data.replyInfo){
  40. httpRequestApi.postReplyComment(this.uid, data).success(res => {
  41. this.setData({
  42. replyModal: false,
  43. replyInfo: ''
  44. });
  45. this.getReplyDetail();//更新 变化后的 replyTemp。
  46. });
  47. }
  48. },
  49. // 查询回复详情
  50. getReplyDetail: function () {
  51. // let uid = wx.getStorageSync('uid');
  52. httpRequestApi.getReplyComment(this.uid, this.data.postId).success((res) => {
  53. // debugger;
  54. const replyList = res.data.data.replyVOList;
  55. const replied = res.data.data;
  56. const replyTemp = [];
  57. const authorDetail = {};
  58. authorDetail.name = replied.user.wechatName;
  59. authorDetail.text = replied.detailDesc;
  60. authorDetail.time = formatDate(replied.gmtModified,3);
  61. authorDetail.likes = replied.postsAttributeInfo.favors;
  62. authorDetail.avatar = replied.user.avatar;
  63. replyTemp.push(authorDetail);
  64. replyList.forEach(item => {
  65. const temp = {};
  66. temp.name = item.user.wechatName;
  67. temp.text = item.content;
  68. temp.time = formatDate(item.gmtModified,3);
  69. temp.likes = 0;
  70. temp.id = item.postId;
  71. temp.avatar = item.user.avatar;
  72. replyTemp.push(temp);
  73. console.log(replyTemp);
  74. });
  75. this.setData({
  76. comment: replyTemp
  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. });
  113. },
  114. // 获取回复楼中楼的内容
  115. inputSBValue: function (e) {
  116. this.setData({
  117. inputSBValue: e.detail.value
  118. });
  119. },
  120. })