index.vue 9.1 KB

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