You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

402 lines
12 KiB

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