input-price.vue
2.13 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
<template>
<div class="input-comp">
<div class="input-wrapper">
<div class="price-symbol">¥</div>
<input ref="input" :value="value" class="tip" type="text" placeholder="定价需以9结尾,例如¥1299" @blur="onBlur"
@change="onChange"></input>
</div>
<div class="num-wrapper" v-if="superSell">
<i class="iconfont iconplus-minus icon-class" @click="onMinus"></i>
<span class="icon-class count">{{num}}</span>
<i class="iconfont iconi-add icon-class" @click="onAdd"></i>
</div>
</div>
</template>
<script>
export default {
name: 'InputPrice',
props: {
value: {
type: [Number, String],
default: ''
},
num: {
type: Number,
default: 1
},
superSell: {
type: Boolean,
default: false
}
},
data() {
return {
val: this.value
};
},
methods: {
onBlur() {
this.$emit('on-blur');
},
onChange() {
this.$emit('input', this.$refs.input.value);
},
onMinus() {
if (this.num > 1) {
const count = this.num - 1;
this.$emit('on-num-change', { count, type: 'minus' });
}
},
onAdd() {
const count = this.num + 1;
this.$emit('on-num-change', { count, type: 'add' });
}
},
watch: {
value(newVal) {
this.val = newVal;
},
}
};
</script>
<style lang="scss" scoped>
.input-comp {
display: flex;
}
.input-wrapper {
display: flex;
flex: 1;
position: relative;
overflow: hidden;
height: 120px;
background: #f5f5f5;
}
.price-symbol {
width: 40px;
margin-left: 20px;
margin-right: 10px;
font-size: 40px;
font-weight: bolder;
line-height: 120px;
}
.tip {
flex: 1;
font-size: 56px;
font-weight: 500;
line-height: 120px;
background: #f5f5f5;
}
::placeholder {
color: #ccc;
font-size: 28px;
opacity: 1; /* Firefox */
}
.num-wrapper {
width: 240px;
height: 120px;
margin-left: 10px;
background: #f5f5f5;
display: flex;
justify-content: space-around;
align-items: center;
.icon-class {
font-size: 40px;
color: #999;
font-weight: bold;
}
.count {
color: black;
}
}
</style>