index.vue 8.9 KB

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