topicDetail.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. },
  13. onLoad: function (options) {
  14. // 页面初始化 options为页面跳转所带来的参数
  15. var that = this;
  16. that.setData({
  17. id: parseInt(options.id)
  18. });
  19. util.request(api.TopicDetail, { id: that.data.id}).then(function (res) {
  20. if (res.errno === 0) {
  21. that.setData({
  22. topic: res.data,
  23. });
  24. WxParse.wxParse('topicDetail', 'html', res.data.content, that);
  25. }
  26. });
  27. util.request(api.TopicRelated, { id: that.data.id}).then(function (res) {
  28. if (res.errno === 0) {
  29. that.setData({
  30. topicList: res.data
  31. });
  32. }
  33. });
  34. },
  35. getCommentList(){
  36. let that = this;
  37. util.request(api.CommentList, { valueId: that.data.id, typeId: 1, size: 5 }).then(function (res) {
  38. if (res.errno === 0) {
  39. that.setData({
  40. commentList: res.data.data,
  41. commentCount: res.data.count
  42. });
  43. }
  44. });
  45. },
  46. postComment (){
  47. wx.navigateTo({
  48. url: '/pages/commentPost/commentPost?valueId='+this.data.id + '&typeId=1',
  49. })
  50. },
  51. onReady: function () {
  52. },
  53. onShow: function () {
  54. // 页面显示
  55. this.getCommentList();
  56. },
  57. onHide: function () {
  58. // 页面隐藏
  59. },
  60. onUnload: function () {
  61. // 页面关闭
  62. }
  63. })