index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. var homeData = new Vue({
  2. el: '#container',
  3. data: {
  4. userId:0,
  5. images: [],
  6. listLoading:true,
  7. advertising: [],
  8. asideNav: [],
  9. productIdArr:[],
  10. liveList:[],//右侧直播模块
  11. cmImageList:[],//右侧活动模块
  12. infoList:[],//右侧文章模块
  13. pageList:[],//左侧楼层
  14. supplierImage:'',//供应商banner
  15. supplierWwwLink:'',//供应商banner 链接
  16. supplierList:[],//供应商列表
  17. topMenuList:[]
  18. },
  19. filters: {
  20. statusType:function(value) {
  21. switch (value) {
  22. case '1':
  23. return '未开始';
  24. break;
  25. case '2':
  26. return '直播中';
  27. break;
  28. case '3':
  29. return '已结束';
  30. break;
  31. }
  32. },
  33. statusTypeClass:function(value) {
  34. switch (value) {
  35. case '1':
  36. return 'icon-wart';
  37. break;
  38. case '2':
  39. return 'icon-live';
  40. break;
  41. case '3':
  42. return 'icon-end';
  43. break;
  44. }
  45. },
  46. NumFormat:function(value) {//处理金额
  47. return Number(value).toFixed(2);
  48. },
  49. },
  50. methods: {
  51. GetBanners: function(){
  52. var _self = this;
  53. PublicApi.GetHomeBanner({},function(response){
  54. if(response.code == 0){
  55. _self.images = response.data;
  56. _self.listLoading =false;
  57. _self.SwiperBanner();
  58. }else{
  59. CAIMEI.Alert(response.msg, '确定');
  60. }
  61. });
  62. },
  63. SwiperBanner: function(){
  64. setTimeout(function(){
  65. if (isPC) {
  66. $('#swiper-container').slide({
  67. mainCell:".swiper-wrapper-banner",
  68. titCell:".swiper-pagination-banner span",
  69. effect: "leftLoop",
  70. prevCell:".swiper-button-prev",
  71. nextCell:".swiper-button-next",
  72. interTime: 3000,
  73. autoPlay: true,
  74. autoPage: false,
  75. trigger: "mouseover"
  76. });
  77. } else {
  78. var swiper = new Swiper('#swiper-container', {
  79. loop : true,
  80. autoplay: {
  81. delay: 3000,
  82. disableOnInteraction: false
  83. },
  84. navigation: {
  85. nextEl: '.swiper-button-next',
  86. prevEl: '.swiper-button-prev'
  87. },
  88. pagination: {
  89. el: '.swiper-pagination',
  90. clickable :true
  91. }
  92. });
  93. }
  94. },300);
  95. },
  96. GetHomeFloorData: function(){
  97. var _self = this;
  98. PublicApi.GetHomeData({userId:GLOBAL_USER_ID,soure:1},function(response){
  99. if(response.code == 0){
  100. var data = response.data;
  101. // var floorList = [];
  102. _self.pageList = data.homePageFloor;
  103. _self.liveList = data.liveList;
  104. _self.supplierList = data.supplierImage.qualitySupplierList;
  105. _self.supplierImage = data.supplierImage.wwwImage;
  106. _self.supplierWwwLink = data.supplierImage.wwwLink;
  107. _self.pageList.forEach(function(page){
  108. if(page.floorContent){
  109. if(isPC){
  110. if(page.floorContent.templateType == '1' || page.floorContent.templateType == '3'){
  111. if (page.floorImageList.length>7){
  112. page.isPageMore = true;
  113. }
  114. }else if(page.floorContent.templateType == '2' || page.floorContent.templateType == '4' || page.floorContent.templateType == '7'){
  115. if (page.floorImageList.length>5){
  116. page.isPageMore = true;
  117. }
  118. }else if(page.floorContent.templateType == '5'){
  119. if (page.floorImageList.length>10){
  120. page.isPageMore = true;
  121. }
  122. }
  123. }else{
  124. if(page.floorContent.templateType == '1' || page.floorContent.templateType == '3'){
  125. if (page.floorImageList.length>3){
  126. page.isPageMore = true;
  127. }
  128. }else if(page.floorContent.templateType == '2' || page.floorContent.templateType == '4'){
  129. if (page.floorImageList.length>2){
  130. page.isPageMore = true;
  131. }
  132. }else if(page.floorContent.templateType == '5'){
  133. if (page.floorImageList.length>4){
  134. page.isPageMore = true;
  135. }
  136. }
  137. }
  138. }
  139. });
  140. console.log(_self.pageList)
  141. _self.GetHomeRightData();
  142. setTimeout(function() {
  143. // 设置侧边导航数据
  144. _self.SetAsideNav();
  145. _self.SwiperFloor();
  146. },500);
  147. }else{
  148. CAIMEI.Alert(response.msg, '确定');
  149. }
  150. });
  151. },
  152. GetHomeRightData: function(){
  153. var _self = this;
  154. PublicApi.GetHomeRightData({ source: 1 },function(response){
  155. if(response.code == 0){
  156. var data = response.data;
  157. _self.liveList = data.liveList;
  158. _self.cmImageList = data.cmImageList;
  159. _self.infoList = data.infoList;
  160. }else{
  161. CAIMEI.Alert(response.msg, '确定');
  162. }
  163. });
  164. },
  165. PromotionsFormat:function(promo){//促销活动类型数据处理
  166. if(promo!=null){
  167. if(promo.type == 1 && promo.mode == 1){
  168. return true
  169. }else{
  170. return false
  171. }
  172. }
  173. return false
  174. },
  175. showMorePageFn:function(page){
  176. page.isPageMore = !page.isPageMore;
  177. },
  178. getAdvertising: function(){
  179. var _self = this;
  180. $.getJSON("/home/advertising").done(function (r) {
  181. if (r.code === 0 && r.data) {
  182. _self.advertising = r.data;
  183. }
  184. });
  185. },
  186. SetAsideNav: function(){
  187. var _self = this;
  188. var titArr = $('.section_page_title').find('h1');
  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. SwiperFloor: function(){
  197. setTimeout(function(){ // 图片懒加载
  198. $("img[data-original]").lazyload();
  199. },500);
  200. setTimeout(function(){
  201. if (isPC) {
  202. $('#recommendBox').slide({
  203. mainCell:".recommendBox-wrapper",
  204. titCell:".swiper-pagination-floor span",
  205. effect: "leftLoop",
  206. autoPlay: false,
  207. scroll:5,
  208. vis:5
  209. });
  210. } else {
  211. var swiper = new Swiper('#recommendBox', {
  212. slidesPerView: 2,
  213. slidesPerColumn: 2,
  214. spaceBetween: 0,
  215. slidesPerGroup: 2,
  216. autoplay: {
  217. delay: 3000,
  218. disableOnInteraction: false
  219. },
  220. pagination: {
  221. el: '.swiper-pagination'
  222. }
  223. });
  224. }
  225. },500);
  226. },
  227. showSubNav: function(event){
  228. var el = event.currentTarget;
  229. var parent = $(el).parent();
  230. parent.siblings().removeAttr("style").removeClass("on").find(".navItem").hide();
  231. if (parent.hasClass("on")) {
  232. parent.removeAttr("style").removeClass("on").find(".navItem").slideUp(200);
  233. } else {
  234. var height = parent.height();
  235. parent.addClass("on").find(".navItem").slideDown(200);
  236. if (parent.find(".navItem").length>0) {
  237. setTimeout(function(){
  238. height += parent.find(".navItem").height();
  239. parent.css("height",height);
  240. },200);
  241. }
  242. }
  243. }
  244. },
  245. created: function() {
  246. var userInfo = localStorage.getItem('userInfo');
  247. if(userInfo){
  248. this.userId = JSON.parse(userInfo).userId;
  249. }
  250. this.GetBanners();
  251. this.GetHomeFloorData();
  252. },
  253. mounted: function() {
  254. // this.getAdvertising();
  255. // 侧边栏滚动判断
  256. var distance = 0;
  257. $(window).scroll(function () {
  258. if($('body').attr("style") && $('body').attr("style").indexOf('fixed')>0){
  259. return false;
  260. }
  261. var scoll = Math.max($('html').scrollTop(), $('body').scrollTop());
  262. if(scoll >300){
  263. $('#sideNav').show();
  264. if(isPC){
  265. $('#advertising').show();
  266. // 鼠标滚动楼层
  267. setTimeout(function () {
  268. distance = scoll;
  269. },0);
  270. $('.section_page_title').each(function (i,e) {
  271. //每个元素距离顶部的距离
  272. var top = $(e).offset().top;
  273. if(scoll > distance){
  274. if(scoll >= (top-300)){
  275. $('#sideNav').find('a').eq(i).addClass('on').siblings().removeClass("on");
  276. }
  277. }else {
  278. if(scoll >= (top-600)){
  279. $('#sideNav').find('a').eq(i).addClass('on').siblings().removeClass("on");
  280. }
  281. }
  282. });
  283. }
  284. }else {
  285. $('#sideNav').hide();
  286. $('#advertising').hide();
  287. }
  288. });
  289. // 侧边导航
  290. setTimeout(function(){
  291. $('#sideNav').on("click", 'a[data-id]',function () {
  292. var id = $(this).attr('data-id');
  293. var floorScroll = $('.section_page_title [data-id='+id+']').offset().top-200;
  294. $('html,body').animate({scrollTop: floorScroll},600);
  295. });
  296. },2000);
  297. //关闭广告图
  298. $('#advertising').on('click','.close',function () {
  299. $(this).parents('.item').hide();
  300. })
  301.  
  302. }
  303. });