index.vue 12 KB

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