replyDetail.js 3.9 KB

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