home.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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/20260105/087c26c68a18424c83763a768a2fd81d.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. <up-list @scrolltolower="scrolltolower" style="height: 100%;">
  48. <up-list-item v-for="(item, index) in activityList" :key="item.id">
  49. <NonprofitActivety :item="item" :index="index"></NonprofitActivety>
  50. </up-list-item>
  51. </up-list>
  52. </view>
  53. <view class="dataEmpty" v-else>
  54. <page-empty></page-empty>
  55. </view>
  56. </view>
  57. <login-register></login-register>
  58. <CusTabbar :tabbarIndex="0"></CusTabbar>
  59. </view>
  60. </template>
  61. <script setup name="">
  62. import CusTabbar from '@/components/CusTabbar/index.vue'
  63. import NonprofitActivety from '@/components/pages/nonprofitActivety/index.vue'
  64. import PageEmpty from '@/components/pageEmpty/index.vue'
  65. import { ref, getCurrentInstance, onMounted, nextTick, watch } from 'vue'
  66. const { proxy } = getCurrentInstance()
  67. import { useUserStore } from '@/common/stores/user';
  68. const userStore = useUserStore();
  69. const bannarList = ref([])
  70. const bannarOrigin = ref([])
  71. const current = ref(0)
  72. const typeList = ref([])
  73. const tlIndex = ref(0)
  74. const scrollLeft = ref(0)
  75. const isOver = ref(false)
  76. const activityList = ref([])
  77. const queryParams = ref({
  78. page:1,
  79. limit:10,
  80. categoryId:'',
  81. userId:''
  82. })
  83. const bannerClick = e => {
  84. let banner = bannarOrigin.value[e];
  85. if(banner&&banner?.redirect){
  86. if(banner?.redirectType==1){//微信公众号
  87. uni.navigateTo({
  88. url:'/pages/webView?src='+banner?.redirect
  89. })
  90. }else if(banner?.redirectType==2){//微信小程序
  91. uni.navigateToMiniProgram({
  92. appId:banner?.redirect
  93. })
  94. }
  95. }
  96. }
  97. const changeType = (item,index) => {
  98. queryParams.value.categoryId = item.id;
  99. tlIndex.value = index;
  100. // if(typeList.value.length>4){
  101. // if(index<3) scrollLeft.value = 0
  102. // else{
  103. // scrollLeft.value = (index-2)*172/2;
  104. // }
  105. // }
  106. initList();
  107. getActivityList();
  108. }
  109. const initList = () => {
  110. queryParams.value.page = 1;
  111. isOver.value = false;
  112. activityList.value = [];
  113. }
  114. const toTurnPage = (url,needLogin) => {
  115. if(!needLogin){
  116. uni.navigateTo({ url })
  117. }
  118. }
  119. const getSwiperList = () => {
  120. proxy.$api.get('/core/advertisement/manage/page',{page:1,limit:-1}).then(({data:res})=>{
  121. if(res.code!==0) return proxy.$showToast(res.msg)
  122. const list = res.data.list.filter(l=>l.enable==1);
  123. bannarOrigin.value = list;
  124. bannarList.value = list.map(l=>l.fileUrl);
  125. })
  126. }
  127. const getTypeList = () => {
  128. proxy.$api.get('/core/activity/category/list').then(({data:res})=>{
  129. if(res.code!==0) return proxy.$showToast(res.msg)
  130. typeList.value = [{id:'',name:'全部'},...res.data.map(d=>({id:d.id,name:d.categoryName}))];
  131. })
  132. }
  133. const scrolltolower = () => {
  134. if(isOver.value) return
  135. getActivityList()
  136. }
  137. const getActivityList = () => {
  138. proxy.$api.get('/core/activity/page',queryParams.value).then(({data:res})=>{
  139. if(res.code!==0) return proxy.$showToast(res.msg)
  140. activityList.value = [...activityList.value,...res.data.list];
  141. activityList.value.forEach(a=>{
  142. let cc = calculateCountdown(a?.signupEndTime);
  143. a.endTimeText = cc===-1?a?.signupEndTime:(`还有${cc.days}天${cc.hours}小时${cc.minutes}分钟`)
  144. a.signupEndTime = a.signupEndTime?new Date(a.signupEndTime).Format('yyyy.MM.dd hh:mm'):''
  145. })
  146. queryParams.value.page++;
  147. if(res.data.list.length===0) isOver.value = true;
  148. })
  149. }
  150. const calculateCountdown = (datetime) => {
  151. if(!datetime) return -1;
  152. const targetDate = new Date(datetime);
  153. const now = new Date();
  154. const difference = targetDate.getTime() - now.getTime();
  155. if (difference <= 0) return -1;
  156. const days = Math.floor(difference / (1000 * 60 * 60 * 24));
  157. const hours = Math.floor((difference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  158. const minutes = Math.floor((difference % (1000 * 60 * 60)) / (1000 * 60));
  159. return {
  160. days,
  161. hours,
  162. minutes
  163. };
  164. }
  165. watch(()=>userStore.token,(newVal,oldVal)=>{
  166. if(oldVal!=newVal&&newVal){
  167. setTimeout(()=>{
  168. uni.showToast({
  169. title: '登录成功',
  170. icon: 'success'
  171. });
  172. },200)
  173. nextTick(()=>{
  174. getActivityList()
  175. })
  176. }
  177. })
  178. onMounted(()=>{
  179. if(uni.getStorageSync('userInfo')){
  180. queryParams.value.userId = JSON.parse(uni.getStorageSync('userInfo'))?.id;
  181. }
  182. getSwiperList()
  183. getTypeList()
  184. getActivityList()
  185. })
  186. </script>
  187. <style scoped lang="scss">
  188. ::v-deep .indicator__dot{
  189. width: 48rpx;
  190. height: 4rpx;
  191. background: #E2E5E9;
  192. border-radius: 2rpx;
  193. margin: 0 8rpx;
  194. }
  195. ::v-deep .indicator__dot--active{
  196. width: 48rpx;
  197. height: 4rpx;
  198. background: #00AE57;
  199. border-radius: 2rpx;
  200. }
  201. ::v-deep .u-swiper__wrapper__item__wrapper__image{
  202. border-radius: 24rpx !important;
  203. }
  204. .scroll-view_H {
  205. white-space: nowrap;
  206. width: 100%;
  207. }
  208. .scroll-view-item_H {
  209. display: inline-block;
  210. // width: 152rpx;
  211. height: 100%;
  212. margin-left: 20rpx;
  213. &:first-child{
  214. margin-left: 0;
  215. }
  216. }
  217. .tab_page{
  218. .c-box{
  219. width: 100%;
  220. height: 100%;
  221. overflow-y: auto;
  222. position: relative;
  223. &-lunbo{
  224. width: 100%;
  225. height: 326rpx;
  226. margin-top: 20rpx;
  227. }
  228. &-title{
  229. margin-top: 58rpx;
  230. &-left{
  231. width: 170rpx;
  232. height: 44rpx;
  233. padding-left: 2rpx;
  234. font-family: PingFang-SC, PingFang-SC;
  235. font-weight: 800;
  236. font-size: 36rpx;
  237. color: #151B29;
  238. line-height: 36rpx;
  239. background-image: url('https://oss.familydaf.cn/sxsnfile/20251218/6198fa26a7ff4fc1bce530fbdfaa20db.png');
  240. background-size: 170rpx 31rpx;
  241. background-position: 0 20rpx;
  242. background-repeat: no-repeat;
  243. }
  244. &-right{
  245. font-family: PingFangSC, PingFang SC;
  246. font-weight: 400;
  247. font-size: 28rpx;
  248. color: #676775;
  249. line-height: 33rpx;
  250. }
  251. }
  252. &-type{
  253. width: 100%;
  254. height: 68rpx;
  255. margin-top: 31rpx;
  256. .cl_item{
  257. // width: 152rpx;
  258. padding: 0 21rpx;
  259. height: 68rpx;
  260. background: #FFFFFF;
  261. border-radius: 34rpx;
  262. font-family: PingFangSC, PingFang SC;
  263. font-weight: 400;
  264. font-size: 28rpx;
  265. color: #676775;
  266. line-height: 68rpx;
  267. text-align: center;
  268. &.active{
  269. background: #B7F358;
  270. font-weight: bold;
  271. font-size: 30rpx;
  272. color: #151B29;
  273. }
  274. }
  275. }
  276. &-list{
  277. width: 100%;
  278. flex: 1;
  279. overflow-y: auto;
  280. margin-top: 20rpx;
  281. }
  282. }
  283. }
  284. </style>