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
<template>
<div class="app-number-range">
<input-number
:max="!maxValue && maxValue != 0 ? Infinity : maxValue - 1"
:active-change="false"
v-model="minValue"
:disabled="disabled"
:readonly="readonly"
:precision="precision"
@on-change="(value) => {onValueChange(value, 0)}">
</input-number>
<div class="app-number-range__separator"> ~ </div>
<input-number
:min="minValue + 1"
:active-change="false"
v-model="maxValue"
:disabled="disabled"
:readonly="readonly"
:precision="precision"
@on-change="(value) => {onValueChange(value, 1)}">
</input-number>
</div>
</template>
<script lang='ts'>
import { Component, Vue, Prop } from 'vue-property-decorator';
@Component({})
export default class AppNumberRange extends Vue {
/**
* 编辑项名称
*
* @type {string}
* @memberof AppNumberRange
*/
@Prop() public name!: string;
/**
* 是否禁用
*
* @type {any}
* @memberof AppNumberRange
*/
@Prop({default: false}) public disabled: any;
/**
* 只读模式
*
* @type {boolean}
*/
@Prop({default: false}) public readonly?: boolean;
/**
* 关系表单项集合
*
* @type {string[]}
* @memberof AppNumberRange
*/
@Prop() public refFormItem!: string[];
/**
* 表单数据对象
*
* @type {*}
* @memberof AppNumberRange
*/
@Prop() public activeData: any;
/**
* 精度
*
* @type {number}
* @memberof AppNumberRange
*/
@Prop({ default: 0 }) public precision?: number;
/**
* vue 生命周期
*
* @memberof AppNumberRange
*/
public mounted() {
if (this.refFormItem?.length == 2) {
if (this.activeData[this.refFormItem[0]]) {
this.minValue = parseFloat(this.activeData[this.refFormItem[0]]);
}
if (this.activeData[this.refFormItem[1]]) {
this.maxValue = parseFloat(this.activeData[this.refFormItem[1]]);
}
}
}
/**
* 最小值
*
* @memberof AppNumberRange
*/
public minValue: any = null;
/**
* 最大值
*
* @memberof AppNumberRange
*/
public maxValue: any = null;
/**
* 值改变
*
* @param {string} value 值
* @param {*} index 项下标
* @memberof AppNumberRange
*/
public onValueChange(value: any, index: number) {
if (this.refFormItem?.length == 2) {
this.$emit('formitemvaluechange', { name: this.refFormItem[index], value: value });
}
}
}
</script>