shop-goods.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. var app = new Vue({
  2. 'el': '#app',
  3. 'data': {
  4. // 列表数据
  5. dataList: [],
  6. // 参数
  7. params: {
  8. page: 1,
  9. pageSize: 6,
  10. type: 1,
  11. },
  12. loading: false,
  13. loaded: false,
  14. },
  15. created: function(){
  16. this.getDataList(0);
  17. },
  18. mounted: function(){
  19. var _this = this;
  20. $(window).scroll(function(){
  21. var scrollHeight = $(this).scrollTop();
  22. var height = $('body')[0].scrollHeight;
  23. var docHeight = $(this).outerHeight();
  24. if(docHeight+scrollHeight >= height-1){
  25. if(_this.loading || _this.loaded){
  26. return false;
  27. }
  28. _this.params.page++;
  29. _this.getDataList(1);
  30. }
  31. })
  32. },
  33. methods: {
  34. // 详情
  35. goDetail: function(id){
  36. if(id){
  37. location.href = '/weixin/goods/detail?id='+id;
  38. }
  39. },
  40. // 编辑商品
  41. editGoods: function(id){
  42. if(id){
  43. location.href = '/weixin/goods/publish?id='+id;
  44. }
  45. },
  46. // 删除商品
  47. delGoods: function(id){
  48. if(id>0 && confirm('确定删除该商品?')){
  49. var _this = this;
  50. $.showLoading("处理中...");
  51. $.post('/weixin/goods/doDel', {id:id}, function (res) {
  52. $.hideLoading();
  53. if (res.code == 'success') {
  54. $.toast(res.message, 'text');
  55. setTimeout(function () {
  56. _this.params.page = 1;
  57. _this.getDataList(0);
  58. }, 500);
  59. }else if(res.code == 'login'){
  60. login(res.data.url);
  61. }else {
  62. $.toast(res.message, 'text');
  63. }
  64. }, "json");
  65. }
  66. },
  67. // 获取列表数据
  68. getDataList: function(more){
  69. var _this = this;
  70. $.showLoading("数据加载中...");
  71. _this.loading = true;
  72. $.post('/weixin/goods/goodsList', _this.params, function (res) {
  73. $.hideLoading();
  74. _this.loading = false;
  75. if (res.code == 'success') {
  76. if(res.data.data.length<=0 && _this.params.page > 1){
  77. _this.loaded = true;
  78. $.toast("已加载完全部...",'text');
  79. return false;
  80. }
  81. if(more){
  82. $.each(res.data.data, function(k,item){
  83. _this.dataList.push(item);
  84. });
  85. }else{
  86. _this.dataList = res.data.data
  87. }
  88. }else if(res.code == 'login'){
  89. login(res.data.url);
  90. }
  91. }, "json");
  92. },
  93. }
  94. })