-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathprice-input.vue
52 lines (48 loc) · 1.4 KB
/
price-input.vue
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
<template>
<span>
<a-input type="text" :value="value.number" style="width: 100px" @change="onNumberChange" />
<a-select
:value="value.currency"
style="width: 80px; margin: 0 8px"
:options="[
{ value: 'rmb', label: 'RMB' },
{ value: 'dollar', label: 'Dollar' },
]"
@change="onCurrencyChange"
></a-select>
</span>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import type { PropType } from 'vue';
import { Form } from 'ant-design-vue';
export type Currency = 'rmb' | 'dollar';
interface PriceValue {
number: number;
currency: Currency;
}
export default defineComponent({
props: {
value: { type: Object as PropType<PriceValue>, isRequired: true },
},
emits: ['update:value'],
setup(props, { emit }) {
const formItemContext = Form.useInjectFormItemContext();
const triggerChange = (changedValue: { number?: number; currency?: Currency }) => {
emit('update:value', { ...props.value, ...changedValue });
formItemContext.onFieldChange();
};
const onNumberChange = (e: InputEvent) => {
const newNumber = parseInt((e.target as any).value || '0', 10);
triggerChange({ number: newNumber });
};
const onCurrencyChange = (newCurrency: Currency) => {
triggerChange({ currency: newCurrency });
};
return {
onNumberChange,
onCurrencyChange,
};
},
});
</script>