replyDetail.js 4.2 KB

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