index.vue 12 KB

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