index.vue 8.4 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 && 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. this.initShoppingCartCount()
  177. this.isNavRequest = true
  178. }).catch(error =>{
  179. this.$util.msg(error.msg,2000)
  180. })
  181. },
  182. initShoppingCartCount(){ // 获取购物车数量
  183. this.OrderService.ShoppingCartCount({ userId: this.userID}).then(res =>{
  184. this.$store.commit('updateAllNum',res.data)
  185. })
  186. },
  187. handleClick(data){
  188. const pageId = 306
  189. this.$api.navigateTo('/pages/user/coupon/coupon-collection')
  190. this.$store.commit('setActivity',data)
  191. uni.setStorageSync('lockTime',Date.now())
  192. uni.setStorageSync('isActivitySwitch',true)
  193. // 友盟自定义事件
  194. // if(process.env.NODE_ENV != 'development'){
  195. // this.$uma.trackEvent('meibohui_click', {
  196. // Um_Key_PageName: '美博会',
  197. // Um_Key_PageCategory: '活动专题页面',
  198. // Um_Key_SourcePage: '首页',
  199. // })
  200. // }
  201. },
  202. handleCancelClick(data){
  203. this.$store.commit('setActivity',data)
  204. uni.setStorageSync('lockTime',Date.now())
  205. uni.setStorageSync('isActivitySwitch',true)
  206. },
  207. handleBeanlClick(){
  208. this.isActivityBean = false
  209. }
  210. },
  211. onPageScroll(e){//实时获取到滚动的值
  212. if(e.scrollTop>50){
  213. this.inputActive = 'fixed'
  214. }else{
  215. this.inputActive = 'float'
  216. }
  217. if(e.scrollTop>400){
  218. this.isScrollTop = true
  219. }else{
  220. this.isScrollTop = false
  221. }
  222. },
  223. onPullDownRefresh() {//下拉刷新
  224. this.getHomeInformation()
  225. uni.stopPullDownRefresh()
  226. },
  227. onShareAppMessage(res){//分享转发
  228. if (res.from === 'button') {
  229. // 来自页面内转发按钮
  230. }
  231. return {
  232. title: '生美医美正品采购服务平台',
  233. path: 'pages/tabBar/home/index',
  234. imageUrl:'https://static.caimei365.com/app/img/bg/min-banner.jpg'
  235. }
  236. },
  237. onShow(){
  238. this.modallayer = false
  239. this.GetWxAuthorize()
  240. }
  241. }
  242. </script>
  243. <style lang="scss">
  244. page{
  245. background-color: #FFFFFF;
  246. }
  247. .container-section{
  248. width: 100%;
  249. height: auto;
  250. background-color: #F7F7F7;
  251. }
  252. </style>