index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. <template>
  2. <view class="home tui-skeleton clearfix">
  3. <tui-skeleton v-if="skeletonShow" :isLoading ="true" :loadingType="2"></tui-skeleton>
  4. <!-- 首页自定义导航栏 -->
  5. <view class='navbar-wrap' :style="{height:(CustomBar+55)+'px',paddingTop:StatusBar+'px'}" :class="inputActive">
  6. <view class="navbar-text"
  7. :style="{color:navbarData.textColor ? navbarData.textColor:'',lineHeight:(CustomBar - StatusBar)+'px;',fontSize:fontSizeSetting+'px;',paddingLeft:navbarData.textLeft ? '' : 12+'px'}" :class="platformClass">
  8. {{navbarData.title ? navbarData.title : " "}}
  9. </view>
  10. <view class="search-input">
  11. <view class="gosearch-btn" @click="this.$api.navigateTo(clickPath)">
  12. <view class="search-icon">
  13. <text class="iconfont icon-sousuo"></text>
  14. </view>
  15. <view class="search-text">搜索商品</view>
  16. </view>
  17. </view>
  18. </view>
  19. <!-- 主页内容 -->
  20. <view class="container-home " :style="{paddingTop:CustomBar+'px'}">
  21. <!-- 轮播 -->
  22. <banner :list="bannerImageList"></banner>
  23. </view>
  24. <!-- 商品列表 -->
  25. <view class="container-section">
  26. <view class="clearfix" v-for="(floor,index1) in productFloor" :key="index1">
  27. <!-- 楼层标题区域 -->
  28. <view class="tui-group-name">
  29. <view class="tui-group-title ">
  30. <view class="tui-group-l">{{floor.title}}</view>
  31. <view class="tui-group-r" @click="NavToDetailPage(floor)" v-if="floor.productList.length>=6">
  32. <text>更多</text> <tui-icon name="arrowright" :size="20" margin="0 0 0 -4rpx"></tui-icon>
  33. </view>
  34. </view>
  35. <view class="tui-sub__desc">{{floor.description}}</view>
  36. </view>
  37. <!-- 商品列表区域 -->
  38. <view class="product-list" v-for="(pro,index2) in floor.productList" :key="index2" @click.stop="Details(pro)">
  39. <view class="product-list-image">
  40. <image class="product-image" :src="pro.mainImage" mode=""></image>
  41. <!-- 推荐 -->
  42. <image class="product-icon" :src="StaticUrl+'recommend.png'" mode="" v-if="pro.recommend === '1'"></image>
  43. </view>
  44. <view class="product-list-msg">
  45. <view class="product-msg-name">{{ pro.name }}</view>
  46. <view class="product-list-tag" v-if="pro.activeStatus == 1">
  47. <text class="tag tag-02">活动价</text>
  48. </view>
  49. <view class="product-list-pri">
  50. <view class="price">¥{{ pro.price | PriceFormat}}</view>
  51. <view class="carts" @click.stop="handAddCarts(pro)">
  52. <view class="carts-add">
  53. <text class="iconfont icon-gouwuche"></text>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. <!-- 侧边 -->
  62. <scroll-top :isScrollTop="isScrollTop" :bottom="160"></scroll-top>
  63. </view>
  64. </template>
  65. <script>
  66. import tuiSkeleton from "@/components/tui-skeleton/tui-skeleton"
  67. import authorize from '@/common/config/authorize.js'
  68. import btSearch from '@/components/uni-search/bt-search.vue'
  69. import banner from '@/components/cm-module/homeIndex/banner.vue'
  70. import { mapState,mapMutations} from 'vuex';
  71. export default {
  72. components:{
  73. tuiSkeleton,
  74. btSearch,
  75. banner,
  76. },
  77. data() {
  78. return {
  79. StaticUrl:this.$Static,
  80. navbarData: {//顶部自定义导航
  81. showCapsule: 1, // 是否显示左上角图标 1表示显示 0表示不显示,
  82. showSearch: 0,
  83. title: '呵呵商城', // 导航栏 中间的标题
  84. haveBack:false,
  85. textLeft:this.$store.state.isIphone,
  86. textColor:'#FFFFFF'
  87. },
  88. inputActive:'bgnone',
  89. clickPath:'/pages/goods/search',
  90. CustomBar:this.CustomBar,// 顶部导航栏高度
  91. StatusBar: this.StatusBar,
  92. fontSizeSetting:this.fontSizeSetting,
  93. screenWidth:this.screenWidth,
  94. capsule:this.capsule,
  95. platformClass:this.platformClass,
  96. userId:0,
  97. modallayer:false,
  98. skeletonShow: true,
  99. userIdentity:'',
  100. productFloor:[],//商品列表
  101. bannerImageList:[],//轮播
  102. pageNum:1,
  103. pageSize:20,
  104. hasNextPage:false,
  105. isScrollTop:false,
  106. isRequest:false,
  107. }
  108. },
  109. filters: {
  110. //处理金额
  111. PriceFormat: function(text) {
  112. return Number(text).toFixed(2)
  113. }
  114. },
  115. onLoad() {
  116. this.modallayer = false
  117. this.InitAuthorize()
  118. },
  119. computed: {
  120. ...mapState(['hasLogin','userInfo','identity','isActivity'])
  121. },
  122. methods: {
  123. ...mapMutations(['login','logout']),
  124. async GetWxAuthorize(){
  125. const wechatCode = await authorize.getCode('weixin');// 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  126. this.UserService.UserWechatAuthorLogin({ code:wechatCode } )
  127. .then(response =>{
  128. const _data = JSON.parse(response.data);
  129. uni.setStorageSync('openId', _data.openId)
  130. this.userId = _data.userId;
  131. this.userIdentity = _data.userIdentity;
  132. this.$store.commit('updateStatus',_data)
  133. this.login(_data);
  134. this.GetHomeBanner()
  135. this.GetHomeProductList()
  136. })
  137. .catch(error =>{
  138. const _data = JSON.parse(error.data);
  139. this.logout()
  140. this.$store.commit('updateStatus',_data)
  141. uni.setStorageSync('openId',_data.openId)
  142. this.GetHomeBanner()
  143. this.GetHomeProductList()
  144. })
  145. },
  146. GetHomeBanner(){//初始化首页数据
  147. this.CommonService.GetProductCarousel().then(response =>{
  148. let data = response.data;
  149. this.bannerImageList = data
  150. this.skeletonShow = false;
  151. }).catch(error =>{
  152. this.$util.msg(error.msg,2000)
  153. })
  154. },
  155. GetHomeProductList(){//初始化首页商品数据
  156. this.ProductService.QueryProductFloor()
  157. .then(response =>{
  158. this.productFloor = response.data;
  159. this.GetCartNumber();
  160. })
  161. .catch(error =>{
  162. this.$util.msg(error.msg,2000)
  163. })
  164. },
  165. NavToDetailPage(floor) {
  166. console.log('跳转');
  167. //跳转
  168. this.$api.navigateTo(
  169. `/pages/goods/good-floorMore?floorId=${floor.floorId}&title=${floor.title}`
  170. )
  171. },
  172. Details(pro){
  173. this.$api.navigateTo(`/pages/goods/product?productId=${pro.productId}`)
  174. },
  175. handAddCarts(pro){
  176. if(!this.hasLogin){
  177. this.$api.navigateTo(`/pages/login/login`)
  178. }else{
  179. this.ProductService.shoppingAddCart(
  180. {
  181. productId:pro.productId,
  182. userId:this.userId,
  183. productCount:1,
  184. heUserId:0,
  185. }
  186. )
  187. .then(response => {
  188. this.$util.msg('加入购物车成功',1500,true,'success')
  189. this.GetCartNumber()
  190. })
  191. .catch(error =>{
  192. this.$util.msg(error.msg,2000);
  193. })
  194. }
  195. },
  196. GetCartNumber(){//查询购物车数量
  197. this.ProductService.QueryShoppingQuantity(
  198. {
  199. userId:this.userId,
  200. }
  201. )
  202. .then(response => {
  203. this.$store.commit('updateAllNum',response.data)
  204. })
  205. .catch(error =>{
  206. console.log('查询购物车数量错误信息',error)
  207. })
  208. },
  209. handleClick(data){
  210. this.$api.navigateTo(`/h5/pages/activity/meobohui`)
  211. this.$store.commit('setActivity',data)
  212. uni.setStorageSync('lockTime',Date.now())
  213. uni.setStorageSync('isActivityStatus',true)
  214. },
  215. handleCancelClick(data){
  216. this.$store.commit('setActivity',data)
  217. uni.setStorageSync('lockTime',Date.now())
  218. uni.setStorageSync('isActivityStatus',true)
  219. },
  220. InitAuthorize(){ //是否已授权 0:为取消授权 1:为已授权 2:为未操作
  221. this.GetWxAuthorize();
  222. }
  223. },
  224. onPageScroll(e){//实时获取到滚动的值
  225. if(e.scrollTop>50){
  226. this.inputActive = 'bgclass'
  227. }else{
  228. this.inputActive = 'bgnone'
  229. }
  230. if(e.scrollTop>400){
  231. this.isScrollTop = true
  232. }else{
  233. this.isScrollTop = false
  234. }
  235. },
  236. //下拉刷新
  237. onPullDownRefresh() {
  238. this.GetHomeBanner()
  239. this.GetHomeProductList()
  240. setTimeout(()=>{
  241. uni.stopPullDownRefresh()
  242. }, 2000)
  243. },
  244. // onReachBottom() {
  245. // console.log("用户把这个页面上拉100时触发我的")
  246. // if(this.hasNextPage){
  247. // this.GetOnReachBottomProductList()
  248. // }
  249. // },
  250. onShareAppMessage(res){//分享转发
  251. if (res.from === 'button') {
  252. // 来自页面内转发按钮
  253. }
  254. return {
  255. title: '国内外知名美容院线护肤品线上商城~',
  256. path: 'pages/tabBar/index/index',
  257. imageUrl:'https://static.caimei365.com/app/mini-hehe/icon/icon-index-share.jpg'
  258. }
  259. },
  260. onShow(){
  261. this.GetCartNumber()
  262. }
  263. }
  264. </script>
  265. <style lang="scss">
  266. page{
  267. background-color: #FFFFFF;
  268. }
  269. .navbar-wrap {
  270. position: fixed;
  271. width: 100%;
  272. top: 0;
  273. z-index: 100000;
  274. box-sizing: border-box;
  275. background-image: linear-gradient(0deg, #f83c6c 0%, #fa55bf 100%);
  276. background-size: cover;
  277. border-bottom:none;
  278. &.bgnone{
  279. background: rgba(255,255,255,0);
  280. }
  281. &.bgclass{
  282. background: #F94A9B;
  283. }
  284. }
  285. .navbar-text {
  286. font-size: 30rpx;
  287. color: #000000;
  288. font-weight: 500;
  289. }
  290. .navbar-text.center{
  291. text-align: center;
  292. }
  293. .navbar-text.left{
  294. text-align: left;
  295. padding-left: 45px;
  296. }
  297. .navbar-icon {
  298. position: fixed;
  299. display: flex;
  300. box-sizing: border-box;
  301. }
  302. .navbar-icon .iconfont {
  303. display: inline-block;
  304. overflow: hidden;
  305. font-size: 44rpx;
  306. padding-right:40rpx;
  307. margin-top: 1px;
  308. }
  309. .navbar-icon .icon-iconfonticonfontsousuo1 {
  310. color: #000000;
  311. }
  312. .navbar-icon view {
  313. height: 18px;
  314. border-left: 0.5px solid rgba(0,0,0, 0.3);
  315. margin-top: 6px;
  316. }
  317. .navbar-loading {
  318. background: #fff;
  319. text-align: center;
  320. }
  321. .search-input{
  322. width: 100%;
  323. height: 110rpx;
  324. padding: 20rpx 24rpx;
  325. box-sizing: border-box;
  326. .gosearch-btn{
  327. width: 100%;
  328. height: 100%;
  329. border-radius: 40rpx;
  330. background: #F0F0F0;
  331. margin: 0 auto;
  332. font-size: 28rpx;
  333. line-height: 70rpx;
  334. color: #8A8A8A;
  335. background: #FFFFFF;
  336. position: relative;
  337. box-sizing: border-box;
  338. padding-left: 80rpx;
  339. .search-icon{
  340. width: 80rpx;
  341. height: 70rpx;
  342. position:absolute ;
  343. left: 0;
  344. top: 0;
  345. text-align: center;
  346. line-height: 70rpx;
  347. .icon-iconfonticonfontsousuo1{
  348. margin:0 6rpx;
  349. font-size: $font-size-34;
  350. color: #8A8A8A;
  351. z-index: 10;
  352. }
  353. }
  354. .search-text{
  355. font-size: $font-size-24;
  356. line-height: 70rpx;
  357. color: #8A8A8A;
  358. }
  359. }
  360. }
  361. .container-home{
  362. background:#F7F7F7 url(https://static.caimei365.com/app/mini-hehe/icon/icon-index-bg.png)top center no-repeat;
  363. background-size: contain;
  364. min-height: 485rpx;
  365. }
  366. .container-section{
  367. width: 100%;
  368. height: auto;
  369. background-color: #F7F7F7;
  370. box-sizing: border-box;
  371. padding: 0 24rpx;
  372. .product-list{
  373. width: 339rpx;
  374. height: 532rpx;
  375. float: left;
  376. margin-right: 24rpx;
  377. margin-bottom: 24rpx;
  378. background-color: #FFFFFF;
  379. border-radius: 16rpx;
  380. &:nth-child(2n+1){
  381. margin-right: 0;
  382. }
  383. .product-list-image{
  384. width: 100%;
  385. height: 339rpx;
  386. float: left;
  387. position: relative;
  388. .product-image{
  389. width: 100%;
  390. height: 100%;
  391. display: block;
  392. border-radius: 16rpx 16rpx 0 0;
  393. }
  394. .product-icon{
  395. width: 68rpx;
  396. height: 55rpx;
  397. display: block;
  398. position: absolute;
  399. top: 0;
  400. left: 34rpx;
  401. }
  402. }
  403. .product-list-msg{
  404. width: 100%;
  405. height: 193rpx;
  406. box-sizing: border-box;
  407. padding: 16rpx 24rpx;
  408. float: left;
  409. position: relative;
  410. .product-msg-name{
  411. width: 100%;
  412. height: 72rpx;
  413. line-height: 35rpx;
  414. text-overflow: ellipsis;
  415. overflow: hidden;
  416. display: -webkit-box;
  417. -webkit-line-clamp: 2;
  418. line-clamp: 2;
  419. -webkit-box-orient: vertical;
  420. font-size: $font-size-26;
  421. color: #333333;
  422. text-align: justify;
  423. float: left;
  424. }
  425. .product-list-tag{
  426. position: relative;
  427. z-index: 9;
  428. width: 100%;
  429. height: 30rpx;
  430. margin-top: 8rpx;
  431. float: left;
  432. .tag{
  433. display: inline-block;
  434. height: 32rpx;
  435. font-size: 22rpx;
  436. line-height: 30rpx;
  437. text-align: center;
  438. color: #f83c6c;
  439. float: left;
  440. margin-right: 10rpx;
  441. &.tag-02{
  442. width: 80rpx;
  443. background: url(https://static.caimei365.com/app/mini-hehe/icon/icon-active.png)top center no-repeat;
  444. background-size: contain;
  445. }
  446. &.tag-01{
  447. width: 56rpx;
  448. color: #fff;
  449. background-color: #f83c6c;
  450. border-radius: 4rpx;
  451. }
  452. }
  453. }
  454. .product-list-pri{
  455. width: 100%;
  456. height: 44rpx;
  457. float: left;
  458. position: absolute;
  459. bottom: 16rpx;
  460. left: 0;
  461. box-sizing: border-box;
  462. padding: 0 24rpx;
  463. .price{
  464. float: left;
  465. font-size:$font-size-26;
  466. color: #f83c6c;
  467. font-weight: bold;
  468. line-height: 44rpx;
  469. }
  470. .carts{
  471. float: right;
  472. .carts-add{
  473. width: 44rpx;
  474. height: 44rpx;
  475. text-align: center;
  476. line-height: 44rpx;
  477. background-color: #ff457b;
  478. border-radius: 50%;
  479. .iconfont{
  480. font-size: 32rpx;
  481. color: #FFFFFF;
  482. }
  483. }
  484. }
  485. }
  486. }
  487. }
  488. }
  489. .tui-group-name {
  490. width: 100%;
  491. height: 92rpx;
  492. padding: 20rpx 0;
  493. }
  494. .tui-group-title {
  495. width: 100%;
  496. float: left;
  497. .tui-group-l {
  498. float: left;
  499. font-size: 34rpx;
  500. font-weight: bold;
  501. text-align: left;
  502. line-height: 49rpx;
  503. color: #333;
  504. }
  505. .tui-group-r {
  506. float: right;
  507. font-size: $font-size-26;
  508. text-align: right;
  509. line-height: 49rpx;
  510. color: #999999;
  511. .icon-xiayibu {
  512. font-size: $font-size-30;
  513. color: #999999;
  514. }
  515. }
  516. }
  517. .tui-sub__desc {
  518. width: 100%;
  519. float: left;
  520. color: rgba(153, 153, 153, 0.9);
  521. font-size: $font-size-26;
  522. }
  523. </style>