replyDetail.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. console.log(123123)
  51. this.flowerBox = this.selectComponent("#flower-box");
  52. this.flowerBox.comeOut();
  53. }
  54. this.getReplyDetail();
  55. });
  56. });
  57. }
  58. },
  59. // 查询回复详情
  60. getReplyDetail: function () {
  61. // let uid = wx.getStorageSync('uid');
  62. httpRequestApi.getReplyComment(this.uid, this.data.postId).success((res) => {
  63. console.log(res);
  64. const replyList = res.data.data.replyVOList;
  65. const replied = res.data.data;
  66. const replyTemp = [];
  67. const authorDetail = {};
  68. authorDetail.name = replied.user.wechatName;
  69. authorDetail.text = decodeURI(replied.detailDesc);
  70. authorDetail.time = formatDate(replied.gmtCreated, 3);
  71. authorDetail.likes = replied.postsAttributeInfo.favors;
  72. authorDetail.avatar = replied.user.avatar;
  73. replyTemp.push(authorDetail);
  74. replyList.forEach(item => {
  75. const temp = {};
  76. temp.name = item.user.wechatName;
  77. temp.text = decodeURI(item.content);
  78. temp.time = formatDate(item.gmtCreated, 3);
  79. temp.likes = 0;
  80. temp.id = item.postId;
  81. temp.avatar = item.user.avatar;
  82. if (item.isRisky === 'NORMAL') {
  83. replyTemp.push(temp);
  84. }
  85. console.log(replyTemp);
  86. });
  87. const count = replyTemp.length - 1;
  88. this.setData({
  89. comment: replyTemp,
  90. count
  91. })
  92. });
  93. },
  94. // 点赞评论
  95. likeCommend: function (e) {
  96. console.log(e);
  97. // let uid = wx.getStorageSync('uid');
  98. let followUid = e.currentTarget.dataset.id;
  99. let index = e.currentTarget.dataset.index;
  100. httpRequestApi.likeCommend(this.uid, followUid).success(res => {
  101. console.log(res);
  102. const str = `comment[${index}].likes`;
  103. this.setData({
  104. [str]: res.data.data.favors
  105. })
  106. });
  107. },
  108. // 设置点击时的id
  109. setSBId: function (e) {
  110. console.log(e)
  111. this.setData({
  112. // replySBId: e.currentTarget.dataset.id,
  113. replyModal: true
  114. })
  115. },
  116. // 回复某个评论
  117. replySB: function () {
  118. const data = {
  119. postsId: this.data.postId,
  120. content: this.data.inputSBValue
  121. }
  122. httpRequestApi.postReplyComment(this.uid, data).success(res => {
  123. console.log(res.data.count)
  124. this.setData({
  125. replyModal: false,
  126. })
  127. });
  128. },
  129. // 获取回复楼中楼的内容
  130. inputSBValue: function (e) {
  131. this.setData({
  132. inputSBValue: e.detail.value
  133. });
  134. },
  135. })