index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <view class="container" :style="appThemeStyle">
  3. <!-- 店铺页面组件 -->
  4. <Page :items="items" />
  5. <!-- 用户隐私保护提示(仅微信小程序) -->
  6. <!-- #ifdef MP-WEIXIN -->
  7. <PrivacyPopup :hideTabBar="true" />
  8. <!-- #endif -->
  9. </view>
  10. </template>
  11. <script>
  12. import {setCartTabBadge} from '@/core/app'
  13. import * as Api from '@/api/page'
  14. import Page from '@/components/page'
  15. import PrivacyPopup from '@/components/privacy-popup'
  16. import {homeData} from './data.js'
  17. import * as AppApi from '@/api/app'
  18. import storage from '@/utils/storage'
  19. const App = getApp()
  20. export default {
  21. components: {
  22. Page,
  23. PrivacyPopup
  24. },
  25. data() {
  26. return {
  27. // 页面参数
  28. options: {},
  29. // 页面属性
  30. page: {},
  31. // 页面元素
  32. items: []
  33. }
  34. },
  35. /**
  36. * 生命周期函数--监听页面加载
  37. */
  38. onLoad(options) {
  39. // 当前页面参数
  40. this.options = options
  41. // 加载首页数据
  42. this.page = homeData.data.pageData.page
  43. this.items = homeData.data.pageData.items
  44. // 设置顶部导航栏
  45. this.setPageBar()
  46. // console.log(homeData, 'homeData')
  47. // 加载页面数据
  48. this.getPageData(() => {
  49. uni.stopPullDownRefresh()
  50. })
  51. },
  52. /**
  53. * 生命周期函数--监听页面显示
  54. */
  55. onShow() {
  56. // 更新购物车角标
  57. setCartTabBadge()
  58. },
  59. methods: {
  60. /**
  61. * 加载页面数据
  62. * @param {Object} callback
  63. */
  64. async getPageData(callback) {
  65. const params = {
  66. 'productagentsqym.value': storage.get('wx_qym'),
  67. pageindex: 1,
  68. rows: 9999
  69. }
  70. // getShopTaochanList
  71. const {Data: res} = await AppApi.getShopTaochanList(params)
  72. const goodsIndex = this.items.findIndex((v) => v.type === 'goods')
  73. this.items[goodsIndex].data = res.Data
  74. console.log(this.items[goodsIndex].data, '上拉加载加载页面数据')
  75. callback()
  76. },
  77. /**
  78. * 设置顶部导航栏
  79. */
  80. setPageBar() {
  81. const {page} = this
  82. // 设置页面标题
  83. uni.setNavigationBarTitle({
  84. title: page.params.title
  85. })
  86. // 设置navbar标题、颜色
  87. uni.setNavigationBarColor({
  88. frontColor: page.style.titleTextColor === 'white' ? '#ffffff' : '#000000',
  89. backgroundColor: page.style.titleBackgroundColor
  90. })
  91. }
  92. },
  93. /**
  94. * 下拉刷新
  95. */
  96. onPullDownRefresh() {
  97. // 获取首页数据 - 上拉加载加载页面数据
  98. this.getPageData(() => {
  99. uni.stopPullDownRefresh()
  100. })
  101. },
  102. /**
  103. * 分享当前页面
  104. */
  105. onShareAppMessage() {
  106. const app = this
  107. const {page} = app
  108. return {
  109. title: page.params.shareTitle,
  110. path: '/pages/index/index?' + app.$getShareUrlParams()
  111. }
  112. },
  113. /**
  114. * 分享到朋友圈
  115. * 本接口为 Beta 版本,暂只在 Android 平台支持,详见分享到朋友圈 (Beta)
  116. * https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
  117. */
  118. onShareTimeline() {
  119. const app = this
  120. const {page} = app
  121. return {
  122. title: page.params.shareTitle,
  123. path: '/pages/index/index?' + app.$getShareUrlParams()
  124. }
  125. }
  126. }
  127. </script>
  128. <style lang="scss" scoped>
  129. .container {
  130. background: #fff;
  131. }
  132. </style>