index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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.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('/pages/supplier/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. if(uni.getStorageSync('isActivitySwitch')){
  127. this.$store.commit('setActivity',false)
  128. }else{
  129. this.$store.commit('setActivity',true)
  130. }
  131. this.getHomeInformation()
  132. })
  133. },
  134. GetHomeInit(){//金刚区分类
  135. this.CommonService.GetHomeInit({source:2}).then(response =>{
  136. let data = response.data
  137. this.navBarsList = data.topMenuList
  138. this.isNavRequest = true
  139. }).catch(error =>{
  140. this.$util.msg(error.msg,2000)
  141. })
  142. },
  143. GetHomeTopDataInfo(){//直播、活动、文章模块
  144. this.CommonService.GetHomeTopDataInfo({source:2}).then(response =>{
  145. this.templateData = response.data
  146. this.isLiveRequest = true
  147. }).catch(error =>{
  148. this.$util.msg(error.msg,2000)
  149. })
  150. },
  151. GetHomeFloorInfo(){//初始化首页楼层数据
  152. this.isRequest = false;
  153. this.CommonService.GetHomeDataInfo({userId:this.userID,soure:2}).then(response =>{
  154. let data = response.data;
  155. this.pageList = data.homePageFloor;
  156. this.supplierObj = data.supplierImage;
  157. this.isRequest = true;
  158. }).catch(error =>{
  159. this.$util.msg(error.msg,2000)
  160. })
  161. },
  162. GetInitBeansInfo(){//初始化采美豆信息
  163. this.UserService.GetHomeObtainBeans({userId:this.userID}).then(response =>{
  164. this.beansType = response.data.beansType
  165. this.beanNumber = response.data.num
  166. this.isActivityBean = true
  167. }).catch(error =>{
  168. console.log('用户暂无采美豆推送~')
  169. })
  170. },
  171. getHomeInformation(){//初始化首页数据
  172. this.CommonService.GetHomeModulesDataInfo({ userId:this.userID }).then(res =>{
  173. let data = res.data;
  174. this.bannerImageList = data.bannerImageList
  175. this.mallPageModules = data.mallPageModules
  176. this.$store.commit('updateAllNum',data.shoppingCartCount)
  177. this.skeletonShow = false;
  178. this.GetHomeInit()
  179. this.GetHomeTopDataInfo()
  180. this.GetHomeFloorInfo()
  181. }).catch(error =>{
  182. this.$util.msg(error.msg,2000)
  183. })
  184. },
  185. handleClick(data){
  186. const pageId = 306
  187. this.$api.navigateTo(`/pages/login/register`)
  188. this.$store.commit('setActivity',data)
  189. uni.setStorageSync('lockTime',Date.now())
  190. uni.setStorageSync('isActivitySwitch',true)
  191. // 友盟自定义事件
  192. // if(process.env.NODE_ENV != 'development'){
  193. // this.$uma.trackEvent('meibohui_click', {
  194. // Um_Key_PageName: '美博会',
  195. // Um_Key_PageCategory: '活动专题页面',
  196. // Um_Key_SourcePage: '首页',
  197. // })
  198. // }
  199. },
  200. handleCancelClick(data){
  201. this.$store.commit('setActivity',data)
  202. uni.setStorageSync('lockTime',Date.now())
  203. uni.setStorageSync('isActivitySwitch',true)
  204. },
  205. handleBeanlClick(){
  206. this.isActivityBean = false
  207. },
  208. InitAuthorize(){ //是否已授权
  209. this.GetWxAuthorize()
  210. this.$api.getComStorage('userInfo').then((resolve) =>{
  211. this.userID = resolve.userId ? resolve.userId :0;
  212. this.getHomeInformation()
  213. }).catch(error =>{
  214. this.getHomeInformation()
  215. })
  216. }
  217. },
  218. onPageScroll(e){//实时获取到滚动的值
  219. if(e.scrollTop>50){
  220. this.inputActive = 'fixed'
  221. }else{
  222. this.inputActive = 'float'
  223. }
  224. if(e.scrollTop>400){
  225. this.isScrollTop = true
  226. }else{
  227. this.isScrollTop = false
  228. }
  229. },
  230. onPullDownRefresh() {//下拉刷新
  231. this.getHomeInformation()
  232. uni.stopPullDownRefresh()
  233. },
  234. onShareAppMessage(res){//分享转发
  235. if (res.from === 'button') {
  236. // 来自页面内转发按钮
  237. }
  238. return {
  239. title: '生美医美正品采购服务平台',
  240. path: 'pages/tabBar/home/index',
  241. imageUrl:'https://static.caimei365.com/app/img/bg/min-banner.jpg'
  242. }
  243. },
  244. onShow(){
  245. this.modallayer = false
  246. this.InitAuthorize()
  247. }
  248. }
  249. </script>
  250. <style lang="scss">
  251. page{
  252. background-color: #FFFFFF;
  253. }
  254. .container-section{
  255. width: 100%;
  256. height: auto;
  257. background-color: #F7F7F7;
  258. }
  259. </style>