index.vue 9.2 KB

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