index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <script lang="ts" setup>
  2. import {getNewSignInInfo, getUserInfo, getYanglaojinStatistics} from "~/apis/user";
  3. import {getProduct} from "~/apis/home";
  4. import Navs from "~/pages/home/components/navs.vue";
  5. import Announcement from "~/pages/home/components/announcement.vue";
  6. import Banner from "~/pages/home/components/banner.vue";
  7. import Header from "~/pages/home/components/header.vue";
  8. import ProductList from "~/pages/home/components/product-list.vue";
  9. import {getHomeBanner, getHomeQuickLink, getLocal, getNoticeList} from "~/apis/common";
  10. import {useUserStore} from "~/stores/userStore";
  11. import CXBDialogSIgnIn from "~/components/CXBDialogSignIn/CXBDialogSIgnIn.vue";
  12. import CXBDialogSIgnInSucceed from "~/components/CXBDialogSignInSucceed/CXBDialogSIgnInSucceed.vue";
  13. import {CDN_URL} from "~/config/app";
  14. // import CXBDialogSIgnIn from "~/components/CXBDialogSignIn/CXBDialogSIgnIn.vue";
  15. // import CXBDialogSIgnInSucceed from "~/components/CXBDialogSignInSucceed/CXBDialogSIgnInSucceed.vue";
  16. const userStore = useUserStore()
  17. const usePageStore = usePageStoreWidthOut()
  18. usePageStore.setPageConfig({
  19. currentPage: {
  20. type: 'tab',
  21. url: '/pages/home/index'
  22. }
  23. })
  24. // const list = ref([])
  25. const state = reactive({
  26. yanglaojine: {},
  27. page: 1,
  28. limit: 10,
  29. currentPage: 1,
  30. productList: [],
  31. // 线上未结算养老金
  32. closeMoney: '',
  33. // 结算养老金
  34. openMoney: '',
  35. all_yanglao: NaN,
  36. signToday: NaN,
  37. isShowSignIn: false,
  38. banners: [],
  39. announcementList: [],
  40. indicatorDots: true,
  41. circular: true,
  42. autoplay: true,
  43. interval: 5000,
  44. duration: 500,
  45. currents: "0",
  46. })
  47. onShow(() => {
  48. usePageStore.setPageConfig({
  49. currentPage: {
  50. type: 'tab',
  51. url: '/pages/home/index'
  52. }
  53. })
  54. if (!userStore.uid) {
  55. state.closeMoney = ''
  56. state.openMoney = ''
  57. } else {
  58. getUserInfo().then(res => {
  59. userStore.setUserInfo(res)
  60. })
  61. getYanglaojinStatistics().then(res => {
  62. state.all_yanglao = res.all_yanglao
  63. })
  64. }
  65. })
  66. onLoad(() => {
  67. getLocal()
  68. getHomeBanner().then(res => {
  69. console.log(res)
  70. state.banners = res
  71. })
  72. // 加载地址数据
  73. // orderStore.getCurrentAddress()
  74. // 1加载首页数据
  75. getHomeQuickLink().then(res => {})
  76. getNoticeList().then(res => {
  77. state.announcementList = res.list
  78. })
  79. state.page = 1
  80. loadProductList()
  81. })
  82. onShow(() => {
  83. if (userStore.uid) {
  84. // 2 检查用户签到信息
  85. getNewSignInInfo().then(res => {
  86. console.log(res)
  87. const {today, day} = res
  88. state.signToday = today
  89. if (today === 0) {
  90. state.isShowSignIn = true
  91. }
  92. state.day = day
  93. // // if (today === 0) {
  94. // 2.1 弹出签到窗口
  95. // }
  96. }).catch(error => {
  97. console.error(error + '->GetNewsSignInInfo')
  98. })
  99. }
  100. })
  101. watch(() => state.isShowSignIn, (val) => {
  102. val ? uni.hideTabBar() : uni.showTabBar()
  103. })
  104. const headerClass = ref('')
  105. onPageScroll((page) => {
  106. // page.scrollTop
  107. if (page.scrollTop >= 76 ) {
  108. headerClass.value = 'bg-white !text-gray-900'
  109. } else {
  110. headerClass.value = ''
  111. }
  112. })
  113. // 下拉刷新
  114. onPullDownRefresh(() => {
  115. state.page = 1
  116. loadProductList()
  117. })
  118. onReachBottom(() => {
  119. state.page += 1
  120. loadProductList()
  121. })
  122. function loadProductList() {
  123. uni.showLoading({
  124. title: '加载中',
  125. });
  126. getProduct({
  127. page: state.page,
  128. limit: state.limit
  129. }).then(res => {
  130. uni.stopPullDownRefresh();
  131. if (state.page === 1) {
  132. state.productList = res
  133. } else {
  134. setTimeout(() => {
  135. state.productList.push(...res)
  136. }, 300)
  137. }
  138. uni.hideLoading()
  139. }).catch(error => {
  140. console.error(error + '->getProduct')
  141. })
  142. }
  143. const homeBanner = CDN_URL + '/static/assets/home-banner.png'
  144. function handleBannerClick(item) {
  145. if(item.url == 'rich') {
  146. uni.navigateTo({
  147. url: '/pages/vip/index'
  148. })
  149. }
  150. }
  151. </script>
  152. <template>
  153. <div class="h-screen ">
  154. <Header :yanglaojin="state.all_yanglao"
  155. :exClass="headerClass"
  156. />
  157. <div class="flex flex-col gap-3 ">
  158. <!-- <image-->
  159. <!-- @click="handleBannerClick"-->
  160. <!-- :src="homeBanner"-->
  161. <!-- mode="widthFix" class="h-60 w-full "-->
  162. <!-- ></image>-->
  163. <div class="w-screen h-65">
  164. <swiper
  165. v-if="state.banners"
  166. :indicator-dots="state.indicatorDots"
  167. indicator-active-color="#e93323"
  168. :autoplay="state.autoplay"
  169. :circular="state.circular"
  170. :interval="state.interval"
  171. :duration="state.duration"
  172. class="w-full h-full"
  173. >
  174. <swiper-item v-for="(item, index) in state.banners" :key="index">
  175. <image :src="item.pic" @tap="handleBannerClick(item)" class="!w-full !h-full" mode="aspectFill"/>
  176. </swiper-item>
  177. </swiper>
  178. </div>
  179. <Navs/>
  180. <Announcement :list="state.announcementList"/>
  181. <!-- {{userStore.userInfo}}-->
  182. <Banner/>
  183. <ProductList :list="state.productList"/>
  184. </div>
  185. </div>
  186. <CXBDialogSIgnIn
  187. :show="state.isShowSignIn"
  188. :today="state.signToday"
  189. :day="state.day"
  190. @confirm="state.isShowSignIn = false"
  191. @close="state.isShowSignIn = false"
  192. />
  193. </template>
  194. <style>
  195. page {
  196. background-color: #f8f8f8;
  197. }
  198. </style>
  199. <route lang="yaml" type="home">
  200. style:
  201. navigationStyle: custom
  202. navigationBarTitleText: 储蓄保
  203. enablePullDownRefresh: true
  204. </route>