index.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. // var isFormal = window.location.href.indexOf('www.caimei365.com') !== -1;
  2. // if(isFormal){var _czc = _czc || [];_czc.push(["_setAccount", "1279558759"]);}
  3. var homeData = new Vue({
  4. el: '#container',
  5. mixins: [cmsMixins,cmSysVitaMixins],
  6. data: {
  7. userId:0,
  8. asideNav: [],
  9. // liveList:[],//右侧直播模块
  10. // cmImageList:[],//右侧活动模块
  11. // infoList:[],//右侧文章模块
  12. newsList:[],
  13. popupFlag:false,
  14. centerImage:{},//广告活动弹窗
  15. couponEntry:2,// 活动优惠券弹窗显示控制
  16. hotListPageFloor:[],// 新皮橱窗
  17. homePageFloor:[],//楼层
  18. quickoperaList: [], // 快捷运营入口列表
  19. dropScreenShow:false,
  20. isCmPopup:false,
  21. isCloseCoupon:true
  22. },
  23. filters: {
  24. },
  25. methods: {
  26. handleHidePopup(){
  27. this.isCmPopup = false
  28. },
  29. showDropScreen(){
  30. this.dropScreenShow = !this.dropScreenShow
  31. },
  32. hideDropScreen(){
  33. this.dropScreenShow = false
  34. },
  35. //处理金额
  36. filtersFormat(value) {
  37. if (value) {
  38. return Number(value).toFixed(2)
  39. } else {
  40. return '0.00'
  41. }
  42. },
  43. // 快捷运营列表
  44. footList(arr) {
  45. if (!Array.isArray(arr)) return []
  46. let newArr = [],a = []
  47. let indexNum = isPC ? 4 : 10
  48. arr.map((item, index) => {
  49. if (index !== 0 && index % indexNum === 0) {
  50. newArr.push(a)
  51. a = []
  52. a.push(item)
  53. }
  54. else a.push(item)
  55. if (arr.length === (index + 1)) {
  56. newArr.push(a)
  57. }
  58. })
  59. return newArr
  60. },
  61. // 是否显示vip标签价格
  62. showVipPriceTag(pros){
  63. //非会员
  64. // if(!GLOBAL_VIP_FLAG === 1) return false;
  65. // 商品所有机构可见
  66. if(pros.priceFlag === 0 && pros.svipProductFlag === 1 && pros.actStatus !==1 ) return true;
  67. // 商品价格仅资质机构可见
  68. if(pros.priceFlag === 2 && pros.svipProductFlag === 1 && GLOBAL_USER_IDENTITY === 2 && pros.actStatus !==1) return true;
  69. // 商品价格仅医美机构可见
  70. if(pros.priceFlag === 3 && pros.svipProductFlag === 1 && GLOBAL_USER_IDENTITY === 2 && GLOBAL_CLUB_TYPE === 1 && pros.actStatus !==1) return true;
  71. // 其它
  72. return false;
  73. },
  74. popupPage(){ // 弹窗点击跳转链接
  75. localStorage.setItem('lockTime',Date.now());
  76. window.localStorage.setItem('isActivityStatus',true);
  77. window.open(this.centerImage.link)
  78. },
  79. closePopup(){ // 关闭弹窗
  80. this.popupFlag=false;
  81. $('.Popup').slideUp(100);
  82. // localStorage.setItem('lockTime',Date.now());
  83. // localStorage.setItem('isActivityStatus',true);
  84. },
  85. diffTime(time){
  86. const date = Date.now();
  87. console.log('缓存时间戳',time);
  88. console.log('当前时间戳',date);
  89. console.log('计算时间戳',(date-time));
  90. return (date -time) < 2*60*1000 ? false : true
  91. },
  92. // 页面主图轮播
  93. swiperBanner: function(){
  94. setTimeout(function(){
  95. if (isPC) {
  96. $('#swiper-container').slide({
  97. mainCell:".swiper-wrapper-banner",
  98. titCell:".swiper-pagination-banner span",
  99. effect: "leftLoop",
  100. prevCell:".swiper-button-prev",
  101. nextCell:".swiper-button-next",
  102. interTime: 3000,
  103. autoPlay: true,
  104. autoPage: false,
  105. trigger: "mouseover"
  106. });
  107. } else {
  108. var swiper = new Swiper('#swiper-container', {
  109. loop : true,
  110. autoplay: {
  111. delay: 3000,
  112. disableOnInteraction: false
  113. },
  114. navigation: {
  115. nextEl: '.swiper-button-next',
  116. prevEl: '.swiper-button-prev'
  117. },
  118. pagination: {
  119. el: '.swiper-pagination',
  120. clickable :true
  121. }
  122. });
  123. }
  124. },300);
  125. },
  126. GetHomeInit: function(){// 初始化
  127. const _self = this;
  128. PublicApi.GetHomeInit({ source: 1 },function(response){
  129. if(response.code === 0){
  130. _self.couponEntry = response.data.couponEntry
  131. _self.quickoperaList = _self.footList(response.data.shortcutList)
  132. if(isPC){
  133. _self.newsList = response.data.annlist.slice(0,2)
  134. }else{
  135. _self.newsList = response.data.annlist.slice(0,1)
  136. }
  137. _self.isCmPopup = GLOBAL_USER_ID <= 0
  138. const centerImageList = response.data.centerImage
  139. if(centerImageList && centerImageList.length > 0){
  140. _self.centerImage = response.data.centerImage[0]
  141. const isActivityStatus = localStorage.getItem('isActivityStatus');
  142. //广告弹窗
  143. if(isActivityStatus){
  144. const lockTime = localStorage.getItem('lockTime');
  145. _self.popupFlag = this.diffTime(lockTime);
  146. }else{
  147. setTimeout(function () {
  148. _self.popupFlag = true;
  149. },1000);
  150. }
  151. }
  152. // if(GLOBAL_USER_ID === 0 && _self.couponEntry === 1){
  153. // const isActivityStatus = localStorage.getItem('isActivityStatus');
  154. // //新加优惠券弹窗
  155. // if(isActivityStatus){
  156. // const lockTime = localStorage.getItem('lockTime');
  157. // _self.popupFlag = this.diffTime(lockTime);
  158. // }else{
  159. // setTimeout(function () {
  160. // _self.popupFlag = true;
  161. // },1000);
  162. // }
  163. // }
  164. }
  165. });
  166. },
  167. hanldDetails:function (id){// 跳转公告详情
  168. const _self = this;
  169. window.open('/news/details.html?id='+id);
  170. },
  171. // GetHomeRightData: function(){//模块加载
  172. // var _self = this;
  173. // PublicApi.GetHomeRightData({ source: 1 },function(response){
  174. // if(response.code == 0){
  175. // var data = response.data;
  176. // _self.liveList = data.liveList;
  177. // _self.cmImageList = data.cmImageList;
  178. // _self.infoList = data.infoList;
  179. // }else{
  180. // CAIMEI.Alert(response.msg, '确定');
  181. // }
  182. // });
  183. // },
  184. GetHomeData: function(){//获取首页楼层
  185. var _self = this;
  186. PublicApi.GetHomeData({ source: 1,userId: _self.userId },function(response){
  187. if(response.code === 0){
  188. var data = response.data;
  189. _self.homePageFloor = data.homePageFloor;
  190. _self.hotListPageFloor = data.pageFloorList;
  191. setTimeout(function(){
  192. // 图片懒加载
  193. $("img[data-original]").lazyload();
  194. _self.setAsideNav();
  195. _self.swiperFloor();
  196. // 设置页面查看更多
  197. _self.setReadeMore();
  198. },500);
  199. }else{
  200. CAIMEI.Alert(response.msg, '确定');
  201. }
  202. });
  203. },
  204. PromotionsFormat:function(promo){//促销活动类型数据处理
  205. if(promo!=null){
  206. if(promo.type == 1 && promo.mode == 1){
  207. return true
  208. }else{
  209. return false
  210. }
  211. }
  212. return false
  213. },
  214. setAsideNav: function(){
  215. var _self = this;
  216. if (isPC) {
  217. var titArr = $('.section_page_title').find('h1');
  218. _self.asideNav = [];
  219. for (var i=0; i<titArr.length; i++){
  220. _self.asideNav.push({
  221. id: $(titArr[i]).attr("data-id"),
  222. value: $(titArr[i]).text()
  223. })
  224. }
  225. }
  226. },
  227. // 初始化普通轮播图
  228. initSimpleSwiper: function(){
  229. $('.recommendBox-wrapper').each(function(index, el){
  230. var cell = $(el).parents('.swiper-container-floor').find('.swiper-pagination')
  231. // var cell = $(".swiper-pagination-floor");
  232. var size = Math.ceil(cell.attr("data-id")/5);
  233. var span = '';
  234. for (var i = 0; i < size; i++) {
  235. span += '<span></span>';
  236. }
  237. cell.html(span);
  238. $('.mySwiperSlide').slide({
  239. mainCell:".recommendBox-wrapper",
  240. titCell:".swiper-pagination span",
  241. effect: "leftLoop",
  242. autoPlay: false,
  243. scroll:5,
  244. vis:5
  245. });
  246. })
  247. },
  248. // 商品楼层轮播
  249. swiperFloor: function(){
  250. var self = this;
  251. setTimeout(function(){
  252. // 商品轮播
  253. if (isPC) {
  254. self.initSimpleSwiper();
  255. // var cell = $(".swiper-pagination-floor");
  256. // var size = Math.ceil(cell.attr("data-id")/5);
  257. // var span = '';
  258. // for (var i = 0; i < size; i++) {
  259. // span += '<span></span>';
  260. // }
  261. // cell.html(span);
  262. var swiper = new Swiper(".mySwiper", {
  263. slidesPerView: 5,
  264. spaceBetween: 13,
  265. slidesPerGroup: 5,
  266. loop: false,
  267. autoplay: {
  268. delay: 4000,
  269. stopOnLastSlide: false,
  270. disableOnInteraction: true,
  271. },
  272. loopFillGroupWithBlank: false,
  273. pagination: {
  274. el: ".swiper-pagination",
  275. clickable:true
  276. }
  277. });
  278. } else {
  279. var swiper = new Swiper('.swiper-container-floor', {
  280. slidesPerView: 2,
  281. slidesPerColumn: 2,
  282. spaceBetween:0,
  283. slidesPerGroup: 2,
  284. autoplay: {
  285. delay: 3000,
  286. disableOnInteraction: false
  287. },
  288. pagination: {
  289. el: '.swiper-pagination'
  290. }
  291. });
  292. }
  293. // 图片懒加载
  294. setTimeout(function(){
  295. $("#recommendBox img[data-original]").lazyload();
  296. },0)
  297. },500);
  298. },
  299. // showSubNav: function(event){
  300. // var el = event.currentTarget;
  301. // var parent = $(el).parent();
  302. // parent.siblings().removeAttr("style").removeClass("on").find(".navItem").hide();
  303. // if (parent.hasClass("on")) {
  304. // parent.removeAttr("style").removeClass("on").find(".navItem").slideUp(200);
  305. // } else {
  306. // var height = parent.height();
  307. // parent.addClass("on").find(".navItem").slideDown(200);
  308. // if (parent.find(".navItem").length>0) {
  309. // setTimeout(function(){
  310. // height += parent.find(".navItem").height();
  311. // parent.css("height",height);
  312. // },200);
  313. // }
  314. // }
  315. // },
  316. // 设置页面查看更多按钮显示
  317. setReadeMore: function(){
  318. $(".section_page_more").each(function(){
  319. var id = $(this).attr('data-id')*1;
  320. var size = $(this).attr('data-size')*1;
  321. var el = $(this);
  322. var readMore = false;
  323. if (isPC) {
  324. if([1,3].indexOf(id) !== -1 && size>7) {
  325. readMore = true;
  326. }
  327. if([2,4].indexOf(id) !== -1 && size>5) {
  328. readMore = true;
  329. }
  330. if([5,6,7].indexOf(id) !== -1 && size>10) {
  331. readMore = true;
  332. }
  333. } else {
  334. if([1,3].indexOf(id) !== -1 && size>3) {
  335. readMore = true;
  336. }
  337. if([2,4].indexOf(id) !== -1 && size>2) {
  338. readMore = true;
  339. }
  340. if([5,6,7].indexOf(id) !== -1 && size>4) {
  341. readMore = true;
  342. }
  343. }
  344. if (readMore) {
  345. el.addClass("show");
  346. } else {
  347. el.parents(".section_page").find(".section_page_main").addClass("max");
  348. }
  349. });
  350. },
  351. // 点击查看更多
  352. showMoreItem: function(e){
  353. var el = e.currentTarget;
  354. $(el).parents(".section_page").find(".section_page_main").addClass("max");
  355. $(el).parents(".section_page_more").hide();
  356. },
  357. // 设置页面商品价格
  358. setPriceShown: function(){
  359. var productIds = [];
  360. var userId = GLOBAL_USER_ID;
  361. var shopId = GLOBAL_SHOP_ID;
  362. var userIdentity = GLOBAL_USER_IDENTITY;
  363. $(".main_price_text").each(function(){
  364. var id = $(this).attr('data-id');
  365. if (productIds.indexOf(id) === -1) {
  366. productIds .push(id);
  367. }
  368. });
  369. // 获取商品价格列表
  370. $.getJSON(coreServer+"/commodity/price/list",{
  371. userId: GLOBAL_USER_ID,
  372. productIds: productIds.join(',')
  373. }).done(function (res) {
  374. if (res.code === 0 && res.data) {
  375. var priceList = res.data;
  376. $(".main_price_none").hide();
  377. $(".price_grade_club").hide();
  378. $(".price_grade_shop").hide();
  379. $(".main_price_login").show();
  380. priceList.map(function(price){
  381. // userIdentity用户身份: 0、个人 1、协销 2、会员机构 3、供应商 4,普通机构
  382. // priceFlag: 0公开价格 1不公开价格 2仅对会员机构公开
  383. var parent = $(".main_price_text.product_"+ price.productId);
  384. var priceFlag = parent.find(".main_price_login").attr('data-id')*1;
  385. if (priceFlag===3 || userIdentity===2 || (priceFlag === 0 && userIdentity===4 ) || (userIdentity===3 && shopId === price.shopId*1)) {
  386. parent.find(".price_o_num").text(Number(price.originalPrice).toFixed(2));
  387. parent.find(".price_num").text(Number(price.price).toFixed(2));
  388. if(price.promotions && price.promotions.type*1===1 && price.promotions.mode*1===1){
  389. parent.find(".main_price_show").hide();
  390. parent.find(".main_price_show.none").show();
  391. parent.find(".price_unit").show();
  392. }
  393. } else if (userIdentity===4 && priceFlag === 2){
  394. parent.find(".main_price_show").hide();
  395. parent.find(".price_grade_club").show();
  396. } else {
  397. parent.find(".main_price_show").hide();
  398. parent.find(".price_grade_shop").show();
  399. }
  400. });
  401. }
  402. });
  403. },
  404. // 快捷运营跳转
  405. goQuickOpera($event) {
  406. // 链接跳转
  407. if ($event.link) window.location.href = $event.link
  408. // 文件浏览记录
  409. BeautyArchiveApi.GetStatisticsAddPv({type: 4, authorId: $event.id}, () => {
  410. console.log("浏览记录成功")
  411. })
  412. },
  413. // 供应商广告图统计
  414. setAdvStatistics ($event) {
  415. BeautyArchiveApi.GetStatisticsAddPv({type: 5, authorId: $event.id}, () => {
  416. console.log("供应商广告图点击统计成功")
  417. })
  418. if ($event.jumpLink) {
  419. window.open($event.jumpLink)
  420. }
  421. },
  422. handleCloseClick(){// 关闭优惠券宣传banner
  423. this.isCloseCoupon = false
  424. }
  425. },
  426. created: function() {
  427. if(GLOBAL_TOKEN){
  428. this.userId = GLOBAL_USER_ID;
  429. }
  430. },
  431. mounted: function() {
  432. var _this = this;
  433. // 页面主图轮播
  434. this.swiperBanner();
  435. // 获取设置商品价格
  436. if (GLOBAL_USER_ID) {
  437. this.GetHomeData();
  438. this.GetHomeInit();
  439. }else{
  440. // 设置页面查看更多
  441. this.setReadeMore();
  442. // 设置右侧导航
  443. this.setAsideNav();
  444. // 推荐专区商品轮播
  445. this.swiperFloor();
  446. this.GetHomeInit();
  447. }
  448. // Dom加载后
  449. this.$nextTick(function(){
  450. // 图片懒加载
  451. $("img[data-original]").lazyload();
  452. });
  453. // 侧边栏滚动判断
  454. var distance = 0;
  455. $(window).scroll(function () {
  456. if($('body').attr("style") && $('body').attr("style").indexOf('fixed')>0){
  457. return false;
  458. }
  459. var scrollSize = Math.max($('html').scrollTop(), $('body').scrollTop());
  460. if(scrollSize >300){
  461. $('#sideNav').show();
  462. if(isPC){
  463. // $('#advertising').show();
  464. // 鼠标滚动楼层
  465. setTimeout(function () {
  466. distance = scrollSize;
  467. },0);
  468. // 侧边导航栏高亮
  469. $('.section_page_title').each(function (i,e) {
  470. //每个元素距离顶部的距离
  471. var top = $(e).offset().top;
  472. if(scrollSize > distance){
  473. if(scrollSize >= (top-300)){
  474. $('#sideNav').find('a').eq(i).addClass('on').siblings().removeClass("on");
  475. }
  476. }else {
  477. if(scrollSize >= (top-600)){
  478. $('#sideNav').find('a').eq(i).addClass('on').siblings().removeClass("on");
  479. }
  480. }
  481. });
  482. // 侧边模块固定 fixed
  483. if($('#fixed-wrap').length>0 && $(window).height()>750) {
  484. var tocWrap = $('#fixed-wrap');
  485. var changeSize = $("#globalHead").outerHeight() + $("#swiper-container").outerHeight() + $("#sidebar").outerHeight();
  486. scrollSize >= changeSize ? tocWrap.addClass("fixed") : tocWrap.removeClass("fixed");
  487. }
  488. }
  489. }else {
  490. $('#sideNav').hide();
  491. $('#advertising').hide();
  492. }
  493. });
  494. // 侧边导航
  495. setTimeout(function(){
  496. $('#sideNav').on("click", 'a[data-id]',function () {
  497. var id = $(this).attr('data-id');
  498. var floorScroll = $('.section_page_title [data-id='+id+']').offset().top-200;
  499. $('html,body').animate({scrollTop: floorScroll},600);
  500. });
  501. },2000);
  502. //关闭广告图
  503. // $('#advertising').on('click','.close',function () {
  504. // $(this).parents('.item').hide();
  505. // });
  506. }
  507. });