topicDetail.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. },onShareAppMessage: function() {//自定义函数 用户点击右上角分享给好友,要先在分享好友这里设置menus的两个参数,才可以分享朋友圈
  13. wx.showShareMenu({
  14. withShareTicket: true,
  15. menus: ['shareAppMessage', 'shareTimeline']
  16. })
  17. return {
  18. title: this.data.topic.title,
  19. desc: this.data.topic.content,
  20. imageUrl: this.data.topic.scene_pic_url,
  21. path: '/pages/topicDetail/topicDetail?id='+this.data.id
  22. }
  23. },onShareTimeline: function () {//用户点击右上角分享朋友圈
  24. return {
  25. title: this.data.topic.title,
  26. query: {
  27. id:this.data.id
  28. },
  29. imageUrl: this.data.topic.scene_pic_url
  30. }
  31. },onLoad: function (options) {
  32. // 页面初始化 options为页面跳转所带来的参数
  33. var that = this;
  34. that.setData({
  35. id: parseInt(options.id)
  36. });
  37. util.request(api.TopicDetail, { id: that.data.id}).then(function (res) {
  38. if (res.errno === 0) {
  39. that.setData({
  40. topic: res.data,
  41. });
  42. WxParse.wxParse('topicDetail', 'html', res.data.content, that);
  43. }
  44. });
  45. util.request(api.TopicRelated, { id: that.data.id}).then(function (res) {
  46. if (res.errno === 0) {
  47. that.setData({
  48. topicList: res.data
  49. });
  50. }
  51. });
  52. },
  53. getCommentList(){
  54. let that = this;
  55. util.request(api.CommentList, { valueId: that.data.id, typeId: 1, size: 5 }).then(function (res) {
  56. if (res.errno === 0) {
  57. that.setData({
  58. commentList: res.data.data,
  59. commentCount: res.data.count
  60. });
  61. }
  62. });
  63. },
  64. postComment (){
  65. wx.navigateTo({
  66. url: '/pages/commentPost/commentPost?valueId='+this.data.id + '&typeId=1',
  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. })