replyDetail.js 4.3 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. },
  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. replyTemp.push(temp);
  82. console.log(replyTemp);
  83. });
  84. this.setData({
  85. comment: replyTemp,
  86. count: replied.replyCount
  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. })