activityTopic.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. var activity = new Vue({
  2. el: '#activity',
  3. data: {
  4. listLoading: true, //加载动画
  5. hotlist: [], //热搜词
  6. recommendPage: 1, //
  7. floorList: [], //楼层列表
  8. pageInfo: null,
  9. userId: 0, //用户id
  10. typeSort: '',
  11. showflag: false, //对话框
  12. params: { //请求参数
  13. pageId: '',
  14. userId: '',
  15. source: 1
  16. },
  17. nav_linkName: '', //导航名
  18. isPc: window.isPC
  19. },
  20. filters: {
  21. NumFormat: function (value) {//处理金额
  22. return Number(value).toFixed(2);
  23. },
  24. marginRight: function (index) {
  25. var strArr = index.toString().split('');
  26. var lastStr = strArr[strArr.length - 1];
  27. return lastStr === '2' || lastStr === '7'
  28. }
  29. },
  30. computed: {},
  31. created: function () {
  32. // this.init();
  33. },
  34. methods: {
  35. //促销活动类型数据处理
  36. PromotionsFormat: function (promo) {
  37. if (promo !== null) {
  38. if (promo.type === 1 && promo.mode === 1) {
  39. return true;
  40. } else {
  41. return false;
  42. }
  43. }
  44. return false;
  45. },
  46. closeup: function () {
  47. this.showflag = false;
  48. document.body.style.overflow = '';
  49. },
  50. showNav: function () {
  51. var _this = this;
  52. _this.showflag = !_this.showflag;
  53. if (_this.showflag) {
  54. document.body.style.overflow = 'hidden';
  55. } else {
  56. document.body.style.overflow = '';
  57. }
  58. },
  59. toserch: function (item) {
  60. window.location.href = '/product/classify-'+this.typeSort+'-'+item.bigTypeID+'.html?name='+this.nav_linkName
  61. },
  62. //查看更多
  63. showMore: function (page) {
  64. page.isPageMore = false
  65. },
  66. //初始化数据
  67. init: function () {
  68. this.nav_linkName = decodeURI(CAIMEI.getUrlParam('name'));
  69. //判断用户是否登录
  70. var userInfo = localStorage.getItem('userInfo');
  71. if (userInfo) {
  72. this.params.userId = JSON.parse(userInfo).userId;
  73. }
  74. //获取页面id
  75. this.params.pageId = getUrlParam('id');
  76. this.getFloorData()
  77. },
  78. //处理商品状态
  79. fromatFloorProductStatus: function (formatData) {
  80. formatData.forEach(function (item) {
  81. item.floorImageList = item.floorImageList.filter(function (val) {
  82. return val.pcStatus === '1'
  83. });
  84. });
  85. },
  86. //获取页面数据
  87. getFloorData: function () {
  88. var _self = this;
  89. ProductApi.getActivityData(_self.params, function (res) {
  90. if (res.code === 0) {
  91. _self.floorList = res.data.floorList;
  92. _self.pageInfo = res.data.page;
  93. setTimeout(function () {
  94. _self.fromatFloorProductStatus(_self.floorList);
  95. if (_self.isPc) {
  96. _self.initFloorListPc(_self.floorList);
  97. } else {
  98. _self.initFloorListMobile(_self.floorList);
  99. }
  100. _self.listLoading = false;
  101. _self.initSwiper();
  102. });
  103. } else {
  104. CAIMEI.Alert(res.msg, '确定');
  105. }
  106. })
  107. },
  108. // PC楼层数据处理
  109. initFloorListPc: function (floorList) {
  110. var _that = this
  111. floorList.forEach(function (list) {
  112. if (list.floorContent) {
  113. var tempType = list.floorContent.templateType
  114. switch (tempType) {
  115. case '1':
  116. list.floorImageList = _that.swiperDataFormat(
  117. list.floorImageList,
  118. 12
  119. )
  120. break
  121. case '2':
  122. case '6':
  123. list.floorImageList = _that.swiperDataFormat(list.floorImageList, 6)
  124. break
  125. case '3':
  126. case '9':
  127. list.floorImageList = _that.swiperDataFormat(list.floorImageList, 4)
  128. break
  129. case '11':
  130. case '12':
  131. case '13':
  132. case '15':
  133. case '17':
  134. case '19':
  135. case '20':
  136. list.floorImageList.length > 5 && (list.isPageMore = true)
  137. break
  138. case '14':
  139. list.floorImageList.length > 10 && (list.isPageMore = true)
  140. break
  141. case '16':
  142. case '18':
  143. list.floorImageList.length > 7 && (list.isPageMore = true)
  144. break
  145. default:
  146. break
  147. }
  148. }
  149. })
  150. },
  151. // 移动端楼层数据处理
  152. initFloorListMobile: function (floorList) {
  153. var _that = this
  154. floorList.forEach(function (list) {
  155. if (list.floorContent) {
  156. var tempType = list.floorContent.templateType
  157. switch (tempType) {
  158. case '1':
  159. list.floorImageList = _that.swiperDataFormat(list.floorImageList, 8)
  160. break
  161. case '2':
  162. list.floorImageList = _that.swiperDataFormat(list.floorImageList, 6)
  163. break
  164. case '9':
  165. list.floorImageList.length > 2 && (list.isPageMore = true)
  166. list.floorImageList = _that.swiperDataFormat(list.floorImageList, 4)
  167. break
  168. case '21':
  169. list.floorImageList = _that.swiperDataFormat(list.floorImageList, 4)
  170. break
  171. case '3':
  172. case '6':
  173. list.floorImageList.length > 4 && (list.isPageMore = true)
  174. break
  175. case '4':
  176. case '8':
  177. list.floorImageList.length > 2 && (list.isPageMore = true)
  178. break
  179. case '10':
  180. list.floorImageList.length > 1 && (list.isPageMore = true)
  181. break
  182. case '11':
  183. case '12':
  184. case '13':
  185. case '15':
  186. list.floorImageList.length > 2 && (list.isPageMore = true)
  187. break
  188. case '14':
  189. case '19':
  190. case '20':
  191. list.floorImageList.length > 4 && (list.isPageMore = true)
  192. break
  193. case '16':
  194. case '17':
  195. case '18':
  196. list.floorImageList.length > 3 && (list.isPageMore = true)
  197. break
  198. default:
  199. break
  200. }
  201. }
  202. })
  203. },
  204. // 轮播图数据处理
  205. swiperDataFormat: function (list, n) {
  206. var result = []
  207. var page = Math.ceil(list.length / n)
  208. for (var i = 0; i < page; i++) {
  209. result.push(list.splice(0, n))
  210. }
  211. return result
  212. },
  213. // 轮播图样式生产方法
  214. swiperStyle: function (tempType, swiperEl, btns) {
  215. var swiper = null
  216. var slides = $(swiperEl).find('.swiper-slide').length
  217. var option = {
  218. loop: true,
  219. noSwiping: false,
  220. noSwipingClass: 'no-swiping',
  221. }
  222. if (typeof Object.assign != 'function') {
  223. Object.assign = function (target) {
  224. 'use strict';
  225. if (target == null) {
  226. throw new TypeError('Cannot convert undefined or null to object');
  227. }
  228. target = Object(target);
  229. for (var index = 1; index < arguments.length; index++) {
  230. var source = arguments[index];
  231. if (source != null) {
  232. for (var key in source) {
  233. if (Object.prototype.hasOwnProperty.call(source, key)) {
  234. target[key] = source[key];
  235. }
  236. }
  237. }
  238. }
  239. return target;
  240. };
  241. }
  242. if (
  243. tempType === '1' ||
  244. tempType === '2' ||
  245. tempType === '3' ||
  246. tempType === '6' ||
  247. tempType === '9'
  248. ) {
  249. var myOption = {
  250. autoplay: {
  251. delay: 5000,
  252. stopOnLastSlide: false,
  253. disableOnInteraction: false,
  254. },
  255. pagination: {
  256. el: '.swiper-pagination',
  257. bulletClass: 'cm-bullet', //需设置.my-bullet样式
  258. bulletActiveClass: 'cm-bullet-active',
  259. clickable: true,
  260. },
  261. }
  262. Object.assign(option, myOption);
  263. } else if (tempType === '21') {
  264. var myOption1 = {
  265. autoplay: {
  266. delay: 5000,
  267. stopOnLastSlide: false,
  268. disableOnInteraction: false,
  269. },
  270. pagination: {
  271. el: '.swiper-pagination',
  272. bulletClass: 'cm-bullet', //需设置.my-bullet样式
  273. bulletActiveClass: 'cm-bullet-active',
  274. clickable: true,
  275. },
  276. }
  277. if (this.isPc) {
  278. var myOption2 = {
  279. slidesPerView: 5,
  280. slidesPerGroup: 5,
  281. spaceBetween: 16,
  282. }
  283. if(slides <= 5){
  284. myOption1.autoplay=false;
  285. option.loop = false;
  286. myOption1.pagination = false;
  287. }
  288. Object.assign(option, myOption2);
  289. }
  290. Object.assign(option, myOption1);
  291. } else if (tempType === '4' || tempType === '8') {
  292. var myOption1 = {
  293. slidesPerView: 2,
  294. slidesPerGroup: 2,
  295. spaceBetween: 16,
  296. noSwipingClass: 'no-swiping',
  297. navigation: {
  298. nextEl: btns.next,
  299. prevEl: btns.prev,
  300. },
  301. }
  302. if (Math.ceil(slides / 2) === 1) {
  303. option.noSwiping = true
  304. option.loop = false
  305. $(swiperEl).parent().find('.cm-swiper-button').css('display', 'none')
  306. }
  307. Object.assign(option, myOption1);
  308. } else if (tempType === '5') {
  309. var myOption1 = {
  310. slidesPerView: 3,
  311. slidesPerGroup: 3,
  312. spaceBetween: 16,
  313. navigation: {
  314. nextEl: btns.next,
  315. prevEl: btns.prev,
  316. },
  317. }
  318. if (Math.ceil(slides / 3) === 1) {
  319. option.noSwiping = true
  320. option.loop = false
  321. $(swiperEl).parent().find('.cm-swiper-button').css('display', 'none')
  322. }
  323. Object.assign(option, myOption1);
  324. } else if (tempType === '7') {
  325. var myOption1 = {
  326. slidesPerView: 4,
  327. slidesPerGroup: 4,
  328. spaceBetween: 16,
  329. navigation: {
  330. nextEl: btns.next,
  331. prevEl: btns.prev,
  332. },
  333. }
  334. if (Math.ceil(slides / 4) === 1) {
  335. option.noSwiping = true
  336. option.loop = false
  337. $(swiperEl).parent().find('.cm-swiper-button').css('display', 'none')
  338. }
  339. Object.assign(option, myOption1);
  340. } else if (tempType === '10') {
  341. var myOption1 = {
  342. navigation: {
  343. nextEl: btns.next,
  344. prevEl: btns.prev,
  345. },
  346. }
  347. if (slides === 1) {
  348. option.noSwiping = true
  349. option.loop = false
  350. $(swiperEl).parent().find('.cm-swiper-button').css('display', 'none')
  351. }
  352. Object.assign(option, myOption1);
  353. }
  354. return function () {
  355. if (slides > 1) {
  356. swiper = new Swiper(swiperEl, option)
  357. if (swiper.pagination.bullets) {
  358. for (i = 0; i < swiper.pagination.bullets.length; i++) {
  359. swiper.pagination.bullets[i].onmouseover = function () {
  360. this.click()
  361. }
  362. }
  363. }
  364. }
  365. }
  366. },
  367. // 初始化轮播图
  368. initSwiper: function () {
  369. var _that = this;
  370. setTimeout(function () {
  371. var swiperTemps = [
  372. '1',
  373. '2',
  374. '3',
  375. '4',
  376. '5',
  377. '6',
  378. '7',
  379. '8',
  380. '9',
  381. '10',
  382. '21',
  383. ];
  384. $('.swiper-container').each(function (i, el) {
  385. // 通过轮播图id解析出模板id及轮播图el
  386. var tempType = el.id.split('-')[1];
  387. var swiperEl = '#' + el.id;
  388. var btns = {
  389. prev: '',
  390. next: '',
  391. };
  392. // 初始化轮播图按钮控件class
  393. var btnList = $(el).parent().find('.cm-swiper-button');
  394. if (btnList.length === 2) {
  395. btns.prev = '.' + btnList[0].classList[2];
  396. btns.next = '.' + btnList[1].classList[2];
  397. }
  398. if (swiperTemps.indexOf(tempType) !== -1) {
  399. console.log(tempType)
  400. _that.swiperStyle(tempType, swiperEl, btns)();
  401. }
  402. });
  403. $('img[data-original]').lazyload();
  404. $('title').html(_that.pageInfo.title);
  405. })
  406. },
  407. },
  408. mounted: function () {
  409. this.init();
  410. // this.testData();
  411. }
  412. });