Selaa lähdekoodia

公告列表增加搜索

Wang-Xiao-Ran 1 vuosi sitten
vanhempi
commit
a26418d8ae
1 muutettua tiedostoa jossa 32 lisäystä ja 5 poistoa
  1. 32 5
      pages/index/announcementList.vue

+ 32 - 5
pages/index/announcementList.vue

@@ -1,5 +1,8 @@
 <template>
 	<view class="list">
+		<view class="selectParam">
+			<uni-search-bar :focus="false" v-model="title"  @input="search" @cancel="cancel"></uni-search-bar>
+		</view>
 		<view v-for="(item, index) in list" :key="item.id" class="item">
 			<img :src="loadImgSrc(`${item.announcementImg}`)" class="avatar" />
 			<view class="info" style="height: 5em;">
@@ -22,13 +25,19 @@ export default {
 			queryParam: {
 				pageNum: 1,
 				pageSize: 10,
+				announcementTitle: '',
 				userId: getApp().globalData.userId
 			},
 			total: null,
-			list: []
+			title:'',
+			list: [],
+			flag: true,
 		};
 	},
 	onLoad() {
+		this.queryParam.pageNum = 1
+		this.queryParam.pageSize = 10
+		this.flag=true
 		this.getAnnoList();
 	},
 	onReachBottom() {
@@ -42,16 +51,34 @@ export default {
 			return;
 		} else {
 			this.queryParam.pageNum += 1;
+			this.flag=true
 			this.getAnnoList();
 		}
 	},
 	methods: {
+		cancel(){
+			this.queryParam.pageNum = 1
+			this.queryParam.pageSize = 10
+			this.queryParam.announcementTitle = ''
+		},
+		search(){
+			this.queryParam.pageNum = 1
+			this.queryParam.pageSize = 10
+			this.queryParam.announcementTitle = this.title
+			this.flag=false
+			this.getAnnoList()
+		},
 		getAnnoList() {
-			console.log(this.queryParam)
 			getList(this.queryParam).then((res) => {
-				this.list = [...this.list,...res.rows]
-				// this.list = res.rows;
-				this.total = res.total;
+				if(this.flag){
+					this.list = [...this.list,...res.rows]
+					// this.list = res.rows;
+					this.total = res.total
+				}else{
+					this.list = res.rows
+					this.total = res.total
+				}
+				
 			});
 		},
 		handleNavigate(item) {