Commit 1b350af8 by 李伟康

feat(OrderPopup): 实现搜索功能并优化展示逻辑

- 在 CarModelList 组件中添加搜索功能,根据输入值过滤车型列表
- 优化 EmployeeList 组件的搜索逻辑
- 在弹窗顶部添加清空搜索框的功能
- 调整搜索结果的展示样式,优化用户体验
1 parent 8fe8604c
......@@ -5,7 +5,7 @@
scroll-y
:scroll-into-view="letter"
>
<template v-for="(i, index) in list">
<template v-for="(i, index) in (searchStatus ? searchList : list)">
<view
class="item-box"
:key="index"
......@@ -18,27 +18,20 @@
:key="cindex"
>
<view class="brand-name">{{c.name}}</view>
<template v-for="(j, jindex) in c.childs">
<view class="brand-list">
<template v-for="(j, jindex) in c.childs_list">
<view
class="brand-list"
:key="jindex"
>
<view class="sub-brand-name">{{j.name}}</view>
<view class="car-model-list">
<template v-for="(k, kindex) in j.childs">
<view
:class="['item flex',{
active: currentId ? k.id == currentId : k.id == data.customer[params.idKey]
}]"
:key="`${k.id}_${kindex}`"
@click="choose(k , c)"
>{{k.name}}</view>
:class="[
{'sub-brand-name':j.isTitle},
{'item flex':!j.isTitle},
{active: currentId ? j.id == currentId : j.id == data.customer[params.idKey]}
]"
@click="choose(j,c)"
>{{j.name}}</view>
</template>
</view>
</view>
</template>
</view>
</template>
</view>
......@@ -67,7 +60,8 @@ export default {
list: [],
currentId: '',
searchList: [],
letter: 'A'
letter: 'A',
searchStatus: false,
}
},
props: {
......@@ -78,11 +72,12 @@ export default {
mounted () {
},
methods: {
async getList () {
async getList (searchValue) {
const { userInfo, apiData } = this
this.currentId = ''
if (apiData && apiData.length) {
this.list = apiData
if (searchValue) this.handleSearch(searchValue)
return
}
const { shopMerchantId } = userInfo,
......@@ -129,14 +124,55 @@ export default {
list,
}
})
console.log(carModelList)
this.list = carModelList
this.$emit('update:apiData', carModelList)
},
handleSearch (searchValue) {
console.log(searchValue)
if (!searchValue) {
this.searchStatus = false
this.letter = 'A'
} else {
searchValue = searchValue.toUpperCase()
let { list } = this,
carBrand = JSON.parse(JSON.stringify(list))
let arr = [];
carBrand.map(c => {
c.list.map(i => {
let childs_list = [],
i_name = i.name.toUpperCase()
i.childs_list.map((k) => {
let k_name = k.name.toUpperCase()
if (k_name.indexOf(searchValue) != -1) {
childs_list.push(k);
}
});
if (i_name.indexOf(searchValue) != -1 || childs_list.length > 0) {
i.childs_list = childs_list.length > 0 ? childs_list : i.childs_list;
arr.push(i);
}
})
})
let letterList = Array.from(new Set([...arr.map((e) => e.letter)]));
let searchList = letterList.map((l) => {
let _list = [];
arr.map((i) => {
if (l === i.letter) {
_list.push(i);
}
})
return {
letter: l,
list: _list,
}
})
this.searchList = searchList
this.searchStatus = true
}
},
choose (that, item) {
if (that.isTitle) return
let chooseItem = {
carBrandId: item.id,
carBrand: item.name,
......@@ -186,22 +222,26 @@ export default {
color: #333333;
font-size: 32rpx;
line-height: 44rpx;
margin-top: 16rpx;
margin: 16rpx 0;
}
.sub-brand-name {
margin: 16rpx 0;
color: #888888;
font-size: 28rpx;
line-height: 40rpx;
width: 100%;
flex-shrink: 0;
}
}
}
.car-model-list {
display: grid;
grid-template-columns: repeat(4, 1fr);
.brand-list {
// display: grid;
// grid-template-columns: repeat(4, 1fr);
gap: 32rpx;
display: flex;
// gap: 32rpx 0;
flex-wrap: wrap;
.item {
width: calc((100% - 96rpx) / 4);
justify-content: center;
height: 72rpx;
border-radius: 8rpx;
......
......@@ -34,7 +34,7 @@ export default {
async getList (searchValue) {
const { userInfo, params, apiData } = this
this.currentId = ''
if (apiData && apiData.length) {
if (!searchValue && apiData && apiData.length) {
this.list = apiData
return
}
......
/**
* popupType
* 0:销售顾问/录单员
* 1:交付专员
* 2:二级流量方
......
......@@ -29,7 +29,16 @@
confirm-type="search"
@confirm="handleSearch"
>
<view
class="clear flex"
@click="clear"
>
<uni-icons
type="closeempty"
size="16"
v-if="searchValue"
></uni-icons>
</view>
</view>
</template>
<view :class="['popup-body',{ 'hide-search' :componentObject.hideSearch}]">
......@@ -43,7 +52,7 @@
:data="data"
ref="componentRef"
@choose="chooseContent = $event"
:apiData.sync="apiData"
:apiData.sync="componentObject.apiData"
></component>
</scroll-view>
......@@ -103,7 +112,6 @@ export default {
position: 'bottom',
searchValue: '',
chooseContent: null,
apiData: null
}
},
watch: {
......@@ -146,7 +154,7 @@ export default {
initPopupData () {
let componentRef = this.componentRef()
if (!componentRef) setTimeout(this.initPopupData, .1e3)
else componentRef.getList && componentRef.getList()
else componentRef.getList && componentRef.getList(this.searchValue)
},
handleSearch () {
let componentRef = this.componentRef()
......@@ -157,11 +165,18 @@ export default {
else componentRef.handleSearch(this.searchValue)
},
confirm () {
let { chooseContent } = this
let { chooseContent, popupType } = this
if (chooseContent) {
this.$emit('onConfirm', chooseContent)
this.$emit('onConfirm', {
chooseContent,
popupType
})
this.$refs.popup.close()
}
},
clear(){
this.searchValue = ''
this.handleSearch()
}
}
......@@ -195,6 +210,7 @@ export default {
border-radius: 40rpx;
background: #f5f7fa;
margin: 0 48rpx;
position: relative;
.input {
height: 100%;
width: 100%;
......@@ -212,13 +228,20 @@ export default {
&::after {
display: block;
content: '\e654';
margin-left: 16rpx;
margin-left: 8rpx;
height: 100%;
display: flex;
align-items: center;
font-size: 36rpx;
}
}
.clear {
position: absolute;
right: 0;
top: 0;
height: 100%;
padding: 0 48rpx;
}
}
.popup-body {
height: calc(100% - 392rpx);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!