shop.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. var app = new Vue({
  2. 'el': '#app',
  3. 'data': {
  4. // 列表数据
  5. dataList: [],
  6. // 参数
  7. params: {
  8. page: 1,
  9. pageSize: 6
  10. },
  11. loading: false,
  12. loaded: false,
  13. },
  14. created: function(){
  15. this.getDataList(0);
  16. },
  17. mounted: function(){
  18. var _this = this;
  19. $(window).scroll(function(){
  20. var scrollHeight = $(this).scrollTop();
  21. var height = $('body')[0].scrollHeight;
  22. var docHeight = $(this).outerHeight();
  23. if(docHeight+scrollHeight >= height-1){
  24. if(_this.loading || _this.loaded){
  25. return false;
  26. }
  27. _this.params.page++;
  28. _this.getDataList(1);
  29. }
  30. })
  31. },
  32. methods: {
  33. // 详情
  34. goDetail: function(id){
  35. if(id){
  36. location.href = '/weixin/goods/detail?id='+id;
  37. }
  38. },
  39. // 获取列表数据
  40. getDataList: function(more){
  41. var _this = this;
  42. $.showLoading("数据加载中...");
  43. _this.loading = true;
  44. $.post('/weixin/goods/goodsList', _this.params, function (res) {
  45. $.hideLoading();
  46. _this.loading = false;
  47. if (res.code == 'success') {
  48. if(res.data.data.length<=0 && _this.params.page > 1){
  49. _this.loaded = true;
  50. $.toast("已加载完全部...",'text');
  51. return false;
  52. }
  53. if(more){
  54. $.each(res.data.data, function(k,item){
  55. _this.dataList.push(item);
  56. });
  57. }else{
  58. _this.dataList = res.data.data
  59. }
  60. }else if(res.code == 'login'){
  61. login(res.data.url);
  62. }
  63. }, "json");
  64. },
  65. }
  66. })