index.vue 12 KB

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