index.js 19 KB

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