home.vue 6.9 KB

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