emis-sapp/components/tpx-search/tpx-search.vue

99 lines
1.9 KiB
Vue
Raw Normal View History

2023-12-06 10:37:54 +00:00
<template>
2023-12-06 11:54:44 +00:00
<view class="sch-cont">
<view>
<u-input shape="circle" :placeholder="placeholder" v-model="keyword" :custom-style="`background-color: ${bgColor};height: ${height}rpx;`"
@focus="handleSwitchFouce()" @blur="handleSwitchFouce()" @confirm="triggerChange()" @change="handleChange()">
<!-- <template v-slot:prefix>
<u-icon name="search" size="32"></u-icon>
</template> -->
<template v-slot:suffix>
<u-row>
<view v-if="focused && keyword.length > 0" style="0 20rpx 0 0">
<u-icon @click="handleClear()" color="#999" name="close-circle-fill" size="36"></u-icon>
</view>
<view>
<u-icon @click="triggerChange()" name="search" size="40" margin="0 0 0 20rpx"></u-icon>
</view>
</u-row>
<!-- <u-button type="primary" shape="circle" custom-style="margin:0;height: 50rpx;">搜索</u-button> -->
</template>
</u-input>
</view>
2023-12-06 10:37:54 +00:00
</view>
</template>
<script>
export default {
props: {
2023-12-06 11:54:44 +00:00
timelyTrigger: {
2023-12-06 10:37:54 +00:00
default () {
2023-12-06 11:54:44 +00:00
return true
2023-12-06 10:37:54 +00:00
}
},
2023-12-06 11:54:44 +00:00
placeholder: {
2023-12-06 10:37:54 +00:00
default () {
return ''
}
},
2023-12-06 11:54:44 +00:00
bgColor: {
2023-12-06 10:37:54 +00:00
default () {
2023-12-06 11:54:44 +00:00
return '#f2f2f2'
2023-12-06 10:37:54 +00:00
}
2023-12-06 11:54:44 +00:00
},
height: {
default () {
return 50
}
},
value: {
default () {
return ''
}
},
2023-12-06 10:37:54 +00:00
},
data() {
return {
2023-12-06 11:54:44 +00:00
focused: false,
keyword: this.value
2023-12-06 10:37:54 +00:00
}
},
created() {
},
onHide() {
},
destroyed() {},
methods: {
2023-12-06 11:54:44 +00:00
handleSwitchFouce() {
setTimeout(()=> {
this.focused = !this.focused
}, 100)
},
handleChange() {
if(this.timelyTrigger) {
this.triggerChange()
}
},
handleClear( ) {
debugger
this.keyword = ''
this.triggerChange()
},
triggerChange() {
let val = this.keyword
this.$emit('change', val)
this.$emit('update:value', val)
2023-12-06 10:37:54 +00:00
}
}
}
</script>
<style scoped lang="scss">
2023-12-06 11:54:44 +00:00
.sch-cont{
2023-12-06 10:37:54 +00:00
position: relative;
}
</style>