Ver Fonte

小程序接口联调修改

S0025136190 há 9 meses atrás
pai
commit
9860ec795e

+ 16 - 4
src/apis/index.ts

@@ -6,6 +6,12 @@ export type LoginApiParams = {
   password: string,
 };
 
+export type pageInfoFacApiParams = {
+  pageNum: number,
+  pageSize: number,
+  dictType: String,
+};
+
 export type pageInfoApiParams = {
   pageNum: number,
   pageSize: number,
@@ -15,10 +21,11 @@ export type pageInfoApiParams = {
 export type LoginApi = (data: LoginApiParams) => Promise<any>;
 export type LogoutApi = () => Promise<any>;
 export type SwiperImageApi = () => Promise<any>;
-export type HouseListApi = () => Promise<any>;
+export type HouseListApi = (data: pageInfoApiParams) => Promise<any>;
 export type HouseDetailApi = (id: string) => Promise<any>;
 export type FacilitiesListApi = (data: pageInfoApiParams) => Promise<any>;
 export type FacilitiesDetailApi = (id: string) => Promise<any>;
+export type RegionDataApi = (data: pageInfoFacApiParams) => Promise<any>;
 
 // 登录
 const loginApi: LoginApi = async (data) => {
@@ -36,8 +43,8 @@ const swiperImageApi: SwiperImageApi = async () => {
 };
 
 // 房型列表
-const houseListApi: HouseListApi = async () => {
-  return api.get('/system/room/wxlist?pageNum=1&pageSize=10');
+const houseListApi: HouseListApi = async (data) => {
+  return api.get('/system/room/wxlist', data);
 };
 
 // 房型详情
@@ -55,6 +62,11 @@ const facilitiesDetailApi: FacilitiesDetailApi = async (id) => {
   return api.get(`/system/facilities/${id}`);
 };
 
+// 区域数据
+const regionDataApi: RegionDataApi = async (data) => {
+  return api.get('/system/dict/data/list', data);
+};
+
 export const apis = {
   login: loginApi,
   logout: logoutApi,
@@ -63,5 +75,5 @@ export const apis = {
   houseDetail: houseDetailApi,
   facilitiesList: facilitiesListApi,
   facilityDetail: facilitiesDetailApi,
-
+  regionList: regionDataApi,
 };

+ 1 - 5
src/pages/facility/houseDetail/index.vue

@@ -91,7 +91,6 @@ const api = {
       title: '加载中',
     });
     try {
-      console.log('1');
       const res = await apis.houseDetail(state.id);
       if(res.code === 200){
         const data = res.data;
@@ -108,9 +107,7 @@ const api = {
         });
 
         const regionData = data.region;  // 区域list
-        console.log(regionData, 'regionData');
         regionData.forEach((item1: any) => {
-          console.log(item1.sysimg, 'item1');
           state.areaList.push({
             title: item1.regionTitle,
             content: item1.regionDesc,
@@ -133,7 +130,6 @@ const api = {
     });
     try {
       const res = await apis.facilityDetail(state.id);
-      console.log(res, 'res');
       if(res.code === 200){
         const data = res.data;
         state.detail = {  // 设施详情
@@ -161,7 +157,7 @@ const init = async () => {
     title: '加载中',
   });
   
-  if(state.type === '2'){
+  if(state.type !== '' && state.type !== undefined){
     // 获取设施详情
     await api.facilityDetail();
   }else{

+ 57 - 49
src/pages/facility/index/index.vue

@@ -11,8 +11,8 @@
             </view>
           </template>
         </wd-search>
-        <wd-tabs slidable="always" v-model="state.tab">
-          <wd-tab v-for="(item, index) in tabList" :key="index" :title="item.name" />
+        <wd-tabs slidable="always" v-model="state.tab" @click="onclickFacilityList()">
+          <wd-tab v-for="(item, index) in state.tabList" :key="index" :title="item.name" />
         </wd-tabs>
         <wd-drop-menu>
           <wd-drop-menu-item v-model="state.dropMenu" :options="state.dropMenuList" />
@@ -49,9 +49,10 @@
 import { reactive } from 'vue';
 import { onShow, onReachBottom, onLoad } from '@dcloudio/uni-app';
 import { apis } from '@/apis';
+import { s } from 'vite/dist/node/types.d-aGj9QkWt';
 
 interface State {
-  tab: number,
+  tab: string,
   dropMenu: string,
   dropMenuList: {
     label: string,
@@ -70,10 +71,16 @@ interface State {
     pageSize: number,
     total: number,
   },
+  tabList: [
+    {
+      name: '',
+      id: '',
+    }
+  ]
 };
 
 const state: State = reactive({
-  tab: 0,
+  tab: '0',
   dropMenu: '1',
   dropMenuList: [
     {
@@ -88,40 +95,17 @@ const state: State = reactive({
   list: [],
   page: {
     pageNumber: 1,
-    pageSize: 10,
+    pageSize: 20,
     total: 0,
   },
+  tabList: [{
+    name: '',
+    id: '',
+  }],
 });
 
-const tabList = [
-  {
-    name: '户型',
-  },
-  {
-    name: '全屋',
-  },
-  {
-    name: '客厅',
-  },
-  {
-    name: '卧室',
-  },
-  {
-    name: '卫生间',
-  },
-  {
-    name: '厨房',
-  },
-  {
-    name: '餐厅',
-  },
-  {
-    name: '阳台',
-  }
-];
-
 const api = {
-  // 获取列表
+  // 获取设施列表
   fetchList: async (concat?: boolean) => {
     uni.showLoading({
       title: '加载中',
@@ -130,32 +114,52 @@ const api = {
       const data = {
         pageNum: state.page.pageNumber,
         pageSize: state.page.pageSize,
+        dictType: state.tab,
       };
       const res = await apis.facilitiesList(data);
-      res.rows.forEach((item: any) => {
-        state.list.push({
+      const list = res.rows.map((item: any) => {
+        return {
           id: item.facilitiesId,
           url: item.sysimg[0].url,
-          sign: '9 | 深色大理石',
+          sign: '',
           title: item.facilitiesTitle,
           content: item.facilitiesDesc,
           date: item.createTime,
-        });
+        };
       });
-      // const list = res.rows;
-      // state.list = concat ? state.list.concat(list) : list;
-      console.log(state.list, 'item.sysimg[0].url');
+      state.list= concat ? state.list.concat(list) : list;
       state.page = {
         ...state.page,
         total: res.total,
       };
-      uni.hideLoading();
     } catch (error: any) {
       console.error(error);
     } finally {
       uni.hideLoading();
     }
   },
+
+  //获取区域列表
+  fetchRegionList: async () => {
+    try {
+      const data = {
+        pageNum: state.page.pageNumber,
+        pageSize: state.page.pageSize,
+        dictType: 'region_type',
+      };
+      const res = await apis.regionList(data);
+      if (res.code === 200) {
+        res.rows.forEach((item: any) => {
+          state.tabList.push({
+            name: item.dictLabel,
+            id: item.dictValue,
+          });
+        });
+      }
+    } catch (error: any) {
+      console.error(error);
+    }
+  }
 }
 
 const init = async () => {
@@ -164,6 +168,7 @@ const init = async () => {
   });
   // 获取列表
   await api.fetchList();
+  await api.fetchRegionList();
   uni.hideLoading();
 };
 
@@ -179,7 +184,7 @@ const onChangePagination = async () => {
   }
 }
 
-onLoad(() => {
+onShow(() => {
   state.page = {
     ...state.page,
     pageNumber: 1,
@@ -187,20 +192,23 @@ onLoad(() => {
   init();
 });
 
-onShow(() => {
-  
-});
-
 onReachBottom(() => {
+  console.log('触发分页');
+
   onChangePagination();
 });
 
 // 点击跳转
-const onClickNavigate = (id: string, type: string) => {
+const onClickNavigate = (id: string) => {
   uni.navigateTo({
-    url: `/pages/facility/houseDetail/index?id=${id}&type=${2}`,
+    url: `/pages/facility/houseDetail/index?id=${id}&type=${state.tab}`,
   });
 }
+
+const onclickFacilityList = async () => {
+  state.list = [];
+  api.fetchList();
+}
 </script>
 
 <style lang="scss" scoped>
@@ -253,7 +261,7 @@ const onClickNavigate = (id: string, type: string) => {
 
       &-text {
         width: 100%;
-        height: 300rpx;
+        max-height: 300rpx;
         color: $gray-color;
         overflow: hidden;
         margin-bottom: 10rpx;

+ 55 - 16
src/pages/home/index/index.vue

@@ -7,7 +7,7 @@
     </view>
     <view>
       <!-- @click="onClickSwiper" -->
-      <wd-swiper :autoplay="true" :list="state.swiperList"  />
+      <wd-swiper :autoplay="true" :list="state.swiperList" />
     </view>
     <view class="home-menu">
       <view class="home-menu-item" v-for="(item, index) in menuList" :key="index">
@@ -68,6 +68,11 @@ interface State {
     content: string,
     date: string,
   }[],
+  page: {
+    pageNumber: number,
+    pageSize: number,
+    total: number,
+  },
 };
 
 const state: State = reactive({
@@ -88,6 +93,11 @@ const state: State = reactive({
   ],
   swiperList: [],
   houseList: [],
+  page: {
+    pageNumber: 1,
+    pageSize: 2,
+    total: 0,
+  },
 });
 
 const menuList = [
@@ -130,35 +140,64 @@ const api = {
     res.rows.forEach((item: any) => {
       state.swiperList.push(item.url);
     });
-    
+
   },
 
   fetchHouseList: async () => {
-    const res = await apis.houseList();
-    res.rows.forEach((item: any) => {
-      state.houseList.push({
-        id: item.roomId,
-        url: item.sysimg[0].url,
-        title: item.roomTitle,
-        content: item.roomDesc,
-        date: item.createTime,
-      });
+    uni.showLoading({
+      title: '加载中',
     });
+    try {
+      const data = {
+        pageNum: state.page.pageNumber,
+        pageSize: state.page.pageSize,
+      };
+      const res = await apis.houseList(data);
+      const list = res.rows.map((item: any) => {
+        return {
+          id: item.roomId,
+          url: item.sysimg[0].url,
+          title: item.roomTitle,
+          content: item.roomDesc,
+          date: item.createTime,
+        }
+      });
+      state.houseList = list.slice(0,2);
+    } catch (error) {
+      console.error(error);
+    } finally {
+      uni.hideLoading();
+    }
   }
 }
 
 const init = () => {
+  uni.showLoading({
+    title: '加载中',
+  });
   api.fetchImgsList(); //轮播图集合
   api.fetchHouseList();//房型集合
 };
 
-onShow(() => {
-  
-});
+const onChangePagination = async () => {
+  const { pageNumber, pageSize, total } = state.page;
+  if (total > pageNumber * pageSize) {
+    state.page = {
+      ...state.page,
+      pageNumber: pageNumber + 1,
+    }
+    // 获取列表
+    await api.fetchHouseList();
+  }
+}
 
-onLoad(() => {
+onShow(() => {
+  state.page = {
+    ...state.page,
+    pageNumber: 1,
+  };
   init();
-})
+});
 
 // 点击轮播
 const onClickSwiper = () => {