index.vue 8.4 KB

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