index.js 20 KB

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