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