index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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="isRequest"></banner>
  9. <!-- 金刚区菜单 -->
  10. <navbars :list="navBarsList" v-if="isRequest"></navbars>
  11. <!-- 直播 -->
  12. <page-special :templateData="templateData" v-if="isRequest"></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. }
  72. },
  73. onLoad() {
  74. },
  75. computed: {
  76. ...mapState(['hasLogin','userInfo','identity'])
  77. },
  78. methods: {
  79. ...mapMutations(['login','logout']),
  80. getWxAuthorize(){
  81. authorize.getCode('weixin').then(wechatcode =>{// 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  82. authorize.getUserInfo('weixin').then(wxResponse =>{
  83. userInfoLogin({code:wechatcode,encryptedData:wxResponse.encryptedData,iv:wxResponse.iv}).then(response =>{
  84. this.isLogin = true;
  85. this.userID = response.data.userID;
  86. this.userIdentity = response.data.userIdentity;
  87. this.clubStatus = response.data.clubStatus;
  88. this.$store.commit('updateStatus',response.data)
  89. this.login(response.data);
  90. uni.setStorageSync('token',response.data.token)
  91. uni.removeStorageSync('sessionid')
  92. uni.setStorageSync('sessionid','JSESSIONID='+response.data.sessionId)
  93. if(response.data.userIdentity ==1){
  94. this.$api.redirectTo('/seller/pages/index/index')
  95. }else if(response.data.userIdentity === 3){
  96. this.$api.redirectTo('/supplier/pages/index/index')
  97. }
  98. this.getHomeInformation()
  99. }).catch(error =>{
  100. this.isLogin = false;
  101. this.logout()
  102. uni.removeStorageSync('sessionid')
  103. uni.setStorageSync('sessionid','JSESSIONID='+error.data)
  104. this.$store.commit('updateStatus',error.data)
  105. this.getHomeInformation()
  106. })
  107. })
  108. })
  109. },
  110. GetHomeInit(){//金刚区分类
  111. this.CommonService.GetHomeInit({source:2}).then(response =>{
  112. let data = response.data
  113. this.navBarsList = data.topMenuList
  114. }).catch(error =>{
  115. this.$util.msg(error.msg,2000)
  116. })
  117. },
  118. GetHomeTopDataInfo(){//金刚区分类
  119. this.CommonService.GetHomeTopDataInfo({source:2}).then(response =>{
  120. this.templateData = response.data
  121. console.log(this.templateData)
  122. }).catch(error =>{
  123. this.$util.msg(error.msg,2000)
  124. })
  125. },
  126. GetHomeFloorInfo(){//初始化首页楼层数据
  127. this.CommonService.GetHomeDataInfo({userId:this.userID,soure:2}).then(response =>{
  128. let data = response.data;
  129. this.liveList = data.liveList;
  130. this.pageList = data.homePageFloor;
  131. this.supplierObj = data.supplierImage;
  132. this.skeletonShow = false;
  133. this.isRequest = true;
  134. }).catch(error =>{
  135. this.$util.msg(error.msg,2000)
  136. })
  137. },
  138. getHomeInformation(){//初始化首页数据
  139. this.CommonService.GetHomeModulesDataInfo({ userId:this.userID }).then(res =>{
  140. let data = res.data;
  141. this.bannerImageList = data.bannerImageList
  142. this.mallPageModules = data.mallPageModules
  143. this.$store.commit('updateAllNum',data.shoppingCartCount)
  144. this.GetHomeInit()
  145. this.GetHomeFloorInfo()
  146. this.GetHomeTopDataInfo()
  147. }).catch(error =>{
  148. this.$util.msg(error.msg,2000)
  149. })
  150. },
  151. handleClick(data){
  152. this.$api.navigateTo(`/h5/pages/activity/activity_mid`)
  153. this.$store.commit('setActivity',data)
  154. },
  155. handleCancelClick(data){
  156. this.$store.commit('setActivity',data)
  157. },
  158. },
  159. onPageScroll(e){//实时获取到滚动的值
  160. if(e.scrollTop>50){
  161. this.inputActive = 'fixed'
  162. }else{
  163. this.inputActive = 'float'
  164. }
  165. if(e.scrollTop>400){
  166. this.isScrollTop = true
  167. }else{
  168. this.isScrollTop = false
  169. }
  170. },
  171. onPullDownRefresh() {//下拉刷新
  172. this.getHomeInformation()
  173. uni.stopPullDownRefresh()
  174. },
  175. onShareAppMessage(res){//分享转发
  176. if (res.from === 'button') {
  177. // 来自页面内转发按钮
  178. }
  179. return {
  180. title: '采美采购商城-生美/医美采购服务平台',
  181. path: 'pages/tabBar/home/index',
  182. imageUrl:'https://img.caimei365.com/group1/M00/03/8C/Cmis215XHXSAWWkhAAXDP4-6m_c397.png'
  183. }
  184. },
  185. onShow(){
  186. this.modallayer = false
  187. authorize.getSetting().then(res =>{// console.log('是否已授权',res);//0:为取消授权 1:为已授权 2:为未操作
  188. if(res == 1){
  189. this.getWxAuthorize()
  190. }else{
  191. this.$api.getComStorage('userInfo').then((resolve) =>{
  192. this.userID = resolve.userID ? resolve.userID :0;
  193. this.getHomeInformation()
  194. }).catch(error =>{
  195. this.getHomeInformation()
  196. })
  197. }
  198. })
  199. }
  200. }
  201. </script>
  202. <style lang="scss">
  203. page{
  204. background-color: #FFFFFF;
  205. }
  206. .container-section{
  207. width: 100%;
  208. height: auto;
  209. background-color: #F7F7F7;
  210. }
  211. </style>