index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <template>
  2. <view id="home" :style="[pageStyle]" class="smallBox" :data-theme="theme">
  3. <!-- 首页组合组件 -->
  4. <homeComb :bgInfo="bgInfo" v-if="showHomeComb && !merId" :dataConfig="homeCombData" @changeTab="changeTab" :isScrolled="isScrolled"
  5. :navIndex="navIndex" :isSmallPage="isSmallPage"
  6. ></homeComb>
  7. <!-- 店铺组合组件 -->
  8. <merHomeComb :isSmallPage="isSmallPage" :bgInfo="bgInfo" v-if="showHomeComb && merId" :dataConfig="homeCombData" :isScrolled="isScrolled" :navIndex="navIndex"
  9. :merId="merId">
  10. </merHomeComb>
  11. <!-- 顶部搜索框 -->
  12. <headerSearch v-if="showHeaderSerch" :isScrolled="isScrolled" :dataConfig="headerSerchCombData" :merId="merId" :isSmallPage="isSmallPage"></headerSearch>
  13. <!-- 分类导航 -->
  14. <cateNav v-if="showCateNav" :dataConfig="cateNavData" @changeTab="changeTab"></cateNav>
  15. <view v-if="navIndex === 0">
  16. <block v-for="(item, index) in styleConfig" :key="index">
  17. <merHome v-if="item.name == 'homeStore'" :dataConfig="item" class="tui-skeleton-rect"
  18. :merchantInfo="merchantAPPInfo" :merId="merId" :isHome="true"></merHome>
  19. <!-- 新闻简报 -->
  20. <news v-if="item.name == 'news'" :dataConfig="item"></news>
  21. <!-- menu -->
  22. <menus v-if="item.name == 'menus'" :dataConfig="item"></menus>
  23. <!-- 文章列表 -->
  24. <articleList v-if="item.name == 'homeArticle'" :dataConfig="item"></articleList>
  25. <!-- 秒杀 -->
  26. <seckill-data v-if="item.name == 'seckill'" :dataConfig="item" :merId="merId"></seckill-data>
  27. <!-- 直播 -->
  28. <!-- #ifdef MP -->
  29. <liveBroadcast v-if="item.name == 'liveBroadcast'" :dataConfig="item"></liveBroadcast>
  30. <!-- #endif -->
  31. <!-- 优惠券 -->
  32. <coupon v-if="item.name == 'homeCoupon'" :dataConfig="item" :merId="merId"></coupon>
  33. <!-- 图片魔方 -->
  34. <pictureCube v-if="item.name == 'pictureCube'" :dataConfig="item"></pictureCube>
  35. <!-- 热区 -->
  36. <hotSpot v-if="item.name == 'homeHotspot'" :dataConfig="item"></hotSpot>
  37. <!-- 轮播图 -->
  38. <swiperBg v-if="item.name == 'swiperBg'" :dataConfig="item"></swiperBg>
  39. <!-- 视频 -->
  40. <shortVideo v-if="item.name == 'video'" :dataConfig="item"></shortVideo>
  41. <!-- 商户 -->
  42. <merchant-list v-if="item.name == 'homeMerchant'" :dataConfig="item"></merchant-list>
  43. <!-- 辅助线 -->
  44. <guide v-if="item.name == 'guide'" :dataConfig="item"></guide>
  45. <!-- 富文本-->
  46. <rich-text-editor v-if="item.name == 'richTextEditor'" :dataConfig="item"></rich-text-editor>
  47. <!-- 辅助空白-->
  48. <blank-page v-if="item.name == 'blankPage'" :dataConfig="item"></blank-page>
  49. <!-- 标题 -->
  50. <home-title v-if="item.name == 'titles'" :dataConfig="item"></home-title>
  51. <!-- 拼团 -->
  52. <group v-if="item.name == 'group'" :dataConfig="item" :merId="merId"></group>
  53. <!-- 积分 -->
  54. <intergralShop v-if="item.name == 'intergral'" :dataConfig="item"></intergralShop>
  55. <!-- 逛逛 -->
  56. <discover v-if="item.name == 'homeDiscover'" :dataConfig="item"></discover>
  57. <!-- 商品列表 -->
  58. <goodList v-if="item.name == 'goodList'" :dataConfig="item" @detail="goDetail" :merId="merId"></goodList>
  59. <!-- 选项卡商品列表-->
  60. <homeTab v-if="item.name == 'homeTab'" :dataConfig="item" @detail="goDetail" :merId="merId"></homeTab>
  61. <!-- 底部导航-->
  62. <page-footer v-if="item.name == 'footer'" :dataConfig="item" :isSmallPage="isSmallPage" :merId="merId"></page-footer>
  63. </block>
  64. </view>
  65. <!-- 分类页-->
  66. <view class="productList" v-if="navIndex > 0 && sortList.length>0">
  67. <view class="sort acea-row" :class="sortList.length ? '' : 'no_pad'"
  68. :style="{ marginTop: sortMarTop + 'px' }">
  69. <navigator hover-class="none"
  70. :url="'/pages/goods/goods_list/index?cid=' + item.id + '&title=' + item.name" class="item"
  71. v-for="(item, index) in sortList" :key="index">
  72. <view class="pictrue">
  73. <!-- <easy-loadimage :image-src="item.icon" class='slide-image skeleton-rect'>
  74. </easy-loadimage> -->
  75. <image :src="item.icon" class='slide-image tui-skeleton-rect'></image>
  76. </view>
  77. <view class="text">{{ item.name }}</view>
  78. </navigator>
  79. <view class="item" @click="bindMore()" v-if="sortList.length >= 9">
  80. <view class="pictrues acea-row row-center-wrapper">
  81. <text class="iconfont icon-gengduo2"></text>
  82. </view>
  83. <view class="text">更多</view>
  84. </view>
  85. </view>
  86. </view>
  87. <!-- 推荐商品,分类商品列表-->
  88. <recommend v-if="categoryId>0" ref="recommendIndex" :categoryId='categoryId' :isShowTitle="isShowTitle"
  89. @getRecommendLength="getRecommendLength"></recommend>
  90. <view class='noCommodity' v-if="isNoCommodity&& navIndex > 0">
  91. <view class='pictrue'>
  92. <image :src="urlDomain+'crmebimage/presets/noShopper.png'"></image>
  93. </view>
  94. <text class="text-ccc">暂无商品</text>
  95. </view>
  96. <!-- <view v-if="bottomNavigationIsCustom" class="footerBottom"></view> -->
  97. </view>
  98. </template>
  99. <script>
  100. import {
  101. getDiy,
  102. getCategoryThird
  103. } from '@/api/api.js';
  104. import {
  105. mapGetters
  106. } from "vuex";
  107. import tuiSkeleton from '@/components/base/tui-skeleton.vue';
  108. import liveBroadcast from '@/components/homeIndex/liveBroadcast';
  109. import merchantList from '@/components/homeIndex/merchant.vue'
  110. import homeComb from '@/components/homeIndex/homeComb';
  111. import merHomeComb from '@/components/homeIndex/merHomeComb.vue';
  112. import seckillData from "@/components/homeIndex/seckill.vue";
  113. import couponDialog from "@/components/homeIndex/couponDialog.vue"
  114. import coupon from "@/components/homeIndex/coupon.vue";
  115. import menus from "@/components/homeIndex/menus.vue";
  116. import pictureCube from '@/components/homeIndex/pictureCube'
  117. import news from '@/components/homeIndex/news'
  118. import goodList from '@/components/homeIndex/goodList'
  119. import guide from '@/components/homeIndex/guide';
  120. import articleList from '@/components/homeIndex/articleList'
  121. import swiperBg from '@/components/homeIndex/swiperBg'
  122. import headerSearch from '@/components/homeIndex/headerSearch';
  123. import cateNav from '@/components/homeIndex/cateNav';
  124. import richTextEditor from '@/components/homeIndex/richTextEditor';
  125. import shortVideo from '@/components/homeIndex/video';
  126. import homeTab from '@/components/homeIndex/homeTab';
  127. import discover from '@/components/homeIndex/discover';
  128. import blankPage from '@/components/homeIndex/blankPage';
  129. import homeTitle from '@/components/homeIndex/title';
  130. import pageFooter from '@/components/pageFooter/index.vue';
  131. import recommend from "@/components/base/recommend.vue";
  132. import group from "@/components/homeIndex/group.vue";
  133. import intergralShop from "@/components/homeIndex/intergralShop.vue";
  134. import hotSpot from '@/components/homeIndex/hotSpot.vue';
  135. import merHome from '@/components/merHome/index.vue'
  136. import {
  137. goProductDetail
  138. } from "../../../libs/order";
  139. let app = getApp();
  140. export default {
  141. data() {
  142. return {
  143. urlDomain: this.$Cache.get("imgHost"),
  144. theme: app.globalData.theme,
  145. isSmallPage: true, //是否是微页面,true是,false不是
  146. styleConfig: [],
  147. bgColor: '',
  148. bgPic: '',
  149. bgTabVal: '',
  150. isFixed: true,
  151. storeHeight: 0,
  152. smallPage: false,
  153. homeCombData: {},
  154. headerSerchCombData: {},
  155. sortList: [],
  156. sortMarTop: 0,
  157. showCateNav: false, //是否显示分类导航组件
  158. cateNavData: {}, //分类导航组件数据
  159. navIndex: 0,
  160. pageStyle: null,
  161. cateNavActive: 0,
  162. categoryId: 0, //分类id
  163. diyId: 0, //diyid
  164. isNoCommodity: false,
  165. showHomeComb: false,
  166. showHeaderSerch: false,
  167. domOffsetTop: 50,
  168. isScrolled: false,
  169. merId:0,
  170. bgInfo:{
  171. colorPicker:'#f5f5f5',
  172. isBgColor:1,
  173. },
  174. }
  175. },
  176. components: {
  177. merchantList,
  178. homeComb,
  179. tuiSkeleton,
  180. seckillData,
  181. liveBroadcast,
  182. couponDialog,
  183. coupon,
  184. menus,
  185. pictureCube,
  186. news,
  187. goodList,
  188. articleList,
  189. swiperBg,
  190. headerSearch,
  191. cateNav,
  192. guide,
  193. richTextEditor,
  194. shortVideo,
  195. homeTab,
  196. discover,
  197. blankPage,
  198. homeTitle,
  199. pageFooter,
  200. recommend,
  201. group,
  202. intergralShop,
  203. hotSpot,
  204. merHomeComb,
  205. merHome
  206. },
  207. computed: mapGetters(['bottomNavigationIsCustom','merchantAPPInfo']),
  208. onLoad(options) {
  209. if (options.scene) {
  210. let value = this.$util.getUrlParams(decodeURIComponent(options.scene));
  211. if (value.id) this.diyId = Number(value.id);
  212. if (value.merId) this.merId = Number(value.merId);
  213. }
  214. if (options.id) {
  215. this.diyId = Number(options.id);
  216. }
  217. if (options.merId) {
  218. this.merId = Number(options.merId);
  219. }
  220. this.diyData(this.diyId)
  221. },
  222. // 滚动监听
  223. onPageScroll(e) {
  224. // 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
  225. uni.$emit('scroll');
  226. if (e.scrollTop > this.domOffsetTop) {
  227. this.isScrolled = true;
  228. }
  229. if (e.scrollTop < this.domOffsetTop) {
  230. this.$nextTick(() => {
  231. this.isScrolled = false;
  232. });
  233. }
  234. },
  235. methods: {
  236. diyData(id) {
  237. let that = this;
  238. that.styleConfig = [];
  239. uni.showLoading({
  240. title: '加载中...'
  241. });
  242. getDiy(id).then(res => {
  243. uni.setNavigationBarTitle({
  244. title: res.data.title
  245. });
  246. uni.setNavigationBarColor({
  247. //必须要16进制小写
  248. frontColor: res.data.titleColor,
  249. backgroundColor: res.data.titleBgColor.toString().toLowerCase(),
  250. })
  251. let data = res.data;
  252. that.styleConfig = that.$util.objToArr(res.data.value);
  253. uni.hideLoading();
  254. that.styleConfig.forEach((item) => {
  255. if (item.name == 'tabNav') {
  256. this.showCateNav = true;
  257. this.cateNavData = item;
  258. }
  259. if (item.name === 'homeComb') {
  260. that.showHomeComb = true
  261. that.homeCombData = item;
  262. }
  263. if (item.name === 'headerSerch') {
  264. that.showHeaderSerch = true
  265. that.headerSerchCombData = item;
  266. }
  267. });
  268. this.bgInfo.isBgColor=data.isBgColor
  269. this.bgInfo.colorPicker=data.colorPicker
  270. this.pageStyle = {
  271. 'background-color': data.isBgColor === 1 ? res.data.colorPicker : '',
  272. 'background-image': data.isBgPic === 1 ? `url(${res.data.bgPic})` : '',
  273. 'background-repeat': res.data.bgTabVal === 1 ? 'repeat-y' : 'no-repeat',
  274. 'background-size': res.data.bgTabVal === 2 ? 'cover' : 'contain'
  275. };
  276. setTimeout(() => {
  277. this.isNodes++;
  278. }, 100);
  279. }).catch(err => {
  280. return that.$util.Tips({
  281. title: err
  282. });
  283. uni.hideLoading();
  284. })
  285. },
  286. getRecommendLength(e) {
  287. this.isNoCommodity = e == 0 ? true : false;
  288. },
  289. // 分类切换点击
  290. changeTab(index, item) {
  291. //type=0微页面,1分类,2首页
  292. this.cateNavActive = index;
  293. if (item.type == 1) {
  294. this.navIndex = 1;
  295. if (!item.val) {
  296. this.sortList = [];
  297. this.categoryId = 0;
  298. this.$util.Tips({
  299. title: "请在平台端选择商品分类!确保加载商品分类数据。"
  300. });
  301. return;
  302. } else {
  303. getCategoryThird(item.val).then(res => {
  304. this.sortList = res.data;
  305. // #ifdef H5
  306. self.sortMarTop = 10;
  307. // #endif
  308. });
  309. this.categoryId = item.val;
  310. this.isShowTitle = false;
  311. }
  312. } else if (item.type == 0) {
  313. this.navIndex = 0;
  314. this.isShowTitle = true;
  315. this.categoryId = 0;
  316. if (!item.val) {
  317. return this.$util.Tips({
  318. title: "请在平台端选择微页面链接!确保加载微页面数据。"
  319. });
  320. } else {
  321. this.styleConfig = [];
  322. this.diyData(item.val, true);
  323. }
  324. } else {
  325. this.categoryId = 0;
  326. this.navIndex = 0;
  327. this.styleConfig = [];
  328. this.diyData(this.diyId, false);
  329. }
  330. },
  331. // 去商品详情页
  332. goDetail(item) {
  333. goProductDetail(item.id, 0, '')
  334. },
  335. },
  336. onReachBottom() {
  337. },
  338. }
  339. </script>
  340. <style lang="scss" scoped>
  341. .smallBox {
  342. padding-bottom: calc(130rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  343. padding-bottom: calc(130rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  344. }
  345. .productList {
  346. background-color: #F5F5F5;
  347. margin-top: 20rpx;
  348. .sort {
  349. width: 710rpx;
  350. max-height: 380rpx;
  351. background: rgba(255, 255, 255, 1);
  352. border-radius: 16rpx;
  353. padding: 0rpx 0rpx 20rpx 0rpx !important;
  354. flex-wrap: wrap;
  355. margin: 25rpx auto 0 auto;
  356. &.no_pad {
  357. padding: 0;
  358. }
  359. .item {
  360. width: 20%;
  361. margin-top: 20rpx;
  362. text-align: center;
  363. .pictrues {
  364. width: 90rpx;
  365. height: 90rpx;
  366. background: #F5F5F5;
  367. border-radius: 50%;
  368. margin: 0 auto;
  369. }
  370. .pictrue {
  371. width: 90rpx;
  372. height: 90rpx;
  373. background: #F5F5F5;
  374. border-radius: 50%;
  375. margin: 0 auto;
  376. }
  377. .slide-image {
  378. width: 90rpx;
  379. height: 90rpx;
  380. border-radius: 50%;
  381. overflow: hidden;
  382. }
  383. /deep/ .easy-loadimage,
  384. uni-image,
  385. .easy-loadimage {
  386. width: 90rpx;
  387. height: 90rpx;
  388. display: inline-block;
  389. }
  390. .text {
  391. color: #272727;
  392. font-size: 24rpx;
  393. margin-top: 10rpx;
  394. white-space: nowrap;
  395. text-overflow: ellipsis;
  396. }
  397. }
  398. }
  399. }
  400. .productList .list.on {
  401. background-color: #fff;
  402. border-top: 1px solid #f6f6f6;
  403. }
  404. .productList .list .item {
  405. width: 345rpx;
  406. margin-top: 20rpx;
  407. background-color: #fff;
  408. border-radius: 10rpx;
  409. .name {
  410. display: flex;
  411. align-items: center;
  412. .name_text {
  413. display: inline-block;
  414. max-width: 200rpx;
  415. }
  416. }
  417. }
  418. </style>