replyDetail.js 3.0 KB

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