index.vue 15 KB

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