index.js 25 KB

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