home.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. })
  145. queryParams.value.page++;
  146. if(res.data.list.length===0) isOver.value = true;
  147. })
  148. }
  149. const calculateCountdown = (datetime) => {
  150. if(!datetime) return -1;
  151. const targetDate = new Date(datetime);
  152. const now = new Date();
  153. const difference = targetDate.getTime() - now.getTime();
  154. if (difference <= 0) return -1;
  155. const days = Math.floor(difference / (1000 * 60 * 60 * 24));
  156. const hours = Math.floor((difference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  157. const minutes = Math.floor((difference % (1000 * 60 * 60)) / (1000 * 60));
  158. return {
  159. days,
  160. hours,
  161. minutes
  162. };
  163. }
  164. watch(()=>userStore.token,(newVal,oldVal)=>{
  165. if(oldVal!=newVal&&newVal){
  166. setTimeout(()=>{
  167. uni.showToast({
  168. title: '登录成功',
  169. icon: 'success'
  170. });
  171. },200)
  172. nextTick(()=>{
  173. getActivityList()
  174. })
  175. }
  176. })
  177. onMounted(()=>{
  178. if(uni.getStorageSync('userInfo')){
  179. queryParams.value.userId = JSON.parse(uni.getStorageSync('userInfo'))?.id;
  180. }
  181. getSwiperList()
  182. getTypeList()
  183. getActivityList()
  184. })
  185. </script>
  186. <style scoped lang="scss">
  187. ::v-deep .indicator__dot{
  188. width: 48rpx;
  189. height: 4rpx;
  190. background: #E2E5E9;
  191. border-radius: 2rpx;
  192. margin: 0 8rpx;
  193. }
  194. ::v-deep .indicator__dot--active{
  195. width: 48rpx;
  196. height: 4rpx;
  197. background: #00AE57;
  198. border-radius: 2rpx;
  199. }
  200. ::v-deep .u-swiper__wrapper__item__wrapper__image{
  201. border-radius: 24rpx !important;
  202. }
  203. .scroll-view_H {
  204. white-space: nowrap;
  205. width: 100%;
  206. }
  207. .scroll-view-item_H {
  208. display: inline-block;
  209. width: 152rpx;
  210. height: 100%;
  211. margin-left: 20rpx;
  212. &:first-child{
  213. margin-left: 0;
  214. }
  215. }
  216. .tab_page{
  217. .c-box{
  218. width: 100%;
  219. height: 100%;
  220. overflow-y: auto;
  221. position: relative;
  222. &-lunbo{
  223. width: 100%;
  224. height: 326rpx;
  225. margin-top: 20rpx;
  226. }
  227. &-title{
  228. margin-top: 58rpx;
  229. &-left{
  230. width: 170rpx;
  231. height: 44rpx;
  232. padding-left: 2rpx;
  233. font-family: PingFang-SC, PingFang-SC;
  234. font-weight: 800;
  235. font-size: 36rpx;
  236. color: #151B29;
  237. line-height: 36rpx;
  238. background-image: url('https://oss.familydaf.cn/sxsnfile/20251218/6198fa26a7ff4fc1bce530fbdfaa20db.png');
  239. background-size: 170rpx 31rpx;
  240. background-position: 0 20rpx;
  241. background-repeat: no-repeat;
  242. }
  243. &-right{
  244. font-family: PingFangSC, PingFang SC;
  245. font-weight: 400;
  246. font-size: 28rpx;
  247. color: #676775;
  248. line-height: 33rpx;
  249. }
  250. }
  251. &-type{
  252. width: 100%;
  253. height: 68rpx;
  254. margin-top: 31rpx;
  255. .cl_item{
  256. width: 152rpx;
  257. height: 68rpx;
  258. background: #FFFFFF;
  259. border-radius: 34rpx;
  260. font-family: PingFangSC, PingFang SC;
  261. font-weight: 400;
  262. font-size: 28rpx;
  263. color: #676775;
  264. line-height: 68rpx;
  265. text-align: center;
  266. &.active{
  267. background: #B7F358;
  268. font-weight: bold;
  269. font-size: 30rpx;
  270. color: #151B29;
  271. }
  272. }
  273. }
  274. &-list{
  275. width: 100%;
  276. flex: 1;
  277. overflow-y: auto;
  278. margin-top: 20rpx;
  279. }
  280. }
  281. }
  282. </style>