hookehuyr

✨ feat(爱心书籍列表页): 新增书籍列表搜索功能

...@@ -117,6 +117,7 @@ watch( ...@@ -117,6 +117,7 @@ watch(
117 } 117 }
118 } 118 }
119 ) 119 )
120 +/**************************************************/
120 </script> 121 </script>
121 122
122 <style lang="less" scoped> 123 <style lang="less" scoped>
......
...@@ -37,8 +37,13 @@ ...@@ -37,8 +37,13 @@
37 <div class="ding right" /> 37 <div class="ding right" />
38 </div> 38 </div>
39 <div class="book-list"> 39 <div class="book-list">
40 + <!-- NOTICE: 新增搜索功能,需要时放出 -->
41 + <!-- <van-sticky>
42 + <van-search v-model="search_value" placeholder="请输入书籍名称" @search="onSearch" />
43 + </van-sticky> -->
40 <template v-for="(item, key) in kgInfo.book_list" :key="key"> 44 <template v-for="(item, key) in kgInfo.book_list" :key="key">
41 - <book-card :type="USER_ROLE.CLIENT" :item="item" @on-click="go('/client/bookDetail', { id: item.id, kg_id })" /> 45 + <book-card v-if="item.show" :type="USER_ROLE.CLIENT" :item="item"
46 + @on-click="go('/client/bookDetail', { id: item.id, kg_id })" />
42 </template> 47 </template>
43 <van-empty v-if="emptyStatus" class="custom-image" :image="no_image" description="暂无书籍信息" /> 48 <van-empty v-if="emptyStatus" class="custom-image" :image="no_image" description="暂无书籍信息" />
44 </div> 49 </div>
...@@ -57,7 +62,7 @@ import { useGo } from '@/hooks/useGo'; ...@@ -57,7 +62,7 @@ import { useGo } from '@/hooks/useGo';
57 import { killPages, store } from '@/hooks/useKeepAlive'; 62 import { killPages, store } from '@/hooks/useKeepAlive';
58 import { Cookies } from '@/utils/generatePackage.js' 63 import { Cookies } from '@/utils/generatePackage.js'
59 import { DonateBar } from '@/utils/generateModules.js' 64 import { DonateBar } from '@/utils/generateModules.js'
60 -import { computed, ref } from 'vue' 65 +import { computed, ref, watch } from 'vue'
61 import { USER_ROLE, USER_TYPE } from '@/constant' 66 import { USER_ROLE, USER_TYPE } from '@/constant'
62 67
63 const go = useGo(); 68 const go = useGo();
...@@ -81,6 +86,27 @@ const userType = Cookies.get('userType') ...@@ -81,6 +86,27 @@ const userType = Cookies.get('userType')
81 const donateType = computed(() => { 86 const donateType = computed(() => {
82 return userType === 'client' ? USER_TYPE.KINDERGARTEN : USER_TYPE.VISIT; 87 return userType === 'client' ? USER_TYPE.KINDERGARTEN : USER_TYPE.VISIT;
83 }) 88 })
89 +
90 +/********************* 搜索功能栏 **********************/
91 +const search_value = ref('')
92 +const onSearch = () => { // 前端过滤搜索结果
93 + kgInfo.value.book_list.forEach(item => {
94 + if (item.name.indexOf(search_value.value) === -1) {
95 + item.show = false;
96 + }
97 + });
98 +}
99 +watch(
100 + search_value,
101 + (v) => {
102 + if (!v) {
103 + kgInfo.value.book_list.forEach(item => {
104 + item.show = true;
105 + });
106 + }
107 + }
108 +)
109 +/**************************************************/
84 </script> 110 </script>
85 111
86 <style lang="less" scoped> 112 <style lang="less" scoped>
......