index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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, getProductShare} 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 CXBPrivacyPopup from "~/components/CXBPrivacyPopup/CXBPrivacyPopup.vue";
  15. import {getShareId} from "~/apis/product";
  16. // import CXBDialogSIgnIn from "~/components/CXBDialogSignIn/CXBDialogSIgnIn.vue";
  17. // import CXBDialogSIgnInSucceed from "~/components/CXBDialogSignInSucceed/CXBDialogSIgnInSucceed.vue";
  18. import Cache from "~/utils/cache";
  19. import CXBBackTopVue from "~/components/CXBBackTop/CXBBackTop.vue";
  20. const userStore = useUserStore()
  21. const usePageStore = usePageStoreWidthOut()
  22. usePageStore.setPageConfig({
  23. currentPage: {
  24. type: 'tab',
  25. url: '/pages/home/index'
  26. }
  27. })
  28. // const list = ref([])
  29. const state = reactive({
  30. shareId: '',
  31. yanglaojine: {},
  32. isEject: 0,
  33. page: 1,
  34. limit: 10,
  35. currentPage: 1,
  36. productList: [],
  37. // 线上未结算养老金
  38. closeMoney: '',
  39. // 结算养老金
  40. openMoney: '',
  41. all_yanglao: NaN,
  42. signToday: NaN,
  43. isShowSignIn: false,
  44. banners: [],
  45. announcementList: [],
  46. indicatorDots: true,
  47. circular: true,
  48. autoplay: true,
  49. interval: 5000,
  50. duration: 500,
  51. currents: "0",
  52. })
  53. // 距离顶部距离
  54. let Scroll_X = ref(0)
  55. onShow(() => {
  56. usePageStore.setPageConfig({
  57. currentPage: {
  58. type: 'tab',
  59. url: '/pages/home/index'
  60. }
  61. })
  62. if (!userStore.uid) {
  63. state.closeMoney = ''
  64. state.openMoney = ''
  65. } else {
  66. getUserInfo().then(res => {
  67. userStore.setUserInfo(res)
  68. })
  69. getYanglaojinStatistics().then(res => {
  70. state.all_yanglao = res.all_yanglao
  71. })
  72. }
  73. })
  74. function checkSignIn() {
  75. // if (userStore.uid && state.isEject === 1) {
  76. // 2 检查用户签到信息
  77. getNewSignInInfo().then(res => {
  78. // console.log(res)
  79. const {today, day} = res
  80. state.signToday = today
  81. if (today === 0) {
  82. state.isShowSignIn = true
  83. }
  84. state.day = day
  85. // // if (today === 0) {
  86. // 2.1 弹出签到窗口
  87. // }
  88. }).catch(error => {
  89. console.error(error + '->GetNewsSignInInfo')
  90. })
  91. // }
  92. }
  93. onLoad((option) => {
  94. if (option && option.shareId) {
  95. userStore.setShareId(option.shareId)
  96. }
  97. getIsShow()
  98. getLocal()
  99. getHomeBanner().then(res => {
  100. // console.log(res)
  101. state.banners = res
  102. })
  103. // 加载地址数据
  104. // orderStore.getCurrentAddress()
  105. // 1加载首页数据
  106. getHomeQuickLink().then(res => {})
  107. getNoticeList().then(res => {
  108. state.announcementList = res.list
  109. })
  110. state.page = 1
  111. loadProductList()
  112. getProductShare().then(res => {
  113. if (res) {
  114. userStore.setShareId(res.share_id)
  115. }
  116. }).catch(message => {
  117. // console.log(message)
  118. })
  119. userStore.setRedirectPage(`/pages/home/index`, 'tab')
  120. })
  121. onShareAppMessage(() => {
  122. const shareId = Cache.get('SHARE_ID')
  123. return {
  124. title: `消费储蓄 保障未来`,
  125. path: `/pages/home/index?shareId=${shareId}`,
  126. imageUrl: 'https://cdn.bjtdba.com/vod/image/2023-10-09/20231009202402136.png'
  127. }
  128. })
  129. onShareTimeline(() => {
  130. const shareId = Cache.get('SHARE_ID')
  131. return {
  132. title: `消费储蓄 保障未来`,
  133. imageUrl: 'https://cdn.bjtdba.com/vod/image/2023-10-11/20231011062523504.png',
  134. query: `from=share&shareId=${shareId}`
  135. // imageUrl: 'https://cdn.bjtdba.com/vod/image/2023-10-09/20231009202402136.png'
  136. }
  137. })
  138. // onShow(() => {
  139. //
  140. // })
  141. watch(() => state.isShowSignIn, (val) => {
  142. val ? uni.hideTabBar() : uni.showTabBar()
  143. })
  144. const headerClass = ref('')
  145. onPageScroll((page) => {
  146. // console.log(page.scrollTop.toFixed(),'距离顶部的距离')
  147. Scroll_X.value = Number(page.scrollTop.toFixed())
  148. // page.scrollTop
  149. if (page.scrollTop >= 76 ) {
  150. headerClass.value = 'bg-white !text-gray-900'
  151. } else {
  152. headerClass.value = ''
  153. }
  154. })
  155. // 下拉刷新
  156. onPullDownRefresh(() => {
  157. state.page = 1
  158. loadProductList()
  159. })
  160. onReachBottom(() => {
  161. state.page += 1
  162. loadProductList()
  163. })
  164. function loadProductList() {
  165. uni.showLoading({
  166. title: '加载中',
  167. });
  168. getProduct({
  169. page: state.page,
  170. limit: state.limit
  171. }).then(res => {
  172. uni.stopPullDownRefresh();
  173. if (state.page === 1) {
  174. state.productList = res
  175. } else {
  176. setTimeout(() => {
  177. state.productList.push(...res)
  178. }, 300)
  179. }
  180. uni.hideLoading()
  181. }).catch(error => {
  182. console.error(error + '->getProduct')
  183. })
  184. }
  185. const homeBanner = CDN_URL + '/static/assets/home-banner.png'
  186. function handleBannerClick(item) {
  187. if(item.url == 'rich') {
  188. uni.navigateTo({
  189. url: '/pages/vip/index'
  190. })
  191. }
  192. }
  193. function getIsShow(){
  194. //首先获取是否执行过
  195. uni.getStorage({
  196. key: 'today',
  197. success: function(res) {
  198. // console.log(res.data)
  199. // console.log('----')
  200. //成功的话 说明之前执行过,再判断时间是否是当天
  201. // 如果不是当天更新
  202. if (res.data && res.data != new Date().toLocaleDateString()) {
  203. // getApp().globalData.isEject = 0; //自定义要更改的变量 或者方法
  204. state.isEject = 1
  205. checkSignIn()
  206. uni.setStorageSync("today", new Date().toLocaleDateString()); //把新得日期更新到本地
  207. }
  208. },
  209. fail: function(res) {
  210. // console.log(res + 'FAIL...')
  211. //没有执行过的话 先存一下当前的执行时间
  212. // console.log(res);
  213. state.isEject = 1
  214. checkSignIn()
  215. // getApp().globalData.isEject = 0; //自定义要更改的变量 或者方法
  216. let today = new Date().toLocaleDateString();
  217. uni.setStorageSync('today', today)
  218. }
  219. })
  220. }
  221. </script>
  222. <template>
  223. <div class="h-screen ">
  224. <CXBBackTopVue :Scroll_X="Scroll_X"/>
  225. <Header :yanglaojin="state.all_yanglao"
  226. :exClass="headerClass"
  227. />
  228. <div class="flex flex-col gap-3 ">
  229. <!-- <image-->
  230. <!-- @click="handleBannerClick"-->
  231. <!-- :src="homeBanner"-->
  232. <!-- mode="widthFix" class="h-60 w-full "-->
  233. <!-- ></image>-->
  234. <div class="w-screen h-65">
  235. <swiper
  236. v-if="state.banners"
  237. :indicator-dots="state.indicatorDots"
  238. indicator-active-color="#e93323"
  239. :autoplay="state.autoplay"
  240. :circular="state.circular"
  241. :interval="state.interval"
  242. :duration="state.duration"
  243. class="w-full h-full"
  244. >
  245. <swiper-item v-for="(item, index) in state.banners" :key="index">
  246. <image :src="item.pic" @tap="handleBannerClick(item)" class="!w-full !h-full" mode="aspectFill"/>
  247. </swiper-item>
  248. </swiper>
  249. </div>
  250. <Navs/>
  251. <Announcement :list="state.announcementList"/>
  252. <!-- {{userStore.userInfo}}-->
  253. <Banner/>
  254. <ProductList :list="state.productList"/>
  255. </div>
  256. </div>
  257. <CXBDialogSIgnIn
  258. :show="state.isShowSignIn"
  259. :today="state.signToday"
  260. :day="state.day"
  261. @confirm="state.isShowSignIn = false"
  262. @close="state.isShowSignIn = false"
  263. />
  264. <CXBPrivacyPopup />
  265. </template>
  266. <style>
  267. page {
  268. background-color: #f8f8f8;
  269. }
  270. </style>
  271. <route lang="yaml" type="home">
  272. style:
  273. navigationStyle: custom
  274. navigationBarTitleText: 储蓄保
  275. enablePullDownRefresh: true
  276. </route>