index.vue 12 KB

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