index.vue 8.7 KB

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