index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  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 {
  69. getCouponV2,
  70. getCouponNewUser
  71. } from '@/api/api.js'
  72. import {
  73. getShare
  74. } from '@/api/public.js';
  75. // #ifdef H5
  76. import mConfig from '@/pages/index/diy/components/index.js';
  77. // #endif
  78. // #ifdef MP || APP-PLUS
  79. import authorize from '@/components/Authorize';
  80. import activeParty from '@/pages/index/diy/components/activeParty';
  81. import headerSerch from '@/pages/index/diy/components/headerSerch';
  82. import swipers from '@/pages/index/diy/components/swipers';
  83. import coupon from '@/pages/index/diy/components/coupon';
  84. import articleList from '@/pages/index/diy/components/articleList';
  85. import bargain from '@/pages/index/diy/components/bargain';
  86. import blankPage from '@/pages/index/diy/components/blankPage';
  87. import combination from '@/pages/index/diy/components/combination';
  88. import customerService from '@/pages/index/diy/components/customerService';
  89. import goodList from '@/pages/index/diy/components/goodList';
  90. import guide from '@/pages/index/diy/components/guide';
  91. import liveBroadcast from '@/pages/index/diy/components/liveBroadcast';
  92. import menus from '@/pages/index/diy/components/menus';
  93. import news from '@/pages/index/diy/components/news';
  94. import promotionList from '@/pages/index/diy/components/promotionList';
  95. import richText from '@/pages/index/diy/components/richText';
  96. import seckill from '@/pages/index/diy/components/seckill';
  97. import swiperBg from '@/pages/index/diy/components/swiperBg';
  98. import tabNav from '@/pages/index/diy/components/tabNav';
  99. import titles from '@/pages/index/diy/components/titles';
  100. import pictureCube from '@/pages/index/diy/components/pictureCube';
  101. import {
  102. getTempIds
  103. } from '@/api/api.js';
  104. import {
  105. SUBSCRIBE_MESSAGE,
  106. TIPS_KEY
  107. } from '@/config/cache';
  108. // #endif
  109. import {
  110. mapGetters
  111. } from 'vuex';
  112. import {
  113. getDiy,
  114. getIndexData
  115. } from '@/api/api.js';
  116. import {
  117. getGroomList
  118. } from '@/api/store.js';
  119. import {
  120. goShopDetail
  121. } from '@/libs/order.js';
  122. import {
  123. toLogin
  124. } from '@/libs/login.js';
  125. import pageFooter from '@/components/pageFooter/index.vue'
  126. export default {
  127. computed: mapGetters(['isLogin', 'uid']),
  128. components: {
  129. pageFooter,
  130. // #ifdef H5
  131. ...mConfig,
  132. // #endif
  133. // #ifdef MP || APP-PLUS
  134. authorize,
  135. activeParty,
  136. headerSerch,
  137. swipers,
  138. coupon,
  139. articleList,
  140. bargain,
  141. blankPage,
  142. combination,
  143. customerService,
  144. goodList,
  145. guide,
  146. liveBroadcast,
  147. menus,
  148. news,
  149. promotionList,
  150. richText,
  151. seckill,
  152. swiperBg,
  153. tabNav,
  154. titles,
  155. pictureCube
  156. // #endif
  157. },
  158. computed: mapGetters(['isLogin']),
  159. data() {
  160. return {
  161. styleConfig: [],
  162. tempArr: [],
  163. goodType: 3,
  164. loading: false,
  165. loadend: false,
  166. loadTitle: this.$t(`加载更多`), //提示语
  167. page: 1,
  168. limit: this.$config.LIMIT,
  169. iSshowH: false,
  170. numConfig: 0,
  171. code: '',
  172. isCouponShow: false,
  173. couponObj: {},
  174. couponObjs: {},
  175. shareInfo: {},
  176. footConfig: {},
  177. pageId: '',
  178. sortMpTop: 0,
  179. newData: {},
  180. activeRouter: '',
  181. footerStatus: false,
  182. bgColor: '',
  183. bgPic: '',
  184. bgTabVal: '',
  185. pageShow: true,
  186. windowHeight: 0
  187. };
  188. },
  189. onLoad(options) {
  190. console.log(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. console.log(data)
  347. if(!data) return
  348. const keys = Object.keys(data)
  349. keys.sort((a, b) => a - b)
  350. const m = keys.map(key => data[key]);
  351. return m;
  352. },
  353. diyData() {
  354. let that = this;
  355. getDiy(this.pageId).then(res => {
  356. let data = res.data;
  357. if (res.data.length == 0) {
  358. return this.$util.Tips({
  359. title: this.$t(`暂无数据`)
  360. }, {
  361. tab: 3
  362. })
  363. }
  364. if (data.is_bg_color) {
  365. this.bgColor = data.color_picker
  366. }
  367. if (data.is_bg_pic) {
  368. this.bgPic = data.bg_pic
  369. this.bgTabVal = data.bg_tab_val
  370. }
  371. this.pageShow = data.is_show
  372. uni.setNavigationBarTitle({
  373. title: res.data.title
  374. })
  375. let temp = []
  376. console.log(res.data)
  377. let lastArr = that.objToArr(res.data.value)
  378. lastArr.forEach((item, index, arr) => {
  379. if (item.name == 'pageFoot') {
  380. uni.setStorageSync('pageFoot', item)
  381. that.$store.commit('FOOT_UPLOAD', item)
  382. arr.splice(index, 1)
  383. this.newData = item
  384. this.footerStatus = item.status.status
  385. }
  386. if (item.name == 'promotionList') {
  387. that.numConfig = item.numConfig.val;
  388. that.getGroomList();
  389. }
  390. temp = arr
  391. });
  392. that.styleConfig = temp;
  393. });
  394. },
  395. getIndexData() {},
  396. changeBarg(item) {
  397. if (!this.isLogin) {
  398. toLogin();
  399. } else {
  400. uni.navigateTo({
  401. url: `/pages/activity/goods_bargain_details/index?id=${item.id}&bargain=${this.uid}`
  402. });
  403. }
  404. },
  405. // 促销列表的点击事件;
  406. changeTab(type) {
  407. this.goodType = type;
  408. this.tempArr = [];
  409. this.page = 1;
  410. this.loadend = false;
  411. let onloadH = true;
  412. this.getGroomList(onloadH);
  413. },
  414. // 精品推荐
  415. getGroomList(onloadH) {
  416. let that = this;
  417. let type = that.goodType;
  418. if (that.loadend) return false;
  419. if (that.loading) return false;
  420. if (onloadH) {
  421. that.$set(that, 'iSshowH', true);
  422. }
  423. getGroomList(type, {
  424. page: that.page,
  425. limit: that.limit
  426. })
  427. .then(({
  428. data
  429. }) => {
  430. that.$set(that, 'iSshowH', false);
  431. let maxPage = Math.ceil(this.numConfig / this.limit);
  432. let list = data.list,
  433. loadend = list.length < that.limit || that.page >= maxPage;
  434. let tempArr = that.$util.SplitArray(list, that.tempArr);
  435. that.$set(that, 'tempArr', tempArr.slice(0, this.numConfig));
  436. that.loadend = loadend;
  437. that.loadTitle = loadend ? that.$t(`没有更多内容啦~`) : that.$t(`加载更多`);
  438. that.page = that.page + 1;
  439. that.loading = false;
  440. })
  441. .catch(res => {
  442. that.loading = false;
  443. that.loadTitle = that.$t(`加载更多`);
  444. });
  445. },
  446. goDetail(item) {
  447. goShopDetail(item, this.uid).then(res => {
  448. uni.navigateTo({
  449. url: `/pages/goods_details/index?id=${item.id}`
  450. });
  451. });
  452. },
  453. // #ifdef H5
  454. // 微信分享;
  455. setOpenShare: function() {
  456. let that = this;
  457. if (that.$wechat.isWeixin()) {
  458. getShare().then(res => {
  459. let data = res.data.data;
  460. let configAppMessage = {
  461. desc: data.synopsis,
  462. title: data.title,
  463. link: location.href,
  464. imgUrl: data.img
  465. };
  466. that.$wechat.wechatEvevt(['updateAppMessageShareData', 'updateTimelineShareData'],
  467. configAppMessage);
  468. });
  469. }
  470. }
  471. // #endif
  472. },
  473. onReachBottom: function() {
  474. this.getGroomList();
  475. },
  476. //#ifdef MP || APP-PLUS
  477. onShareAppMessage() {
  478. return {
  479. title: this.shareInfo.title,
  480. path: '/pages/index/index',
  481. imageUrl: this.storeInfo.img,
  482. };
  483. },
  484. //#endif
  485. };
  486. </script>
  487. <style lang="scss">
  488. .page {
  489. padding-bottom: 50px;
  490. }
  491. .ysize {
  492. background-size: 100%;
  493. }
  494. .fullsize {
  495. background-size: 100% 100%;
  496. }
  497. .repeat {
  498. background-repeat: repeat;
  499. }
  500. .noRepeat {
  501. background-repeat: no-repeat;
  502. }
  503. .page-footer {
  504. position: fixed;
  505. bottom: 0;
  506. z-index: 30;
  507. display: flex;
  508. align-items: center;
  509. justify-content: space-around;
  510. width: 100%;
  511. height: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  512. height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  513. box-sizing: border-box;
  514. border-top: solid 1rpx #F3F3F3;
  515. background-color: #fff;
  516. box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
  517. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  518. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  519. .foot-item {
  520. display: flex;
  521. width: max-content;
  522. align-items: center;
  523. justify-content: center;
  524. flex-direction: column;
  525. position: relative;
  526. .count-num {
  527. position: absolute;
  528. display: flex;
  529. justify-content: center;
  530. align-items: center;
  531. width: 40rpx;
  532. height: 40rpx;
  533. top: 0rpx;
  534. right: -15rpx;
  535. color: #fff;
  536. font-size: 20rpx;
  537. background-color: #FD502F;
  538. border-radius: 50%;
  539. padding: 4rpx;
  540. }
  541. }
  542. .foot-item image {
  543. height: 50rpx;
  544. width: 50rpx;
  545. text-align: center;
  546. margin: 0 auto;
  547. }
  548. .foot-item .txt {
  549. font-size: 24rpx;
  550. &.active {}
  551. }
  552. }
  553. </style>