|
@@ -0,0 +1,286 @@
|
|
|
+<template>
|
|
|
+ <div class="selector-money select-input-container select-common-inputs">
|
|
|
+ <el-select
|
|
|
+ ref="selectprice"
|
|
|
+ :placeholder="placeholder"
|
|
|
+ :value="inputValue"
|
|
|
+ :popper-append-to-body="false"
|
|
|
+ class="select_common"
|
|
|
+ popper-class="select_common_data"
|
|
|
+ >
|
|
|
+ <div slot="empty" class="select_box_container">
|
|
|
+ <div class="price-content">
|
|
|
+ <el-checkbox :value="checkedAll" @click.native="clickAll">全部</el-checkbox>
|
|
|
+ <div class="price-exact-container">
|
|
|
+ <div class="price-input-group" :class="{ active: !checkedAll }">
|
|
|
+ <div class="price-input">
|
|
|
+ <div class="price-input-group-item">
|
|
|
+ <input
|
|
|
+ type="text"
|
|
|
+ class="min-input"
|
|
|
+ name="minprice"
|
|
|
+ maxlength="9"
|
|
|
+ oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')"
|
|
|
+ v-model.number="inputGroupCache.min"
|
|
|
+ />
|
|
|
+ <span class="unit">万元</span>
|
|
|
+ </div>
|
|
|
+ <span class="splitter"></span>
|
|
|
+ <div class="price-input-group-item">
|
|
|
+ <input
|
|
|
+ type="text"
|
|
|
+ class="max-input"
|
|
|
+ name="maxprice"
|
|
|
+ maxlength="9"
|
|
|
+ oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')"
|
|
|
+ v-model.number="inputGroupCache.max"
|
|
|
+ />
|
|
|
+ <span class="unit">万元</span>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <button class="select-btn" @click="onConfirm">确定</button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </el-select>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import { Select, Checkbox, CheckboxGroup } from 'element-ui'
|
|
|
+import { selectorVModelMixin } from '@/utils/mixins/selector-v-model'
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: 'MoneySelection',
|
|
|
+ mixins: [selectorVModelMixin],
|
|
|
+ components: {
|
|
|
+ [CheckboxGroup.name]: CheckboxGroup,
|
|
|
+ [Checkbox.name]: Checkbox,
|
|
|
+ [Select.name]: Select
|
|
|
+ },
|
|
|
+ props: {
|
|
|
+ placeholder: {
|
|
|
+ type: String,
|
|
|
+ default: '价格区间'
|
|
|
+ },
|
|
|
+ allRequired: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false
|
|
|
+ }
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ checkedAll: true,
|
|
|
+ inputGroupCache: {
|
|
|
+ min: '',
|
|
|
+ max: ''
|
|
|
+ },
|
|
|
+ price: {
|
|
|
+ min: '',
|
|
|
+ max: ''
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ inputValue() {
|
|
|
+ const { min, max } = this.price
|
|
|
+ if (min !== '' && max !== '') {
|
|
|
+ return `${min || 0}万~${max || ''}万`
|
|
|
+ } else {
|
|
|
+ return `${this.placeholder}`
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ resetStatePrice() {
|
|
|
+ this.checkedAll = true
|
|
|
+ this.inputGroupCache.min = ''
|
|
|
+ this.inputGroupCache.max = ''
|
|
|
+ this.price.min = ''
|
|
|
+ this.price.max = ''
|
|
|
+ },
|
|
|
+ clickAll() {
|
|
|
+ this.resetStatePrice()
|
|
|
+ // this.onChange()
|
|
|
+ },
|
|
|
+ compareMinMax() {
|
|
|
+ const { min, max } = this.inputGroupCache
|
|
|
+ const hasMinAndMax = String(min).length && String(max).length
|
|
|
+ if (hasMinAndMax && min > max) {
|
|
|
+ this.inputGroupCache.max = min
|
|
|
+ this.inputGroupCache.min = max
|
|
|
+ }
|
|
|
+ },
|
|
|
+ setState({ min = '', max = '' }) {
|
|
|
+ this.price.min = min
|
|
|
+ this.price.max = max
|
|
|
+ if (min !== '') {
|
|
|
+ this.checkedAll = false
|
|
|
+ this.inputGroupCache.min = min
|
|
|
+ }
|
|
|
+ if (max !== '') {
|
|
|
+ this.checkedAll = false
|
|
|
+ this.inputGroupCache.max = max
|
|
|
+ }
|
|
|
+ if (min !== '' && max !== '') {
|
|
|
+ this.compareMinMax()
|
|
|
+ this.syncToPrice()
|
|
|
+ }
|
|
|
+
|
|
|
+ if (min === '' && max === '') {
|
|
|
+ this.resetStatePrice()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ getState() {
|
|
|
+ if (this.checkedAll) {
|
|
|
+ return { min: '', max: '' }
|
|
|
+ } else {
|
|
|
+ return this.inputGroupCache
|
|
|
+ }
|
|
|
+ },
|
|
|
+ syncToPrice() {
|
|
|
+ Object.assign(this.price, this.inputGroupCache)
|
|
|
+ },
|
|
|
+ onConfirm() {
|
|
|
+ this.compareMinMax()
|
|
|
+ const { min, max } = this.inputGroupCache
|
|
|
+ if (min || max) {
|
|
|
+ this.checkedAll = false
|
|
|
+ }
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.$refs.selectprice.blur()
|
|
|
+ this.syncToPrice()
|
|
|
+ this.onChange()
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onChange() {
|
|
|
+ const state = this.getState()
|
|
|
+ const { min, max } = state
|
|
|
+ if (this.allRequired) {
|
|
|
+ if (min === '' || max === '') {
|
|
|
+ return this.$toast('最小值和最大值均为必填')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.$emit('change', state)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss" scoped>
|
|
|
+$hover-border-color: #e0e0e0;
|
|
|
+
|
|
|
+.select-common-inputs {
|
|
|
+ position: relative;
|
|
|
+ ::v-deep {
|
|
|
+ .el-input__inner {
|
|
|
+ height: 30px;
|
|
|
+ width: 200px;
|
|
|
+ background-color: transparent;
|
|
|
+
|
|
|
+ // ellipsis
|
|
|
+ overflow: hidden;
|
|
|
+ text-overflow: ellipsis;
|
|
|
+ white-space: nowrap;
|
|
|
+ text-align: justify;
|
|
|
+ }
|
|
|
+ .el-select__caret {
|
|
|
+ color: #aaa;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ }
|
|
|
+ .el-input__icon {
|
|
|
+ line-height: normal;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+::v-deep {
|
|
|
+ .el-select-dropdown.el-popper {
|
|
|
+ &.select_common_data {
|
|
|
+ left: 0 !important;
|
|
|
+ margin: 0;
|
|
|
+ margin-top: 5px;
|
|
|
+ border: 1px solid #2cb7ca;
|
|
|
+ min-width: 425px;
|
|
|
+ // height: 104px;
|
|
|
+ // box-sizing: border-box;
|
|
|
+ z-index: 99 !important;
|
|
|
+ }
|
|
|
+
|
|
|
+ .popper__arrow {
|
|
|
+ display: none;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+@media only screen and (max-width: 1230px),
|
|
|
+ only screen and (max-device-width: 1230px) {
|
|
|
+ ::v-deep {
|
|
|
+ .el-select-dropdown.el-popper.select_common_data {
|
|
|
+ left: -225px !important;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+.select_box_container {
|
|
|
+ min-width: 425px;
|
|
|
+ padding: 18px 12px;
|
|
|
+ box-sizing: border-box;
|
|
|
+}
|
|
|
+
|
|
|
+.price-exact-container {
|
|
|
+ margin-top: 4px;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: space-between
|
|
|
+}
|
|
|
+.price-input-group {
|
|
|
+ border: 1px solid #f5f6f7;
|
|
|
+ background-color: #f5f6f7;
|
|
|
+ padding: 5px 5px;
|
|
|
+ border-radius: 2px;
|
|
|
+ &.active {
|
|
|
+ border-color: #2cb7ca;
|
|
|
+ background-color: #2cb7ca;
|
|
|
+ }
|
|
|
+}
|
|
|
+.price-input-group-item {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ padding: 0 10px;
|
|
|
+ background-color: #fff;
|
|
|
+ border: 1px solid #2cb7ca;
|
|
|
+ border-radius: 4px;
|
|
|
+ input {
|
|
|
+ width: 106px;
|
|
|
+ height: 28px;
|
|
|
+ padding-left: 0;
|
|
|
+ border: none;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+.splitter {
|
|
|
+ margin: 0 6px;
|
|
|
+ width: 14px;
|
|
|
+ height: 1px;
|
|
|
+ line-height: 15px;
|
|
|
+ background-color: $hover-border-color;
|
|
|
+}
|
|
|
+.unit {
|
|
|
+ color: #1d1d1d;
|
|
|
+ font-size: 14px;
|
|
|
+}
|
|
|
+
|
|
|
+.price-input {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+}
|
|
|
+
|
|
|
+.select-btn {
|
|
|
+ color: #2cb7ca;
|
|
|
+ background-color: transparent;
|
|
|
+}
|
|
|
+</style>
|