|
@@ -1,12 +1,14 @@
|
|
|
<template lang="pug">
|
|
|
.input-group
|
|
|
+ .input-group-button(v-if='withPrefix')
|
|
|
+ button(type='button') {{ prefix }}
|
|
|
input(type='text' v-model='formattedValue')
|
|
|
- .input-group-button
|
|
|
- button(type='button' @click='onShowOptions' :disabled='isDisabledOptions()' ref='button') {{ text }}
|
|
|
+ .input-group-button(v-if='withSuffix')
|
|
|
+ button(type='button' @click='onShowSuffixOptions' :disabled='withSuffixOptions()' ref='suffixButton') {{ suffix }}
|
|
|
span.caret
|
|
|
- ul.dropdown(:style="{ 'display': isShowOptions ? 'block' : 'none' }" ref='dropdown')
|
|
|
- li(v-for='option in options' :key='option.id')
|
|
|
- a(@click='onClickOption(option)') {{ option.name }}
|
|
|
+ ul.dropdown(:style="{ 'display': isShowSuffixOptions ? 'block' : 'none' }" ref='suffixDropdown')
|
|
|
+ li(v-for='option in suffixOptions' :key='option.id')
|
|
|
+ a(@click='onClickSuffixOption(option)') {{ option.name }}
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
@@ -16,33 +18,46 @@
|
|
|
type: String,
|
|
|
default: ''
|
|
|
},
|
|
|
- text: {
|
|
|
+ format: {
|
|
|
type: String,
|
|
|
- default: 'Dropdown'
|
|
|
+ default: 'text'
|
|
|
},
|
|
|
- options: {
|
|
|
+ withPrefix: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false
|
|
|
+ },
|
|
|
+ prefix: {
|
|
|
+ type: String,
|
|
|
+ default: ''
|
|
|
+ },
|
|
|
+ prefixOptions: {
|
|
|
type: Array,
|
|
|
default: []
|
|
|
},
|
|
|
- format: {
|
|
|
- type: String,
|
|
|
- default: 'text'
|
|
|
+ withSuffix: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false
|
|
|
},
|
|
|
- prefix: {
|
|
|
+ suffix: {
|
|
|
type: String,
|
|
|
default: ''
|
|
|
+ },
|
|
|
+ suffixOptions: {
|
|
|
+ type: Array,
|
|
|
+ default: []
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
formattedValue: {
|
|
|
get() {
|
|
|
- let value = 0
|
|
|
+ let value = ''
|
|
|
|
|
|
if (this.format === 'number') {
|
|
|
value = this.formatValue(this.value)
|
|
|
+ value = !!this.value ? value : value.replace(/\d/, '')
|
|
|
}
|
|
|
|
|
|
- return !!this.value ? value : value.replace(/\d/, '')
|
|
|
+ return value
|
|
|
},
|
|
|
set(value) {
|
|
|
if (this.format === 'number') {
|
|
@@ -50,6 +65,8 @@
|
|
|
}
|
|
|
|
|
|
this.value = value
|
|
|
+
|
|
|
+ this.onChange(value)
|
|
|
}
|
|
|
}
|
|
|
},
|
|
@@ -97,32 +114,40 @@
|
|
|
onChange(data) {
|
|
|
this.$emit('onChange', data)
|
|
|
},
|
|
|
- hideOptions() {
|
|
|
- this.isShowOptions = false
|
|
|
+ hideSuffixOptions() {
|
|
|
+ this.isShowSuffixOptions = false
|
|
|
+ },
|
|
|
+ withPrefixOptions() {
|
|
|
+ return this.prefixOptions.length == 0
|
|
|
},
|
|
|
- isDisabledOptions() {
|
|
|
- return this.options.length == 0
|
|
|
+ withSuffixOptions() {
|
|
|
+ return this.suffixOptions.length == 0
|
|
|
},
|
|
|
- onShowOptions() {
|
|
|
- this.isShowOptions = !this.isShowOptions
|
|
|
+ onShowSuffixOptions() {
|
|
|
+ this.isShowSuffixOptions = !this.isShowSuffixOptions
|
|
|
},
|
|
|
onClickOutside(e) {
|
|
|
+ let suffixButton = this.$refs.suffixButton
|
|
|
+
|
|
|
+ if (!suffixButton) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
let target = e.target
|
|
|
- let button = this.$refs.button
|
|
|
|
|
|
- if (target === button) {
|
|
|
+ if (target === suffixButton) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- let el = this.$refs.dropdown
|
|
|
+ let el = this.$refs.suffixDropdown
|
|
|
|
|
|
if (el !== target && !el.contains(target)) {
|
|
|
- this.hideOptions()
|
|
|
+ this.hideSuffixOptions()
|
|
|
}
|
|
|
},
|
|
|
- onClickOption(option) {
|
|
|
- this.hideOptions()
|
|
|
- this.$emit('onOption', option)
|
|
|
+ onClickSuffixOption(suffixOption) {
|
|
|
+ this.hideSuffixOptions()
|
|
|
+ this.$emit('onSuffix', suffixOption)
|
|
|
}
|
|
|
},
|
|
|
created() {
|
|
@@ -134,7 +159,7 @@
|
|
|
data() {
|
|
|
return {
|
|
|
value: '',
|
|
|
- isShowOptions: false
|
|
|
+ isShowSuffixOptions: false
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -154,13 +179,21 @@
|
|
|
border-radius: 0
|
|
|
margin-bottom: 0
|
|
|
z-index: 2
|
|
|
+ font-size: 12pt
|
|
|
&:focus
|
|
|
z-index: 3
|
|
|
.input-group-button
|
|
|
+ position: relative
|
|
|
display: table-cell
|
|
|
width: 1%
|
|
|
white-space: nowrap
|
|
|
vertical-align: middle
|
|
|
+ &:first-child
|
|
|
+ & > button
|
|
|
+ margin-right: -1px
|
|
|
+ &:last-child
|
|
|
+ & > button
|
|
|
+ margin-left: -1px
|
|
|
button
|
|
|
height: 35px
|
|
|
display: inline-block
|
|
@@ -171,7 +204,6 @@
|
|
|
border: 1px solid #ccc
|
|
|
border-radius: 0
|
|
|
box-shadow: none
|
|
|
- margin-left: -1px
|
|
|
background: #e0e0e0
|
|
|
&:focus
|
|
|
outline: 0 !important
|