home.vue 7.3 KB

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