index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <view class="container home clearfix" :style="{paddingTop:CustomBar+'px'}">
  3. <customer ref="customer" :navbar-data='nvabarData'></customer>
  4. <!-- 主页内容 -->
  5. <tui-skeleton v-if="skeletonShow" backgroundColor="#fafafa" borderRadius="10rpx" :isLoading ="true" :loadingType="5"></tui-skeleton>
  6. <view class="container-home tui-skeleton">
  7. <!-- 轮播 -->
  8. <banner :list="bannerImageList" v-if="isNavRequest"></banner>
  9. <!-- 金刚区菜单 -->
  10. <navbars :list="navBarsList" v-if="isNavRequest"></navbars>
  11. <!-- 直播 -->
  12. <page-special :templateData="templateData" v-if="isLiveRequest"></page-special>
  13. </view>
  14. <!-- 楼层 -->
  15. <view class="container-section tui-skeleton">
  16. <page-floor :list="pageList" :userIdentity="userIdentity" :pageType='1' v-if="isRequest"></page-floor>
  17. <supplier-list :supplierObj="supplierObj" v-if="isRequest"></supplier-list>
  18. </view>
  19. <!-- 侧边 -->
  20. <scroll-top :isScrollTop="isScrollTop" :bottom="50"></scroll-top>
  21. </view>
  22. </template>
  23. <script>
  24. import tuiSkeleton from "@/components/tui-skeleton/tui-skeleton"
  25. import authorize from '@/common/config/authorize.js'
  26. import customer from '@/components/cm-module/homeIndex/customer.vue'
  27. import banner from '@/components/cm-module/homeIndex/banner.vue'
  28. import navbars from '@/components/cm-module/homeIndex/navbars.vue'
  29. import pageFloor from '@/components/cm-module/homeIndex/pageFloor.vue'
  30. import pageSpecial from '@/components/cm-module/homeIndex/pageSpecial.vue'
  31. import supplierList from '@/components/cm-module/homeIndex/supplierList.vue'
  32. import { userInfoLogin } from "@/api/use.js"
  33. import { mapState,mapMutations} from 'vuex';
  34. export default {
  35. components:{
  36. tuiSkeleton,
  37. customer,
  38. banner,
  39. navbars,
  40. pageFloor,
  41. pageSpecial,
  42. supplierList
  43. },
  44. data() {
  45. return {
  46. nvabarData: {//顶部自定义导航
  47. showCapsule: 1, // 是否显示左上角图标 1表示显示 0表示不显示,
  48. showSearch: 0,
  49. title: '采美采购商城', // 导航栏 中间的标题
  50. haveBack:false,
  51. textLeft:this.$store.state.isIphone,
  52. textColor:'#FFFFFF'
  53. },
  54. CustomBar:this.CustomBar,// 顶部导航栏高度
  55. userID:0,
  56. clubStatus:'',
  57. current:0,
  58. mode:'round',
  59. modallayer:false,
  60. isLogin:false,
  61. skeletonShow: true,
  62. userIdentity:'',
  63. flootData:[],//楼层
  64. bannerImageList:[],//轮播
  65. navBarsList:[],//导航分类
  66. templateData:{},
  67. pageList:[],//楼层
  68. supplierObj:{},//供应商列表
  69. isScrollTop:false,
  70. isRequest:false,
  71. isNavRequest:false,
  72. isLiveRequest:false,
  73. }
  74. },
  75. onLoad() {
  76. },
  77. computed: {
  78. ...mapState(['hasLogin','userInfo','identity'])
  79. },
  80. methods: {
  81. ...mapMutations(['login','logout']),
  82. getWxAuthorize(){
  83. authorize.getCode('weixin').then(wechatcode =>{// 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  84. authorize.getUserInfo('weixin').then(wxResponse =>{
  85. userInfoLogin({code:wechatcode,encryptedData:wxResponse.encryptedData,iv:wxResponse.iv}).then(response =>{
  86. this.isLogin = true;
  87. this.userID = response.data.userID;
  88. this.userIdentity = response.data.userIdentity;
  89. this.clubStatus = response.data.clubStatus;
  90. this.$store.commit('updateStatus',response.data)
  91. this.login(response.data);
  92. uni.setStorageSync('token',response.data.token)
  93. uni.removeStorageSync('sessionid')
  94. uni.setStorageSync('sessionid','JSESSIONID='+response.data.sessionId)
  95. if(response.data.userIdentity ==1){
  96. this.$api.redirectTo('/seller/pages/index/index')
  97. }else if(response.data.userIdentity === 3){
  98. this.$api.redirectTo('/supplier/pages/index/index')
  99. }
  100. this.getHomeInformation()
  101. }).catch(error =>{
  102. this.isLogin = false;
  103. this.logout()
  104. uni.removeStorageSync('sessionid')
  105. uni.setStorageSync('sessionid','JSESSIONID='+error.data)
  106. this.$store.commit('updateStatus',error.data)
  107. this.getHomeInformation()
  108. })
  109. })
  110. })
  111. },
  112. GetHomeInit(){//金刚区分类
  113. this.CommonService.GetHomeInit({source:2}).then(response =>{
  114. let data = response.data
  115. this.navBarsList = data.topMenuList
  116. this.isNavRequest = true
  117. }).catch(error =>{
  118. this.$util.msg(error.msg,2000)
  119. })
  120. },
  121. GetHomeTopDataInfo(){//直播、活动、文章模块
  122. this.CommonService.GetHomeTopDataInfo({source:2}).then(response =>{
  123. this.templateData = response.data
  124. this.isLiveRequest = true
  125. }).catch(error =>{
  126. this.$util.msg(error.msg,2000)
  127. })
  128. },
  129. GetHomeFloorInfo(){//初始化首页楼层数据
  130. this.CommonService.GetHomeDataInfo({userId:this.userID,soure:2}).then(response =>{
  131. let data = response.data;
  132. this.liveList = data.liveList;
  133. this.pageList = data.homePageFloor;
  134. this.supplierObj = data.supplierImage;
  135. this.isRequest = true;
  136. }).catch(error =>{
  137. this.$util.msg(error.msg,2000)
  138. })
  139. },
  140. getHomeInformation(){//初始化首页数据
  141. this.CommonService.GetHomeModulesDataInfo({ userId:this.userID }).then(res =>{
  142. let data = res.data;
  143. this.bannerImageList = data.bannerImageList
  144. this.mallPageModules = data.mallPageModules
  145. this.$store.commit('updateAllNum',data.shoppingCartCount)
  146. this.skeletonShow = false;
  147. this.GetHomeInit()
  148. this.GetHomeTopDataInfo()
  149. this.GetHomeFloorInfo()
  150. }).catch(error =>{
  151. this.$util.msg(error.msg,2000)
  152. })
  153. },
  154. handleClick(data){
  155. this.$api.navigateTo(`/h5/pages/activity/activity_mid`)
  156. this.$store.commit('setActivity',data)
  157. },
  158. handleCancelClick(data){
  159. this.$store.commit('setActivity',data)
  160. },
  161. },
  162. onPageScroll(e){//实时获取到滚动的值
  163. if(e.scrollTop>50){
  164. this.inputActive = 'fixed'
  165. }else{
  166. this.inputActive = 'float'
  167. }
  168. if(e.scrollTop>400){
  169. this.isScrollTop = true
  170. }else{
  171. this.isScrollTop = false
  172. }
  173. },
  174. onPullDownRefresh() {//下拉刷新
  175. this.getHomeInformation()
  176. uni.stopPullDownRefresh()
  177. },
  178. onShareAppMessage(res){//分享转发
  179. if (res.from === 'button') {
  180. // 来自页面内转发按钮
  181. }
  182. return {
  183. title: '生美医美正品采购服务平台',
  184. path: 'pages/tabBar/home/index',
  185. imageUrl:'https://static.caimei365.com/app/img/bg/min-banner.jpg'
  186. }
  187. },
  188. onShow(){
  189. this.modallayer = false
  190. authorize.getSetting().then(res =>{// console.log('是否已授权',res);//0:为取消授权 1:为已授权 2:为未操作
  191. if(res == 1){
  192. this.getWxAuthorize()
  193. }else{
  194. this.$api.getComStorage('userInfo').then((resolve) =>{
  195. this.userID = resolve.userID ? resolve.userID :0;
  196. this.getHomeInformation()
  197. }).catch(error =>{
  198. this.getHomeInformation()
  199. })
  200. }
  201. })
  202. }
  203. }
  204. </script>
  205. <style lang="scss">
  206. page{
  207. background-color: #FFFFFF;
  208. }
  209. .container-section{
  210. width: 100%;
  211. height: auto;
  212. background-color: #F7F7F7;
  213. }
  214. </style>