index.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. let quickOpreationMain = new Vue({
  2. el: '#app',
  3. mixins: [swiperMixin, showMoreMixin, cmSysVitaMixins],
  4. data: {
  5. isMobile: window.innerWidth < 992,
  6. showCouponEntry: false,
  7. isActive: true,
  8. isRequest: true,
  9. isLoading: true,
  10. showPhoneNum: false,
  11. showWechat: false,
  12. // showScrollTop: false,
  13. activityEntryVisiable: false,
  14. contactVisiable: false,
  15. scrollTopSize: 0,
  16. msg: 'hello world',
  17. src: './img/test.jpg',
  18. // 显示个数
  19. countMap: {},
  20. size: 10,
  21. swiperList: {},
  22. needReload: false,
  23. floorList: [],
  24. pageInfo: null,
  25. params: {
  26. //请求参数
  27. pageId: '293',
  28. userId: '',
  29. source: 1
  30. },
  31. selectVideoTabMap: {},
  32. //用户权限
  33. globalUserData: '',
  34. GLOBAL_USER_ID: 0,
  35. GLOBAL_USER_IDENTITY: 0,//2-会员机构;3-供应商;4-普通机构
  36. GLOBAL_SHOP_ID: 0,
  37. },
  38. filters: {
  39. NumFormat: function NumFormat(value) {//处理金额
  40. return Number(value).toFixed(2);
  41. }
  42. ,
  43. tabTime: function tabTime(val) { // 处理时间
  44. // 2021-08-16 00:00:00
  45. const first = val.split(' ')[0];
  46. const second = first.split('-');
  47. return second[1] + '-' + second[2];
  48. }
  49. },
  50. watch: {
  51. isMobile: function isMobile() {
  52. // if (this.needReload) window.location.reload()
  53. this.isLoading = true;
  54. window.location.reload();
  55. }
  56. },
  57. computed: {
  58. showScrollTop: function () {
  59. return this.scrollTopSize > 600
  60. }
  61. },
  62. created() {
  63. this.cmSysParams.pageType = 13;
  64. this.initUserInfo();
  65. this.getQuickOpreationList();
  66. },
  67. mounted() {
  68. // this.getQuickOpreationList() // 快捷运营信息
  69. this.pageLoaded();
  70. // this.showCouponEntry = true 优惠券弹窗入口2
  71. // 关闭视频播放
  72. this.$nextTick(function(){
  73. $('#video-popup .close').on('click', function(){
  74. $(this).parents('#video-popup').hide();
  75. });
  76. })
  77. },
  78. methods: {
  79. // 获取快捷运营信息
  80. getQuickOpreationList() {
  81. const paramsArr = window.location.pathname.split(".")[0].split("-");
  82. this.params.pageId = paramsArr.length >= 1 ? paramsArr[1] : '';
  83. ProductApi.getActivityData(this.params, (res) => {
  84. if (res.code === 0) {
  85. this.floorList = res.data.floorList;
  86. this.pageInfo = res.data.page;
  87. this.cmSysParams.pageLabel = this.pageInfo.contentLabel;
  88. this.isRequest = false;
  89. this.makeVideoFetchMap();
  90. this.contactVisiable = res.data.page.infoBarStatus === 1;
  91. }
  92. })
  93. },
  94. // 初始化用户信息
  95. initUserInfo () {
  96. const userInfo = localStorage.getItem('userInfo');
  97. if (!userInfo) {
  98. console.log('用户未登录...');
  99. return false
  100. }
  101. this.globalUserData = JSON.parse(localStorage.getItem('userInfo'));
  102. this.GLOBAL_USER_ID = this.globalUserData.userId * 1;
  103. this.GLOBAL_USER_IDENTITY = this.globalUserData.userIdentity * 1;
  104. this.GLOBAL_SHOP_ID = this.globalUserData.shopId * 1;
  105. this.params.userId = this.globalUserData.userId;
  106. if (this.GLOBAL_USER_ID === 5261 || this.GLOBAL_USER_ID === 10947 || this.GLOBAL_USER_ID === 11579) {
  107. this.GLOBAL_USER_IDENTITY = 1;
  108. }
  109. console.log('已获取用户登录信息')
  110. },
  111. fetchTemplate: function fetchTemplate(list, type) {
  112. return list.indexOf(parseInt(type)) !== -1;
  113. },
  114. //促销活动类型数据处理
  115. PromotionsFormat: function (promo) {
  116. if (promo !== null) {
  117. if (promo.type === 1 && promo.mode === 1) {
  118. return true;
  119. } else {
  120. return false;
  121. }
  122. }
  123. return false;
  124. },
  125. // 创建tab与轮播图的对应关系
  126. makeVideoFetchMap: function makeVideoFetchMap() {
  127. const videoList = [22, 23, 24, 25];
  128. const videoMap = {};
  129. this.floorList.forEach((item, index) => {
  130. if (videoList.indexOf(parseInt(item["floorContent"]["templateType"])) !== -1) {
  131. videoMap[item["floorContent"]["templateType"] + '-' + index] = 0;
  132. }
  133. });
  134. this.selectVideoTabMap = videoMap;
  135. },
  136. // tab点击事件
  137. handleTabClick(type, index, val) {
  138. const swiperId = 'swiper-template-' + index + '-' + type + '-' + val;
  139. this.selectVideoTabMap[type + '-' + index] = val;
  140. if (this.swiperList[swiperId]) this.swiperList[swiperId].destroy();
  141. setTimeout(() => {
  142. this.swiperList[swiperId] = utils.createSwiperId(swiperId, swiperConfig);
  143. utils.responsive('.aspect', 'scalc');
  144. console.log('轮播图切换');
  145. });
  146. },
  147. // 当前选中的轮播图
  148. currentVideoSwiper(type, index) {
  149. return this.selectVideoTabMap[type + '-' + index];
  150. },
  151. getFloorImageListType(index) {
  152. return index === 0 ? 'floorImageList' : 'floorImageList' + (index + 1);
  153. },
  154. // 获取直播状态
  155. makeVideoStatus(floorData, index) {
  156. const displayDate = new Date(floorData.floorContent['displayDate' + index].replace(/-/g, '/')).getTime();
  157. const nowDate = new Date().getTime();
  158. // 一天的时间戳
  159. const oneDay = 60 * 60 * 24 * 1000;
  160. // 直播开始时间:displayDate
  161. // 直播结束时间:displayDate + oneDay
  162. if (nowDate < displayDate) return 0; // 未开始
  163. if (nowDate >= displayDate && nowDate <= displayDate + oneDay) return 1; // 已开始
  164. if (nowDate - oneDay > displayDate) return 2; // 已结束
  165. },
  166. // 使用产品楼层的布局
  167. getProductScalcMap(templateId) {
  168. const current = this.isMobile ? 'mobile' : 'pc';
  169. const scalcLayout = layoutMapping.productScalcMap['template-' + templateId];
  170. return {
  171. scalc: scalcLayout[current].scalc,
  172. col: scalcLayout[current].col
  173. };
  174. },
  175. // 使用文章楼层的布局
  176. getArticleScalcMap(templateId) {
  177. const current = this.isMobile ? 'mobile' : 'pc';
  178. const scalcLayout = layoutMapping.articleScalcMap['template-' + templateId];
  179. return {
  180. scalc: scalcLayout[current],
  181. swiper: scalcLayout['swiper']
  182. };
  183. },
  184. // 使用图片楼层的布局
  185. getImageScalcMap(templateId) {
  186. const current = this.isMobile ? 'mobile' : 'pc';
  187. const scalcLayout = layoutMapping.imageScalcMap['template-' + templateId];
  188. return {
  189. scalc: scalcLayout[current],
  190. swiper: scalcLayout['swiper']
  191. };
  192. },
  193. // 使用直播楼层的布局
  194. getVideoScalcMap(templateId) {
  195. const current = this.isMobile ? 'mobile' : 'pc';
  196. const scalcLayout = layoutMapping.videoScalcMap['template-' + templateId];
  197. return {
  198. scalc: scalcLayout[current],
  199. swiper: scalcLayout['swiper']
  200. };
  201. },
  202. // 播放视频
  203. onPlayVideo(link) {
  204. $('#video-popup video').attr('src', link);
  205. $('#video-popup').show();
  206. },
  207. // 处理link
  208. reallink(link) {
  209. if(!link) return 'javascript:void(0)';
  210. return link;
  211. },
  212. handleToggleActive(flag) {
  213. this.isActive = flag;
  214. },
  215. // 页面挂载完毕
  216. pageLoaded() {
  217. // 轮播图配置
  218. const options = {
  219. el: '.swiper-container',
  220. split: '-',
  221. config: swiperConfig,
  222. protertyFix: 'swiper-template-'
  223. };
  224. let resizeTimer = null;
  225. // 延迟处理
  226. let timer;
  227. timer = setInterval(() => {
  228. if (!this.isRequest) {
  229. this.swiperList = utils.createSwiper(options);
  230. // console.log(that.swiperList);
  231. console.log('轮播图创建完毕...');
  232. this.initCountMap(countMapping);
  233. // console.log(that.countMap);
  234. console.log('商品列表处理完毕...');
  235. utils.responsive('.aspect', 'scalc');
  236. this.isLoading = false;
  237. clearInterval(timer);
  238. this.$nextTick(() => {
  239. $('img[data-original]').lazyload();
  240. });
  241. console.log('页面图片初始化完成...');
  242. }
  243. }, 500);
  244. // 监听window窗口大小
  245. window.addEventListener('resize', () => {
  246. clearTimeout(resizeTimer);
  247. resizeTimer = setTimeout(() => {
  248. utils.responsive('.aspect', 'scalc');
  249. console.log('图片大小已刷新...');
  250. }, 200);
  251. quickOpreationMain.$set(quickOpreationMain.$data, 'isMobile', window.innerWidth < 560);
  252. });
  253. window.addEventListener('scroll', (event) => {
  254. this.scrollTopSize = $('body').scrollTop();
  255. });
  256. console.log('窗口resize事件注册完毕...');
  257. },
  258. }
  259. })