replyDetail.js 3.9 KB

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