topicDetail.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. var app = getApp();
  2. var WxParse = require('../../lib/wxParse/wxParse.js');
  3. var util = require('../../utils/util.js');
  4. var api = require('../../config/api.js');
  5. Page({
  6. data: {
  7. id: 0,
  8. topic: {},
  9. topicList: [],
  10. commentCount: 0,
  11. commentList: [],
  12. topicGoods: [],
  13. collect: false,
  14. userHasCollect: 0
  15. },
  16. onLoad: function(options) {
  17. // 页面初始化 options为页面跳转所带来的参数
  18. var that = this;
  19. that.setData({
  20. id: options.id
  21. });
  22. util.request(api.TopicDetail, {
  23. id: that.data.id
  24. }).then(function(res) {
  25. if (res.errno === 0) {
  26. that.setData({
  27. topic: res.data.topic,
  28. topicGoods: res.data.goods,
  29. userHasCollect: res.data.userHasCollect,
  30. collect: res.data.userHasCollect == 1
  31. });
  32. WxParse.wxParse('topicDetail', 'html', res.data.topic.content, that);
  33. }
  34. });
  35. util.request(api.TopicRelated, {
  36. id: that.data.id
  37. }).then(function(res) {
  38. if (res.errno === 0) {
  39. that.setData({
  40. topicList: res.data.list
  41. });
  42. }
  43. });
  44. },
  45. getCommentList() {
  46. let that = this;
  47. util.request(api.CommentList, {
  48. valueId: that.data.id,
  49. type: 1,
  50. showType: 0,
  51. page: 1,
  52. limit: 5
  53. }).then(function(res) {
  54. if (res.errno === 0) {
  55. that.setData({
  56. commentList: res.data.list,
  57. commentCount: res.data.total
  58. });
  59. }
  60. });
  61. },
  62. //添加或是取消收藏
  63. addCollectOrNot: function() {
  64. let that = this;
  65. util.request(api.CollectAddOrDelete, {
  66. type: 1,
  67. valueId: this.data.id
  68. }, "POST")
  69. .then(function(res) {
  70. if (that.data.userHasCollect == 1) {
  71. that.setData({
  72. collect: false,
  73. userHasCollect: 0
  74. });
  75. } else {
  76. that.setData({
  77. collect: true,
  78. userHasCollect: 1
  79. });
  80. }
  81. });
  82. },
  83. postComment() {
  84. if (!app.globalData.hasLogin) {
  85. wx.navigateTo({
  86. url: "/pages/auth/login/login"
  87. });
  88. } else {
  89. wx.navigateTo({
  90. url: '/pages/topicCommentPost/topicCommentPost?valueId=' + this.data.id + '&type=1',
  91. })
  92. }
  93. },
  94. onReady: function() {
  95. },
  96. onShow: function() {
  97. // 页面显示
  98. this.getCommentList();
  99. },
  100. onHide: function() {
  101. // 页面隐藏
  102. },
  103. onUnload: function() {
  104. // 页面关闭
  105. }
  106. })