index.vue 15 KB

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