index.vue 8.2 KB

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