home.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <template>
  2. <view class="tab_page adffc" :style="{'height':h+'px', 'padding-top':mt+'px'}">
  3. <up-navbar title=" " bgColor="transparent">
  4. <template #left>
  5. <view class="u-nav-slot" slot="left" style="display: flex;background-color: transparent;">
  6. <image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/09/11/a5ad7f10-d625-4c9a-89f3-59f98c56dee8.png" style="width: 370rpx;height: 40rpx;"></image>
  7. </view>
  8. </template>
  9. </up-navbar>
  10. <image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/09/11/a7f990ec-1bff-4bd6-8b7f-fa61c0170d3b.png" class="top_bg_img" mode="widthFix"></image>
  11. <view class="c-box adffc">
  12. <view class="c-box-lunbo">
  13. <up-swiper
  14. :list="bannarList"
  15. @change="e => current = e.current"
  16. :autoplay="true"
  17. :interval="2000"
  18. :duration="200"
  19. :circular="true"
  20. imgMode="scaleToFill"
  21. height="326rpx"
  22. >
  23. <template #indicator>
  24. <view class="indicator adf">
  25. <view class="indicator__dot" v-for="(item, index) in bannarList" :key="index"
  26. :class="[index === current && 'indicator__dot--active']">
  27. </view>
  28. </view>
  29. </template>
  30. </up-swiper>
  31. </view>
  32. <view class="c-box-title adfacjb">
  33. <view class="c-box-title-left">公益活动</view>
  34. <view class="c-box-title-right adfac" @click="toTurnPage('/pagesHome/allActivity',false)">更多 <up-icon name="arrow-right" size="30rpx" style="margin-left: 10rpx;"></up-icon></view>
  35. </view>
  36. <view class="c-box-type">
  37. <scroll-view class="scroll-view_H" scroll-x="true" scroll-with-animation="true" :scroll-left="scrollLeft">
  38. <view class="scroll-view-item_H" :id="'svih_'+index" v-for="(item,index) in typeList" :key="index" @click="changeType(item,index)">
  39. <view class="cl_item" :class="{'active':tlIndex===index}">
  40. <text>{{item.name}}</text>
  41. </view>
  42. </view>
  43. </scroll-view>
  44. </view>
  45. <view class="c-box-list" v-if="activityList.length">
  46. <template v-for="item in activityList" :key="item.id">
  47. <NonprofitActivety :item="item"></NonprofitActivety>
  48. </template>
  49. </view>
  50. <view class="dataEmpty" v-else>
  51. <page-empty text="暂无公益活动"></page-empty>
  52. </view>
  53. </view>
  54. <login-register @loginSucc="loginSucc"></login-register>
  55. <CusTabbar :tabbarIndex="0"></CusTabbar>
  56. </view>
  57. </template>
  58. <script setup name="">
  59. import CusTabbar from '@/components/CusTabbar/index.vue'
  60. import NonprofitActivety from '@/components/pages/nonprofitActivety/index.vue'
  61. import PageEmpty from '@/components/pageEmpty/index.vue'
  62. import { ref, getCurrentInstance, onMounted, watch } from 'vue'
  63. const { proxy } = getCurrentInstance()
  64. import { useUserStore } from '@/common/stores/user';
  65. const userStore = useUserStore();
  66. const bannarList = ref([])
  67. const bannarOrigin = ref([])
  68. const current = ref(0)
  69. const typeList = ref([])
  70. const tlIndex = ref(0)
  71. const scrollLeft = ref(0)
  72. const activityList = ref([])
  73. const changeType = (item,index) => {
  74. tlIndex.value = index;
  75. if(typeList.value.length>4){
  76. if(index<3) scrollLeft.value = 0
  77. else{
  78. scrollLeft.value = (index-2)*172/2;
  79. }
  80. }
  81. getActivityList(item.id)
  82. }
  83. const toTurnPage = (url,needLogin) => {
  84. if(!needLogin){
  85. uni.navigateTo({ url })
  86. }
  87. }
  88. const getSwiperList = () => {
  89. proxy.$api.get('/core/advertisement/manage/page',{page:1,limit:-1}).then(({data:res})=>{
  90. if(res.code!==0) return proxy.$showToast(res.msg)
  91. bannarOrigin.value = res.data.list;
  92. bannarList.value = res.data.list.map(l=>l.fileUrl);
  93. })
  94. }
  95. const getTypeList = () => {
  96. proxy.$api.get('/core/activity/category/list').then(({data:res})=>{
  97. if(res.code!==0) return proxy.$showToast(res.msg)
  98. typeList.value = [{id:'',name:'全部'},...res.data.map(d=>({id:d.id,name:d.categoryName}))];
  99. })
  100. }
  101. const getActivityList = (categoryId) => {
  102. let userId = '';
  103. if(uni.getStorageSync('userInfo')) userId = JSON.parse(uni.getStorageSync('userInfo'))?.id;
  104. proxy.$api.get('/core/activity/page',{page:1,limit:2,categoryId,userId}).then(({data:res})=>{
  105. if(res.code!==0) return proxy.$showToast(res.msg)
  106. activityList.value = res.data.list;
  107. activityList.value.forEach(a=>{
  108. let cc = calculateCountdown(a?.signupEndTime);
  109. a.endTimeText = cc===-1?a?.signupEndTime:(`还有${cc.days}天${cc.hours}小时${cc.minutes}分钟`)
  110. })
  111. })
  112. }
  113. const calculateCountdown = (datetime) => {
  114. if(!datetime) return -1;
  115. const targetDate = new Date(datetime);
  116. const now = new Date();
  117. const difference = targetDate.getTime() - now.getTime();
  118. if (difference <= 0) return -1;
  119. const days = Math.floor(difference / (1000 * 60 * 60 * 24));
  120. const hours = Math.floor((difference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  121. const minutes = Math.floor((difference % (1000 * 60 * 60)) / (1000 * 60));
  122. return {
  123. days,
  124. hours,
  125. minutes
  126. };
  127. }
  128. watch(()=>userStore.token,newVal=>{
  129. getActivityList('')
  130. })
  131. onMounted(()=>{
  132. getSwiperList()
  133. getTypeList()
  134. getActivityList('')
  135. })
  136. </script>
  137. <style scoped lang="scss">
  138. ::v-deep .indicator__dot{
  139. width: 48rpx;
  140. height: 4rpx;
  141. background: #E2E5E9;
  142. border-radius: 2rpx;
  143. margin: 0 8rpx;
  144. }
  145. ::v-deep .indicator__dot--active{
  146. width: 48rpx;
  147. height: 4rpx;
  148. background: #00AE57;
  149. border-radius: 2rpx;
  150. }
  151. .scroll-view_H {
  152. white-space: nowrap;
  153. width: 100%;
  154. }
  155. .scroll-view-item_H {
  156. display: inline-block;
  157. width: 152rpx;
  158. height: 100%;
  159. margin-left: 20rpx;
  160. &:first-child{
  161. margin-left: 0;
  162. }
  163. }
  164. .tab_page{
  165. .c-box{
  166. width: 100%;
  167. height: 100%;
  168. overflow-y: auto;
  169. position: relative;
  170. &-lunbo{
  171. width: 100%;
  172. height: 326rpx;
  173. margin-top: 20rpx;
  174. }
  175. &-title{
  176. margin-top: 58rpx;
  177. &-left{
  178. width: 170rpx;
  179. height: 44rpx;
  180. padding-left: 2rpx;
  181. font-family: PingFang-SC, PingFang-SC;
  182. font-weight: 800;
  183. font-size: 36rpx;
  184. color: #151B29;
  185. line-height: 36rpx;
  186. background-image: url('https://transcend.ringzle.com/xiaozhi-app/profile/2025/09/11/6ec1f999-fcbb-4a0b-a1a5-d0b5e1374bb1.png');
  187. background-size: 170rpx 31rpx;
  188. background-position: 0 20rpx;
  189. background-repeat: no-repeat;
  190. }
  191. &-right{
  192. font-family: PingFangSC, PingFang SC;
  193. font-weight: 400;
  194. font-size: 28rpx;
  195. color: #676775;
  196. line-height: 33rpx;
  197. }
  198. }
  199. &-type{
  200. width: 100%;
  201. height: 68rpx;
  202. margin-top: 31rpx;
  203. .cl_item{
  204. width: 152rpx;
  205. height: 68rpx;
  206. background: #FFFFFF;
  207. border-radius: 34rpx;
  208. font-family: PingFangSC, PingFang SC;
  209. font-weight: 400;
  210. font-size: 28rpx;
  211. color: #676775;
  212. line-height: 68rpx;
  213. text-align: center;
  214. &.active{
  215. background: #B7F358;
  216. font-weight: bold;
  217. font-size: 30rpx;
  218. color: #151B29;
  219. }
  220. }
  221. }
  222. &-list{
  223. width: 100%;
  224. flex: 1;
  225. overflow-y: auto;
  226. }
  227. }
  228. }
  229. </style>