1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/**
* @Author Sean
* @Date 2019/11/21
*/
<template>
<input
:value="formatValue" :readonly="disable" type="text"
@blur="onBlur" @click="keyboradShow();onFocus($event)">
</template>
<script>
export default {
name: 'CurrencyInput',
props: {
value: {
default: '4',
},
// disable: {
// type: Boolean,
// default: true,
// },
content: {
type: String,
default: '',
},
},
data () {
return {
focused: false,
disable: true,
newVal: '',
}
},
filter: {
uncurrency (val) {
if (!val) return ''
return Number((val).replace(/,|%/gi, ''))
},
},
computed: {
formatValue () {
let currency = this.$options.filters['rate']
if (!this.focused) {
if (this.value !== '' && this.value !== null) {
return `${currency(this.value)}%`
}
} else {
return this.value
}
},
},
methods: {
keyboradShow () {
let vm = this
hlsPopup.showNumberKeyborad({
title: '数字键盘',
keyDown: (text) => {
vm.onInput(text)
},
keyDelete: () => {
vm.onDelete()
},
})
},
onInput (value) {
// if (this.disable) return
// let uncurrency = this.$options.filter['uncurrency']
// this.newVal = uncurrency(this.value)
this.newVal = this.value
if (this.newVal.includes('.') && value === '.') {
} else {
this.newVal += ('' + value)
}
this.$emit('input', this.newVal)
},
onDelete () {
this.newVal = ''
this.$emit('input', this.newVal)
},
// onInput: function (value) {
// if (this.disable) return
// let uncurrency = this.$options.filter['uncurrency']
// this.currencyValue = uncurrency(value)
// this.$emit('input', this.currencyValue)
// },
onFocus (event) {
// if (this.disable) return
let vm = this
this.focused = true
let value = (event.target.value).trim()
let uncurrency = this.$options.filter['uncurrency']
let newVal = uncurrency(value)
event.target.value = newVal
setTimeout(function () {
let dom = document.querySelector('.content')
let veiwHeight = vm.getClientHeight()
let eleHeight = vm.getOffsetTop(event.target)
let scrollTop = Math.floor(dom.scrollTop)
let result = Math.floor(veiwHeight - (eleHeight - scrollTop))
let fontS = parseFloat(document.documentElement.style.fontSize) * 5
console.log(fontS)
if (result >= fontS) {
} else {
let ele = document.createElement('div')
ele.setAttribute('class', 'add-height')
ele.style.height = (fontS - result + 44) + 'px'
ele.style.background = '#fff'
// setTimeout(() => {
dom.appendChild(ele)
// }, 100)
dom.scrollTop = scrollTop + (fontS - result + 44)
// dom.scrollTo(dom.scrollLeft, scrollTop + (256 - result))
}
console.log(veiwHeight, eleHeight, scrollTop, result)
event.target.type = 'text'
event.target.value = newVal
// event.target.focus()
}, 0)
},
onBlur (event) {
// if (this.disable) return
if (document.querySelector('.add-height')) {
document.querySelector('.content').removeChild(document.querySelector('.add-height'))
}
event.target.type = 'text'
this.focused = false
},
// 取窗口可视范围的高度
getClientHeight () {
var clientHeight = 0
if (document.body.clientHeight && document.documentElement.clientHeight) {
clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
} else {
clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
}
return clientHeight
},
// 取窗口滚动条高度
getOffsetTop (obj) {
var tmp = obj.offsetTop
var node = obj.offsetParent
while (node != null) {
tmp += node.offsetTop
node = node.offsetParent
}
return tmp
},
},
}
</script>
<style scoped lang="less">
</style>