index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. const util = require("../../../utils/util.js");
  2. Page({
  3. data: {
  4. datas: [],
  5. queryData:{
  6. pageIndex:1,
  7. pageSize: 20,
  8. sort: 1,
  9. keyword: '',
  10. aid: ""
  11. },
  12. score:0,
  13. loadMore:true
  14. },
  15. onLoad(options) {
  16. this.data.queryData.aid = options.aid;
  17. this.data.queryData.sort = options.sort || 1;
  18. this.data.queryData.keyword = options.keyword || '';
  19. this.setData({ queryData: this.data.queryData });
  20. this.getFeedbook();
  21. },
  22. getFeedbook(load) {//获取评论
  23. let that = this;
  24. util.ajax({
  25. func: "comments/list",
  26. data: that.data.queryData,
  27. load: load
  28. }, function (res) {
  29. if (res.code == 0) {
  30. let loadMore = true;
  31. let newData = res.data.comments;
  32. let oldData = !load ? newData : [...that.data.datas.comments, ...newData];
  33. if (newData.length < that.data.queryData.pageSize && oldData.length > that.data.queryData.pageSize) {
  34. loadMore = false;
  35. }
  36. for (let i in oldData) {
  37. oldData[i].contented = oldData[i].content.replace(/#([^#]+)#/g, "").replace(/<br\/>/g,'\n');
  38. oldData[i].fcomments.fcontent = oldData[i].fcomments.fcontent.replace(/<br\/>/g,'\n')
  39. oldData[i].option = oldData[i].content.match(/#([^#]+)#/g);
  40. }
  41. that.setData({ datas: { tagList: res.data.tagList, comments: oldData }, loadMore, score: res.data.score });
  42. } else {
  43. util.showTips(res.reason);
  44. }
  45. })
  46. },
  47. setTag(e){
  48. let data = e.currentTarget.dataset;
  49. this.data.queryData.sort = data.sort;
  50. this.data.queryData.keyword = data.keyword;
  51. this.data.queryData.pageIndex = 1;
  52. this.setData({ queryData: this.data.queryData, loadMore: false});
  53. this.getFeedbook();
  54. },
  55. previewImage(e) {
  56. let index = e.currentTarget.dataset.index, i = e.target.dataset.i, comments = this.data.datas.comments;
  57. wx.previewImage({
  58. current: comments[index].imageList[i], // 当前显示图片的http链接
  59. urls: comments[index].imageList // 需要预览的图片http链接列表
  60. })
  61. },
  62. previewFimages(e) {
  63. let index = e.currentTarget.dataset.index, i = e.target.dataset.i, comments = this.data.datas.comments;
  64. wx.previewImage({
  65. current: comments[index].fcomments.fimages[i], // 当前显示图片的http链接
  66. urls: comments[index].fcomments.fimages // 需要预览的图片http链接列表
  67. })
  68. },
  69. onPullDownRefresh: function () {
  70. var self = this;
  71. wx.showNavigationBarLoading();
  72. setTimeout(function () {
  73. self.data.queryData.pageIndex = 1;
  74. self.setData({ queryData: self.data.queryData });
  75. self.getFeedbook(false);
  76. wx.hideNavigationBarLoading();
  77. wx.stopPullDownRefresh();
  78. }, 1000);
  79. },
  80. onReachBottom: function () {
  81. var self = this;
  82. if (self.data.loadMore == false) return false;
  83. setTimeout(function () {
  84. self.data.queryData.pageIndex = self.data.queryData.pageIndex + 1;
  85. self.setData({ queryData: self.data.queryData });
  86. self.getFeedbook(true);
  87. }, 1000);
  88. },
  89. })