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