home.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. proxy.$api.get('/core/activity/page',{page:1,limit:2,categoryId}).then(({data:res})=>{
  97. if(res.code!==0) return proxy.$showToast(res.msg)
  98. activityList.value = res.data.list;
  99. activityList.value.forEach(a=>{
  100. let cc = calculateCountdown(a?.signupEndTime);
  101. a.endTimeText = cc===-1?a?.signupEndTime:(`还有${cc.days}天${cc.hours}小时${cc.minutes}分钟`)
  102. })
  103. })
  104. }
  105. const calculateCountdown = (datetime) => {
  106. if(!datetime) return -1;
  107. const targetDate = new Date(datetime);
  108. const now = new Date();
  109. const difference = targetDate.getTime() - now.getTime();
  110. if (difference <= 0) return -1;
  111. const days = Math.floor(difference / (1000 * 60 * 60 * 24));
  112. const hours = Math.floor((difference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  113. const minutes = Math.floor((difference % (1000 * 60 * 60)) / (1000 * 60));
  114. return {
  115. days,
  116. hours,
  117. minutes
  118. };
  119. }
  120. onMounted(()=>{
  121. getSwiperList()
  122. getTypeList()
  123. getActivityList('')
  124. })
  125. </script>
  126. <style scoped lang="scss">
  127. ::v-deep .indicator__dot{
  128. width: 48rpx;
  129. height: 4rpx;
  130. background: #E2E5E9;
  131. border-radius: 2rpx;
  132. margin: 0 8rpx;
  133. }
  134. ::v-deep .indicator__dot--active{
  135. width: 48rpx;
  136. height: 4rpx;
  137. background: #00AE57;
  138. border-radius: 2rpx;
  139. }
  140. .scroll-view_H {
  141. white-space: nowrap;
  142. width: 100%;
  143. }
  144. .scroll-view-item_H {
  145. display: inline-block;
  146. width: 152rpx;
  147. height: 100%;
  148. margin-left: 20rpx;
  149. &:first-child{
  150. margin-left: 0;
  151. }
  152. }
  153. .tab_page{
  154. .c-box{
  155. width: 100%;
  156. height: 100%;
  157. overflow-y: auto;
  158. position: relative;
  159. &-lunbo{
  160. width: 100%;
  161. height: 326rpx;
  162. margin-top: 20rpx;
  163. }
  164. &-title{
  165. margin-top: 58rpx;
  166. &-left{
  167. width: 170rpx;
  168. height: 44rpx;
  169. padding-left: 2rpx;
  170. font-family: PingFang-SC, PingFang-SC;
  171. font-weight: 800;
  172. font-size: 36rpx;
  173. color: #151B29;
  174. line-height: 36rpx;
  175. background-image: url('https://transcend.ringzle.com/xiaozhi-app/profile/2025/09/11/6ec1f999-fcbb-4a0b-a1a5-d0b5e1374bb1.png');
  176. background-size: 170rpx 31rpx;
  177. background-position: 0 20rpx;
  178. background-repeat: no-repeat;
  179. }
  180. &-right{
  181. font-family: PingFangSC, PingFang SC;
  182. font-weight: 400;
  183. font-size: 28rpx;
  184. color: #676775;
  185. line-height: 33rpx;
  186. }
  187. }
  188. &-type{
  189. width: 100%;
  190. height: 68rpx;
  191. margin-top: 31rpx;
  192. .cl_item{
  193. width: 152rpx;
  194. height: 68rpx;
  195. background: #FFFFFF;
  196. border-radius: 34rpx;
  197. font-family: PingFangSC, PingFang SC;
  198. font-weight: 400;
  199. font-size: 28rpx;
  200. color: #676775;
  201. line-height: 68rpx;
  202. text-align: center;
  203. &.active{
  204. background: #B7F358;
  205. font-weight: bold;
  206. font-size: 30rpx;
  207. color: #151B29;
  208. }
  209. }
  210. }
  211. &-list{
  212. width: 100%;
  213. flex: 1;
  214. overflow-y: auto;
  215. }
  216. }
  217. }
  218. </style>