index.vue 8.2 KB

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