index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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" @changeTab="changeTab"
  9. :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. <shortVideo v-if="item.name == 'shortVideo'" :dataConfig="item" :isSortType="isSortType">
  15. </shortVideo>
  16. <userInfor v-if="item.name == 'userInfor'" :dataConfig="item" :isSortType="isSortType">
  17. </userInfor>
  18. <newVip v-if="item.name == 'newVip'" :dataConfig="item" :isSortType="isSortType">
  19. </newVip>
  20. <activeParty v-if="item.name == 'activeParty'" :dataConfig="item"></activeParty>
  21. <articleList v-if="item.name == 'articleList'" :dataConfig="item"></articleList>
  22. <bargain v-if="item.name == 'bargain'" :dataConfig="item" @changeBarg="changeBarg"></bargain>
  23. <blankPage v-if="item.name == 'blankPage'" :dataConfig="item"></blankPage>
  24. <combination v-if="item.name == 'combination'" :dataConfig="item"></combination>
  25. <coupon v-if="item.name == 'coupon'" :dataConfig="item"></coupon>
  26. <customerService v-if="item.name == 'customerService'" :dataConfig="item"></customerService>
  27. <goodList v-if="item.name == 'goodList'" :dataConfig="item" @detail="goDetail"></goodList>
  28. <guide v-if="item.name == 'guide'" :dataConfig="item"></guide>
  29. <headerSerch v-if="item.name == 'headerSerch'" :dataConfig="item" :special="1"></headerSerch>
  30. <liveBroadcast v-if="item.name == 'liveBroadcast'" :dataConfig="item"></liveBroadcast>
  31. <menus v-if="item.name == 'menus'" :dataConfig="item"></menus>
  32. <news v-if="item.name == 'news'" :dataConfig="item"></news>
  33. <pictureCube v-if="item.name == 'pictureCube'" :dataConfig="item" :isSortType="isSortType">
  34. </pictureCube>
  35. <promotionList v-if="item.name == 'promotionList'" :dataConfig="item" @changeTab="changeTab"
  36. :tempArr="tempArr" :iSshowH="iSshowH" @detail="goDetail"></promotionList>
  37. <richText v-if="item.name == 'richText'" :dataConfig="item"></richText>
  38. <seckill v-if="item.name == 'seckill'" :dataConfig="item"></seckill>
  39. <swiperBg v-if="item.name == 'swiperBg'" :dataConfig="item"></swiperBg>
  40. <swipers v-if="item.name == 'swipers'" :dataConfig="item"></swipers>
  41. <tabNav v-if="item.name == 'tabNav'" :dataConfig="item" :fromType="1"></tabNav>
  42. <titles v-if="item.name == 'titles'" :dataConfig="item"></titles>
  43. </block>
  44. <!-- #endif -->
  45. <view class="loadingicon acea-row row-center-wrapper"
  46. v-if="tempArr.length && styleConfig[styleConfig.length - 1].name == 'promotionList'">
  47. <text class="loading iconfont icon-jiazai" :hidden="loading == false"></text>
  48. {{ loadTitle }}
  49. </view>
  50. <pageFooter></pageFooter>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. const app = getApp();
  56. import couponWindow from '@/components/couponWindow/index'
  57. import {
  58. getCouponV2,
  59. getCouponNewUser
  60. } from '@/api/api.js'
  61. import {
  62. getShare
  63. } from '@/api/public.js';
  64. // #ifdef H5
  65. import mConfig from '@/pages/index/components/index.js';
  66. import {
  67. silenceAuth
  68. } from '@/api/public.js';
  69. // #endif
  70. // #ifdef MP || APP-PLUS
  71. import userInfor from '@/pages/index/components/userInfor';
  72. import newVip from '@/pages/index/components/newVip';
  73. import shortVideo from '@/pages/index/components/shortVideo';
  74. import activeParty from '@/pages/index/components/activeParty';
  75. import headerSerch from '@/pages/index/components/headerSerch';
  76. import swipers from '@/pages/index/components/swipers';
  77. import coupon from '@/pages/index/components/coupon';
  78. import articleList from '@/pages/index/components/articleList';
  79. import bargain from '@/pages/index/components/bargain';
  80. import blankPage from '@/pages/index/components/blankPage';
  81. import combination from '@/pages/index/components/combination';
  82. import customerService from '@/pages/index/components/customerService';
  83. import goodList from '@/pages/index/components/goodList';
  84. import guide from '@/pages/index/components/guide';
  85. import liveBroadcast from '@/pages/index/components/liveBroadcast';
  86. import menus from '@/pages/index/components/menus';
  87. import news from '@/pages/index/components/news';
  88. import promotionList from '@/pages/index/components/promotionList';
  89. import richText from '@/pages/index/components/richText';
  90. import seckill from '@/pages/index/components/seckill';
  91. import swiperBg from '@/pages/index/components/swiperBg';
  92. import tabNav from '@/pages/index/components/tabNav';
  93. import titles from '@/pages/index/components/titles';
  94. import pictureCube from '@/pages/index/components/pictureCube';
  95. import {
  96. getTemlIds
  97. } from '@/api/api.js';
  98. import {
  99. SUBSCRIBE_MESSAGE,
  100. TIPS_KEY
  101. } from '@/config/cache';
  102. // #endif
  103. import {
  104. mapGetters
  105. } from 'vuex';
  106. import {
  107. getDiy,
  108. getIndexData
  109. } from '@/api/api.js';
  110. import {
  111. getGroomList
  112. } from '@/api/store.js';
  113. import {
  114. goShopDetail
  115. } from '@/libs/order.js';
  116. import {
  117. toLogin
  118. } from '@/libs/login.js';
  119. import pageFooter from '@/components/pageFooter/index.vue'
  120. export default {
  121. computed: mapGetters(['isLogin', 'uid']),
  122. components: {
  123. pageFooter,
  124. couponWindow,
  125. // #ifdef H5
  126. ...mConfig,
  127. // #endif
  128. // #ifdef MP || APP-PLUS
  129. newVip,
  130. userInfor,
  131. shortVideo,
  132. activeParty,
  133. headerSerch,
  134. swipers,
  135. coupon,
  136. articleList,
  137. bargain,
  138. blankPage,
  139. combination,
  140. customerService,
  141. goodList,
  142. guide,
  143. liveBroadcast,
  144. menus,
  145. news,
  146. promotionList,
  147. richText,
  148. seckill,
  149. swiperBg,
  150. tabNav,
  151. titles,
  152. pictureCube
  153. // #endif
  154. },
  155. data() {
  156. return {
  157. styleConfig: [],
  158. tempArr: [],
  159. goodType: 3,
  160. loading: false,
  161. loadend: false,
  162. loadTitle: '加载更多', //提示语
  163. page: 1,
  164. limit: this.$config.LIMIT,
  165. iSshowH: false,
  166. numConfig: 0,
  167. code: '',
  168. isCouponShow: false,
  169. couponObj: {},
  170. couponObjs: {},
  171. shareInfo: {},
  172. footConfig: {},
  173. pageId: '',
  174. sortMpTop: 0,
  175. bgColor: '',
  176. bgPic: '',
  177. bgTabVal: '',
  178. pageShow: true,
  179. windowHeight: 0
  180. };
  181. },
  182. onLoad(options) {
  183. let that = this
  184. this.$nextTick(function() {
  185. uni.getSystemInfo({
  186. success: function(res) {
  187. that.windowHeight = res.windowHeight;
  188. }
  189. });
  190. })
  191. const {
  192. state,
  193. scope
  194. } = options;
  195. this.pageId = options.id
  196. // #ifdef MP
  197. if (options.scene) {
  198. let value = that.$util.getUrlParams(decodeURIComponent(options.scene));
  199. this.pageId = value.id
  200. }
  201. // #endif
  202. uni.setNavigationBarTitle({
  203. title: '专题栏'
  204. });
  205. // #ifdef APP-PLUS
  206. this.sortMpTop = -50
  207. // #endif
  208. uni.getLocation({
  209. type: 'wgs84',
  210. success: function(res) {
  211. try {
  212. uni.setStorageSync('user_latitude', res.latitude);
  213. uni.setStorageSync('user_longitude', res.longitude);
  214. } catch {}
  215. }
  216. });
  217. this.diyData();
  218. this.getIndexData();
  219. // #ifdef H5
  220. this.setOpenShare();
  221. // #endif
  222. // #ifdef MP || APP-PLUS
  223. this.getTemlIds();
  224. // #endif
  225. getShare().then(res => {
  226. this.shareInfo = res.data;
  227. })
  228. },
  229. watch: {
  230. isLogin: {
  231. deep: true, //深度监听设置为 true
  232. handler: function(newV, oldV) {
  233. // 优惠券弹窗
  234. var newDates = new Date().toLocaleDateString();
  235. if (newV) {
  236. try {
  237. var oldDate = uni.getStorageSync('oldDate') || ''
  238. } catch {}
  239. if (oldDate != newDates) {
  240. this.getCoupon();
  241. }
  242. }
  243. }
  244. }
  245. },
  246. onShow() {
  247. uni.removeStorageSync('form_type_cart');
  248. // 优惠券弹窗
  249. var newDates = new Date().toLocaleDateString();
  250. if (this.isLogin) {
  251. try {
  252. var oldDate = uni.getStorageSync('oldDate') || ''
  253. } catch {}
  254. if (oldDate != newDates) {
  255. this.getCoupon();
  256. }
  257. let oldUser = uni.getStorageSync('oldUser') || 0;
  258. if (!oldUser) {
  259. this.getCouponOnce();
  260. }
  261. }
  262. },
  263. mounted() {},
  264. methods: {
  265. // 新用户优惠券
  266. getCouponOnce() {
  267. getCouponNewUser().then(res => {
  268. this.couponObjs = res.data;
  269. });
  270. },
  271. couponCloses() {
  272. this.couponObjs.show = false;
  273. try {
  274. uni.setStorageSync('oldUser', 1);
  275. } catch (e) {
  276. }
  277. },
  278. // 优惠券弹窗
  279. getCoupon() {
  280. getCouponV2().then(res => {
  281. this.couponObj = res.data
  282. if (res.data.list.length > 0) {
  283. this.isCouponShow = true
  284. }
  285. })
  286. },
  287. // 优惠券弹窗关闭
  288. couponClose() {
  289. this.isCouponShow = false
  290. try {
  291. uni.setStorageSync('oldDate', new Date().toLocaleDateString());
  292. } catch {}
  293. },
  294. onLoadFun() {},
  295. // #ifdef H5
  296. // 获取url后面的参数
  297. getQueryString(name) {
  298. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  299. var reg_rewrite = new RegExp("(^|/)" + name + "/([^/]*)(/|$)", "i");
  300. var r = window.location.search.substr(1).match(reg);
  301. var q = window.location.pathname.substr(1).match(reg_rewrite);
  302. if (r != null) {
  303. return unescape(r[2]);
  304. } else if (q != null) {
  305. return unescape(q[2]);
  306. } else {
  307. return null;
  308. }
  309. },
  310. // #endif
  311. // #ifdef MP || APP-PLUS
  312. getTemlIds() {
  313. let messageTmplIds = wx.getStorageSync(SUBSCRIBE_MESSAGE);
  314. if (!messageTmplIds) {
  315. getTemlIds().then(res => {
  316. if (res.data) wx.setStorageSync(SUBSCRIBE_MESSAGE, JSON.stringify(res.data));
  317. });
  318. }
  319. },
  320. // #endif
  321. // 对象转数组
  322. objToArr(data) {
  323. const keys = Object.keys(data)
  324. keys.sort((a, b) => a - b)
  325. const m = keys.map(key => data[key]);
  326. return m;
  327. },
  328. diyData() {
  329. let that = this;
  330. getDiy(this.pageId).then(res => {
  331. let data = res.data;
  332. if (res.data.length == 0) {
  333. return this.$util.Tips({
  334. title: '暂无数据'
  335. }, {
  336. tab: 3
  337. })
  338. }
  339. if (data.is_bg_color) {
  340. this.bgColor = data.color_picker
  341. }
  342. if (data.is_bg_pic) {
  343. this.bgPic = data.bg_pic
  344. this.bgTabVal = data.bg_tab_val
  345. }
  346. this.pageShow = data.is_show
  347. uni.setNavigationBarTitle({
  348. title: res.data.title
  349. })
  350. let temp = []
  351. let lastArr = that.objToArr(res.data.value)
  352. lastArr.forEach((item, index, arr) => {
  353. if (item.name == 'pageFoot') {
  354. uni.setStorageSync('pageFoot', item)
  355. that.$store.commit('FOOT_UPLOAD', item)
  356. arr.splice(index, 1)
  357. }
  358. if (item.name == 'promotionList') {
  359. that.numConfig = item.numConfig.val;
  360. that.getGroomList();
  361. }
  362. temp = arr
  363. });
  364. that.styleConfig = temp;
  365. });
  366. },
  367. getIndexData() {
  368. },
  369. changeBarg(item) {
  370. if (!this.isLogin) {
  371. toLogin();
  372. } else {
  373. uni.navigateTo({
  374. url: `/pages/activity/goods_bargain_details/index?id=${item.id}&bargain=${this.uid}`
  375. });
  376. }
  377. },
  378. // 促销列表的点击事件;
  379. changeTab(type) {
  380. this.goodType = type;
  381. this.tempArr = [];
  382. this.page = 1;
  383. this.loadend = false;
  384. let onloadH = true;
  385. this.getGroomList(onloadH);
  386. },
  387. // 精品推荐
  388. getGroomList(onloadH) {
  389. let that = this;
  390. let type = that.goodType;
  391. if (that.loadend) return false;
  392. if (that.loading) return false;
  393. if (onloadH) {
  394. that.$set(that, 'iSshowH', true);
  395. }
  396. getGroomList(type, {
  397. page: that.page,
  398. limit: that.limit
  399. })
  400. .then(({
  401. data
  402. }) => {
  403. that.$set(that, 'iSshowH', false);
  404. let maxPage = Math.ceil(this.numConfig / this.limit);
  405. let list = data.list,
  406. loadend = list.length < that.limit || that.page >= maxPage;
  407. let tempArr = that.$util.SplitArray(list, that.tempArr);
  408. that.$set(that, 'tempArr', tempArr.slice(0, this.numConfig));
  409. that.loadend = loadend;
  410. that.loadTitle = loadend ? '没有更多内容啦~' : '加载更多';
  411. that.page = that.page + 1;
  412. that.loading = false;
  413. })
  414. .catch(res => {
  415. that.loading = false;
  416. that.loadTitle = '加载更多';
  417. });
  418. },
  419. goDetail(item) {
  420. goShopDetail(item, this.uid).then(res => {
  421. uni.navigateTo({
  422. url: `/pages/goods_details/index?id=${item.id}`
  423. });
  424. });
  425. },
  426. // #ifdef H5
  427. // 微信分享;
  428. setOpenShare: function() {
  429. let that = this;
  430. if (that.$wechat.isWeixin()) {
  431. getShare().then(res => {
  432. let data = res.data.data;
  433. let configAppMessage = {
  434. desc: data.synopsis,
  435. title: data.title,
  436. link: location.href,
  437. imgUrl: data.img
  438. };
  439. that.$wechat.wechatEvevt(['updateAppMessageShareData', 'updateTimelineShareData'],
  440. configAppMessage);
  441. });
  442. }
  443. }
  444. // #endif
  445. },
  446. onReachBottom: function() {
  447. this.getGroomList();
  448. },
  449. //#ifdef MP || APP-PLUS
  450. onShareAppMessage() {
  451. return {
  452. title: this.shareInfo.title,
  453. path: '/pages/index/index',
  454. imageUrl: this.storeInfo.img,
  455. };
  456. },
  457. //#endif
  458. };
  459. </script>
  460. <style lang="scss">
  461. .page {
  462. padding-bottom: 50px;
  463. }
  464. .ysize {
  465. background-size: 100%;
  466. }
  467. .fullsize {
  468. background-size: 100% 100%;
  469. }
  470. .repeat {
  471. background-repeat: repeat;
  472. }
  473. .noRepeat {
  474. background-repeat: no-repeat;
  475. }
  476. </style>