index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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-iconfonticonfontsousuo1"></text>
  13. </view>
  14. <view class="search-text">{{hotSearchText}}</view>
  15. </view>
  16. </view>
  17. </view>
  18. <!-- 主页内容 -->
  19. <tui-skeleton v-if="skeletonShow" backgroundColor="#fafafa" borderRadius="10rpx" :isLoading ="true" :loadingType="5"></tui-skeleton>
  20. <view class="container-home tui-skeleton" :style="{paddingTop:CustomBar+'px'}">
  21. <!-- 轮播 -->
  22. <banner :list="bannerImageList" v-if="isNavRequest"></banner>
  23. </view>
  24. <!-- 楼层 -->
  25. <view class="container-section tui-skeleton">
  26. </view>
  27. <!-- 侧边 -->
  28. <scroll-top :isScrollTop="isScrollTop" :bottom="50"></scroll-top>
  29. </view>
  30. </template>
  31. <script>
  32. import tuiSkeleton from "@/components/tui-skeleton/tui-skeleton"
  33. import authorize from '@/common/config/authorize.js'
  34. import btSearch from '@/components/uni-search/bt-search.vue'
  35. import banner from '@/components/cm-module/homeIndex/banner.vue'
  36. import { mapState,mapMutations} from 'vuex';
  37. export default {
  38. components:{
  39. tuiSkeleton,
  40. btSearch,
  41. banner,
  42. },
  43. data() {
  44. return {
  45. navbarData: {//顶部自定义导航
  46. showCapsule: 1, // 是否显示左上角图标 1表示显示 0表示不显示,
  47. showSearch: 0,
  48. title: '呵呵商城', // 导航栏 中间的标题
  49. haveBack:false,
  50. textLeft:this.$store.state.isIphone,
  51. textColor:'#FFFFFF'
  52. },
  53. inputActive:'bgnone',
  54. clickPath:'/search/pages/search/search',
  55. hotSearchText:'搜索商品',
  56. CustomBar:this.CustomBar,// 顶部导航栏高度
  57. StatusBar: this.StatusBar,
  58. fontSizeSetting:this.fontSizeSetting,
  59. screenWidth:this.screenWidth,
  60. capsule:this.capsule,
  61. platformClass:this.platformClass,
  62. userID:0,
  63. clubStatus:'',
  64. current:0,
  65. mode:'round',
  66. modallayer:false,
  67. isLogin:false,
  68. skeletonShow: false,
  69. userIdentity:'',
  70. flootData:[],//楼层
  71. bannerImageList:[
  72. image:'',
  73. ],//轮播
  74. navBarsList:[],//导航分类
  75. templateData:{},
  76. pageList:[],//楼层
  77. isScrollTop:false,
  78. isRequest:false,
  79. isNavRequest:false,
  80. isLiveRequest:false,
  81. }
  82. },
  83. onLoad() {
  84. },
  85. computed: {
  86. ...mapState(['hasLogin','userInfo','identity','isActivity'])
  87. },
  88. methods: {
  89. ...mapMutations(['login','logout']),
  90. GetWxAuthorize(){
  91. authorize.getCode('weixin').then(wechatcode =>{// 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  92. authorize.getUserInfo('weixin').then(getUserInfo =>{
  93. this.UserService.UserLoginAuthApplets({
  94. code:wechatcode,
  95. encryptedData:getUserInfo.encryptedData,
  96. iv:getUserInfo.iv ,
  97. })
  98. .then(response =>{
  99. this.isLogin = true;
  100. this.userID = response.data.userId;
  101. this.userIdentity = response.data.userIdentity;
  102. this.clubStatus = response.data.clubStatus;
  103. this.$store.commit('updateStatus',response.data)
  104. this.login(response.data);
  105. uni.setStorageSync('token',response.data.token)
  106. uni.setStorageSync('unionId',response.data.unionId)
  107. if(response.data.userIdentity ==1){
  108. this.$api.redirectTo('/seller/pages/index/index')
  109. }else if(response.data.userIdentity === 3){
  110. this.$api.redirectTo('/supplier/pages/index/index')
  111. }
  112. this.getHomeInformation()
  113. })
  114. .catch(error =>{
  115. this.isLogin = false;
  116. this.logout()
  117. uni.setStorageSync('unionId',error.data.unionId)
  118. this.$store.commit('updateStatus',error.data)
  119. this.getHomeInformation()
  120. })
  121. })
  122. })
  123. },
  124. async getWxAuthorize(){
  125. const wechatCode = await authorize.getCode('weixin');// 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  126. const getUserInfo = await authorize.getUserInfo('weixin');
  127. this.UserService.UserLoginAuthApplets({
  128. code:wechatCode,
  129. encryptedData:getUserInfo.encryptedData,
  130. iv:getUserInfo.iv
  131. })
  132. .then(response =>{
  133. this.isLogin = true;
  134. this.userID = response.data.userId;
  135. this.userIdentity = response.data.userIdentity;
  136. this.clubStatus = response.data.clubStatus;
  137. this.$store.commit('updateStatus',response.data)
  138. this.login(response.data);
  139. uni.setStorageSync('token',response.data.token)
  140. uni.setStorageSync('unionId',response.data.unionId)
  141. if(response.data.userIdentity ==1){
  142. this.$api.redirectTo('/seller/pages/index/index')
  143. }else if(response.data.userIdentity === 3){
  144. this.$api.redirectTo('/supplier/pages/index/index')
  145. }
  146. this.getHomeInformation()
  147. })
  148. .catch(error =>{
  149. this.isLogin = false;
  150. this.logout()
  151. uni.setStorageSync('unionId',error.data.unionId)
  152. this.$store.commit('updateStatus',error.data)
  153. this.getHomeInformation()
  154. })
  155. },
  156. GetHomeInit(){//金刚区分类
  157. this.CommonService.GetHomeInit({source:2}).then(response =>{
  158. let data = response.data
  159. this.navBarsList = data.topMenuList
  160. this.isNavRequest = true
  161. }).catch(error =>{
  162. this.$util.msg(error.msg,2000)
  163. })
  164. },
  165. GetHomeTopDataInfo(){//直播、活动、文章模块
  166. this.CommonService.GetHomeTopDataInfo({source:2}).then(response =>{
  167. this.templateData = response.data
  168. this.isLiveRequest = true
  169. }).catch(error =>{
  170. this.$util.msg(error.msg,2000)
  171. })
  172. },
  173. GetHomeFloorInfo(){//初始化首页楼层数据
  174. this.CommonService.GetHomeDataInfo({userId:this.userID,soure:2}).then(response =>{
  175. let data = response.data;
  176. this.liveList = data.liveList;
  177. this.pageList = data.homePageFloor;
  178. this.isRequest = true;
  179. }).catch(error =>{
  180. this.$util.msg(error.msg,2000)
  181. })
  182. },
  183. getHomeInformation(){//初始化首页数据
  184. this.CommonService.GetHomeModulesDataInfo({ userId:this.userID }).then(res =>{
  185. let data = res.data;
  186. this.bannerImageList = data.bannerImageList
  187. this.mallPageModules = data.mallPageModules
  188. this.$store.commit('updateAllNum',data.shoppingCartCount)
  189. this.skeletonShow = false;
  190. this.GetHomeInit()
  191. this.GetHomeTopDataInfo()
  192. this.GetHomeFloorInfo()
  193. }).catch(error =>{
  194. this.$util.msg(error.msg,2000)
  195. })
  196. },
  197. handleClick(data){
  198. this.$api.navigateTo(`/h5/pages/activity/meobohui`)
  199. this.$store.commit('setActivity',data)
  200. uni.setStorageSync('lockTime',Date.now())
  201. uni.setStorageSync('isActivityStatus',true)
  202. },
  203. handleCancelClick(data){
  204. this.$store.commit('setActivity',data)
  205. uni.setStorageSync('lockTime',Date.now())
  206. uni.setStorageSync('isActivityStatus',true)
  207. },
  208. async InitAuthorize(){ //是否已授权 0:为取消授权 1:为已授权 2:为未操作
  209. authorize.checkLogin()
  210. .then(res => {
  211. this.GetWxAuthorize()
  212. })
  213. .catch(err => {
  214. this.$api.getComStorage('userInfo').then((resolve) =>{
  215. this.userID = resolve.userId ? resolve.userId :0;
  216. this.getHomeInformation()
  217. }).catch(error =>{
  218. this.getHomeInformation()
  219. })
  220. })
  221. }
  222. },
  223. onPageScroll(e){//实时获取到滚动的值
  224. if(e.scrollTop>50){
  225. this.inputActive = 'bgclass'
  226. }else{
  227. this.inputActive = 'bgnone'
  228. }
  229. if(e.scrollTop>400){
  230. this.isScrollTop = true
  231. }else{
  232. this.isScrollTop = false
  233. }
  234. },
  235. onPullDownRefresh() {//下拉刷新
  236. this.getHomeInformation()
  237. uni.stopPullDownRefresh()
  238. },
  239. onShareAppMessage(res){//分享转发
  240. if (res.from === 'button') {
  241. // 来自页面内转发按钮
  242. }
  243. return {
  244. title: '生美医美正品采购服务平台',
  245. path: 'pages/tabBar/home/index',
  246. imageUrl:'https://static.caimei365.com/app/img/bg/min-banner.jpg'
  247. }
  248. },
  249. onShow(){
  250. this.modallayer = false
  251. // this.InitAuthorize()
  252. }
  253. }
  254. </script>
  255. <style lang="scss">
  256. page{
  257. background-color: #FFFFFF;
  258. }
  259. .navbar-wrap {
  260. position: fixed;
  261. width: 100%;
  262. top: 0;
  263. z-index: 100000;
  264. box-sizing: border-box;
  265. background-image: linear-gradient(0deg, #f83c6c 0%, #fa55bf 100%);
  266. background-size: cover;
  267. border-bottom:none;
  268. &.bgnone{
  269. background: rgba(255,255,255,0);
  270. }
  271. &.bgclass{
  272. background: #f83c6c;
  273. }
  274. }
  275. .navbar-text {
  276. font-size: 30rpx;
  277. color: #000000;
  278. font-weight: 500;
  279. }
  280. .navbar-text.center{
  281. text-align: center;
  282. }
  283. .navbar-text.left{
  284. text-align: left;
  285. padding-left: 45px;
  286. }
  287. .navbar-icon {
  288. position: fixed;
  289. display: flex;
  290. box-sizing: border-box;
  291. }
  292. .navbar-icon .iconfont {
  293. display: inline-block;
  294. overflow: hidden;
  295. font-size: 44rpx;
  296. padding-right:40rpx;
  297. margin-top: 1px;
  298. }
  299. .navbar-icon .icon-iconfonticonfontsousuo1 {
  300. color: #000000;
  301. }
  302. .navbar-icon view {
  303. height: 18px;
  304. border-left: 0.5px solid rgba(0,0,0, 0.3);
  305. margin-top: 6px;
  306. }
  307. .navbar-loading {
  308. background: #fff;
  309. text-align: center;
  310. }
  311. .search-input{
  312. width: 100%;
  313. height: 110rpx;
  314. padding: 20rpx 24rpx;
  315. box-sizing: border-box;
  316. .gosearch-btn{
  317. width: 100%;
  318. height: 100%;
  319. border-radius: 40rpx;
  320. background: #F0F0F0;
  321. margin: 0 auto;
  322. font-size: 28rpx;
  323. line-height: 70rpx;
  324. color: #8A8A8A;
  325. background: #FFFFFF;
  326. position: relative;
  327. box-sizing: border-box;
  328. padding-left: 80rpx;
  329. .search-icon{
  330. width: 80rpx;
  331. height: 70rpx;
  332. position:absolute ;
  333. left: 0;
  334. top: 2rpx;
  335. text-align: center;
  336. line-height: 70rpx;
  337. .icon-iconfonticonfontsousuo1{
  338. margin:0 6rpx;
  339. font-size: $font-size-34;
  340. color: #8A8A8A;
  341. z-index: 10;
  342. }
  343. }
  344. .search-text{
  345. font-size: $font-size-24;
  346. line-height: 70rpx;
  347. color: #8A8A8A;
  348. }
  349. }
  350. }
  351. .container-home{
  352. background: url(https://static.caimei365.com/app/mini-hehe/icon/icon-index-bg.png)top center no-repeat;
  353. background-size: contain;
  354. min-height: 528rpx;
  355. }
  356. .container-section{
  357. width: 100%;
  358. height: auto;
  359. background-color: #F7F7F7;
  360. }
  361. </style>