index.vue 12 KB

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