Files
hht-tongbo/components/SearchBox.vue

139 lines
2.8 KiB
Vue
Raw Normal View History

2022-10-12 08:51:05 +08:00
<template>
<view class="search_wraper">
<input
type="text"
class="filter_input search_input"
:value="value"
2023-01-30 16:48:34 +08:00
:focus="focusState"
@blur="handleBlur($event)"
2022-10-12 08:51:05 +08:00
@input="handleChange($event)">
<view class="buttons_wraper">
2023-03-28 10:55:08 +08:00
<view class="iconfont icon_del" @tap="toDel">&#xe6dc;</view>
<view class="iconfont icon_scan" :class="{'icon_scan_active': focusState === true}" @tap="toScan">&#xe6e2;</view>
<view class="iconfont icon_phone" @tap="toPhone">&#xe663;</view>
<view v-show="seaShow" class="iconfont icon_search" @tap="toSearch">&#xe6e1;</view>
2022-10-12 08:51:05 +08:00
</view>
</view>
</template>
<script>
import permision from "@/utils/permission.js"
export default {
data() {
return {
2023-01-30 16:48:34 +08:00
cur: '',
focusState: false
2022-10-12 08:51:05 +08:00
};
},
model: {
prop: 'value',
event: 'input'
},
props: {
value: String,
seaShow: {
2022-12-03 14:31:36 +08:00
type: Boolean,
default: false
},
focused: {
type: Boolean,
default: false
}
2022-10-12 08:51:05 +08:00
},
2023-01-30 16:48:34 +08:00
mounted () {
if (this.focused) {
this.focusState = true
}
},
2022-10-12 08:51:05 +08:00
methods: {
handleChange ($event) {
2022-10-15 11:03:56 +08:00
this.cur = $event.target.value
2022-10-28 10:46:22 +08:00
this.$emit('input', this.cur)
2022-11-30 12:10:49 +08:00
this.$emit('handleChange', this.cur)
2023-01-30 16:48:34 +08:00
if (this.focusState) {
this.focusState = false
}
},
handleBlur () {
this.focusState = false
2022-10-12 08:51:05 +08:00
},
toSearch () {
this.$emit('toSearch', this.cur)
},
2022-12-03 14:31:36 +08:00
toDel () {
2023-01-30 16:48:34 +08:00
this.cur = ''
2022-12-03 14:31:36 +08:00
this.$emit('input', '')
},
2023-01-30 16:48:34 +08:00
toScan () {
setTimeout(() => {
this.focusState = true
},0)
setTimeout(() => {
uni.hideKeyboard()
}, 300)
this.cur = ''
this.$emit('input', '')
2023-03-28 10:55:08 +08:00
},
async toPhone() {
// #ifdef APP-PLUS
let status = await this.checkPermission();
if (status !== 1) {
return;
}
// #endif
uni.scanCode({
success: (res) => {
this.$emit('input', res.result)
this.$emit('handleChange', res.result)
},
fail: (err) => {
// uni.showToast({
// title: '出错',
// icon: 'none'
// })
}
});
2022-10-12 08:51:05 +08:00
}
2023-03-28 10:55:08 +08:00
// #ifdef APP-PLUS
,
async checkPermission(code) {
let status = permision.isIOS ? await permision.requestIOS('camera') :
await permision.requestAndroid('android.permission.CAMERA');
2022-10-12 08:51:05 +08:00
2023-03-28 10:55:08 +08:00
if (status === null || status === 1) {
status = 1;
} else {
uni.showModal({
content: "需要相机权限",
confirmText: "设置",
success: function(res) {
if (res.confirm) {
permision.gotoAppSetting();
}
}
})
}
return status;
}
// #endif
2022-10-12 08:51:05 +08:00
}
}
</script>
<style lang="stylus">
@import '../common/style/mixin.styl';
.search_wraper
position relative
_wh(100%, 70rpx)
.search_input
2022-12-03 14:31:36 +08:00
padding-right: 160rpx;
2022-10-12 08:51:05 +08:00
.buttons_wraper
position absolute
top 0
2023-03-28 10:55:08 +08:00
right 10rpx
2022-10-12 08:51:05 +08:00
_wh(auto, 70rpx)
2023-03-28 10:55:08 +08:00
_fj(flex-end)
2023-01-30 16:48:34 +08:00
.icon_scan_active
color $red
2022-10-12 08:51:05 +08:00
</style>