123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- var supplierList = new Vue({
- el: "#supplierList",
- data: {
- searchFlag: false,
- listLoading: true,
- requestFlag: true,
- noMore: false,
- params: {
- size: 0,
- num: 0,
- keyword: ""
- },
- listData: [],
- listRecord: 0,
- pageInput: ''
- },
- computed: {
- pageTotal: function () {
- var total = Math.ceil(this.listRecord / this.params.size);
- console.log(total)
- return total > 0 ? total : 1;
- },
- showPageBtn: function () {
- var total = Math.ceil(this.listRecord / this.params.size);
- total = total > 0 ? total : 1;
- var index = this.params.num, arr = [];
- if (total <= 6) {
- for (var i = 1; i <= total; i++) {
- arr.push(i);
- }
- return arr;
- }
- if (index <= 3) return [1, 2, 3, 4, 5, 0, total];
- if (index >= total - 2) return [1, 0, total - 4, total - 3, total - 2, total - 1, total];
- return [1, 0, index - 2, index - 1, index, index + 1, index + 2, 0, total];
- }
- },
- methods: {
- toPagination: function (pageNum) {
- if (pageNum <= this.pageTotal) {
- var params = {pageNum: pageNum};
- window.location.href = updateUrlParam(params);
- }
- },
- checkNum: function () {
- if (this.pageInput > this.pageTotal) {
- this.pageInput = this.pageTotal;
- } else if (this.pageInput < 1) {
- this.pageInput = 1;
- }
- },
- getListByKeyword: function () {
- var _self = this;
- SupplierApi.GetSearchShopList({
- keyword: this.params.keyword,
- pageSize: this.params.size,
- pageNum: this.params.num
- },function (res) {
- if (res.code === 0 && res.data) {
- var result = JSON.parse(res.data);
- console.log(result);
- _self.listRecord = result.total;
- var resultData = result.items;
- if(isPC){
- _self.listData = resultData;
- }else{
- _self.listData = _self.listData.concat(resultData);
- }
- setTimeout(function(){
- // 图片懒加载
- $("img[data-original]").lazyload();
- },500);
- _self.listLoading = false;
- _self.requestFlag = true;
- }else {
- CAIMEI.Alert(res.msg, '确定');
- }
- });
- },
- hanldHrefLink:function (shop) {
- console.log('shopId',shopId)
- if(shop.shopType == 2){
- return;
- }
- window.open('/supplier-'+shop.shopId+'.html');
- }
- },
- created: function () {
- if(isPC){
- this.params.size = getUrlParam("pageSize") ? getUrlParam("pageSize") * 1 : 10;
- this.params.num = getUrlParam("pageNum") ? getUrlParam("pageNum") * 1 : 1;
- }else{
- this.params.size = 10;
- this.params.num = 1;
- }
- this.params.keyword = getUrlParam("keyword") ? getUrlParam("keyword") : "";
- // 搜索框赋值
- $('#topSearch').find('[data-select]').attr("data-select", 1).text("供应商");
- $('#topSearch').find('.jqSelect').find('select').val(1);
- $('#topSearch').find('.keyword').val(this.params.keyword);
- // 获取列表数据
- this.getListByKeyword();
- },
- mounted: function () {
- var _self = this;
- if(!isPC){
- $('footer').addClass("noneImportant");
- //移动端上垃加载更多
- $(window).on('scroll', function(){
- var scrollTop = $(this).scrollTop();
- var scrollHeight = $(document).height();
- var windowHeight = window.innerHeight;
- if (scrollTop + windowHeight >= scrollHeight) {
- //此处是滚动条到底部时候触发的事件,在这里写要加载的数据,或者是拉动滚动条的操作
- var totalPage = Math.ceil(_self.listRecord / _self.params.size)?Math.ceil(_self.listRecord / _self.params.size):1;
- var next = _self.params.num+1;
- if(next <= totalPage){
- if (_self.requestFlag){
- _self.params.num = next;
- // 获取列表数据
- _self.getListByKeyword();
- }
- _self.requestFlag = false;
- }else{
- //到底了
- _self.noMore = true;
- $('footer').removeClass("noneImportant");
- }
- }
- });
- }
- }
- });
|