index.vue 12 KB

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