home.vue 6.7 KB

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