index.js
4.66 KB
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
function t(t, e) {
var a = Math.pow(10, 10);
return Math.round((t + e) * a) / a;
}
function e(t, e) {
return String(t) === String(e);
}
var a = require("../common/component"), i = require("../common/utils");
(0, a.VantComponent)({
field: !0,
classes: [ "input-class", "plus-class", "minus-class" ],
props: {
value: {
type: null,
observer: function(t) {
e(t, this.data.currentValue) || this.setData({
currentValue: this.format(t)
});
}
},
integer: {
type: Boolean,
observer: "check"
},
disabled: Boolean,
inputWidth: null,
buttonSize: null,
asyncChange: Boolean,
disableInput: Boolean,
decimalLength: {
type: Number,
value: null,
observer: "check"
},
min: {
type: null,
value: 1,
observer: "check"
},
max: {
type: null,
value: Number.MAX_SAFE_INTEGER,
observer: "check"
},
step: {
type: null,
value: 1
},
showPlus: {
type: Boolean,
value: !0
},
showMinus: {
type: Boolean,
value: !0
},
disablePlus: Boolean,
disableMinus: Boolean,
longPress: {
type: Boolean,
value: !0
}
},
data: {
currentValue: ""
},
created: function() {
this.setData({
currentValue: this.format(this.data.value)
});
},
methods: {
check: function() {
var t = this.format(this.data.currentValue);
e(t, this.data.currentValue) || this.setData({
currentValue: t
});
},
isDisabled: function(t) {
return "plus" === t ? this.data.disabled || this.data.disablePlus || this.data.currentValue >= this.data.max : this.data.disabled || this.data.disableMinus || this.data.currentValue <= this.data.min;
},
onFocus: function(t) {
this.$emit("focus", t.detail);
},
onBlur: function(t) {
var e = this.format(t.detail.value);
this.emitChange(e), this.$emit("blur", Object.assign(Object.assign({}, t.detail), {
value: e
}));
},
filter: function(t) {
return t = String(t).replace(/[^0-9.-]/g, ""), this.data.integer && -1 !== t.indexOf(".") && (t = t.split(".")[0]),
t;
},
format: function(t) {
return t = this.filter(t), t = "" === t ? 0 : +t, t = Math.max(Math.min(this.data.max, t), this.data.min),
(0, i.isDef)(this.data.decimalLength) && (t = t.toFixed(this.data.decimalLength)),
t;
},
onInput: function(t) {
var e = (t.detail || {}).value, a = void 0 === e ? "" : e;
if ("" !== a) {
var s = this.filter(a);
if ((0, i.isDef)(this.data.decimalLength) && -1 !== s.indexOf(".")) {
var n = s.split(".");
s = n[0] + "." + n[1].slice(0, this.data.decimalLength);
}
this.emitChange(s);
}
},
emitChange: function(t) {
this.data.asyncChange || this.setData({
currentValue: t
}), this.$emit("change", t);
},
onChange: function() {
var e = this.type;
if (this.isDisabled(e)) this.$emit("overlimit", e); else {
var a = "minus" === e ? -this.data.step : +this.data.step, i = this.format(t(+this.data.currentValue, a));
this.emitChange(i), this.$emit(e);
}
},
longPressStep: function() {
var t = this;
this.longPressTimer = setTimeout(function() {
t.onChange(), t.longPressStep();
}, 200);
},
onTap: function(t) {
var e = t.currentTarget.dataset.type;
this.type = e, this.onChange();
},
onTouchStart: function(t) {
var e = this;
if (this.data.longPress) {
clearTimeout(this.longPressTimer);
var a = t.currentTarget.dataset.type;
this.type = a, this.isLongPress = !1, this.longPressTimer = setTimeout(function() {
e.isLongPress = !0, e.onChange(), e.longPressStep();
}, 600);
}
},
onTouchEnd: function() {
this.data.longPress && clearTimeout(this.longPressTimer);
}
}
});