index.js 18 KB

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