home.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. <template>
  2. <view class="zaiui-home-box" :class="show?'show':''">
  3. <!--欢迎-->
  4. <welcome-tip content="中午好,仔仔" :show="true" :c_s="3000" @closeFinish="welcomeClose"/>
  5. <!--轮播背景-->
  6. <swiper-background :list_data="swiperInfo.list" :indexs="swiperInfo.index" :show="swiperInfo.show" :welcome="swiperInfo.welcome"/>
  7. <view class="zaiui-head-search-box" :class="headInfo.Class" :style="[{backgroundColor:'rgba(229, 77, 66,'+ headInfo.opacity +')'}]">
  8. <!--小程序端的标题-->
  9. <!-- #ifdef MP -->
  10. <view class="text-center text-white zaiui-small-routine-title">首页</view>
  11. <!-- #endif -->
  12. <!--搜索框-->
  13. <view class="cu-bar search zaiui-search-box">
  14. <view class="search-form round" @tap="searchTap">
  15. <text class="cuIcon-search"/>
  16. <text>口罩</text>
  17. </view>
  18. <view class="action text-white"></view>
  19. </view>
  20. <!--选项卡-->
  21. <view class="zaiui-flex-tab show">
  22. <view class="flex text-white">
  23. <view class="basis-xxl">
  24. <scroll-view scroll-x class="nav z" scroll-with-animation :scroll-left="headTab.scrollLeft">
  25. <block v-for="(item,index) in headTab.list" :key="item.id">
  26. <view class="cu-item" :class="item.id==headTab.TabCur?'select':''" @tap="tabSelect" :data-id="item.id">
  27. <view>{{item.name}}</view>
  28. <view class="tab-dot bg-white"/>
  29. </view>
  30. </block>
  31. </scroll-view>
  32. </view>
  33. <view class="basis-xxs">
  34. <view class="sort-icon" @tap="sortVueTap">
  35. <text class="cuIcon-sort"/>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. <!--中间内容区域-->
  42. <view class="zaiui-view-content" :class="[viewContent.welcome?'welcome':'',headTab.TabCur==0?'show':'']">
  43. <!--轮播图-->
  44. <view class="zaiui-swiper-box">
  45. <swiper class="screen-swiper square-dot c" autoplay circular indicator-dots :current="swiperInfo.index" @change="swiperChange">
  46. <swiper-item v-for="(item,index) in swiperInfo.list" :key="index">
  47. <view class="swiper-padding">
  48. <image :src="item.swiper" mode="widthFix"/>
  49. </view>
  50. </swiper-item>
  51. </swiper>
  52. </view>
  53. <!--滑动菜单-->
  54. <grid-menu-list v-if="gridMenuData.length" :list_data='gridMenuData' @listTap='gridMenuTap'/>
  55. <!--红包块-->
  56. <!-- <view class="bg-red margin radius padding-sm">
  57. <image class="red-envelopes" src="/static/images/home/sundry/2.png" mode="widthFix"/>
  58. </view> -->
  59. <!--免费鉴别-->
  60. <!-- <identify-list :list_data='identifyData' @listTap='identifyTap'/> -->
  61. <!--省心快卖-->
  62. <!-- <sell-quickly-list :list_data='quickly' @listTap='quicklyTap'/> -->
  63. <!--活动区域-->
  64. <!-- <activity-list :list_data='activity' @listTap='activityTap'/> -->
  65. <!--商品tab-->
  66. <!-- <view class="zaiui-goods-tab-box">
  67. <scroll-view scroll-x class="nav z margin-tb-sm">
  68. <view class="flex text-center">
  69. <block v-for="(item,index) in goodsTabData.list" :key="index">
  70. <view class="cu-item flex-sub nf" :class="index==goodsTabData.TabCur?'select':''" @tap="goodsTab" :data-id="index">
  71. <view class="cu-tag badge z bg-gradual-pink" v-if="item.tag">{{item.tag}}</view>
  72. <view :class="index == goodsTabData.TabCur?'text-red':''">{{item.title}}</view>
  73. <view class="tab-dot bg-red"/>
  74. </view>
  75. </block>
  76. </view>
  77. </scroll-view>
  78. </view> -->
  79. <view class="zaiui-tab-list">
  80. <!--商品列表-->
  81. <goods-list :list_data="goodsData" @listTap="goodsListTap" :show="goodsTabData.TabCur!=2 && goodsTabData.TabCur!=4?true:false"/>
  82. <!--直播列表-->
  83. <!-- <live-list :list_data="liveData" @listTap="liveListTap" :show="goodsTabData.TabCur==2?true:false"/> -->
  84. <!--视频列表-->
  85. <!-- <video-list :list_data="videoData" @listTap="videoListTap" :show="goodsTabData.TabCur==4?true:false"/> -->
  86. </view>
  87. <!--占位底部距离-->
  88. <view class="cu-tabbar-height"/>
  89. </view>
  90. <!--中间内容区域-分类-->
  91. <view class="zaiui-view-content" :class="headTab.TabCur!=0?'show':''">
  92. <!--宫格分类-->
  93. <grid-sort-list v-if="gridSortData.length" :list_data="gridSortData" @listTap="gridSortTap"/>
  94. <!--广告-->
  95. <!-- <view class="margin">
  96. <image class="zaiui-ad-img" src="/static/images/home/swiper/swiper-1.png" mode="widthFix"/>
  97. </view> -->
  98. <!--标题-->
  99. <!-- <view class="margin-bottom-sm zaiui-tab-list-title">
  100. <view class="flex flex-wrap">
  101. <view class="basis-sm text-right">
  102. <image class="img-aau" src="/static/zaiui/img/aau.png" lazy-load mode="widthFix"/>
  103. </view>
  104. <view class="basis-xs text-center">
  105. <text class="text-black text-xl text-bold">为您推荐</text>
  106. </view>
  107. <view class="basis-sm text-left">
  108. <image class="img-aau" src="/static/zaiui/img/aau.png" lazy-load mode="widthFix"/>
  109. </view>
  110. </view>
  111. </view> -->
  112. <!--商品列表-->
  113. <goods-list :list_data="goodsData" @listTap="goodsListTap"/>
  114. <!--占位底部距离-->
  115. <view class="cu-tabbar-height"/>
  116. </view>
  117. <!--弹出框-->
  118. <modal-img :show="modalShow" src="/static/images/home/sundry/reward.png" @imgTap="imgTap" @closeTap="closeTap"/>
  119. </view>
  120. </template>
  121. <script>
  122. //加载组件
  123. import welcomeTip from '@/components/zaiui-common/basics/welcome-tip';
  124. import swiperBackground from '@/components/zaiui-common/basics/swiper-background';
  125. import gridMenuList from '@/components/zaiui-common/list/grid-menu-list';
  126. import identifyList from '@/components/zaiui-common/list/identify-list';
  127. import sellQuicklyList from '@/components/zaiui-common/list/sell-quickly-list';
  128. import activityList from '@/components/zaiui-common/list/activity-list';
  129. import goodsList from '@/components/zaiui-common/list/goods-list';
  130. import liveList from '@/components/zaiui-common/list/live-list';
  131. import videoList from '@/components/zaiui-common/list/video-list';
  132. import footerTabbar from '@/components/zaiui-common/footer/footer-tabbar';
  133. import gridSortList from '@/components/zaiui-common/list/grid-sort-list';
  134. import modalImg from '@/components/zaiui-common/basics/modal-img';
  135. //======================================================================
  136. import _home_data from '@/static/zaiui/data/home.js'; //虚拟数据
  137. import _tool from '@/static/zaiui/util/tools.js';
  138. export default {
  139. name: 'home',
  140. components: {
  141. welcomeTip, swiperBackground, gridMenuList, identifyList, sellQuicklyList, activityList, goodsList, liveList, videoList, footerTabbar,
  142. gridSortList, modalImg
  143. },
  144. data() {
  145. return {
  146. swiperInfo: {index: 0, show: true, welcome: true, list: []}, headInfo: {Class: "", opacity: 0,}, goodsShow: true,
  147. headTab: {TabCur: 0, scrollLeft: 0, list: []}, viewContent: {welcome: false,}, gridMenuData: [], identifyData: [],
  148. quickly: {}, activity: [], goodsTabData: {TabCur: 0, list: []}, goodsData: [], liveData: [], videoData: [],
  149. gridSortData: [], modalShow: false,
  150. }
  151. },
  152. props: {
  153. show: {
  154. type: Boolean,
  155. default: true
  156. },
  157. scrollY: {
  158. type: Number,
  159. default: 0
  160. },
  161. scrollBottom: {
  162. type: Number,
  163. default: 0
  164. }
  165. },
  166. watch: {
  167. scrollY() {
  168. //通知他妈的滚动了。
  169. this.setPageScroll(this.scrollY);
  170. },
  171. scrollBottom() {
  172. if(this.scrollBottom != 0) {
  173. //通知他妈的触底了
  174. this.setReachBottom();
  175. }
  176. },
  177. },
  178. created() {
  179. //加载虚拟数据
  180. // this.headTab.list = _home_data.tab();
  181. this.swiperInfo.list = _home_data.swiper();
  182. // this.gridMenuData = _home_data.nav();
  183. // this.identifyData = _home_data.live();
  184. // this.quickly.swiper = _home_data.earn();
  185. // this.quickly.list = _home_data.sellQuickly();
  186. // this.activity = _home_data.activity();
  187. // this.goodsTabData.list = _home_data.goodsTab();
  188. //商品列表数据
  189. // let GoodsData = _home_data.goodsList();
  190. //推荐感兴趣数据
  191. // let recommendData = _home_data.recommend();
  192. //把推荐感兴趣的数据,添加到商品数据里,可扩展为随机位置显示。
  193. // GoodsData.splice(1, 0, recommendData);
  194. // this.goodsData = GoodsData;
  195. this.headInfo.Class = '';
  196. this.welcomeClose(true)
  197. this.getListByCate('')
  198. },
  199. mounted() {
  200. uni.pageScrollTo({
  201. scrollTop: 0,
  202. duration: 0
  203. });
  204. //次级虚拟数据加载
  205. this.liveData = _home_data.liveData();
  206. this.videoData = _home_data.videoData();
  207. // this.gridSortData = _home_data.gridSortData();
  208. },
  209. methods: {
  210. getListByCate(cate_id) {
  211. this.req({
  212. url: '?l=resource.home',
  213. data: {type: 3, cate_id},
  214. success: res => {
  215. if(res.data.status == 1) {
  216. console.log(res.data.data)
  217. if(!cate_id) {
  218. this.headTab.list = [{name: '全部', id: ''},...res.data.data.cate_parent];
  219. this.gridMenuData = res.data.data.cate_child
  220. } else {
  221. this.gridSortData = res.data.data.cate_child
  222. }
  223. this.goodsData = res.data.data.list;
  224. }else {
  225. this.error = res.data.msg
  226. }
  227. }
  228. })
  229. },
  230. //页面被滚动
  231. setPageScroll(scrollTop) {
  232. //console.log(scrollTop);
  233. if(this.headTab.TabCur == 0) {
  234. if(scrollTop <= 100) {
  235. let num = scrollTop / 100;
  236. this.headInfo.opacity = num;
  237. } else if(scrollTop > 100) {
  238. this.headInfo.opacity = 1;
  239. }
  240. }
  241. },
  242. //触底了
  243. setReachBottom() {
  244. console.log('触底了');
  245. },
  246. //欢迎提示关闭事件
  247. welcomeClose(bol) {
  248. this.swiperInfo.welcome = bol;
  249. this.headTab.welcome = bol;
  250. let Class = this.headInfo.Class;
  251. this.headInfo.Class = Class.replace(/welcome/g, '');
  252. this.viewContent.welcome = bol;
  253. //设置颜色
  254. _tool.setBarColor(false);
  255. console.log(bol);
  256. },
  257. //搜索框下的tab菜单被点击
  258. tabSelect(e) {
  259. let index = e.currentTarget.dataset.id;
  260. this.headTab.TabCur = index;
  261. this.headTab.scrollLeft = (index - 1) * 60;
  262. if(index == 0) {
  263. this.swiperInfo.show = true;
  264. this.headInfo.opacity = 0;
  265. } else {
  266. this.swiperInfo.show = false;
  267. this.headInfo.opacity = 1;
  268. }
  269. uni.pageScrollTo({
  270. scrollTop: 0,
  271. duration: 0
  272. });
  273. this.getListByCate(index)
  274. },
  275. swiperChange(e) {
  276. this.swiperInfo.index = e.detail.current;
  277. },
  278. gridMenuTap(e) {
  279. console.log(e);
  280. uni.navigateTo({
  281. url: "/pages/home/sort_list"
  282. });
  283. },
  284. identifyTap(e) {
  285. console.log(e);
  286. },
  287. quicklyTap(e) {
  288. console.log(e);
  289. },
  290. activityTap(e) {
  291. console.log(e);
  292. },
  293. //商品列表上的分类tab被点击
  294. goodsTab(e) {
  295. this.goodsTabData.TabCur = e.currentTarget.dataset.id;
  296. // #ifdef H5
  297. uni.pageScrollTo({
  298. scrollTop: 1060,
  299. duration: 200
  300. });
  301. // #endif
  302. // #ifdef APP-PLUS
  303. uni.pageScrollTo({
  304. scrollTop: 1010,
  305. duration: 200
  306. });
  307. // #endif
  308. },
  309. goodsListTap(e) {
  310. console.log(e);
  311. // if(e.index==0) {
  312. uni.navigateTo({
  313. url: '/pages/goods/goods?id='+e.data.id
  314. });
  315. // } else if(e.index == 2) {
  316. // uni.navigateTo({
  317. // url: '/pages/goods/second_hand'
  318. // });
  319. // } else if(e.index == 3) {
  320. // uni.navigateTo({
  321. // url: '/pages/goods/second_terrace'
  322. // });
  323. // } else {
  324. // }
  325. },
  326. liveListTap(e) {
  327. console.log(e);
  328. },
  329. videoListTap(e) {
  330. console.log(e);
  331. },
  332. gridSortTap(e) {
  333. console.log(e);
  334. },
  335. rewardTap() {
  336. uni.navigateTo({
  337. url: "/pages/goods/reward"
  338. });
  339. },
  340. imgTap() {
  341. this.modalShow = false;
  342. uni.navigateTo({
  343. url: "/pages/goods/reward"
  344. });
  345. console.log('图片被点击');
  346. },
  347. closeTap() {
  348. this.modalShow = false;
  349. console.log('点击了关闭');
  350. },
  351. sortVueTap() {
  352. uni.navigateTo({
  353. url: "/pages/home/sort"
  354. });
  355. },
  356. searchTap() {
  357. uni.navigateTo({
  358. url: "/pages/home/search"
  359. });
  360. }
  361. }
  362. }
  363. </script>
  364. <style lang="scss" scoped>
  365. .zaiui-head-search-box {
  366. position: fixed;
  367. width: 100%;
  368. top: 0;
  369. z-index: 9999;
  370. background-color: rgba(229, 77, 66,0);
  371. padding-top: var(--status-bar-height);
  372. transition: top .25s;
  373. padding-bottom: 10upx;
  374. .zaiui-search-box {
  375. position: relative;
  376. }
  377. .zaiui-flex-tab {
  378. position: relative;
  379. transition: opacity .25s;
  380. .flex {
  381. .basis-xxl {
  382. flex-basis: 90%;
  383. width: 90%;
  384. z-index: 1;
  385. }
  386. .basis-xxs {
  387. flex-basis: 10%;
  388. z-index: 1;
  389. width: 10%;
  390. }
  391. .sort-icon {
  392. font-size: 55upx;
  393. height: 64upx;
  394. line-height: 64upx;
  395. text-align: center;
  396. }
  397. }
  398. }
  399. }
  400. .zaiui-head-search-box.welcome {
  401. top: calc(var(--status-bar-height) + 101upx);
  402. transition: top .25s;
  403. }
  404. .zaiui-view-content {
  405. display: none;
  406. width: 100%;
  407. /* #ifdef APP-PLUS */
  408. margin-top: calc(var(--status-bar-height) + 30upx);
  409. /* #endif */
  410. /* #ifdef H5 */
  411. margin-top: calc(var(--status-bar-height) + 70upx);
  412. /* #endif */
  413. /* #ifdef MP */
  414. margin-top: calc(var(--status-bar-height) + 85upx);
  415. /* #endif */
  416. .zaiui-tab-list {
  417. position: relative;
  418. width: 100%;
  419. }
  420. }
  421. .zaiui-view-content.welcome {
  422. /* #ifdef APP-PLUS */
  423. margin-top: calc(var(--status-bar-height) + 180upx);
  424. /* #endif */
  425. /* #ifdef H5 */
  426. margin-top: calc(var(--status-bar-height) + 220upx);
  427. /* #endif */
  428. /* #ifdef MP */
  429. margin-top: calc(var(--status-bar-height) + 220upx);
  430. /* #endif */
  431. transition: all .25s;
  432. }
  433. .zaiui-view-content.show {
  434. display: block;
  435. }
  436. .zaiui-swiper-box {
  437. width: 100%;
  438. .screen-swiper {
  439. height: 230upx;
  440. min-height: 230upx;
  441. .swiper-padding {
  442. padding: 0 25upx;
  443. }
  444. }
  445. }
  446. .red-envelopes {
  447. width: 100%;
  448. }
  449. .zaiui-goods-tab-box {
  450. position: sticky;
  451. padding: 2upx 0;
  452. transition: all .25s;
  453. z-index: 9999;
  454. background: #fff;
  455. /* #ifndef MP */
  456. top: calc(var(--status-bar-height) + 101upx);
  457. /* #endif */
  458. /* #ifdef MP */
  459. top: calc(var(--status-bar-height) + 161upx);
  460. /* #endif */
  461. .cu-tag.z {
  462. top: 0px;
  463. right: -32.72upx;
  464. font-size: 20upx;
  465. padding: 19upx 6upx;
  466. transform: scale(0.8);
  467. }
  468. }
  469. .zaiui-ad-img {
  470. width: 100%;
  471. }
  472. .zaiui-tab-list-title {
  473. .img-aau {
  474. width: 101.81upx;
  475. margin-top: 12.72upx;
  476. }
  477. .text-right {
  478. .img-aau {
  479. margin-right: 14.54upx;
  480. }
  481. }
  482. .text-left {
  483. .img-aau {
  484. margin-left: 14.54upx;
  485. }
  486. }
  487. }
  488. .zaiui-add-btn-view-box {
  489. position: fixed;
  490. z-index: 999999;
  491. bottom: 181.81upx;
  492. right: 27.27upx;
  493. .cu-btn {
  494. margin: auto;
  495. width: 81.81upx;
  496. height: 81.81upx;
  497. font-weight: 800;
  498. border-radius: 50%;
  499. font-size: 36.36upx;
  500. border: 9.09upx solid #fff;
  501. box-shadow: 0 0 14.54upx 7.27upx #d0d0d0;
  502. }
  503. }
  504. .zaiui-home-box {
  505. display: none;
  506. }
  507. .zaiui-home-box.show {
  508. display: block;
  509. }
  510. </style>