index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. this.isNavRequest = true
  156. }).catch(error =>{
  157. this.$util.msg(error.msg,2000)
  158. })
  159. },
  160. GetHomeTopDataInfo(){//直播、活动、文章模块
  161. this.CommonService.GetHomeTopDataInfo({source:2}).then(response =>{
  162. this.templateData = response.data
  163. this.isLiveRequest = true
  164. }).catch(error =>{
  165. this.$util.msg(error.msg,2000)
  166. })
  167. },
  168. GetHomeFloorInfo(){//初始化首页楼层数据
  169. this.CommonService.GetHomeDataInfo({userId:this.userID,soure:2}).then(response =>{
  170. let data = response.data;
  171. this.liveList = data.liveList;
  172. this.pageList = data.homePageFloor;
  173. this.supplierObj = data.supplierImage;
  174. this.isRequest = true;
  175. }).catch(error =>{
  176. this.$util.msg(error.msg,2000)
  177. })
  178. },
  179. getHomeInformation(){//初始化首页数据
  180. this.CommonService.GetHomeModulesDataInfo({ userId:this.userID }).then(res =>{
  181. let data = res.data;
  182. this.bannerImageList = data.bannerImageList
  183. this.mallPageModules = data.mallPageModules
  184. this.$store.commit('updateAllNum',data.shoppingCartCount)
  185. this.skeletonShow = false;
  186. this.GetHomeInit()
  187. this.GetHomeTopDataInfo()
  188. this.GetHomeFloorInfo()
  189. }).catch(error =>{
  190. this.$util.msg(error.msg,2000)
  191. })
  192. },
  193. handleClick(data){
  194. this.$api.navigateTo(`/h5/pages/activity/meobohui`)
  195. this.$store.commit('setActivity',data)
  196. uni.setStorageSync('lockTime',Date.now())
  197. uni.setStorageSync('isActivityStatus',true)
  198. },
  199. handleCancelClick(data){
  200. this.$store.commit('setActivity',data)
  201. uni.setStorageSync('lockTime',Date.now())
  202. uni.setStorageSync('isActivityStatus',true)
  203. },
  204. async InitAuthorize(){ //是否已授权 0:为取消授权 1:为已授权 2:为未操作
  205. const code = await authorize.getSetting();
  206. console.log(code)
  207. if(code == 1){
  208. this.GetWxAuthorize()
  209. }else{
  210. this.$api.getComStorage('userInfo').then((resolve) =>{
  211. this.userID = resolve.userId ? resolve.userId :0;
  212. this.getHomeInformation()
  213. }).catch(error =>{
  214. this.getHomeInformation()
  215. })
  216. }
  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.InitAuthorize()
  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>