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

95 lines
2.0 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-10 17:10:09 +00:00
<u-input shape="circle" :placeholder="placeholder" :modelValue="value" :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;"
2023-12-10 17:10:09 +00:00
@focus="handleSwitchFouce" @blur="handleSwitchFouce" @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%;">
2023-12-10 17:10:09 +00:00
<u-row v-if="focused && value.length > 0" @click="handleClear()" justify="end" style="0 20rpx 0 0;height: 100%;flex: 1;">
2023-12-07 03:22:48 +00:00
<u-icon color="#999" name="close-circle-fill" size="36"></u-icon>
</u-row>
2023-12-16 17:34:29 +00:00
<slot name="rightIcon">
<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>
</slot>
2023-12-07 03:22:48 +00:00
</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,
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)
},
2023-12-10 17:10:09 +00:00
handleChange(val) {
this.triggerChange(val, this.timelyTrigger)
2023-12-06 11:54:44 +00:00
},
handleClear( ) {
2023-12-10 17:10:09 +00:00
this.triggerChange('')
2023-12-06 11:54:44 +00:00
},
2023-12-10 17:10:09 +00:00
triggerChange(val, isTriggerChange = true) {
typeof val == 'undefined' && (val = this.value)
if(isTriggerChange) {
this.$emit('change', val)
}
2023-12-06 11:54:44 +00:00
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>