index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 && couponEntry == 1"></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. couponEntry:2,
  88. }
  89. },
  90. onLoad() {
  91. },
  92. computed: {
  93. ...mapState(['hasLogin','userInfo','identity','isActivity','isWxAuthorize'])
  94. },
  95. methods: {
  96. ...mapMutations(['login','logout']),
  97. async GetWxAuthorize(){
  98. const wechatCode = await authorize.getCode('weixin');// 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  99. const getUserInfo = await authorize.getUserInfo('weixin');
  100. this.UserService.UserLoginAuthApplets({
  101. code:wechatCode,
  102. encryptedData:getUserInfo.encryptedData,
  103. iv:getUserInfo.iv
  104. })
  105. .then(response =>{
  106. this.isLogin = true;
  107. this.userID = response.data.userId;
  108. this.userIdentity = response.data.userIdentity;
  109. this.clubStatus = response.data.clubStatus;
  110. this.$store.commit('updateStatus',response.data)
  111. this.login(response.data);
  112. uni.setStorageSync('token',response.data.token)
  113. uni.setStorageSync('unionId',response.data.unionId)
  114. if(response.data.userIdentity ==1){
  115. this.$api.redirectTo('/pages/seller/index/index')
  116. }else if(response.data.userIdentity === 3){
  117. this.$api.redirectTo('/pages/supplier/index/index')
  118. }
  119. this.GetInitBeansInfo()
  120. this.getHomeInformation()
  121. })
  122. .catch(error =>{
  123. this.isLogin = false;
  124. this.logout()
  125. uni.setStorageSync('unionId',error.data.unionId)
  126. this.$store.commit('updateStatus',error.data)
  127. this.getHomeInformation()
  128. })
  129. },
  130. GetHomeInit(){//金刚区分类
  131. this.CommonService.GetHomeInit({source:2}).then(response =>{
  132. let data = response.data
  133. this.navBarsList = data.topMenuList
  134. this.couponEntry = data.couponEntry
  135. if(!this.hasLogin && this.couponEntry == 1){
  136. if(uni.getStorageSync('isActivitySwitch')){
  137. this.$store.commit('setActivity',false)
  138. }else{
  139. this.$store.commit('setActivity',true)
  140. }
  141. }
  142. this.isNavRequest = true
  143. }).catch(error =>{
  144. this.$util.msg(error.msg,2000)
  145. })
  146. },
  147. GetHomeTopDataInfo(){//直播、活动、文章模块
  148. this.CommonService.GetHomeTopDataInfo({source:2}).then(response =>{
  149. this.templateData = response.data
  150. this.isLiveRequest = true
  151. }).catch(error =>{
  152. this.$util.msg(error.msg,2000)
  153. })
  154. },
  155. GetHomeFloorInfo(){//初始化首页楼层数据
  156. this.CommonService.GetHomeDataInfo({userId:this.userID,soure:2}).then(response =>{
  157. let data = response.data;
  158. this.pageList = data.homePageFloor;
  159. this.supplierObj = data.supplierImage;
  160. setTimeout(()=>{
  161. this.isRequest = true;
  162. },500)
  163. }).catch(error =>{
  164. this.$util.msg(error.msg,2000)
  165. })
  166. },
  167. GetInitBeansInfo(){//初始化采美豆信息
  168. this.UserService.GetHomeObtainBeans({userId:this.userID}).then(response =>{
  169. this.beansType = response.data.beansType
  170. this.beanNumber = response.data.num
  171. this.isActivityBean = true
  172. }).catch(error =>{
  173. console.log('用户暂无采美豆推送~')
  174. })
  175. },
  176. getHomeInformation(){//初始化首页数据
  177. this.CommonService.GetHomeModulesDataInfo({ userId:this.userID }).then(res =>{
  178. let data = res.data;
  179. this.bannerImageList = data.bannerImageList
  180. this.mallPageModules = data.mallPageModules
  181. this.$store.commit('updateAllNum',data.shoppingCartCount)
  182. this.skeletonShow = false;
  183. this.GetHomeInit()
  184. this.GetHomeTopDataInfo()
  185. this.GetHomeFloorInfo()
  186. }).catch(error =>{
  187. this.$util.msg(error.msg,2000)
  188. })
  189. },
  190. handleClick(data){
  191. const pageId = 306
  192. this.$api.navigateTo(`/pages/user/coupon/coupon-collection`)
  193. this.$store.commit('setActivity',data)
  194. uni.setStorageSync('lockTime',Date.now())
  195. uni.setStorageSync('isActivitySwitch',true)
  196. // 友盟自定义事件
  197. // if(process.env.NODE_ENV != 'development'){
  198. // this.$uma.trackEvent('meibohui_click', {
  199. // Um_Key_PageName: '美博会',
  200. // Um_Key_PageCategory: '活动专题页面',
  201. // Um_Key_SourcePage: '首页',
  202. // })
  203. // }
  204. },
  205. handleCancelClick(data){
  206. this.$store.commit('setActivity',data)
  207. uni.setStorageSync('lockTime',Date.now())
  208. uni.setStorageSync('isActivitySwitch',true)
  209. },
  210. handleBeanlClick(){
  211. this.isActivityBean = false
  212. }
  213. },
  214. onPageScroll(e){//实时获取到滚动的值
  215. if(e.scrollTop>50){
  216. this.inputActive = 'fixed'
  217. }else{
  218. this.inputActive = 'float'
  219. }
  220. if(e.scrollTop>400){
  221. this.isScrollTop = true
  222. }else{
  223. this.isScrollTop = false
  224. }
  225. },
  226. onPullDownRefresh() {//下拉刷新
  227. this.getHomeInformation()
  228. uni.stopPullDownRefresh()
  229. },
  230. onShareAppMessage(res){//分享转发
  231. if (res.from === 'button') {
  232. // 来自页面内转发按钮
  233. }
  234. return {
  235. title: '生美医美正品采购服务平台',
  236. path: 'pages/tabBar/home/index',
  237. imageUrl:'https://static.caimei365.com/app/img/bg/min-banner.jpg'
  238. }
  239. },
  240. onShow(){
  241. this.modallayer = false
  242. this.GetWxAuthorize()
  243. }
  244. }
  245. </script>
  246. <style lang="scss">
  247. page{
  248. background-color: #FFFFFF;
  249. }
  250. .container-section{
  251. width: 100%;
  252. height: auto;
  253. background-color: #F7F7F7;
  254. }
  255. </style>