replyDetail.js 3.5 KB

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