replyDetail.js 3.0 KB

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