| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- <template>
- <view class="facility">
- <wd-sticky :z-index="10">
- <view class="facility-top">
- <wd-search :placeholder-left="true" placeholder="请输入内容" v-model="state.text">
- <template #suffix>
- <view style="display: flex;align-items: center;margin: 0 20rpx;">
- <view style="margin-right: 20rpx;">
- <wd-button size="small" @click="onClickSearch">
- 搜索
- </wd-button>
- </view>
- <view>
- <wd-button type="info" size="small" @click="onClickReset">
- 重置
- </wd-button>
- </view>
- </view>
- </template>
- </wd-search>
- <wd-tabs slidable="always" v-model="state.tabValue">
- <wd-tab v-for="(item, index) in state.tabList" :title="item.label" :key="index" />
- </wd-tabs>
- </view>
- </wd-sticky>
- <view class="facility-list">
- <view class="facility-list-item" v-for="(item, index) in state.list" :key="index"
- @click="onClickNavigate(item.id)">
- <view class="facility-list-item-sign">
- {{ item.sign }}
- </view>
- <wd-img height="300rpx" mode="heightFix" :src="item.url" />
- <view style="padding: 0 10rpx;">
- <view class="facility-list-item-title">
- {{ item.title }}
- </view>
- <view class="facility-list-item-text">
- {{ item.description }}
- </view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script lang="ts" setup>
- import { reactive } from 'vue';
- import { onShow, onReachBottom } from '@dcloudio/uni-app';
- import { apis } from '@/apis';
- interface State {
- text?: string,
- tabValue?: string,
- tabList: {
- label: string,
- value: string,
- }[],
- list: {
- id: string,
- url: string,
- sign: string,
- title: string,
- description: string,
- }[],
- page: {
- pageNum: number,
- pageSize: number,
- total: number,
- },
- };
- const state = reactive<State>({
- text: undefined,
- tabValue: undefined,
- tabList: [],
- list: [],
- page: {
- pageNum: 1,
- pageSize: 20,
- total: 0,
- },
- });
- const api = {
- // 获取区域列表
- fetchRegionList: async () => {
- try {
- const data = {
- dictType: 'region_type',
- };
- const res = await apis.fetchRegionList(data);
- const list = res.rows.map((item: any) => {
- return {
- label: item.dictLabel,
- value: item.dictValue,
- }
- });
- state.tabValue = list.length ? list[0].value : undefined;
- state.tabList = list;
- } catch (error: any) {
- console.error(error);
- }
- },
- // 获取设施列表
- fetchFacilityList: async (concat?: boolean) => {
- uni.showLoading({
- title: '加载中',
- });
- try {
- const data = {
- facilitiesTitle: state.text,
- dictType: state.tabValue,
- pageNum: state.page.pageNum,
- pageSize: state.page.pageSize,
- };
- const res = await apis.fetchFacilityList(data);
- const list = res.rows.map((item: any) => {
- return {
- id: item.facilitiesId,
- url: item.sysimg[0].url,
- sign: item.facilitiesName,
- title: item.facilitiesTitle,
- description: item.facilitiesDesc,
- };
- });
- state.list = concat ? state.list.concat(list) : list;
- state.page = {
- ...state.page,
- total: res.total,
- };
- } catch (error: any) {
- console.error(error);
- } finally {
- uni.hideLoading();
- }
- },
- }
- const init = async () => {
- uni.showLoading({
- title: '加载中',
- });
- // 获取区域列表
- api.fetchRegionList();
- // 获取设施列表
- api.fetchFacilityList();
- uni.hideLoading();
- };
- onShow(() => {
- state.page = {
- ...state.page,
- pageNum: 1,
- };
- init();
- });
- const onChangePagination = async () => {
- const { pageNum, pageSize, total } = state.page;
- if (total > pageNum * pageSize) {
- state.page = {
- ...state.page,
- pageNum: pageNum + 1,
- }
- // 获取设施列表
- await api.fetchFacilityList(true);
- }
- }
- onReachBottom(() => {
- onChangePagination();
- });
- // 点击搜索
- const onClickSearch = async () => {
- state.page = {
- ...state.page,
- pageNum: 1,
- };
- // 获取设施列表
- await api.fetchFacilityList();
- }
- // 点击重置
- const onClickReset = async () => {
- state.text = undefined;
- state.tabValue = undefined
- state.page = {
- ...state.page,
- pageNum: 1,
- };
- // 获取设施列表
- await api.fetchFacilityList();
- }
- // 点击跳转
- const onClickNavigate = (id: string) => {
- uni.navigateTo({
- url: `/pages/facility/facilityDetail/index?id=${id}`,
- });
- }
- </script>
- <style lang="scss" scoped>
- .facility {
- &-top {
- width: 100vw;
- border-bottom: 2rpx solid $border-color;
- }
- &-list {
- padding: 0 20rpx;
- display: flex;
- flex-wrap: wrap;
- margin-top: 20rpx;
- &-item {
- width: calc(50% - 10rpx);
- background: #F4F4F4;
- border-radius: $border-radius-base;
- margin-bottom: 20rpx;
- position: relative;
- overflow: hidden;
- &-sign {
- width: 85%;
- height: 50rpx;
- padding: 0 10rpx;
- background: rgba(0, 0, 0, 0.4);
- border-top-right-radius: $border-radius-base;
- display: flex;
- align-items: center;
- font-size: $font-size-mini;
- color: #FFFFFF;
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- position: absolute;
- top: 250rpx;
- left: 0;
- z-index: 2;
- }
- &-title {
- font-weight: bold;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 2;
- line-clamp: 2;
- overflow: hidden;
- text-overflow: ellipsis;
- margin-bottom: 10rpx;
- }
- &-text {
- width: 100%;
- max-height: 300rpx;
- color: $gray-color;
- overflow: hidden;
- margin-bottom: 10rpx;
- }
- }
- &-item:nth-child(odd) {
- margin-right: 10rpx;
- }
- &-item:nth-child(even) {
- margin-left: 10rpx;
- }
- }
- }
- </style>
|