home.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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></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, nextTick, 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,oldVal)=>{
  144. if(oldVal!=newVal&&newVal){
  145. setTimeout(()=>{
  146. uni.showToast({
  147. title: '登录成功',
  148. icon: 'success'
  149. });
  150. },200)
  151. nextTick(()=>{
  152. getActivityList('')
  153. })
  154. }
  155. })
  156. onMounted(()=>{
  157. getSwiperList()
  158. getTypeList()
  159. getActivityList('')
  160. })
  161. </script>
  162. <style scoped lang="scss">
  163. ::v-deep .indicator__dot{
  164. width: 48rpx;
  165. height: 4rpx;
  166. background: #E2E5E9;
  167. border-radius: 2rpx;
  168. margin: 0 8rpx;
  169. }
  170. ::v-deep .indicator__dot--active{
  171. width: 48rpx;
  172. height: 4rpx;
  173. background: #00AE57;
  174. border-radius: 2rpx;
  175. }
  176. .scroll-view_H {
  177. white-space: nowrap;
  178. width: 100%;
  179. }
  180. .scroll-view-item_H {
  181. display: inline-block;
  182. width: 152rpx;
  183. height: 100%;
  184. margin-left: 20rpx;
  185. &:first-child{
  186. margin-left: 0;
  187. }
  188. }
  189. .tab_page{
  190. .c-box{
  191. width: 100%;
  192. height: 100%;
  193. overflow-y: auto;
  194. position: relative;
  195. &-lunbo{
  196. width: 100%;
  197. height: 326rpx;
  198. margin-top: 20rpx;
  199. }
  200. &-title{
  201. margin-top: 58rpx;
  202. &-left{
  203. width: 170rpx;
  204. height: 44rpx;
  205. padding-left: 2rpx;
  206. font-family: PingFang-SC, PingFang-SC;
  207. font-weight: 800;
  208. font-size: 36rpx;
  209. color: #151B29;
  210. line-height: 36rpx;
  211. background-image: url('https://oss.familydaf.cn/sxsnfile/20251218/6198fa26a7ff4fc1bce530fbdfaa20db.png');
  212. background-size: 170rpx 31rpx;
  213. background-position: 0 20rpx;
  214. background-repeat: no-repeat;
  215. }
  216. &-right{
  217. font-family: PingFangSC, PingFang SC;
  218. font-weight: 400;
  219. font-size: 28rpx;
  220. color: #676775;
  221. line-height: 33rpx;
  222. }
  223. }
  224. &-type{
  225. width: 100%;
  226. height: 68rpx;
  227. margin-top: 31rpx;
  228. .cl_item{
  229. width: 152rpx;
  230. height: 68rpx;
  231. background: #FFFFFF;
  232. border-radius: 34rpx;
  233. font-family: PingFangSC, PingFang SC;
  234. font-weight: 400;
  235. font-size: 28rpx;
  236. color: #676775;
  237. line-height: 68rpx;
  238. text-align: center;
  239. &.active{
  240. background: #B7F358;
  241. font-weight: bold;
  242. font-size: 30rpx;
  243. color: #151B29;
  244. }
  245. }
  246. }
  247. &-list{
  248. width: 100%;
  249. flex: 1;
  250. overflow-y: auto;
  251. }
  252. }
  253. }
  254. </style>