comment.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // pages/comment/comment.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. start: 1,//短评开始
  8. count: 10//短评显示条数
  9. },
  10. /**
  11. * 生命周期函数--监听页面加载
  12. */
  13. onLoad: function (options) {
  14. var that =this;
  15. that.setData({
  16. title: options.title,
  17. imgUrl: options.imgUrl,
  18. rate: options.rate,
  19. id: options.id,
  20. type: options.type
  21. });
  22. that.getComments(1);
  23. },
  24. getComments:function(start){
  25. var that = this;
  26. var type = that.data.type;
  27. var id = that.data.id;
  28. var dpurl;//短评的url
  29. var count = that.data.count;//短评显示条数
  30. var start = start;//短评开始
  31. if (type == "movie") {
  32. dpurl = 'https://m.douban.com/rexxar/api/v2/movie/' + id + '/interests?count=' + count + '&start=' + start;
  33. } else if (type == "tvs" || type == "shows") {
  34. dpurl = 'https://m.douban.com/rexxar/api/v2/tv/' + id + '/interests?count=' + count + '&start=' + start;
  35. }
  36. //获取短评信息
  37. wx.request({
  38. url: dpurl,
  39. success: function (res) {
  40. that.setData({
  41. comments: res.data.interests,
  42. start: start
  43. });
  44. wx.pageScrollTo({
  45. scrollTop: 0,
  46. });
  47. }
  48. })
  49. },
  50. onItemTapEvent:function(event){
  51. //返回上一页
  52. wx.navigateBack({})
  53. },
  54. upPage:function(event){
  55. var that = this;
  56. var start = that.data.start;
  57. var count = that.data.count;
  58. if (start - count > 0){
  59. that.getComments(start - count);
  60. }
  61. },
  62. nextPage: function (event) {
  63. var that = this;
  64. var start = that.data.start;
  65. var count = that.data.count;
  66. that.getComments(start + count);
  67. },
  68. })