topicDetail.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. },
  14. onLoad: function(options) {
  15. // 页面初始化 options为页面跳转所带来的参数
  16. var that = this;
  17. that.setData({
  18. id: options.id
  19. });
  20. util.request(api.TopicDetail, {
  21. id: that.data.id
  22. }).then(function(res) {
  23. if (res.errno === 0) {
  24. that.setData({
  25. topic: res.data.topic,
  26. topicGoods: res.data.goods
  27. });
  28. WxParse.wxParse('topicDetail', 'html', res.data.topic.content, that);
  29. }
  30. });
  31. util.request(api.TopicRelated, {
  32. id: that.data.id
  33. }).then(function(res) {
  34. if (res.errno === 0) {
  35. that.setData({
  36. topicList: res.data.list
  37. });
  38. }
  39. });
  40. },
  41. getCommentList() {
  42. let that = this;
  43. util.request(api.CommentList, {
  44. valueId: that.data.id,
  45. type: 1,
  46. showType: 0,
  47. page: 1,
  48. limit: 5
  49. }).then(function(res) {
  50. if (res.errno === 0) {
  51. that.setData({
  52. commentList: res.data.list,
  53. commentCount: res.data.total
  54. });
  55. }
  56. });
  57. },
  58. postComment() {
  59. if (!app.globalData.hasLogin) {
  60. wx.navigateTo({
  61. url: "/pages/auth/login/login"
  62. });
  63. } else {
  64. wx.navigateTo({
  65. url: '/pages/topicCommentPost/topicCommentPost?valueId=' + this.data.id + '&type=1',
  66. })
  67. }
  68. },
  69. onReady: function() {
  70. },
  71. onShow: function() {
  72. // 页面显示
  73. this.getCommentList();
  74. },
  75. onHide: function() {
  76. // 页面隐藏
  77. },
  78. onUnload: function() {
  79. // 页面关闭
  80. }
  81. })