index.vue 12 KB

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