123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- var supplierHome = new Vue({
- el: "#supplierHome",
- mixins: [cmSysVitaMixins],
- data: {
- requestFlag: true,
- userId: 0,
- supplierInfo: {},
- supplierBanner: [],
- shopCategory: [],
- mainProducts: [],
- choiceIndex: '',
- handleTabIndex: 1,
- params: {
- size: 12,
- num: 1,
- id: 0,
- keyword: ''
- },
- listRecord: 0,
- productLists: [],
- categoryProducts: [],// 类别商品列表
- isShopAll: true,
- addhtml: '<span class="tag">美博会</span>'
- },
- computed: {
- floorData: function () {
- return [
- {
- type: 1,
- title: '主推商品',
- productList: this.mainProducts,
- showEmpty: false
- },
- {
- type: 2,
- title: '全部商品',
- productList: this.productLists,
- showEmpty: true
- }
- ]
- }
- },
- filters: {
- NumFormat: function (value) {
- return Number(value).toFixed(2);
- }
- },
- methods: {
- handleTabClick(type) {
- this.handleTabIndex = type
- },
- // 是否显示vip标签价格
- showVipPriceTag(pros) {
- //非会员
- // if(!GLOBAL_VIP_FLAG === 1) return false;
- // 商品所有机构可见
- if (pros.priceFlag === 0) return true;
- // 商品价格仅资质机构可见
- if (pros.priceFlag === 2 && GLOBAL_USER_IDENTITY === 2) return true;
- // 商品价格仅医美机构可见
- if (pros.priceFlag === 3 && GLOBAL_USER_IDENTITY === 2 && GLOBAL_CLUB_TYPE === 1) return true;
- // 其它
- return false;
- },
- getShopInfo() {
- const _self = this;
- SupplierApi.getShopHomeData({shopId: this.params.id }, function (res) {
- if (res.code === 0) {
- const data = res.data
- _self.supplierInfo = data
- _self.supplierBanner = data.shopHomeImages // 供应商轮播
- _self.shopCategory = data.shopCategory// 供应商类别
- _self.getMainProducts()
- _self.getProductLists()
- 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 {
- const 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);
- }
- });
- },
- // 点击全部
- handleChangeAll() {
- this.choiceIndex = ''
- this.isShopAll = true
- this.getMainProducts()
- this.getProductLists(false)
- },
- handleCategory(category, index) {
- this.isShopAll = false
- this.choiceIndex = index
- this.getCategoryProducts({shopId: this.handleShopId, categoryId: category.id})
- },
- // 获取类别商品列表
- getCategoryProducts(params) {
- const _self = this;
- SupplierApi.getCategoryProducts(params, function (res) {
- if (res.code === 0) {
- if (_self.userId && _self.userId > 0) {
- const productIdArr = [];
- res.data.map((item) => {
- // 0公开价格 1不公开价格 2仅对会员机构公开
- if (item.priceFlag !== 1) {
- productIdArr.push(item.productId)
- }
- });
- setProductPrice(res.data, productIdArr.join(","), _self.userId, function () {
- _self.$forceUpdate();
- });
- }
- _self.categoryProducts = res.data
- setTimeout(function () {
- // 图片懒加载
- $("img[data-original]").lazyload();
- }, 500);
- }
- });
- },
- getMainProducts() {
- const _self = this;
- SupplierApi.GetShopProductMain({ shopId: _self.params.id,identity: IDENTITY },function (res) {
- if (res.code === 0 && res.data) {
- if (_self.userId && _self.userId > 0) {
- const 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();
- });
- }
- _self.mainProducts = res.data;
- setTimeout(function () {
- // 图片懒加载
- $("img[data-original]").lazyload();
- }, 500);
- }
- }
- );
- },
- getProductLists(flag) {
- const _self = this;
- SupplierApi.GetSearchQueryProductSupplier(
- {
- keyword: _self.params.keyword,
- pageSize: _self.params.size,
- pageNum: _self.params.num,
- identity: IDENTITY,
- id: _self.params.id
- },
- function (res) {
- if (res.code === 0 && res.data) {
- const result = JSON.parse(res.data);
- _self.listRecord = result.total;
- const resultData = setSearchProductList(result.items, _self.userId, function () {
- _self.$forceUpdate();
- setTimeout(function () {
- // 图片懒加载
- $("img[data-original]").lazyload();
- }, 500);
- });
- if (flag) {
- _self.productLists = _self.productLists.concat(resultData);
- } else {
- _self.productLists = []
- _self.productLists = resultData
- }
- console.log('productLists', _self.productLists)
- _self.requestFlag = true;
- }
- }
- );
- },
- PromotionsFormat(promo) {//促销活动类型数据处理
- if (promo != null) {
- if (promo.type === 1 && promo.mode === 1) {
- return true
- } else {
- return false
- }
- }
- return false
- },
- keyupSearch(event) {
- // 搜索输入框 按回车键搜索
- var keyCode = event.keyCode || event.which;
- if (keyCode === 13) {
- this.supplierSearch();
- }
- },
- supplierSearch() {
- 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.choiceIndex = ''
- this.isShopAll = true
- this.productLists = [];
- this.getProductLists(false);
- var floorScroll = $('#supProduct').offset().top;
- $('html,body').animate({scrollTop: floorScroll}, 600);
- },
- upgrade: function () {
- location.href = '/upgrade.html';
- }
- },
- created() {
- const paramsArr = window.location.pathname.split(".")[0].split("-");
- this.params.id = this.cmSysParams.shopId = this.handleShopId = paramsArr.length >= 1 ? paramsArr[1] * 1 : 0;
- this.cmSysParams.pageType = 14;
- this.cmSysParams.pageLabel = `供应商主页`;//设置统计数据标签
- if (globalUserData) {
- this.userId = globalUserData.userId;
- }
- if (this.params.id !== 0) {
- this.getShopInfo();
- }
- },
- mounted: function () {
- //上垃加载更多
- const _self = this;
- $(window).on('scroll', function () {
- const scrollTop = $(this).scrollTop();
- const scrollHeight = $(document).height();
- const windowHeight = window.innerHeight + $("footer").height();
- if (scrollTop + windowHeight >= scrollHeight) {
- //此处是滚动条到底部时候触发的事件,在这里写要加载的数据,或者是拉动滚动条的操作
- const totalPage = Math.ceil(_self.listRecord / _self.params.size) ? Math.ceil(_self.listRecord / _self.params.size) : 1;
- const next = _self.params.num + 1;
- if (next <= totalPage) {
- if (_self.requestFlag) {
- _self.params.num = next;
- // 获取列表数据
- _self.getProductLists(true);
- }
- _self.requestFlag = false;
- }
- }
- });
- $('body').on("click", '.showSearch', function () {
- $('.supplierTit .search').show();
- })
- }
- });
|