index.vue 12 KB

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