index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <view class="container home clearfix" :style="{ paddingTop: CustomBar + 'px' }">
  3. <customer ref="customer" :navbar-data="nvabarData"></customer>
  4. <!-- 主页内容 -->
  5. <tui-skeleton
  6. v-if="skeletonShow"
  7. backgroundColor="#fafafa"
  8. borderRadius="10rpx"
  9. :isLoading="true"
  10. :loadingType="5"
  11. ></tui-skeleton>
  12. <view class="container-home tui-skeleton">
  13. <!-- 轮播 -->
  14. <banner :list="bannerImageList" v-if="isNavRequest"></banner>
  15. <!-- 金刚区菜单 -->
  16. <navbars :list="navBarsList" v-if="isNavRequest"></navbars>
  17. <!-- 轮播公告 -->
  18. <notice :list="newsList" v-if="isNavRequest && newsList.length > 0"></notice>
  19. <!-- 优惠券入口 -->
  20. <coupon v-if="isNavRequest && couponEntry == 1"></coupon>
  21. <!-- 直播 -->
  22. <page-special :templateData="templateData" v-if="isLiveRequest"></page-special>
  23. <!-- 新品橱窗 -->
  24. <hot-floor
  25. :list="hotListPageFloor"
  26. :usserIdentity="userIdentity"
  27. :autoplay="autoplay"
  28. v-if="isRequest && hotListPageFloor.length > 0"
  29. ></hot-floor>
  30. </view>
  31. <!-- 楼层 -->
  32. <view class="container-section tui-skeleton">
  33. <page-floor :list="pageList" :userIdentity="userIdentity" :pageType="1" v-if="isRequest"></page-floor>
  34. <supplier-list :supplierObj="supplierObj" v-if="isRequest"></supplier-list>
  35. </view>
  36. <!-- 资质证书 -->
  37. <Certificate v-if="isRequest"></Certificate>
  38. <!-- 侧边 -->
  39. <scroll-top :isScrollTop="isScrollTop" :bottom="50"></scroll-top>
  40. <!-- 活动弹窗 -->
  41. <activityAlert :show="isActivity" @click="handleClick" @cancel="handleCancelClick"></activityAlert>
  42. <!-- 采美豆提示弹窗 -->
  43. <activityBean
  44. v-if="isActivityBean"
  45. :show="isActivityBean"
  46. :beansType="beansType"
  47. :beanNumber="beanNumber"
  48. @cancel="handleBeanlClick"
  49. ></activityBean>
  50. </view>
  51. </template>
  52. <script>
  53. import tuiSkeleton from '@/components/tui-skeleton/tui-skeleton'
  54. import authorize from '@/common/config/authorize.js'
  55. import customer from '@/components/cm-module/homeIndex/customer.vue'
  56. import banner from '@/components/cm-module/homeIndex/banner.vue'
  57. import navbars from '@/components/cm-module/homeIndex/navbars.vue'
  58. import notice from '@/components/cm-module/homeIndex/notice.vue'
  59. import coupon from '@/components/cm-module/homeIndex/coupon.vue'
  60. import pageFloor from '@/components/cm-module/homeIndex/pageFloor.vue'
  61. import hotFloor from '@/components/cm-module/homeIndex/hotFloor.vue'
  62. import Certificate from '@/components/cm-module/homeIndex/certificate.vue'
  63. import pageSpecial from '@/components/cm-module/homeIndex/pageSpecial.vue'
  64. import supplierList from '@/components/cm-module/homeIndex/supplierList.vue'
  65. import activityAlert from '@/components/cm-module/activity/activity.vue'
  66. import activityBean from '@/components/cm-module/activity/activityBean.vue'
  67. import { mapState, mapMutations } from 'vuex'
  68. export default {
  69. components: {
  70. tuiSkeleton,
  71. customer,
  72. banner,
  73. navbars,
  74. notice,
  75. coupon,
  76. pageFloor,
  77. hotFloor,
  78. Certificate,
  79. pageSpecial,
  80. supplierList,
  81. activityAlert,
  82. activityBean
  83. },
  84. data() {
  85. return {
  86. nvabarData: {
  87. // 顶部自定义导航
  88. showCapsule: 1, // 是否显示左上角图标 1表示显示 0表示不显示,
  89. showSearch: 0,
  90. title: '采美采购商城', // 导航栏 中间的标题
  91. haveBack: false,
  92. textLeft: this.$store.state.isIphone,
  93. textColor: '#FFFFFF'
  94. },
  95. CustomBar: this.CustomBar, // 顶部导航栏高度
  96. userID: 0,
  97. clubStatus: '',
  98. current: 0,
  99. mode: 'round',
  100. modallayer: false,
  101. isLogin: false,
  102. skeletonShow: true,
  103. userIdentity: 0,
  104. flootData: [], // 楼层
  105. bannerImageList: [], // 轮播
  106. navBarsList: [], // 导航分类
  107. newsList: [], // 公告
  108. templateData: {},
  109. hotListPageFloor: [], // 新品橱窗
  110. pageList: [], // 楼层
  111. supplierObj: {}, // 供应商列表
  112. isScrollTop: false,
  113. isRequest: false,
  114. isNavRequest: false,
  115. isLiveRequest: false,
  116. isActivityBean: false,
  117. beansType: 1,
  118. beanNumber: 50,
  119. couponEntry: 2,
  120. autoplay: true
  121. }
  122. },
  123. onLoad() {},
  124. computed: {
  125. ...mapState(['hasLogin', 'userInfo', 'identity', 'isActivity', 'isWxAuthorize'])
  126. },
  127. methods: {
  128. ...mapMutations(['login', 'logout']),
  129. async GetWxAuthorize() {
  130. const wechatCode = await authorize.getCode('weixin') // 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  131. const getUserInfo = await authorize.getUserInfo('weixin')
  132. this.UserService.UserLoginAuthApplets({
  133. code: wechatCode,
  134. encryptedData: getUserInfo.encryptedData,
  135. iv: getUserInfo.iv
  136. })
  137. .then(response => {
  138. this.isLogin = true
  139. this.userID = response.data.userId
  140. this.userIdentity = response.data.userIdentity
  141. this.clubStatus = response.data.clubStatus
  142. this.$store.commit('updateStatus', response.data)
  143. this.login(response.data)
  144. uni.setStorageSync('token', response.data.token)
  145. uni.setStorageSync('unionId', response.data.unionId)
  146. if (response.data.userIdentity == 1) {
  147. this.$api.redirectTo('/pages/seller/index/index')
  148. } else if (response.data.userIdentity === 3) {
  149. this.$api.redirectTo('/pages/supplier/index/index')
  150. }
  151. this.GetInitBeansInfo()
  152. this.getHomeInformation()
  153. })
  154. .catch(error => {
  155. this.isLogin = false
  156. this.logout()
  157. uni.setStorageSync('unionId', error.data.unionId)
  158. this.$store.commit('updateStatus', error.data)
  159. this.getHomeInformation()
  160. })
  161. },
  162. GetHomeTopDataInfo() {
  163. //直播、活动、文章模块
  164. this.CommonService.GetHomeTopDataInfo({ source: 2 })
  165. .then(response => {
  166. this.templateData = response.data
  167. this.isLiveRequest = true
  168. })
  169. .catch(error => {
  170. this.$util.msg(error.msg, 2000)
  171. })
  172. },
  173. GetHomeFloorInfo() {
  174. //初始化首页楼层数据
  175. this.CommonService.GetHomeDataInfo({ userId: this.userID, source: 2 })
  176. .then(response => {
  177. let data = response.data
  178. this.pageList = data.homePageFloor
  179. this.hotListPageFloor = data.pageFloorList
  180. this.supplierObj = data.supplierImage
  181. setTimeout(() => {
  182. this.isRequest = true
  183. }, 500)
  184. })
  185. .catch(error => {
  186. this.$util.msg(error.msg, 2000)
  187. })
  188. },
  189. GetInitBeansInfo() {
  190. //初始化采美豆信息
  191. this.UserService.GetHomeObtainBeans({ userId: this.userID })
  192. .then(response => {
  193. this.beansType = response.data.beansType
  194. this.beanNumber = response.data.num
  195. this.isActivityBean = true
  196. })
  197. .catch(error => {
  198. console.log('用户暂无采美豆推送~')
  199. })
  200. },
  201. getHomeInformation() {
  202. //初始化首页数据
  203. this.CommonService.GetHomeModulesDataInfo({ source: 2 })
  204. .then(res => {
  205. let data = res.data
  206. this.bannerImageList = data.bannerList
  207. this.mallPageModules = data.mallPageModules
  208. this.skeletonShow = false
  209. this.navBarsList = data.topMenuList
  210. this.couponEntry = data.couponEntry
  211. this.newsList = data.annlist
  212. if (!this.hasLogin && this.couponEntry == 1) {
  213. if (uni.getStorageSync('isActivitySwitch')) {
  214. this.$store.commit('setActivity', false)
  215. } else {
  216. this.$store.commit('setActivity', true)
  217. }
  218. }
  219. this.GetHomeTopDataInfo()
  220. this.GetHomeFloorInfo()
  221. if (this.hasLogin) {
  222. this.initShoppingCartCount()
  223. }
  224. this.isNavRequest = true
  225. })
  226. .catch(error => {
  227. this.$util.msg(error.msg, 2000)
  228. })
  229. },
  230. initShoppingCartCount() {
  231. // 获取购物车数量
  232. this.OrderService.ShoppingCartCount({ userId: this.userID }).then(res => {
  233. this.$store.commit('updateAllNum', res.data)
  234. })
  235. },
  236. handleClick(data) {
  237. const pageId = 306
  238. this.$api.navigateTo('/pages/user/coupon/coupon-collection')
  239. this.$store.commit('setActivity', data)
  240. uni.setStorageSync('lockTime', Date.now())
  241. uni.setStorageSync('isActivitySwitch', true)
  242. // 友盟自定义事件
  243. // if(process.env.NODE_ENV != 'development'){
  244. // this.$uma.trackEvent('meibohui_click', {
  245. // Um_Key_PageName: '美博会',
  246. // Um_Key_PageCategory: '活动专题页面',
  247. // Um_Key_SourcePage: '首页',
  248. // })
  249. // }
  250. },
  251. handleCancelClick(data) {
  252. this.$store.commit('setActivity', data)
  253. uni.setStorageSync('lockTime', Date.now())
  254. uni.setStorageSync('isActivitySwitch', true)
  255. },
  256. handleBeanlClick() {
  257. this.isActivityBean = false
  258. }
  259. },
  260. onPageScroll(e) {
  261. //实时获取到滚动的值
  262. if (e.scrollTop > 50) {
  263. this.inputActive = 'fixed'
  264. } else {
  265. this.inputActive = 'float'
  266. }
  267. if (e.scrollTop > 400) {
  268. this.isScrollTop = true
  269. } else {
  270. this.isScrollTop = false
  271. }
  272. },
  273. onPullDownRefresh() {
  274. //下拉刷新
  275. this.getHomeInformation()
  276. uni.stopPullDownRefresh()
  277. },
  278. onShareAppMessage(res) {
  279. //分享转发
  280. if (res.from === 'button') {
  281. // 来自页面内转发按钮
  282. }
  283. return {
  284. title: '生美医美正品采购服务平台',
  285. path: 'pages/tabBar/home/index',
  286. imageUrl: 'https://static.caimei365.com/app/img/bg/min-banner.jpg'
  287. }
  288. },
  289. onShow() {
  290. this.modallayer = false
  291. this.autoplay = true
  292. this.GetWxAuthorize()
  293. },
  294. onHide() {
  295. this.autoplay = false
  296. }
  297. }
  298. </script>
  299. <style lang="scss">
  300. page {
  301. background-color: #ffffff;
  302. }
  303. .container-section {
  304. width: 100%;
  305. height: auto;
  306. background-color: #f7f7f7;
  307. }
  308. </style>