index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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. mounted() {},
  274. methods: {
  275. goRouter(item) {
  276. var pages = getCurrentPages();
  277. var page = (pages[pages.length - 1]).$page.fullPath;
  278. if (item.link == page) return
  279. uni.switchTab({
  280. url: item.link,
  281. fail(err) {
  282. uni.redirectTo({
  283. url: item.link
  284. })
  285. }
  286. })
  287. },
  288. // 新用户优惠券
  289. getCouponOnce() {
  290. getCouponNewUser().then(res => {
  291. this.couponObjs = res.data;
  292. });
  293. },
  294. couponCloses() {
  295. this.couponObjs.show = false;
  296. try {
  297. uni.setStorageSync('oldUser', 1);
  298. } catch (e) {
  299. }
  300. },
  301. // 优惠券弹窗
  302. getCoupon() {
  303. getCouponV2().then(res => {
  304. this.couponObj = res.data
  305. if (res.data.list.length > 0) {
  306. this.isCouponShow = true
  307. }
  308. })
  309. },
  310. // 优惠券弹窗关闭
  311. couponClose() {
  312. this.isCouponShow = false
  313. try {
  314. uni.setStorageSync('oldDate', new Date().toLocaleDateString());
  315. } catch {}
  316. },
  317. onLoadFun() {},
  318. // #ifdef H5
  319. // 获取url后面的参数
  320. getQueryString(name) {
  321. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  322. var reg_rewrite = new RegExp("(^|/)" + name + "/([^/]*)(/|$)", "i");
  323. var r = window.location.search.substr(1).match(reg);
  324. var q = window.location.pathname.substr(1).match(reg_rewrite);
  325. if (r != null) {
  326. return unescape(r[2]);
  327. } else if (q != null) {
  328. return unescape(q[2]);
  329. } else {
  330. return null;
  331. }
  332. },
  333. // #endif
  334. // #ifdef MP || APP-PLUS
  335. getTempIds() {
  336. let messageTmplIds = wx.getStorageSync(SUBSCRIBE_MESSAGE);
  337. if (!messageTmplIds) {
  338. getTempIds().then(res => {
  339. if (res.data) wx.setStorageSync(SUBSCRIBE_MESSAGE, JSON.stringify(res.data));
  340. });
  341. }
  342. },
  343. // #endif
  344. // 对象转数组
  345. objToArr(data) {
  346. if (!data) return
  347. const keys = Object.keys(data)
  348. keys.sort((a, b) => a - b)
  349. const m = keys.map(key => data[key]);
  350. return m;
  351. },
  352. diyData() {
  353. let that = this;
  354. getDiy(this.pageId).then(res => {
  355. let data = res.data;
  356. if (res.data.length == 0) {
  357. return this.$util.Tips({
  358. title: this.$t(`暂无数据`)
  359. }, {
  360. tab: 3
  361. })
  362. }
  363. if (data.is_bg_color) {
  364. this.bgColor = data.color_picker
  365. }
  366. if (data.is_bg_pic) {
  367. this.bgPic = data.bg_pic
  368. this.bgTabVal = data.bg_tab_val
  369. }
  370. this.pageShow = data.is_show
  371. uni.setNavigationBarTitle({
  372. title: res.data.title
  373. })
  374. let temp = []
  375. let lastArr = that.objToArr(res.data.value)
  376. lastArr.forEach((item, index, arr) => {
  377. if (item.name == 'pageFoot') {
  378. uni.setStorageSync('pageFoot', item)
  379. that.$store.commit('FOOT_UPLOAD', item)
  380. arr.splice(index, 1)
  381. this.newData = item
  382. }
  383. if (item.name == 'promotionList') {
  384. that.numConfig = item.numConfig.val;
  385. that.getGroomList();
  386. }
  387. temp = arr
  388. });
  389. that.styleConfig = temp;
  390. });
  391. },
  392. getIndexData() {},
  393. changeBarg(item) {
  394. if (!this.isLogin) {
  395. toLogin();
  396. } else {
  397. uni.navigateTo({
  398. url: `/pages/activity/goods_bargain_details/index?id=${item.id}&bargain=${this.uid}`
  399. });
  400. }
  401. },
  402. // 促销列表的点击事件;
  403. changeTab(type) {
  404. this.goodType = type;
  405. this.tempArr = [];
  406. this.page = 1;
  407. this.loadend = false;
  408. let onloadH = true;
  409. this.getGroomList(onloadH);
  410. },
  411. // 精品推荐
  412. getGroomList(onloadH) {
  413. let that = this;
  414. let type = that.goodType;
  415. if (that.loadend) return false;
  416. if (that.loading) return false;
  417. if (onloadH) {
  418. that.$set(that, 'iSshowH', true);
  419. }
  420. getGroomList(type, {
  421. page: that.page,
  422. limit: that.limit
  423. })
  424. .then(({
  425. data
  426. }) => {
  427. that.$set(that, 'iSshowH', false);
  428. let maxPage = Math.ceil(this.numConfig / this.limit);
  429. let list = data.list,
  430. loadend = list.length < that.limit || that.page >= maxPage;
  431. let tempArr = that.$util.SplitArray(list, that.tempArr);
  432. that.$set(that, 'tempArr', tempArr.slice(0, this.numConfig));
  433. that.loadend = loadend;
  434. that.loadTitle = loadend ? that.$t(`没有更多内容啦~`) : that.$t(`加载更多`);
  435. that.page = that.page + 1;
  436. that.loading = false;
  437. })
  438. .catch(res => {
  439. that.loading = false;
  440. that.loadTitle = that.$t(`加载更多`);
  441. });
  442. },
  443. goDetail(item) {
  444. goShopDetail(item, this.uid).then(res => {
  445. uni.navigateTo({
  446. url: `/pages/goods_details/index?id=${item.id}`
  447. });
  448. });
  449. },
  450. // #ifdef H5
  451. // 微信分享;
  452. setOpenShare: function() {
  453. let that = this;
  454. if (that.$wechat.isWeixin()) {
  455. getShare().then(res => {
  456. let data = res.data.data;
  457. let configAppMessage = {
  458. desc: data.synopsis,
  459. title: data.title,
  460. link: location.href,
  461. imgUrl: data.img
  462. };
  463. that.$wechat.wechatEvevt(['updateAppMessageShareData', 'updateTimelineShareData'],
  464. configAppMessage);
  465. });
  466. }
  467. }
  468. // #endif
  469. },
  470. onReachBottom: function() {
  471. this.getGroomList();
  472. },
  473. //#ifdef MP || APP-PLUS
  474. onShareAppMessage() {
  475. return {
  476. title: this.shareInfo.title,
  477. path: '/pages/index/index',
  478. imageUrl: this.storeInfo.img,
  479. };
  480. },
  481. //#endif
  482. };
  483. </script>
  484. <style lang="scss">
  485. .page {
  486. padding-bottom: 50px;
  487. }
  488. .ysize {
  489. background-size: 100%;
  490. }
  491. .fullsize {
  492. background-size: 100% 100%;
  493. }
  494. .repeat {
  495. background-repeat: repeat;
  496. }
  497. .noRepeat {
  498. background-repeat: no-repeat;
  499. }
  500. .page-footer {
  501. position: fixed;
  502. bottom: 0;
  503. z-index: 30;
  504. display: flex;
  505. align-items: center;
  506. justify-content: space-around;
  507. width: 100%;
  508. height: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  509. height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  510. box-sizing: border-box;
  511. border-top: solid 1rpx #F3F3F3;
  512. background-color: #fff;
  513. box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
  514. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  515. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  516. .foot-item {
  517. display: flex;
  518. width: max-content;
  519. align-items: center;
  520. justify-content: center;
  521. flex-direction: column;
  522. position: relative;
  523. .count-num {
  524. position: absolute;
  525. display: flex;
  526. justify-content: center;
  527. align-items: center;
  528. width: 40rpx;
  529. height: 40rpx;
  530. top: 0rpx;
  531. right: -15rpx;
  532. color: #fff;
  533. font-size: 20rpx;
  534. background-color: #FD502F;
  535. border-radius: 50%;
  536. padding: 4rpx;
  537. }
  538. }
  539. .foot-item image {
  540. height: 50rpx;
  541. width: 50rpx;
  542. text-align: center;
  543. margin: 0 auto;
  544. }
  545. .foot-item .txt {
  546. font-size: 24rpx;
  547. &.active {}
  548. }
  549. }
  550. </style>