wholeEvaluation.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. item.commentImg=item.commentImgs.split(',');
  34. item.date=item.createTime.substr(0,10);
  35. return item;
  36. });
  37. this.setData({
  38. evalList: this.data.evalList.concat(list),
  39. totalPages: res.data.pages
  40. });
  41. }
  42. });
  43. },
  44. onReachBottom() {
  45. if (this.data.totalPages > this.data.page) {
  46. this.setData({
  47. page: this.data.page + 1
  48. });
  49. this.getEvalList();
  50. } else {
  51. wx.showToast({
  52. title: '没有更多评价了',
  53. icon: 'none',
  54. duration: 2000
  55. });
  56. return false;
  57. }
  58. },
  59. previewImg(e){
  60. let img=e.currentTarget.dataset.img;
  61. let imgs=e.currentTarget.dataset.imgs;
  62. wx.previewImage({
  63. current:img,
  64. urls: imgs
  65. })
  66. },
  67. onReady: function() {
  68. // 页面渲染完成
  69. },
  70. onShow: function() {
  71. // 页面显示
  72. },
  73. onHide: function() {
  74. // 页面隐藏
  75. },
  76. onUnload: function() {
  77. // 页面关闭
  78. }
  79. })