home.vue 9.2 KB

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