index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. <template>
  2. <view v-if="pageShow" class="page"
  3. :class="bgTabVal==2?'fullsize noRepeat':bgTabVal==1?'repeat ysize':'noRepeat ysize'"
  4. :style="'background-color:'+bgColor+';background-image: url('+bgPic+');min-height:'+windowHeight+'px;'">
  5. <view :style="{ marginTop: sortMpTop + 'px' }">
  6. <!-- #ifdef H5 -->
  7. <view v-for="(item, index) in styleConfig" :key="index">
  8. <component :is="item.name" :index="index" :dataConfig="item" @changeBarg="changeBarg"
  9. @changeTab="changeTab" :tempArr="tempArr" :iSshowH="iSshowH" @detail="goDetail"></component>
  10. </view>
  11. <!-- #endif -->
  12. <!-- #ifdef MP || APP-PLUS-->
  13. <block v-for="(item, index) in styleConfig" :key="index">
  14. <activeParty v-if="item.name == 'activeParty'" :dataConfig="item"></activeParty>
  15. <articleList v-if="item.name == 'articleList'" :dataConfig="item"></articleList>
  16. <bargain v-if="item.name == 'bargain'" :dataConfig="item" @changeBarg="changeBarg"></bargain>
  17. <blankPage v-if="item.name == 'blankPage'" :dataConfig="item"></blankPage>
  18. <combination v-if="item.name == 'combination'" :dataConfig="item"></combination>
  19. <coupon v-if="item.name == 'coupon'" :dataConfig="item"></coupon>
  20. <customerService v-if="item.name == 'customerService'" :dataConfig="item"></customerService>
  21. <goodList v-if="item.name == 'goodList'" :dataConfig="item" @detail="goDetail"></goodList>
  22. <guide v-if="item.name == 'guide'" :dataConfig="item"></guide>
  23. <headerSerch v-if="item.name == 'headerSerch'" :dataConfig="item" :special="1"></headerSerch>
  24. <liveBroadcast v-if="item.name == 'liveBroadcast'" :dataConfig="item"></liveBroadcast>
  25. <menus v-if="item.name == 'menus'" :dataConfig="item"></menus>
  26. <news v-if="item.name == 'news'" :dataConfig="item"></news>
  27. <pictureCube v-if="item.name == 'pictureCube'" :dataConfig="item" :isSortType="isSortType">
  28. </pictureCube>
  29. <promotionList v-if="item.name == 'promotionList'" :dataConfig="item" @changeTab="changeTab"
  30. :tempArr="tempArr" :iSshowH="iSshowH" @detail="goDetail"></promotionList>
  31. <richText v-if="item.name == 'richText'" :dataConfig="item"></richText>
  32. <seckill v-if="item.name == 'seckill'" :dataConfig="item"></seckill>
  33. <swiperBg v-if="item.name == 'swiperBg'" :dataConfig="item"></swiperBg>
  34. <swipers v-if="item.name == 'swipers'" :dataConfig="item"></swipers>
  35. <tabNav v-if="item.name == 'tabNav'" :dataConfig="item"></tabNav>
  36. <titles v-if="item.name == 'titles'" :dataConfig="item"></titles>
  37. </block>
  38. <!-- #endif -->
  39. <view class="loadingicon acea-row row-center-wrapper"
  40. v-if="tempArr.length && styleConfig[styleConfig.length - 1].name == 'promotionList'">
  41. <text class="loading iconfont icon-jiazai" :hidden="loading == false"></text>
  42. {{ loadTitle }}
  43. </view>
  44. <view class="foot" v-if="newData.menuList && newData.status.status">
  45. <view class="page-footer" id="target" :style="{'background-color':newData.bgColor.color[0].item}">
  46. <view class="foot-item" v-for="(item,index) in newData.menuList" :key="index"
  47. @click="goRouter(item)">
  48. <block v-if="item.link == activeRouter">
  49. <image :src="item.imgList[0]"></image>
  50. <view class="txt" :style="{color:newData.activeTxtColor.color[0].item}">{{item.name}}</view>
  51. </block>
  52. <block v-else>
  53. <image :src="item.imgList[1]"></image>
  54. <view class="txt" :style="{color:newData.txtColor.color[0].item}">{{item.name}}</view>
  55. </block>
  56. <div class="count-num"
  57. v-if="item.link === '/pages/order_addcart/order_addcart' && $store.state.indexData.cartNum && $store.state.indexData.cartNum > 0">
  58. {{$store.state.indexData.cartNum}}
  59. </div>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </template>
  66. <script>
  67. const app = getApp();
  68. import couponWindow from '@/components/couponWindow/index'
  69. import {
  70. getCouponV2,
  71. getCouponNewUser
  72. } from '@/api/api.js'
  73. import {
  74. getShare
  75. } from '@/api/public.js';
  76. // #ifdef H5
  77. import mConfig from '@/pages/index/diy/components/index.js';
  78. // #endif
  79. // #ifdef MP || APP-PLUS
  80. import authorize from '@/components/Authorize';
  81. import activeParty from '@/pages/index/diy/components/activeParty';
  82. import headerSerch from '@/pages/index/diy/components/headerSerch';
  83. import swipers from '@/pages/index/diy/components/swipers';
  84. import coupon from '@/pages/index/diy/components/coupon';
  85. import articleList from '@/pages/index/diy/components/articleList';
  86. import bargain from '@/pages/index/diy/components/bargain';
  87. import blankPage from '@/pages/index/diy/components/blankPage';
  88. import combination from '@/pages/index/diy/components/combination';
  89. import customerService from '@/pages/index/diy/components/customerService';
  90. import goodList from '@/pages/index/diy/components/goodList';
  91. import guide from '@/pages/index/diy/components/guide';
  92. import liveBroadcast from '@/pages/index/diy/components/liveBroadcast';
  93. import menus from '@/pages/index/diy/components/menus';
  94. import news from '@/pages/index/diy/components/news';
  95. import promotionList from '@/pages/index/diy/components/promotionList';
  96. import richText from '@/pages/index/diy/components/richText';
  97. import seckill from '@/pages/index/diy/components/seckill';
  98. import swiperBg from '@/pages/index/diy/components/swiperBg';
  99. import tabNav from '@/pages/index/diy/components/tabNav';
  100. import titles from '@/pages/index/diy/components/titles';
  101. import pictureCube from '@/pages/index/diy/components/pictureCube';
  102. import {
  103. getTempIds
  104. } from '@/api/api.js';
  105. import {
  106. SUBSCRIBE_MESSAGE,
  107. TIPS_KEY
  108. } from '@/config/cache';
  109. // #endif
  110. import {
  111. mapGetters
  112. } from 'vuex';
  113. import {
  114. getDiy,
  115. getIndexData
  116. } from '@/api/api.js';
  117. import {
  118. getGroomList
  119. } from '@/api/store.js';
  120. import {
  121. goShopDetail
  122. } from '@/libs/order.js';
  123. import {
  124. toLogin
  125. } from '@/libs/login.js';
  126. import pageFooter from '@/components/pageFooter/index.vue'
  127. export default {
  128. computed: mapGetters(['isLogin', 'uid']),
  129. components: {
  130. pageFooter,
  131. couponWindow,
  132. // #ifdef H5
  133. ...mConfig,
  134. // #endif
  135. // #ifdef MP || APP-PLUS
  136. authorize,
  137. activeParty,
  138. headerSerch,
  139. swipers,
  140. coupon,
  141. articleList,
  142. bargain,
  143. blankPage,
  144. combination,
  145. customerService,
  146. goodList,
  147. guide,
  148. liveBroadcast,
  149. menus,
  150. news,
  151. promotionList,
  152. richText,
  153. seckill,
  154. swiperBg,
  155. tabNav,
  156. titles,
  157. pictureCube
  158. // #endif
  159. },
  160. computed: mapGetters(['isLogin']),
  161. data() {
  162. return {
  163. styleConfig: [],
  164. tempArr: [],
  165. goodType: 3,
  166. loading: false,
  167. loadend: false,
  168. loadTitle: this.$t(`加载更多`), //提示语
  169. page: 1,
  170. limit: this.$config.LIMIT,
  171. iSshowH: false,
  172. numConfig: 0,
  173. code: '',
  174. isCouponShow: false,
  175. couponObj: {},
  176. couponObjs: {},
  177. shareInfo: {},
  178. footConfig: {},
  179. pageId: '',
  180. sortMpTop: 0,
  181. newData: {},
  182. activeRouter: '',
  183. bgColor: '',
  184. bgPic: '',
  185. bgTabVal: '',
  186. pageShow: true,
  187. windowHeight: 0
  188. };
  189. },
  190. onLoad(options) {
  191. let that = this
  192. this.$nextTick(function() {
  193. uni.getSystemInfo({
  194. success: function(res) {
  195. that.windowHeight = res.windowHeight;
  196. }
  197. });
  198. })
  199. const {
  200. state,
  201. scope
  202. } = options;
  203. this.pageId = options.id
  204. // #ifdef MP
  205. if (options.scene) {
  206. let value = that.$util.getUrlParams(decodeURIComponent(options.scene));
  207. this.pageId = value.id
  208. }
  209. // #endif
  210. uni.setNavigationBarTitle({
  211. title: this.$t(`专题栏`)
  212. });
  213. // #ifdef APP-PLUS
  214. this.sortMpTop = -50
  215. // #endif
  216. uni.getLocation({
  217. type: 'wgs84',
  218. success: function(res) {
  219. try {
  220. uni.setStorageSync('user_latitude', res.latitude);
  221. uni.setStorageSync('user_longitude', res.longitude);
  222. } catch {}
  223. }
  224. });
  225. this.diyData();
  226. this.getIndexData();
  227. // #ifdef H5
  228. this.setOpenShare();
  229. // #endif
  230. // #ifdef MP || APP-PLUS
  231. this.getTempIds();
  232. // #endif
  233. getShare().then(res => {
  234. this.shareInfo = res.data;
  235. })
  236. let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
  237. let curRoute = routes[routes.length - 1].route //获取当前页面路由
  238. this.activeRouter = '/' + curRoute + '?id=' + this.pageId
  239. },
  240. watch: {
  241. isLogin: {
  242. deep: true, //深度监听设置为 true
  243. handler: function(newV, oldV) {
  244. // 优惠券弹窗
  245. var newDates = new Date().toLocaleDateString();
  246. if (newV) {
  247. try {
  248. var oldDate = uni.getStorageSync('oldDate') || ''
  249. } catch {}
  250. if (oldDate != newDates) {
  251. this.getCoupon();
  252. }
  253. }
  254. }
  255. }
  256. },
  257. mounted() {
  258. // 优惠券弹窗
  259. var newDates = new Date().toLocaleDateString();
  260. if (this.isLogin) {
  261. try {
  262. var oldDate = uni.getStorageSync('oldDate') || ''
  263. } catch {}
  264. if (oldDate != newDates) {
  265. this.getCoupon();
  266. }
  267. let oldUser = uni.getStorageSync('oldUser') || 0;
  268. if (!oldUser) {
  269. this.getCouponOnce();
  270. }
  271. }
  272. },
  273. methods: {
  274. goRouter(item) {
  275. var pages = getCurrentPages();
  276. var page = (pages[pages.length - 1]).$page.fullPath;
  277. if (item.link == page) return
  278. uni.switchTab({
  279. url: item.link,
  280. fail(err) {
  281. uni.redirectTo({
  282. url: item.link
  283. })
  284. }
  285. })
  286. },
  287. // 新用户优惠券
  288. getCouponOnce() {
  289. getCouponNewUser().then(res => {
  290. this.couponObjs = res.data;
  291. });
  292. },
  293. couponCloses() {
  294. this.couponObjs.show = false;
  295. try {
  296. uni.setStorageSync('oldUser', 1);
  297. } catch (e) {
  298. }
  299. },
  300. // 优惠券弹窗
  301. getCoupon() {
  302. getCouponV2().then(res => {
  303. this.couponObj = res.data
  304. if (res.data.list.length > 0) {
  305. this.isCouponShow = true
  306. }
  307. })
  308. },
  309. // 优惠券弹窗关闭
  310. couponClose() {
  311. this.isCouponShow = false
  312. try {
  313. uni.setStorageSync('oldDate', new Date().toLocaleDateString());
  314. } catch {}
  315. },
  316. onLoadFun() {},
  317. // #ifdef H5
  318. // 获取url后面的参数
  319. getQueryString(name) {
  320. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  321. var reg_rewrite = new RegExp("(^|/)" + name + "/([^/]*)(/|$)", "i");
  322. var r = window.location.search.substr(1).match(reg);
  323. var q = window.location.pathname.substr(1).match(reg_rewrite);
  324. if (r != null) {
  325. return unescape(r[2]);
  326. } else if (q != null) {
  327. return unescape(q[2]);
  328. } else {
  329. return null;
  330. }
  331. },
  332. // #endif
  333. // #ifdef MP || APP-PLUS
  334. getTempIds() {
  335. let messageTmplIds = wx.getStorageSync(SUBSCRIBE_MESSAGE);
  336. if (!messageTmplIds) {
  337. getTempIds().then(res => {
  338. if (res.data) wx.setStorageSync(SUBSCRIBE_MESSAGE, JSON.stringify(res.data));
  339. });
  340. }
  341. },
  342. // #endif
  343. // 对象转数组
  344. objToArr(data) {
  345. if (!data) return
  346. const keys = Object.keys(data)
  347. keys.sort((a, b) => a - b)
  348. const m = keys.map(key => data[key]);
  349. return m;
  350. },
  351. diyData() {
  352. let that = this;
  353. getDiy(this.pageId).then(res => {
  354. let data = res.data;
  355. if (res.data.length == 0) {
  356. return this.$util.Tips({
  357. title: this.$t(`暂无数据`)
  358. }, {
  359. tab: 3
  360. })
  361. }
  362. if (data.is_bg_color) {
  363. this.bgColor = data.color_picker
  364. }
  365. if (data.is_bg_pic) {
  366. this.bgPic = data.bg_pic
  367. this.bgTabVal = data.bg_tab_val
  368. }
  369. this.pageShow = data.is_show
  370. uni.setNavigationBarTitle({
  371. title: res.data.title
  372. })
  373. let temp = []
  374. let lastArr = that.objToArr(res.data.value)
  375. lastArr.forEach((item, index, arr) => {
  376. if (item.name == 'pageFoot') {
  377. uni.setStorageSync('pageFoot', item)
  378. that.$store.commit('FOOT_UPLOAD', item)
  379. arr.splice(index, 1)
  380. this.newData = item
  381. }
  382. if (item.name == 'promotionList') {
  383. that.numConfig = item.numConfig.val;
  384. that.getGroomList();
  385. }
  386. temp = arr
  387. });
  388. that.styleConfig = temp;
  389. });
  390. },
  391. getIndexData() {},
  392. changeBarg(item) {
  393. if (!this.isLogin) {
  394. toLogin();
  395. } else {
  396. uni.navigateTo({
  397. url: `/pages/activity/goods_bargain_details/index?id=${item.id}&bargain=${this.uid}`
  398. });
  399. }
  400. },
  401. // 促销列表的点击事件;
  402. changeTab(type) {
  403. this.goodType = type;
  404. this.tempArr = [];
  405. this.page = 1;
  406. this.loadend = false;
  407. let onloadH = true;
  408. this.getGroomList(onloadH);
  409. },
  410. // 精品推荐
  411. getGroomList(onloadH) {
  412. let that = this;
  413. let type = that.goodType;
  414. if (that.loadend) return false;
  415. if (that.loading) return false;
  416. if (onloadH) {
  417. that.$set(that, 'iSshowH', true);
  418. }
  419. getGroomList(type, {
  420. page: that.page,
  421. limit: that.limit
  422. })
  423. .then(({
  424. data
  425. }) => {
  426. that.$set(that, 'iSshowH', false);
  427. let maxPage = Math.ceil(this.numConfig / this.limit);
  428. let list = data.list,
  429. loadend = list.length < that.limit || that.page >= maxPage;
  430. let tempArr = that.$util.SplitArray(list, that.tempArr);
  431. that.$set(that, 'tempArr', tempArr.slice(0, this.numConfig));
  432. that.loadend = loadend;
  433. that.loadTitle = loadend ? that.$t(`没有更多内容啦~`) : that.$t(`加载更多`);
  434. that.page = that.page + 1;
  435. that.loading = false;
  436. })
  437. .catch(res => {
  438. that.loading = false;
  439. that.loadTitle = that.$t(`加载更多`);
  440. });
  441. },
  442. goDetail(item) {
  443. goShopDetail(item, this.uid).then(res => {
  444. uni.navigateTo({
  445. url: `/pages/goods_details/index?id=${item.id}`
  446. });
  447. });
  448. },
  449. // #ifdef H5
  450. // 微信分享;
  451. setOpenShare: function() {
  452. let that = this;
  453. if (that.$wechat.isWeixin()) {
  454. getShare().then(res => {
  455. let data = res.data.data;
  456. let configAppMessage = {
  457. desc: data.synopsis,
  458. title: data.title,
  459. link: location.href,
  460. imgUrl: data.img
  461. };
  462. that.$wechat.wechatEvevt(['updateAppMessageShareData', 'updateTimelineShareData'],
  463. configAppMessage);
  464. });
  465. }
  466. }
  467. // #endif
  468. },
  469. onReachBottom: function() {
  470. this.getGroomList();
  471. },
  472. //#ifdef MP || APP-PLUS
  473. onShareAppMessage() {
  474. return {
  475. title: this.shareInfo.title,
  476. path: '/pages/index/index',
  477. imageUrl: this.storeInfo.img,
  478. };
  479. },
  480. //#endif
  481. // 滚动监听
  482. onPageScroll(e) {
  483. // 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
  484. uni.$emit('scroll');
  485. },
  486. };
  487. </script>
  488. <style lang="scss">
  489. .page {
  490. padding-bottom: 50px;
  491. }
  492. .ysize {
  493. background-size: 100%;
  494. }
  495. .fullsize {
  496. background-size: 100% 100%;
  497. }
  498. .repeat {
  499. background-repeat: repeat;
  500. }
  501. .noRepeat {
  502. background-repeat: no-repeat;
  503. }
  504. .page-footer {
  505. position: fixed;
  506. bottom: 0;
  507. z-index: 30;
  508. display: flex;
  509. align-items: center;
  510. justify-content: space-around;
  511. width: 100%;
  512. height: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  513. height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  514. box-sizing: border-box;
  515. border-top: solid 1rpx #F3F3F3;
  516. background-color: #fff;
  517. box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
  518. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  519. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  520. .foot-item {
  521. display: flex;
  522. width: max-content;
  523. align-items: center;
  524. justify-content: center;
  525. flex-direction: column;
  526. position: relative;
  527. .count-num {
  528. position: absolute;
  529. display: flex;
  530. justify-content: center;
  531. align-items: center;
  532. width: 40rpx;
  533. height: 40rpx;
  534. top: 0rpx;
  535. right: -15rpx;
  536. color: #fff;
  537. font-size: 20rpx;
  538. background-color: #FD502F;
  539. border-radius: 50%;
  540. padding: 4rpx;
  541. }
  542. }
  543. .foot-item image {
  544. height: 50rpx;
  545. width: 50rpx;
  546. text-align: center;
  547. margin: 0 auto;
  548. }
  549. .foot-item .txt {
  550. font-size: 24rpx;
  551. &.active {}
  552. }
  553. }
  554. </style>