Commit 1b350af8 by 李伟康

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

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