index.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  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. topAdvertisement:{},// 专属广告图
  16. couponEntry:2,// 活动优惠券弹窗显示控制
  17. hotListPageFloor:[],// 新品橱窗
  18. homePageFloor:[],//楼层
  19. quickoperaList: [], // 快捷运营入口列表
  20. supplierList:[],// 优质供应商列表
  21. recommendList:[],// 推荐列表
  22. dropScreenShow:false,
  23. isCmPopup:false,
  24. isCloseCoupon:false,
  25. currentHour: new Date().getHours(),
  26. timeSpeech:'',
  27. userInfo:{},
  28. paymentCount:0,//待付款
  29. waitShipmentsCount:0,//待发货
  30. shipmentsCount:0,//已发货
  31. salesReturnCount:0,//退货/款
  32. listQuery:{
  33. orderNo:'',
  34. orderState:0,
  35. userId:0,
  36. beginTime:'',
  37. endTime:'',
  38. pageNum:1,
  39. pageSize:1
  40. },
  41. orders:null,
  42. categories:[],
  43. isMenuHovered:false,
  44. selectedCategory:null,
  45. hideTimer:null,
  46. categoryTabIndex:1
  47. },
  48. filters: {
  49. },
  50. methods: {
  51. //切换分类
  52. handleClickTabS(index){
  53. this.categories = []
  54. this.categoryTabIndex = index
  55. this.GetProductClassify(index);
  56. },
  57. //获取一级分类
  58. GetProductClassify(index){
  59. const _self = this
  60. PublicApi.GetProductClassify({typeSort:index,source :'crm'},function (response) {
  61. if(response.code === 0){
  62. _self.categories = response.data
  63. }
  64. })
  65. },
  66. GetMyPcCenterInfo(userId){
  67. const _self = this;
  68. UserApi.GetMyPcCenterInfo({userId:userId},function (response) {
  69. if(response.code === 0){
  70. var data = response.data;
  71. _self.userInfo = data.user;
  72. }
  73. })
  74. },
  75. // 获取订单数量
  76. GetQueryOrderNum(userId){
  77. const _self = this;
  78. OrderApi.GetQueryOrderNum({userId: userId}, function (response) {
  79. if (response.code === 0) {
  80. const data = response.data;
  81. _self.paymentCount = data.paymentCount
  82. _self.waitShipmentsCount = data.waitShipmentsCount
  83. _self.shipmentsCount = data.shipmentsCount
  84. _self.salesReturnCount = data.salesReturnCount
  85. }
  86. })
  87. },
  88. getOrderList(params){//查询订单列表
  89. const _self = this;
  90. OrderApi.GetQueryOrderListData(params,function (response) {
  91. if(response.code === 0){
  92. const data = response.data;
  93. if(data.list && data.list.length>0) {
  94. _self.orders = data.list[0].orderProductList[0];
  95. }else{
  96. _self.orders = null;
  97. }
  98. }
  99. })
  100. },
  101. handleHidePopup(){
  102. this.isCmPopup = false
  103. },
  104. showDropScreen(){
  105. this.dropScreenShow = !this.dropScreenShow
  106. },
  107. hideDropScreen(){
  108. this.dropScreenShow = false
  109. },
  110. //处理金额
  111. filtersFormat(value) {
  112. if (value) {
  113. return Number(value).toFixed(2)
  114. } else {
  115. return '0.00'
  116. }
  117. },
  118. // 快捷运营列表
  119. footList(arr) {
  120. if (!Array.isArray(arr)) return []
  121. let newArr = [],a = []
  122. let indexNum = isPC ? 12 : 10
  123. arr.map((item, index) => {
  124. if (index !== 0 && index % indexNum === 0) {
  125. newArr.push(a)
  126. a = []
  127. a.push(item)
  128. }
  129. else a.push(item)
  130. if (arr.length === (index + 1)) {
  131. newArr.push(a)
  132. }
  133. })
  134. return newArr
  135. },
  136. // 处理供应商列表
  137. checkedSupplierList(arr) {
  138. if (!Array.isArray(arr)) return []
  139. let newArr = [],a = []
  140. let indexNum = isPC ? 4 : 4
  141. arr.map((item, index) => {
  142. if (index !== 0 && index % indexNum === 0) {
  143. newArr.push(a)
  144. a = []
  145. a.push(item)
  146. }
  147. else a.push(item)
  148. if (arr.length === (index + 1)) {
  149. newArr.push(a)
  150. }
  151. })
  152. return newArr
  153. },
  154. // 是否显示vip标签价格
  155. showVipPriceTag(pros){
  156. if(pros){
  157. //非会员
  158. // if(!GLOBAL_VIP_FLAG === 1) return false;
  159. // 商品所有机构可见
  160. if(pros.priceFlag === 0 && pros.svipProductFlag === 1 && pros.actStatus !==1 ) return true;
  161. // 商品价格仅资质机构可见
  162. if(pros.priceFlag === 2 && pros.svipProductFlag === 1 && GLOBAL_USER_IDENTITY === 2 && pros.actStatus !==1) return true;
  163. // 商品价格仅医美机构可见
  164. if(pros.priceFlag === 3 && pros.svipProductFlag === 1 && GLOBAL_USER_IDENTITY === 2 && GLOBAL_CLUB_TYPE === 1 && pros.actStatus !==1) return true;
  165. // 其它
  166. return false;
  167. }
  168. },
  169. popupPage(){ // 弹窗点击跳转链接
  170. window.open(this.centerImage.link)
  171. // localStorage.setItem('lockTime',Date.now());
  172. // window.localStorage.setItem('isActivityStatus',true);
  173. },
  174. closePopup(){ // 关闭弹窗
  175. this.popupFlag=false;
  176. $('.Popup').slideUp(100);
  177. localStorage.setItem('lockTime',Date.now());
  178. localStorage.setItem('isActivityStatus',true);
  179. },
  180. diffTime(time){
  181. const date = Date.now();
  182. console.log('缓存时间戳',time);
  183. console.log('当前时间戳',date);
  184. console.log('计算时间戳',(date-time));
  185. return (date - time) >= 2 * 60 * 1000
  186. },
  187. // 页面主图轮播
  188. swiperBanner: function(){
  189. setTimeout(function(){
  190. if (isPC) {
  191. $('#swiper-container').slide({
  192. mainCell:".swiper-wrapper-banner",
  193. titCell:".swiper-pagination-banner span",
  194. effect: "leftLoop",
  195. prevCell:".swiper-button-prev",
  196. nextCell:".swiper-button-next",
  197. interTime: 3000,
  198. autoPlay: true,
  199. autoPage: false,
  200. trigger: "mouseover"
  201. });
  202. } else {
  203. var swiper = new Swiper('#swiper-container', {
  204. loop : true,
  205. autoplay: {
  206. delay: 3000,
  207. disableOnInteraction: false
  208. },
  209. navigation: {
  210. nextEl: '.swiper-button-next',
  211. prevEl: '.swiper-button-prev'
  212. },
  213. pagination: {
  214. el: '.swiper-pagination',
  215. clickable :true
  216. }
  217. });
  218. }
  219. },300);
  220. },
  221. GetHomeInit: function(){// 初始化
  222. const _self = this;
  223. PublicApi.GetHomeInit({ source: 1 },function(response){
  224. if(response.code === 0){
  225. _self.couponEntry = response.data.couponEntry
  226. _self.quickoperaList = _self.footList(response.data.shortcutList)
  227. if(isPC){
  228. _self.newsList = response.data.annlist.slice(0,2)
  229. }else{
  230. _self.newsList = response.data.annlist.slice(0,1)
  231. }
  232. _self.isCmPopup = GLOBAL_USER_ID <= 0
  233. const centerImageList = response.data.centerImage
  234. if(centerImageList && centerImageList.length > 0){
  235. _self.centerImage = response.data.centerImage[0]
  236. const isActivityStatus = localStorage.getItem('isActivityStatus');
  237. //广告弹窗
  238. if(isActivityStatus){
  239. const lockTime = localStorage.getItem('lockTime');
  240. _self.popupFlag = this.diffTime(lockTime);
  241. }else{
  242. setTimeout(function () {
  243. _self.popupFlag = true;
  244. },1000);
  245. }
  246. }
  247. // if(GLOBAL_USER_ID === 0 && _self.couponEntry === 1){
  248. // const isActivityStatus = localStorage.getItem('isActivityStatus');
  249. // //新加优惠券弹窗
  250. // if(isActivityStatus){
  251. // const lockTime = localStorage.getItem('lockTime');
  252. // _self.popupFlag = this.diffTime(lockTime);
  253. // }else{
  254. // setTimeout(function () {
  255. // _self.popupFlag = true;
  256. // },1000);
  257. // }
  258. // }
  259. }
  260. });
  261. },
  262. hanldDetails:function (id){// 跳转公告详情
  263. const _self = this;
  264. window.open('/news/details.html?id='+id);
  265. },
  266. // GetHomeRightData: function(){//模块加载
  267. // var _self = this;
  268. // PublicApi.GetHomeRightData({ source: 1 },function(response){
  269. // if(response.code == 0){
  270. // var data = response.data;
  271. // _self.liveList = data.liveList;
  272. // _self.cmImageList = data.cmImageList;
  273. // _self.infoList = data.infoList;
  274. // }else{
  275. // CAIMEI.Alert(response.msg, '确定');
  276. // }
  277. // });
  278. // },
  279. GetHomeData: function(){//获取首页楼层
  280. var _self = this;
  281. PublicApi.GetHomeData({ source: 1,userId: _self.userId },function(response){
  282. if(response.code === 0){
  283. var data = response.data;
  284. _self.homePageFloor = data.zones;
  285. _self.hotListPageFloor = data.pageFloorList;
  286. _self.recommendList = data.recommendProducts
  287. _self.supplierList = _self.checkedSupplierList(data.supplierImage);
  288. setTimeout(function(){
  289. // 图片懒加载
  290. $("img[data-original]").lazyload();
  291. _self.setAsideNav();
  292. _self.swiperFloor();
  293. // 设置页面查看更多
  294. _self.setReadeMore();
  295. },500);
  296. }else{
  297. CAIMEI.Alert(response.msg, '确定');
  298. }
  299. });
  300. },
  301. PromotionsFormat:function(promo){//促销活动类型数据处理
  302. if(promo!=null){
  303. if(promo.type == 1 && promo.mode == 1){
  304. return true
  305. }else{
  306. return false
  307. }
  308. }
  309. return false
  310. },
  311. setAsideNav: function(){
  312. var _self = this;
  313. if (isPC) {
  314. var titArr = $('.section_page_title').find('h1');
  315. _self.asideNav = [];
  316. for (var i=0; i<titArr.length; i++){
  317. _self.asideNav.push({
  318. id: $(titArr[i]).attr("data-id"),
  319. value: $(titArr[i]).text()
  320. })
  321. }
  322. }
  323. },
  324. // 初始化普通轮播图
  325. initSimpleSwiper: function(){
  326. $('.recommendBox-wrapper').each(function(index, el){
  327. var cell = $(el).parents('.swiper-container-floor').find('.swiper-pagination')
  328. // var cell = $(".swiper-pagination-floor");
  329. var size = Math.ceil(cell.attr("data-id")/6);
  330. var span = '';
  331. for (var i = 0; i < size; i++) {
  332. span += '<span></span>';
  333. }
  334. cell.html(span);
  335. $('.mySwiperSlide').slide({
  336. mainCell:".recommendBox-wrapper",
  337. titCell:".swiper-pagination span",
  338. effect: "leftLoop",
  339. autoPlay: false,
  340. scroll:5,
  341. vis:5
  342. });
  343. })
  344. },
  345. // 商品楼层轮播
  346. swiperFloor: function(){
  347. var self = this;
  348. setTimeout(function(){
  349. // 商品轮播
  350. if (isPC) {
  351. self.initSimpleSwiper();
  352. // var cell = $(".swiper-pagination-floor");
  353. // var size = Math.ceil(cell.attr("data-id")/5);
  354. // var span = '';
  355. // for (var i = 0; i < size; i++) {
  356. // span += '<span></span>';
  357. // }
  358. // cell.html(span);
  359. var swiper = new Swiper(".mySwiper", {
  360. slidesPerView: 6,
  361. spaceBetween: 13,
  362. slidesPerGroup: 5,
  363. loop: false,
  364. autoplay: {
  365. delay: 8000,
  366. stopOnLastSlide: false,
  367. disableOnInteraction: true,
  368. },
  369. loopFillGroupWithBlank: false,
  370. pagination: {
  371. el: ".swiper-pagination",
  372. clickable:true
  373. }
  374. });
  375. } else {
  376. var swiper = new Swiper('.swiper-container-floor', {
  377. slidesPerView: 2,
  378. slidesPerColumn: 2,
  379. spaceBetween:0,
  380. slidesPerGroup: 2,
  381. autoplay: {
  382. delay: 3000,
  383. disableOnInteraction: false
  384. },
  385. pagination: {
  386. el: '.swiper-pagination'
  387. }
  388. });
  389. }
  390. // 图片懒加载
  391. setTimeout(function(){
  392. $("#recommendBox img[data-original]").lazyload();
  393. },0)
  394. },500);
  395. },
  396. // showSubNav: function(event){
  397. // var el = event.currentTarget;
  398. // var parent = $(el).parent();
  399. // parent.siblings().removeAttr("style").removeClass("on").find(".navItem").hide();
  400. // if (parent.hasClass("on")) {
  401. // parent.removeAttr("style").removeClass("on").find(".navItem").slideUp(200);
  402. // } else {
  403. // var height = parent.height();
  404. // parent.addClass("on").find(".navItem").slideDown(200);
  405. // if (parent.find(".navItem").length>0) {
  406. // setTimeout(function(){
  407. // height += parent.find(".navItem").height();
  408. // parent.css("height",height);
  409. // },200);
  410. // }
  411. // }
  412. // },
  413. // 设置页面查看更多按钮显示
  414. setReadeMore: function(){
  415. $(".section_page_more").each(function(){
  416. var id = $(this).attr('data-id')*1;
  417. var size = $(this).attr('data-size')*1;
  418. var el = $(this);
  419. var readMore = false;
  420. if (isPC) {
  421. if([1,3].indexOf(id) !== -1 && size>7) {
  422. readMore = true;
  423. }
  424. if([2,4].indexOf(id) !== -1 && size>5) {
  425. readMore = true;
  426. }
  427. if([5,6,7].indexOf(id) !== -1 && size>10) {
  428. readMore = true;
  429. }
  430. } else {
  431. if([1,3].indexOf(id) !== -1 && size>3) {
  432. readMore = true;
  433. }
  434. if([2,4].indexOf(id) !== -1 && size>2) {
  435. readMore = true;
  436. }
  437. if([5,6,7].indexOf(id) !== -1 && size>4) {
  438. readMore = true;
  439. }
  440. }
  441. if (readMore) {
  442. el.addClass("show");
  443. } else {
  444. el.parents(".section_page").find(".section_page_main").addClass("max");
  445. }
  446. });
  447. },
  448. // 点击查看更多
  449. showMoreItem: function(e){
  450. var el = e.currentTarget;
  451. $(el).parents(".section_page").find(".section_page_main").addClass("max");
  452. $(el).parents(".section_page_more").hide();
  453. },
  454. // 设置页面商品价格
  455. setPriceShown: function(){
  456. var productIds = [];
  457. var userId = GLOBAL_USER_ID;
  458. var shopId = GLOBAL_SHOP_ID;
  459. var userIdentity = GLOBAL_USER_IDENTITY;
  460. $(".main_price_text").each(function(){
  461. var id = $(this).attr('data-id');
  462. if (productIds.indexOf(id) === -1) {
  463. productIds .push(id);
  464. }
  465. });
  466. // 获取商品价格列表
  467. $.getJSON(coreServer+"/commodity/price/list",{
  468. userId: GLOBAL_USER_ID,
  469. productIds: productIds.join(',')
  470. }).done(function (res) {
  471. if (res.code === 0 && res.data) {
  472. var priceList = res.data;
  473. $(".main_price_none").hide();
  474. $(".price_grade_club").hide();
  475. $(".price_grade_shop").hide();
  476. $(".main_price_login").show();
  477. priceList.map(function(price){
  478. // userIdentity用户身份: 0、个人 1、协销 2、会员机构 3、供应商 4,普通机构
  479. // priceFlag: 0公开价格 1不公开价格 2仅对会员机构公开
  480. var parent = $(".main_price_text.product_"+ price.productId);
  481. var priceFlag = parent.find(".main_price_login").attr('data-id')*1;
  482. if (priceFlag===3 || userIdentity===2 || (priceFlag === 0 && userIdentity===4 ) || (userIdentity===3 && shopId === price.shopId*1)) {
  483. parent.find(".price_o_num").text(Number(price.originalPrice).toFixed(2));
  484. parent.find(".price_num").text(Number(price.price).toFixed(2));
  485. if(price.promotions && price.promotions.type*1===1 && price.promotions.mode*1===1){
  486. parent.find(".main_price_show").hide();
  487. parent.find(".main_price_show.none").show();
  488. parent.find(".price_unit").show();
  489. }
  490. } else if (userIdentity===4 && priceFlag === 2){
  491. parent.find(".main_price_show").hide();
  492. parent.find(".price_grade_club").show();
  493. } else {
  494. parent.find(".main_price_show").hide();
  495. parent.find(".price_grade_shop").show();
  496. }
  497. });
  498. }
  499. });
  500. },
  501. // 快捷运营跳转
  502. goQuickOpera($event) {
  503. // 链接跳转
  504. if ($event.link) window.open($event.link)
  505. // 文件浏览记录
  506. BeautyArchiveApi.GetStatisticsAddPv({type: 4, authorId: $event.id}, () => {
  507. console.log("浏览记录成功")
  508. })
  509. },
  510. // 供应商广告图统计
  511. setAdvStatistics ($event) {
  512. BeautyArchiveApi.GetStatisticsAddPv({type: 5, authorId: $event.id}, () => {
  513. console.log("供应商广告图点击统计成功")
  514. })
  515. if ($event.jumpLink) {
  516. window.open($event.jumpLink)
  517. }
  518. },
  519. handleCloseClick(){// 关闭优惠券宣传banner
  520. this.isCloseCoupon = false
  521. },
  522. //
  523. handleMenuCategory(category){
  524. this.selectedCategory = category
  525. },
  526. handleMenuLeave() {
  527. this.isMenuHovered = false
  528. this.selectedCategory = null
  529. },
  530. // 延迟隐藏面板(用于平滑过渡)
  531. scheduleHidePanel() {
  532. this.hideTimer = setTimeout(() => {
  533. this.isMenuHovered = false
  534. this.selectedCategory = null
  535. }, 300)
  536. },
  537. cancelHidePanel() {
  538. clearTimeout(this.hideTimer)
  539. }
  540. },
  541. created() {
  542. if(globalUserData){
  543. this.userId = this.listQuery.userId = globalUserData.userId;
  544. this.GetMyPcCenterInfo(this.userId)
  545. this.GetQueryOrderNum(this.userId)
  546. this.getOrderList(this.listQuery)
  547. }
  548. },
  549. computed: {
  550. greeting() {
  551. if (this.currentHour < 12) return 'Hi~ 上午好 🌞'
  552. else if (this.currentHour < 18) return 'Hi~ 下午好 ☕'
  553. else return 'Hi~ 晚上好 🌙'
  554. },
  555. // 计算属性控制面板显示
  556. isPanelVisible(){
  557. return this.isMenuHovered && this.selectedCategory
  558. }
  559. },
  560. mounted() {
  561. const _this = this;
  562. // 页面主图轮播
  563. this.GetProductClassify(this.categoryTabIndex)
  564. this.swiperBanner();
  565. // 获取设置商品价格
  566. if (GLOBAL_USER_ID) {
  567. this.GetHomeData();
  568. this.GetHomeInit();
  569. }else{
  570. // 设置页面查看更多
  571. this.setReadeMore();
  572. // 设置右侧导航
  573. this.setAsideNav();
  574. // 推荐专区商品轮播
  575. this.swiperFloor();
  576. this.GetHomeInit();
  577. this.GetHomeData();
  578. }
  579. // Dom加载后
  580. this.$nextTick(function(){
  581. // 图片懒加载
  582. $("img[data-original]").lazyload();
  583. });
  584. // 侧边栏滚动判断
  585. var distance = 0;
  586. $(window).scroll(function () {
  587. if($('body').attr("style") && $('body').attr("style").indexOf('fixed')>0){
  588. return false;
  589. }
  590. var scrollSize = Math.max($('html').scrollTop(), $('body').scrollTop());
  591. if(scrollSize >300){
  592. $('#sideNav').show();
  593. if(isPC){
  594. // $('#advertising').show();
  595. // 鼠标滚动楼层
  596. setTimeout(function () {
  597. distance = scrollSize;
  598. },0);
  599. // 侧边导航栏高亮
  600. $('.section_page_title').each(function (i,e) {
  601. //每个元素距离顶部的距离
  602. var top = $(e).offset().top;
  603. if(scrollSize > distance){
  604. if(scrollSize >= (top-300)){
  605. $('#sideNav').find('a').eq(i).addClass('on').siblings().removeClass("on");
  606. }
  607. }else {
  608. if(scrollSize >= (top-600)){
  609. $('#sideNav').find('a').eq(i).addClass('on').siblings().removeClass("on");
  610. }
  611. }
  612. });
  613. // 侧边模块固定 fixed
  614. if($('#fixed-wrap').length>0 && $(window).height()>750) {
  615. var tocWrap = $('#fixed-wrap');
  616. var changeSize = $("#globalHead").outerHeight() + $("#swiper-container").outerHeight() + $("#sidebar").outerHeight();
  617. scrollSize >= changeSize ? tocWrap.addClass("fixed") : tocWrap.removeClass("fixed");
  618. }
  619. }
  620. }else {
  621. $('#sideNav').hide();
  622. $('#advertising').hide();
  623. }
  624. });
  625. // 侧边导航
  626. setTimeout(function(){
  627. $('#sideNav').on("click", 'a[data-id]',function () {
  628. var id = $(this).attr('data-id');
  629. var floorScroll = $('.section_page_title [data-id='+id+']').offset().top-200;
  630. $('html,body').animate({scrollTop: floorScroll},600);
  631. });
  632. },2000);
  633. //关闭广告图
  634. // $('#advertising').on('click','.close',function () {
  635. // $(this).parents('.item').hide();
  636. // });
  637. }
  638. });