var supplierHome = new Vue({ el: "#supplierHome", data: { requestFlag: true, userId: 0, supplierInfo:{}, supplierBanner: [], mainProducts:[], params: { size: 12, num: 1, id: 0, keyword: '' }, listRecord:0, productLists:[], addhtml:'美博会' }, computed: { }, methods: { getShopInfo: function(){ var _self = this; $.getJSON(spiServer + "/supplier/home/detail",{supplierId: this.params.id}).done(function (r) { if (r.code === 0 && r.data) { _self.supplierInfo = r.data; } }); }, getBanners: function(){ var _self = this; $.getJSON(spiServer + "/supplier/home/images",{supplierId: this.params.id}).done(function (r) { if (r.code === 0 && r.data) { _self.supplierBanner = r.data; _self.supplierBanner = r.data; setTimeout(function(){ if (isPC) { $('#supplierBanner').slide({ mainCell:".swiper-wrapper" ,titCell:".swiper-pagination span" ,effect: "leftLoop" ,prevCell:".swiper-button-prev" ,nextCell:".swiper-button-next" ,interTime: 2000 ,autoPlay: true ,autoPage: false ,trigger: "mouseover" }); } else { var swiper = new Swiper('#supplierBanner', { loop : true, autoplay: { delay: 2000, disableOnInteraction: false }, navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev' }, pagination: { el: '.swiper-pagination', clickable :true } }); } },500); } }); }, getMainProducts: function(){ var _self = this; SupplierApi.GetShopProductMain( { shopId: _self.params.id, identity: GLOBAL_USER_IDENTITY }, function (res) { if (res.code === 0 && res.data) { if(_self.userId && _self.userId>0){ var productIdArr = []; res.data.map(function (item) { // 0公开价格 1不公开价格 2仅对会员机构公开 if (item.priceFlag !== 1) { productIdArr.push(item.productId) } }); setProductPrice(res.data, productIdArr.join(","), _self.userId, function () { _self.$forceUpdate(); setTimeout(function(){ // 图片懒加载 $("img[data-original]").lazyload(); },500); }); } _self.mainProducts = res.data; } else { CAIMEI.Alert(res.msg, '确定'); } } ); }, getProductLists: function(){ var _self = this; SupplierApi.GetSearchQueryProductSupplier( { keyword: _self.params.keyword, pageSize: _self.params.size, pageNum: _self.params.num, identity: GLOBAL_USER_IDENTITY, id:_self.params.id }, function (res) { if (res.code === 0 && res.data) { var result = JSON.parse(res.data); _self.listRecord = result.total; var resultData = setSearchProductList(result.items, _self.userId, function () { _self.$forceUpdate(); setTimeout(function () { // 图片懒加载 $("img[data-original]").lazyload(); }, 500); }); _self.productLists = _self.productLists.concat(resultData); _self.requestFlag = true; } else { CAIMEI.Alert(res.msg, '确定'); } } ); }, keyupSearch: function(event) { // 搜索输入框 按回车键搜索 var keyCode = event.keyCode || event.which; if(keyCode === 13){ this.supplierSearch(); } }, supplierSearch: function(){ if (this.params.keyword.length < 2) { $.confirm({ useBootstrap: false, boxWidth: (isPC?'300px':'70%'), title:'提示', content:'请至少输入两个关键字!', closeIcon: true, animation: 'opacity', closeAnimation: 'opacity', animateFromElement: false, buttons: { close: { text: '确定', btnClass: 'btn-confirm' } } }); return false; } this.productLists = []; this.getProductLists(); var floorScroll = $('#supProduct').offset().top; $('html,body').animate({scrollTop: floorScroll},600); }, upgrade: function () { location.href='/upgrade.html'; } }, created: function () { this.params.id = getUrlParam("id") ? getUrlParam("id") * 1 : 0; if(this.params.id !== 0) { this.getShopInfo(); this.getBanners(); } }, mounted: function () { if(this.params.id !== 0) { this.getMainProducts(); this.getProductLists(); } var userInfo = localStorage.getItem('userInfo'); if(userInfo){ this.userId = JSON.parse(userInfo).userId; } var _self = this; $('.supplierInfo').slide({ mainCell:".tabCon" ,titCell:".tabTit span" ,trigger: "click" }); //上垃加载更多 $(window).on('scroll', function(){ var scrollTop = $(this).scrollTop(); var scrollHeight = $(document).height(); var windowHeight = window.innerHeight + $("footer").height(); 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.getProductLists(); } _self.requestFlag = false; } } }); $('body').on("click", '.showSearch', function(){ $('.supplierTit .search').show(); }) } });