wholeEvaluation.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. var app = getApp();
  4. Page({
  5. data: {
  6. evalList: [],
  7. page: 1,
  8. limit: 10,
  9. goodsId:''
  10. },
  11. onLoad: function(options) {
  12. // 页面初始化 options为页面跳转所带来的参数
  13. if(options.id){
  14. this.setData({
  15. goodsId:options.id
  16. });
  17. this.getEvalList();
  18. }
  19. },
  20. getEvalList() {
  21. wx.showLoading({
  22. title: '加载中',
  23. });
  24. util.request(api.getGoodsComment, {
  25. goodsId: this.data.goodsId,
  26. page: this.data.page,
  27. limit: this.data.limit
  28. }).then(res=> {
  29. wx.hideLoading();
  30. if (res.errno === 0) {
  31. console.log(res.data);
  32. let list=res.data.list.map(item=>{
  33. if(item.commentImgs==null||item.commentImgs==''){
  34. item.commentImg=[];
  35. }else{
  36. item.commentImg=item.commentImgs.split(',');
  37. }
  38. item.date=item.createTime.substr(0,10);
  39. return item;
  40. });
  41. this.setData({
  42. evalList: this.data.evalList.concat(list),
  43. totalPages: res.data.pages
  44. });
  45. }
  46. });
  47. },
  48. onReachBottom() {
  49. if (this.data.totalPages > this.data.page) {
  50. this.setData({
  51. page: this.data.page + 1
  52. });
  53. this.getEvalList();
  54. } else {
  55. wx.showToast({
  56. title: '没有更多评价了',
  57. icon: 'none',
  58. duration: 2000
  59. });
  60. return false;
  61. }
  62. },
  63. previewImg(e){
  64. let img=e.currentTarget.dataset.img;
  65. let imgs=e.currentTarget.dataset.imgs;
  66. wx.previewImage({
  67. current:img,
  68. urls: imgs
  69. })
  70. },
  71. onReady: function() {
  72. // 页面渲染完成
  73. },
  74. onShow: function() {
  75. // 页面显示
  76. },
  77. onHide: function() {
  78. // 页面隐藏
  79. },
  80. onUnload: function() {
  81. // 页面关闭
  82. }
  83. })