index.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { getReplyList, getReplyConfig} from '../../api/store.js';
  2. const app=getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. parameter: {
  9. 'navbar': '1',
  10. 'return': '1',
  11. 'title': '商品评分',
  12. 'color': false,
  13. },
  14. replyData:{},
  15. product_id:0,
  16. reply:[],
  17. type:0,
  18. loading:false,
  19. loadend:false,
  20. loadTitle:'加载更多',
  21. page:1,
  22. limit:8
  23. },
  24. /**
  25. * 授权回调
  26. *
  27. */
  28. onLoadFun:function(){
  29. this.getProductReplyCount();
  30. this.getProductReplyList();
  31. },
  32. /**
  33. * 生命周期函数--监听页面加载
  34. */
  35. onLoad: function (options) {
  36. if(!options.product_id) return app.Tips({title:'缺少参数'},{tab:3,url:1});
  37. this.setData({product_id:options.product_id});
  38. },
  39. /**
  40. * 获取评论统计数据
  41. *
  42. */
  43. getProductReplyCount:function(){
  44. var that=this;
  45. getReplyConfig(that.data.product_id).then(res=>{
  46. that.setData({ replyData: res.data });
  47. });
  48. },
  49. /**
  50. * 分页获取评论
  51. */
  52. getProductReplyList:function(){
  53. var that=this;
  54. if (that.data.loadend) return;
  55. if (that.data.loading) return;
  56. that.setData({loading:true,loadTitle:''});
  57. getReplyList(that.data.product_id, {
  58. page: that.data.page,
  59. limit: that.data.limit,
  60. type: that.data.type,
  61. }).then(res=>{
  62. var list = res.data, loadend = list.length < that.data.limit;
  63. that.data.reply = app.SplitArray(list, that.data.reply);
  64. that.setData({
  65. reply: that.data.reply,
  66. loading: false,
  67. loadend: loadend,
  68. loadTitle: loadend ? "😕人家是有底线的~~" : "加载更多",
  69. page: that.data.page + 1
  70. });
  71. }).catch(err=>{
  72. that.setData({ loading: false, loadTitle: '加载更多' });
  73. });
  74. },
  75. /*
  76. * 点击事件切换
  77. * */
  78. changeType:function(e){
  79. var type = e.target.dataset.type;
  80. type=parseInt(type);
  81. if(type==this.data.type) return;
  82. this.setData({type:type,page:1,loadend:false,reply:[]});
  83. this.getProductReplyList();
  84. },
  85. /**
  86. * 页面上拉触底事件的处理函数
  87. */
  88. onReachBottom: function () {
  89. this.getProductReplyList();
  90. },
  91. })