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

95 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>
2023-12-07 03:22:48 +00:00
<u-input shape="circle" :placeholder="placeholder" v-model="keyword" :custom-style="`background-color: ${bgColor};height: ${height}rpx;${true?'padding-right:120rpx;': ''}`"
2023-12-09 02:13:25 +00:00
font-size="28rpx" placeholder-style="font-size: 28rpx;"
@focus="handleSwitchFouce()" @blur="handleSwitchFouce()" @confirm="triggerChange()" @change="handleChange()">
2023-12-06 11:54:44 +00:00
</u-input>
2023-12-07 03:22:48 +00:00
<u-row justify="end" custom-style="position: absolute;width: 120rpx;top: 0;bottom: 0;right: 20rpx;">
<u-row justify="end" customStyle="height: 100%;width:100%;">
<u-row v-if="focused && keyword.length > 0" @click="handleClear()" justify="end" style="0 20rpx 0 0;height: 100%;flex: 1;">
<u-icon color="#999" name="close-circle-fill" size="36"></u-icon>
</u-row>
<u-row @click="triggerChange()" justify="end" style="height: 100%;flex: 1;">
<u-icon name="search" size="40" margin="0 0 0 20rpx"></u-icon>
</u-row>
</u-row>
</u-row>
2023-12-06 11:54:44 +00:00
</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 () {
2023-12-06 18:53:44 +00:00
return 38
2023-12-06 11:54:44 +00:00
}
},
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( ) {
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>