Files
hht-tongbo-two/components/SearchBoxMx.vue

90 lines
1.8 KiB
Vue

<template>
<view class="zd-row scan_wraper">
<slot></slot>
<uni-icons class="mgr20" type="clear" size="24" color="#666" @tap="toDel"></uni-icons>
<uni-icons type="scan" size="22" :color="focused ? '#D7592F' : '#666'" @tap="toScan"></uni-icons>
</view>
</template>
<script>
import permision from "@/utils/permission.js"
export default {
props: {
focused: {
type: Boolean,
default: false
}
},
methods: {
toDel () {
this.$emit('inputDel')
},
toScan () {
this.$emit('inputScan', '')
},
async toPhone() {
// #ifdef APP-PLUS
let status = await this.checkPermission();
if (status !== 1) {
return;
}
// #endif
uni.scanCode({
success: (res) => {
this.$emit('toPhone', res.result)
},
fail: (err) => {
// uni.showToast({
// title: '出错',
// icon: 'none'
// })
}
});
}
// #ifdef APP-PLUS
,
async checkPermission(code) {
let status = permision.isIOS ? await permision.requestIOS('camera') :
await permision.requestAndroid('android.permission.CAMERA');
if (status === null || status === 1) {
status = 1;
} else {
uni.showModal({
content: "需要相机权限",
confirmText: "设置",
success: function(res) {
if (res.confirm) {
permision.gotoAppSetting();
}
}
})
}
return status;
}
// #endif
}
}
</script>
<style lang="stylus" scoped>
@import '../common/style/mixin.styl';
.scan_wraper
position relative
_wh(100%, 80rpx)
border: 1px solid #dcdfe6;
background-color: #fff;
border-radius: 10rpx;
padding: 0 10rpx
.search_input
padding-right: 160rpx;
.buttons_wraper
position absolute
top 0
right 10rpx
_wh(auto, 80rpx)
_fj(flex-end)
.icon_scan_active
color $red
</style>