index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. console.log(this.navBarsList);
  122. this.isNavRequest = true
  123. }).catch(error =>{
  124. this.$util.msg(error.msg,2000)
  125. })
  126. },
  127. GetHomeTopDataInfo(){//直播、活动、文章模块
  128. this.CommonService.GetHomeTopDataInfo({source:2}).then(response =>{
  129. this.templateData = response.data
  130. this.isLiveRequest = true
  131. }).catch(error =>{
  132. this.$util.msg(error.msg,2000)
  133. })
  134. },
  135. GetHomeFloorInfo(){//初始化首页楼层数据
  136. this.CommonService.GetHomeDataInfo({userId:this.userID,soure:2}).then(response =>{
  137. let data = response.data;
  138. this.pageList = data.homePageFloor;
  139. this.supplierObj = data.supplierImage;
  140. this.isRequest = true;
  141. }).catch(error =>{
  142. this.$util.msg(error.msg,2000)
  143. })
  144. },
  145. getHomeInformation(){//初始化首页数据
  146. this.CommonService.GetHomeModulesDataInfo({ userId:this.userID }).then(res =>{
  147. let data = res.data;
  148. this.bannerImageList = data.bannerImageList
  149. this.mallPageModules = data.mallPageModules
  150. this.$store.commit('updateAllNum',data.shoppingCartCount)
  151. this.skeletonShow = false;
  152. this.GetHomeInit()
  153. this.GetHomeTopDataInfo()
  154. this.GetHomeFloorInfo()
  155. }).catch(error =>{
  156. this.$util.msg(error.msg,2000)
  157. })
  158. },
  159. handleClick(data){
  160. this.$api.navigateTo(`/h5/pages/activity/meobohui`)
  161. this.$store.commit('setActivity',data)
  162. uni.setStorageSync('lockTime',Date.now())
  163. uni.setStorageSync('isActivityStatus',true)
  164. },
  165. handleCancelClick(data){
  166. this.$store.commit('setActivity',data)
  167. uni.setStorageSync('lockTime',Date.now())
  168. uni.setStorageSync('isActivityStatus',true)
  169. },
  170. InitAuthorize(){ //是否已授权
  171. authorize.getSetting().then(res =>{
  172. console.log('用户是否授权过',res)
  173. if(res == 1){
  174. this.GetWxAuthorize()
  175. }else{
  176. this.$api.getComStorage('userInfo').then((resolve) =>{
  177. this.userID = resolve.userId ? resolve.userId :0;
  178. this.getHomeInformation()
  179. }).catch(error =>{
  180. this.getHomeInformation()
  181. })
  182. }
  183. })
  184. // if(uni.getStorageSync('_WX_State')){
  185. // this.GetWxAuthorize()
  186. // }else{
  187. // this.$api.getComStorage('userInfo').then((resolve) =>{
  188. // this.userID = resolve.userId ? resolve.userId :0;
  189. // this.getHomeInformation()
  190. // }).catch(error =>{
  191. // this.getHomeInformation()
  192. // })
  193. // }
  194. }
  195. },
  196. onPageScroll(e){//实时获取到滚动的值
  197. if(e.scrollTop>50){
  198. this.inputActive = 'fixed'
  199. }else{
  200. this.inputActive = 'float'
  201. }
  202. if(e.scrollTop>400){
  203. this.isScrollTop = true
  204. }else{
  205. this.isScrollTop = false
  206. }
  207. },
  208. onPullDownRefresh() {//下拉刷新
  209. this.getHomeInformation()
  210. uni.stopPullDownRefresh()
  211. },
  212. onShareAppMessage(res){//分享转发
  213. if (res.from === 'button') {
  214. // 来自页面内转发按钮
  215. }
  216. return {
  217. title: '生美医美正品采购服务平台',
  218. path: 'pages/tabBar/home/index',
  219. imageUrl:'https://static.caimei365.com/app/img/bg/min-banner.jpg'
  220. }
  221. },
  222. onShow(){
  223. this.modallayer = false
  224. this.InitAuthorize()
  225. }
  226. }
  227. </script>
  228. <style lang="scss">
  229. page{
  230. background-color: #FFFFFF;
  231. }
  232. .container-section{
  233. width: 100%;
  234. height: auto;
  235. background-color: #F7F7F7;
  236. }
  237. </style>