list.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. var supplierList = new Vue({
  2. el: "#supplierList",
  3. data: {
  4. searchFlag: false,
  5. listLoading: true,
  6. requestFlag: true,
  7. noMore: false,
  8. params: {
  9. size: 0,
  10. num: 0,
  11. keyword: ""
  12. },
  13. listData: [],
  14. listRecord: 0,
  15. pageInput: ''
  16. },
  17. computed: {
  18. pageTotal: function () {
  19. var total = Math.ceil(this.listRecord / this.params.size);
  20. console.log(total)
  21. return total > 0 ? total : 1;
  22. },
  23. showPageBtn: function () {
  24. var total = Math.ceil(this.listRecord / this.params.size);
  25. total = total > 0 ? total : 1;
  26. var index = this.params.num, arr = [];
  27. if (total <= 6) {
  28. for (var i = 1; i <= total; i++) {
  29. arr.push(i);
  30. }
  31. return arr;
  32. }
  33. if (index <= 3) return [1, 2, 3, 4, 5, 0, total];
  34. if (index >= total - 2) return [1, 0, total - 4, total - 3, total - 2, total - 1, total];
  35. return [1, 0, index - 2, index - 1, index, index + 1, index + 2, 0, total];
  36. }
  37. },
  38. methods: {
  39. toPagination: function (pageNum) {
  40. if (pageNum <= this.pageTotal) {
  41. var params = {pageNum: pageNum};
  42. window.location.href = updateUrlParam(params);
  43. }
  44. },
  45. checkNum: function () {
  46. if (this.pageInput > this.pageTotal) {
  47. this.pageInput = this.pageTotal;
  48. } else if (this.pageInput < 1) {
  49. this.pageInput = 1;
  50. }
  51. },
  52. getListByKeyword: function () {
  53. var _self = this;
  54. SupplierApi.GetSearchShopList({
  55. keyword: this.params.keyword,
  56. pageSize: this.params.size,
  57. pageNum: this.params.num
  58. },function (res) {
  59. if (res.code === 0 && res.data) {
  60. var result = JSON.parse(res.data);
  61. console.log(result);
  62. _self.listRecord = result.total;
  63. var resultData = result.items;
  64. if(isPC){
  65. _self.listData = resultData;
  66. }else{
  67. _self.listData = _self.listData.concat(resultData);
  68. }
  69. setTimeout(function(){
  70. // 图片懒加载
  71. $("img[data-original]").lazyload();
  72. },500);
  73. _self.listLoading = false;
  74. _self.requestFlag = true;
  75. }else {
  76. CAIMEI.Alert(res.msg, '确定');
  77. }
  78. });
  79. },
  80. hanldHrefLink:function (shop) {
  81. console.log('shopId',shopId)
  82. if(shop.shopType == 2){
  83. return;
  84. }
  85. window.open('/supplier-'+shop.shopId+'.html');
  86. }
  87. },
  88. created: function () {
  89. if(isPC){
  90. this.params.size = getUrlParam("pageSize") ? getUrlParam("pageSize") * 1 : 10;
  91. this.params.num = getUrlParam("pageNum") ? getUrlParam("pageNum") * 1 : 1;
  92. }else{
  93. this.params.size = 10;
  94. this.params.num = 1;
  95. }
  96. this.params.keyword = getUrlParam("keyword") ? getUrlParam("keyword") : "";
  97. // 搜索框赋值
  98. $('#topSearch').find('[data-select]').attr("data-select", 1).text("供应商");
  99. $('#topSearch').find('.jqSelect').find('select').val(1);
  100. $('#topSearch').find('.keyword').val(this.params.keyword);
  101. // 获取列表数据
  102. this.getListByKeyword();
  103. },
  104. mounted: function () {
  105. var _self = this;
  106. if(!isPC){
  107. $('footer').addClass("noneImportant");
  108. //移动端上垃加载更多
  109. $(window).on('scroll', function(){
  110. var scrollTop = $(this).scrollTop();
  111. var scrollHeight = $(document).height();
  112. var windowHeight = window.innerHeight;
  113. if (scrollTop + windowHeight >= scrollHeight) {
  114. //此处是滚动条到底部时候触发的事件,在这里写要加载的数据,或者是拉动滚动条的操作
  115. var totalPage = Math.ceil(_self.listRecord / _self.params.size)?Math.ceil(_self.listRecord / _self.params.size):1;
  116. var next = _self.params.num+1;
  117. if(next <= totalPage){
  118. if (_self.requestFlag){
  119. _self.params.num = next;
  120. // 获取列表数据
  121. _self.getListByKeyword();
  122. }
  123. _self.requestFlag = false;
  124. }else{
  125. //到底了
  126. _self.noMore = true;
  127. $('footer').removeClass("noneImportant");
  128. }
  129. }
  130. });
  131. }
  132. }
  133. });