index.vue 12 KB

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