index.js 17 KB

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