Files
Smart-Farm/uniapp/uni-app/home/pages/welfare.vue
2025-12-22 17:13:05 +08:00

146 lines
3.2 KiB
Vue

<template>
<view class="home-welfare">
<fixed>
<view class="fill-base pt-big pb-big pl-md pr-md">
<search @input="toSearch" type="input" :padding="0" :radius="70"
:placeholder="`搜索${placeholder[options.type]}名称`"></search>
</view>
</fixed>
<block v-for="(item,index) in list.data" :key="index">
<view @tap.stop="goDetail(index)"
class="welfare-item flex-center mt-md ml-md mr-md pd-lg fill-base radius-16">
<image mode="aspectFill" lazy-load class="cover radius-16" :src="item.cover"></image>
<view class="flex-1 ml-lg">
<view class="f-title c-title text-bold mb-md ellipsis">{{item.title}}
</view>
<view class="f-caption c-caption">{{item.create_time_text}}</view>
</view>
</view>
</block>
<load-more :noMore="list.current_page>=list.last_page&&list.data.length>0" :loading="loading" v-if="loading">
</load-more>
<abnor v-if="!loading&&list.data.length<=0&&list.current_page==1"></abnor>
<view class="space-footer"></view>
</view>
</template>
<script>
import {
mapState,
mapActions,
mapMutations
} from "vuex"
export default {
components: {},
data() {
return {
options: {},
placeholder: {
1: '栏目',
2: '公告',
},
param: {
page: 1,
type: 1 //1公益栏目 2系统公告 3运营公告
},
list: {
data: []
},
loading: true,
lockTap: false,
}
},
computed: mapState({
primaryColor: state => state.config.configInfo.primaryColor,
subColor: state => state.config.configInfo.subColor,
userInfo: state => state.user.userInfo,
location: state => state.user.location,
}),
async onLoad(options) {
let {
type = 1
} = options
options.type = type
this.$util.showLoading()
this.options = options
this.param.type = type
await this.initIndex()
uni.setNavigationBarTitle({
title: type === 1 ? '公益栏目' : '系统公告'
})
},
onPullDownRefresh() {
// #ifndef APP-PLUS
uni.showNavigationBarLoading()
// #endif
this.initRefresh()
uni.stopPullDownRefresh()
},
onReachBottom() {
if (this.list.current_page >= this.list.last_page || this.loading) return
this.param.page = this.param.page + 1
this.loading = true
this.getList()
},
methods: {
...mapActions(['getConfigInfo']),
...mapMutations(['updateUserItem']),
async initIndex() {
this.getList()
},
initRefresh() {
this.param.page = 1
this.initIndex()
},
toSearch(val) {
this.loading = true
this.param.page = 1
this.param.title = val
this.getList()
},
async getList() {
let {
list: oldList,
param,
} = this
let newList = await this.$api.home.welfareColumnList(param)
if (this.param.page == 1) {
this.list = newList
} else {
newList.data = oldList.data.concat(newList.data)
this.list = newList
}
this.loading = false
this.$util.hideAll()
},
async goDetail(index) {
let {
id
} = this.list.data[index]
let url = `/home/pages/article?id=${id}&type=2`
this.$util.goUrl({
url
})
}
}
}
</script>
<style lang="scss">
.home-welfare {
.welfare-item {
.cover {
width: 180rpx;
height: 160rpx;
}
.ellipsis {
max-width: 440rpx;
}
}
}
</style>