emis-app/components/tpx-input/tpx-input.vue
2024-06-02 18:16:18 +08:00

128 lines
2.1 KiB
Vue

<template>
<u-input shape="circle" :placeholder="placeholder" :modelValue="value" :clearable="clearable"
:custom-style="inputStyle" :readonly="readonly" :type="type" :inputAlign="inputAlign"
:placeholder-style="`color: #999;${placeholderStyle};` " @change="handleChange"
:formatter="formatter" :disabled="disabled"
>
<template v-if="suffix" #suffix>
<text class="font-26 clr-sub pl-10">{{suffix}}</text>
</template>
</u-input>
</template>
<script>
export default {
computed: {
inputStyle(){
let bgColor = '#F6F6F6'
let sty1 = 'border:0;border-radius: 10rpx;padding: 11rpx 20rpx;'
if(this.isWhite) {
bgColor = '#fff'
sty1 += 'border: 1rpx solid #dadbde;'
}
if(!this.disabled) {
sty1 += `background-color:${bgColor};`
}
return `${sty1};${this.customStyle};`
}
},
props: {
isWhite: {
default () {
return false
}
},
suffix: {
default () {
return ''
}
},
clearable: {
default () {
return false
}
},
type: {
default () {
return ''
}
},
readonly: {
default () {
return false
}
},
value: {
default () {
return ''
}
},
disabled:{
default () {
return false
}
},
placeholder:{
default () {
return ''
}
},
_digit:{ // 保留小数位
},
_maxNum:{ // 最大数值
},
customStyle:{
default () {
return ''
}
},
placeholderStyle:{
default () {
return ''
}
},
inputAlign:{
default () {
return ''
}
},
},
data() {
return {
}
},
created() {
},
onHide() {
},
unmounted() {},
methods: {
handleChange(val){
this.$emit('change', val)
this.$emit('update:value', val)
},
formatter(val) {
let newVal = val
if(this._digit) {
let reg = new RegExp(`^\\d*(\\.?\\d{0,${this._digit}})`, 'g')
newVal = val.match(reg)[0]
}
if(typeof this._maxNum != 'undefined') {
if(val > this._maxNum) {
newVal = this._maxNum
}
}
return newVal
}
}
}
</script>
<style scoped lang="scss">
</style>