|
|
@@ -0,0 +1,90 @@
|
|
|
+<!-- FormCreate 自定义控件:金额(数字 + 可选人民币大写) -->
|
|
|
+<template>
|
|
|
+ <div class="oa-money-field">
|
|
|
+ <template v-if="isDesignerHost">
|
|
|
+ <el-input model-value="" :placeholder="placeholder || '请输入金额'" disabled />
|
|
|
+ <div v-if="showUpper" class="oa-money-field__upper">大写金额预览</div>
|
|
|
+ </template>
|
|
|
+ <template v-else-if="disabled">
|
|
|
+ <div class="oa-money-field__readonly">
|
|
|
+ <span>{{ displayNumber || '—' }}</span>
|
|
|
+ <div v-if="showUpper && upperText" class="oa-money-field__upper">{{ upperText }}</div>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ <template v-else>
|
|
|
+ <AmountInput
|
|
|
+ :model-value="numericValue"
|
|
|
+ :placeholder="placeholder || '请输入金额'"
|
|
|
+ :min="0"
|
|
|
+ :precision="2"
|
|
|
+ @update:model-value="onInput"
|
|
|
+ />
|
|
|
+ <div v-if="showUpper && upperText" class="oa-money-field__upper">{{ upperText }}</div>
|
|
|
+ </template>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup lang="ts">
|
|
|
+ import { computed } from 'vue'
|
|
|
+ import AmountInput from '@/components/common/amount-input/index.vue'
|
|
|
+ import { formatMoneyDisplay } from '@/utils/money-format'
|
|
|
+ import { toRmbUpper } from '@/utils/rmb-upper'
|
|
|
+
|
|
|
+ defineOptions({ name: 'money' })
|
|
|
+
|
|
|
+ const props = withDefaults(
|
|
|
+ defineProps<{
|
|
|
+ modelValue?: number | string | null
|
|
|
+ disabled?: boolean
|
|
|
+ showUpper?: boolean
|
|
|
+ placeholder?: string
|
|
|
+ formCreateInject?: Record<string, unknown>
|
|
|
+ }>(),
|
|
|
+ { showUpper: true, placeholder: '请输入金额' }
|
|
|
+ )
|
|
|
+
|
|
|
+ const emit = defineEmits<{
|
|
|
+ (e: 'update:modelValue', v: number | null): void
|
|
|
+ (e: 'change', v: number | null): void
|
|
|
+ }>()
|
|
|
+
|
|
|
+ /** 表单设计器隔离宿主(无 Pinia / Token) */
|
|
|
+ function detectDesignerHost() {
|
|
|
+ try {
|
|
|
+ return /oa-fc-host\.html/i.test(String(window.location?.pathname || ''))
|
|
|
+ } catch {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const isDesignerHost = detectDesignerHost()
|
|
|
+
|
|
|
+ function toNum(v: unknown): number | null {
|
|
|
+ if (v == null || v === '') return null
|
|
|
+ const n = typeof v === 'number' ? v : Number(String(v).replace(/,/g, ''))
|
|
|
+ if (!Number.isFinite(n) || n < 0) return null
|
|
|
+ return Math.round(n * 100) / 100
|
|
|
+ }
|
|
|
+
|
|
|
+ const numericValue = computed(() => toNum(props.modelValue))
|
|
|
+ const displayNumber = computed(() => formatMoneyDisplay(numericValue.value, 2))
|
|
|
+ const upperText = computed(() => {
|
|
|
+ const n = numericValue.value
|
|
|
+ if (n == null) return ''
|
|
|
+ return toRmbUpper(n)
|
|
|
+ })
|
|
|
+
|
|
|
+ function onInput(v: number | null) {
|
|
|
+ const next = v == null || v < 0 ? null : Math.round(Number(v) * 100) / 100
|
|
|
+ emit('update:modelValue', next)
|
|
|
+ emit('change', next)
|
|
|
+ }
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+ .oa-money-field__upper {
|
|
|
+ margin-top: 6px;
|
|
|
+ font-size: 12px;
|
|
|
+ line-height: 1.4;
|
|
|
+ color: var(--mint-text-muted, #64748b);
|
|
|
+ }
|
|
|
+</style>
|