replyDetail.js 4.4 KB

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