index.vue 7.1 KB

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