index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. <!-- 新品橱窗 -->
  18. <hot-floor :list="hotListPageFloor" :usserIdentity="userIdentity" v-if="isRequest && hotListPageFloor.length > 0"></hot-floor>
  19. </view>
  20. <!-- 楼层 -->
  21. <view class="container-section tui-skeleton">
  22. <page-floor :list="pageList" :userIdentity="userIdentity" :pageType='1' v-if="isRequest"></page-floor>
  23. <supplier-list :supplierObj="supplierObj" v-if="isRequest"></supplier-list>
  24. </view>
  25. <!-- 侧边 -->
  26. <scroll-top :isScrollTop="isScrollTop" :bottom="50"></scroll-top>
  27. <!-- 活动弹窗 -->
  28. <activityAlert :show="isActivity" @click="handleClick" @cancel="handleCancelClick"></activityAlert>
  29. <!-- 采美豆提示弹窗 -->
  30. <activityBean v-if="isActivityBean" :show="isActivityBean" :beansType="beansType" :beanNumber="beanNumber" @cancel="handleBeanlClick"></activityBean>
  31. </view>
  32. </template>
  33. <script>
  34. import tuiSkeleton from '@/components/tui-skeleton/tui-skeleton'
  35. import authorize from '@/common/config/authorize.js'
  36. import customer from '@/components/cm-module/homeIndex/customer.vue'
  37. import banner from '@/components/cm-module/homeIndex/banner.vue'
  38. import navbars from '@/components/cm-module/homeIndex/navbars.vue'
  39. import notice from '@/components/cm-module/homeIndex/notice.vue'
  40. import coupon from '@/components/cm-module/homeIndex/coupon.vue'
  41. import pageFloor from '@/components/cm-module/homeIndex/pageFloor.vue'
  42. import hotFloor from '@/components/cm-module/homeIndex/hotFloor.vue'
  43. import pageSpecial from '@/components/cm-module/homeIndex/pageSpecial.vue'
  44. import supplierList from '@/components/cm-module/homeIndex/supplierList.vue'
  45. import activityAlert from '@/components/cm-module/activity/activity.vue'
  46. import activityBean from '@/components/cm-module/activity/activityBean.vue'
  47. import { mapState,mapMutations} from 'vuex'
  48. export default {
  49. components:{
  50. tuiSkeleton,
  51. customer,
  52. banner,
  53. navbars,
  54. notice,
  55. coupon,
  56. pageFloor,
  57. hotFloor,
  58. pageSpecial,
  59. supplierList,
  60. activityAlert,
  61. activityBean
  62. },
  63. data() {
  64. return {
  65. nvabarData: { // 顶部自定义导航
  66. showCapsule: 1, // 是否显示左上角图标 1表示显示 0表示不显示,
  67. showSearch: 0,
  68. title: '采美采购商城', // 导航栏 中间的标题
  69. haveBack:false,
  70. textLeft:this.$store.state.isIphone,
  71. textColor:'#FFFFFF'
  72. },
  73. CustomBar:this.CustomBar, // 顶部导航栏高度
  74. userID:0,
  75. clubStatus:'',
  76. current:0,
  77. mode:'round',
  78. modallayer:false,
  79. isLogin:false,
  80. skeletonShow: true,
  81. userIdentity:0,
  82. flootData:[], // 楼层
  83. bannerImageList:[], // 轮播
  84. navBarsList:[], // 导航分类
  85. newsList:[], // 公告
  86. templateData:{},
  87. hotListPageFloor:[], // 新品橱窗
  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,source:2}).then(response =>{
  150. let data = response.data
  151. this.pageList = data.homePageFloor
  152. this.hotListPageFloor = data.pageFloorList
  153. this.supplierObj = data.supplierImage
  154. setTimeout(()=>{
  155. this.isRequest = true
  156. },500)
  157. }).catch(error =>{
  158. this.$util.msg(error.msg,2000)
  159. })
  160. },
  161. GetInitBeansInfo(){//初始化采美豆信息
  162. this.UserService.GetHomeObtainBeans({userId:this.userID}).then(response =>{
  163. this.beansType = response.data.beansType
  164. this.beanNumber = response.data.num
  165. this.isActivityBean = true
  166. }).catch(error =>{
  167. console.log('用户暂无采美豆推送~')
  168. })
  169. },
  170. getHomeInformation(){//初始化首页数据
  171. this.CommonService.GetHomeModulesDataInfo({ source: 2 }).then(res =>{
  172. let data = res.data
  173. this.bannerImageList = data.bannerList
  174. this.mallPageModules = data.mallPageModules
  175. this.skeletonShow = false
  176. this.navBarsList = data.topMenuList
  177. this.couponEntry = data.couponEntry
  178. this.newsList = data.annlist
  179. if(!this.hasLogin && this.couponEntry == 1){
  180. if(uni.getStorageSync('isActivitySwitch')){
  181. this.$store.commit('setActivity',false)
  182. }else{
  183. this.$store.commit('setActivity',true)
  184. }
  185. }
  186. this.GetHomeTopDataInfo()
  187. this.GetHomeFloorInfo()
  188. if(this.hasLogin){
  189. this.initShoppingCartCount()
  190. }
  191. this.isNavRequest = true
  192. }).catch(error =>{
  193. this.$util.msg(error.msg,2000)
  194. })
  195. },
  196. initShoppingCartCount(){ // 获取购物车数量
  197. this.OrderService.ShoppingCartCount({ userId: this.userID}).then(res =>{
  198. this.$store.commit('updateAllNum',res.data)
  199. })
  200. },
  201. handleClick(data){
  202. const pageId = 306
  203. this.$api.navigateTo('/pages/user/coupon/coupon-collection')
  204. this.$store.commit('setActivity',data)
  205. uni.setStorageSync('lockTime',Date.now())
  206. uni.setStorageSync('isActivitySwitch',true)
  207. // 友盟自定义事件
  208. // if(process.env.NODE_ENV != 'development'){
  209. // this.$uma.trackEvent('meibohui_click', {
  210. // Um_Key_PageName: '美博会',
  211. // Um_Key_PageCategory: '活动专题页面',
  212. // Um_Key_SourcePage: '首页',
  213. // })
  214. // }
  215. },
  216. handleCancelClick(data){
  217. this.$store.commit('setActivity',data)
  218. uni.setStorageSync('lockTime',Date.now())
  219. uni.setStorageSync('isActivitySwitch',true)
  220. },
  221. handleBeanlClick(){
  222. this.isActivityBean = false
  223. }
  224. },
  225. onPageScroll(e){//实时获取到滚动的值
  226. if(e.scrollTop>50){
  227. this.inputActive = 'fixed'
  228. }else{
  229. this.inputActive = 'float'
  230. }
  231. if(e.scrollTop>400){
  232. this.isScrollTop = true
  233. }else{
  234. this.isScrollTop = false
  235. }
  236. },
  237. onPullDownRefresh() {//下拉刷新
  238. this.getHomeInformation()
  239. uni.stopPullDownRefresh()
  240. },
  241. onShareAppMessage(res){//分享转发
  242. if (res.from === 'button') {
  243. // 来自页面内转发按钮
  244. }
  245. return {
  246. title: '生美医美正品采购服务平台',
  247. path: 'pages/tabBar/home/index',
  248. imageUrl:'https://static.caimei365.com/app/img/bg/min-banner.jpg'
  249. }
  250. },
  251. onShow(){
  252. this.modallayer = false
  253. this.GetWxAuthorize()
  254. }
  255. }
  256. </script>
  257. <style lang="scss">
  258. page{
  259. background-color: #FFFFFF;
  260. }
  261. .container-section{
  262. width: 100%;
  263. height: auto;
  264. background-color: #F7F7F7;
  265. }
  266. </style>