index.vue 8.1 KB

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