index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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 authorize from '@/common/config/authorize.js'
  54. import customer from '@/components/cm-module/homeIndex/customer.vue'
  55. import banner from '@/components/cm-module/homeIndex/banner.vue'
  56. import navbars from '@/components/cm-module/homeIndex/navbars.vue'
  57. import notice from '@/components/cm-module/homeIndex/notice.vue'
  58. import coupon from '@/components/cm-module/homeIndex/coupon.vue'
  59. import pageFloor from '@/components/cm-module/homeIndex/pageFloor.vue'
  60. import hotFloor from '@/components/cm-module/homeIndex/hotFloor.vue'
  61. import Certificate from '@/components/cm-module/homeIndex/certificate.vue'
  62. import pageSpecial from '@/components/cm-module/homeIndex/pageSpecial.vue'
  63. import supplierList from '@/components/cm-module/homeIndex/supplierList.vue'
  64. import activityAlert from '@/components/cm-module/activity/activity.vue'
  65. import activityBean from '@/components/cm-module/activity/activityBean.vue'
  66. import { mapState, mapMutations } from 'vuex'
  67. export default {
  68. components: {
  69. customer,
  70. banner,
  71. navbars,
  72. notice,
  73. coupon,
  74. pageFloor,
  75. hotFloor,
  76. Certificate,
  77. pageSpecial,
  78. supplierList,
  79. activityAlert,
  80. activityBean
  81. },
  82. data() {
  83. return {
  84. nvabarData: {
  85. // 顶部自定义导航
  86. showCapsule: 1, // 是否显示左上角图标 1表示显示 0表示不显示,
  87. showSearch: 0,
  88. title: '采美采购商城', // 导航栏 中间的标题
  89. haveBack: false,
  90. textLeft: this.$store.state.isIphone,
  91. textColor: '#FFFFFF'
  92. },
  93. CustomBar: this.CustomBar, // 顶部导航栏高度
  94. userID: 0,
  95. clubId: 0,
  96. clubStatus: '',
  97. current: 0,
  98. mode: 'round',
  99. modallayer: false,
  100. isLogin: false,
  101. skeletonShow: true,
  102. userIdentity: 0,
  103. flootData: [], // 楼层
  104. bannerImageList: [], // 轮播
  105. navBarsList: [], // 导航分类
  106. newsList: [], // 公告
  107. templateData: {},
  108. hotListPageFloor: [], // 新品橱窗
  109. pageList: [], // 楼层
  110. supplierObj: {}, // 供应商列表
  111. isScrollTop: false,
  112. isRequest: false,
  113. isNavRequest: false,
  114. isLiveRequest: false,
  115. isActivityBean: false,
  116. beansType: 1,
  117. beanNumber: 50,
  118. couponEntry: 2,
  119. autoplay: true
  120. }
  121. },
  122. onLoad() {},
  123. computed: {
  124. ...mapState(['hasLogin', 'userInfo', 'identity', 'isActivity', 'isWxAuthorize'])
  125. },
  126. methods: {
  127. ...mapMutations(['login', 'logout','updateNoticeNum','updateRossShow']),
  128. async GetWxAuthorize() {
  129. const wechatCode = await authorize.getCode('weixin') // 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  130. const getUserInfo = await authorize.getUserInfo('weixin')
  131. this.UserService.UserLoginAuthApplets({
  132. code: wechatCode,
  133. encryptedData: getUserInfo.encryptedData,
  134. iv: getUserInfo.iv
  135. })
  136. .then(response => {
  137. this.isLogin = true
  138. this.userID = response.data.userId
  139. this.clubId = response.data.clubId
  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.updateRossShow()
  152. this.GetInitBeansInfo()
  153. this.getHomeInformation()
  154. })
  155. .catch(error => {
  156. this.isLogin = false
  157. this.logout()
  158. uni.setStorageSync('unionId', error.data.unionId)
  159. this.$store.commit('updateStatus', error.data)
  160. this.updateRossShow()
  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. uni.setStorageSync('pageLabel','首页')
  184. setTimeout(() => {
  185. this.isRequest = true
  186. }, 500)
  187. })
  188. .catch(error => {
  189. this.$util.msg(error.msg, 2000)
  190. })
  191. },
  192. GetInitBeansInfo() {
  193. //初始化采美豆信息
  194. this.UserService.GetHomeObtainBeans({ userId: this.userID })
  195. .then(response => {
  196. this.beansType = response.data.beansType
  197. this.beanNumber = response.data.num
  198. this.isActivityBean = true
  199. })
  200. .catch(error => {
  201. console.log('用户暂无采美豆推送~')
  202. })
  203. },
  204. getHomeInformation() {
  205. //初始化首页数据
  206. this.CommonService.GetHomeModulesDataInfo({ source: 2 })
  207. .then(res => {
  208. let data = res.data
  209. this.bannerImageList = data.bannerList
  210. this.mallPageModules = data.mallPageModules
  211. this.skeletonShow = false
  212. this.navBarsList = data.topMenuList
  213. this.couponEntry = data.couponEntry
  214. this.newsList = data.annlist
  215. if (!this.hasLogin && this.couponEntry == 1) {
  216. if (uni.getStorageSync('isActivitySwitch')) {
  217. this.$store.commit('setActivity', false)
  218. } else {
  219. this.$store.commit('setActivity', true)
  220. }
  221. }
  222. this.GetHomeTopDataInfo()
  223. this.GetHomeFloorInfo()
  224. if (this.hasLogin) {
  225. this.initShoppingCartCount()
  226. this.updateNoticeNum()
  227. }
  228. this.isNavRequest = true
  229. })
  230. .catch(error => {
  231. this.$util.msg(error.msg, 2000)
  232. })
  233. },
  234. initShoppingCartCount() {
  235. // 获取购物车数量
  236. this.OrderService.ShoppingCartCount({ userId: this.userID }).then(res => {
  237. this.$store.commit('updateAllNum', res.data)
  238. })
  239. },
  240. handleClick(data) {
  241. const pageId = 306
  242. this.$api.navigateTo('/pages/user/coupon/coupon-collection')
  243. this.$store.commit('setActivity', data)
  244. uni.setStorageSync('lockTime', Date.now())
  245. uni.setStorageSync('isActivitySwitch', true)
  246. // 友盟自定义事件
  247. // if(process.env.NODE_ENV != 'development'){
  248. // this.$uma.trackEvent('meibohui_click', {
  249. // Um_Key_PageName: '美博会',
  250. // Um_Key_PageCategory: '活动专题页面',
  251. // Um_Key_SourcePage: '首页',
  252. // })
  253. // }
  254. },
  255. handleCancelClick(data) {
  256. this.$store.commit('setActivity', data)
  257. uni.setStorageSync('lockTime', Date.now())
  258. uni.setStorageSync('isActivitySwitch', true)
  259. },
  260. handleBeanlClick() {
  261. this.isActivityBean = false
  262. }
  263. },
  264. onPageScroll(e) {
  265. //实时获取到滚动的值
  266. if (e.scrollTop > 50) {
  267. this.inputActive = 'fixed'
  268. } else {
  269. this.inputActive = 'float'
  270. }
  271. if (e.scrollTop > 400) {
  272. this.isScrollTop = true
  273. } else {
  274. this.isScrollTop = false
  275. }
  276. },
  277. onPullDownRefresh() {
  278. //下拉刷新
  279. this.getHomeInformation()
  280. uni.stopPullDownRefresh()
  281. },
  282. onShareAppMessage(res) {
  283. //分享转发
  284. if (res.from === 'button') {
  285. // 来自页面内转发按钮
  286. }
  287. return {
  288. title: '生美医美正品采购服务平台',
  289. path: 'pages/tabBar/home/index',
  290. imageUrl: 'https://static.caimei365.com/app/img/bg/min-banner.jpg'
  291. }
  292. },
  293. onShow() {
  294. this.modallayer = false
  295. this.autoplay = true
  296. this.GetWxAuthorize()
  297. },
  298. onHide() {
  299. this.autoplay = false
  300. }
  301. }
  302. </script>
  303. <style lang="scss">
  304. page {
  305. background-color: #ffffff;
  306. }
  307. .container-section {
  308. width: 100%;
  309. height: auto;
  310. background-color: #f7f7f7;
  311. }
  312. </style>