| | |
| | | <el-input |
| | | ref="value" |
| | | v-model="value" |
| | | type="number" |
| | | :style="{width: width + 'px'}" |
| | | :class="{'web-display-none': showDisplay, 'web-display-inline': !showDisplay}" |
| | | :disabled="disabled" |
| | | @blur="moneyBlur($event.target.value)" |
| | | /> |
| | | > |
| | | <template v-if="showCh" slot="append">{{ customChinese }}</template> |
| | | </el-input> |
| | | <!-- 金额格式输入框 --> |
| | | <el-input |
| | | v-model="valueStr" |
| | |
| | | :class="{'web-display-none': !showDisplay, 'web-display-inline': showDisplay}" |
| | | :disabled="disabled" |
| | | @focus="moneyFocus($event.target.value)" |
| | | /> |
| | | > |
| | | <template v-if="showCh" slot="append">{{ customChinese }}</template> |
| | | </el-input> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | import Nzh from 'nzh' |
| | | |
| | | export default { |
| | | name: 'AssemblyMoneyInput', |
| | | model: { |
| | |
| | | default() { |
| | | return false |
| | | } |
| | | }, |
| | | showCh: { |
| | | type: Boolean, |
| | | default() { |
| | | return false |
| | | } |
| | | } |
| | | }, |
| | | data() { |
| | |
| | | valueStr: null |
| | | } |
| | | }, |
| | | computed: { |
| | | customNzh() { |
| | | return new Nzh({ |
| | | ch: '0123456789', // 数字字符 |
| | | ch_u: '个十百千万亿兆京', // 数位单位 |
| | | ch_f: '负', // 负号 |
| | | ch_d: '点', // 小数点 |
| | | m_u: '元角分厘', // 金额单位 |
| | | m_t: '人民币', // 金额前缀 |
| | | m_z: '整' // 无小数后缀 |
| | | }) |
| | | }, |
| | | customChinese() { |
| | | // 使用自定义配置进行转换 |
| | | if (this.value === null || this.value === undefined) { |
| | | return '' |
| | | } |
| | | return this.customNzh.toMoney(this.value, { outSymbol: false }).replace(/[个十百千]/g, '') |
| | | } |
| | | }, |
| | | watch: { |
| | | // 监听金额标准输入框数据变化:赋值给modelVal |
| | | value(val) { |
| | | this.$emit('change', Number(val)) |
| | | this.$emit('change', val !== null && val !== undefined ? Number(val) : null) |
| | | // 回调钩子 |
| | | this.$emit('afterChange') |
| | | } |
| | |
| | | // 金额格式化 |
| | | getInputValue(el) { |
| | | // 金额 |
| | | const inputVal = el.toString() || '' |
| | | // 金额添加千分位(金额去除千分位(金额)) |
| | | this.comdify(this.delcommafy(inputVal)) |
| | | const inputVal = el !== null && el !== undefined ? el.toString() : '' |
| | | if (inputVal.trim() !== '') { |
| | | // 金额添加千分位(金额去除千分位(金额)) |
| | | this.comdify(this.delcommafy(inputVal)) |
| | | } else { |
| | | // 清空金额 |
| | | this.valueStr = null |
| | | this.value = null |
| | | } |
| | | }, |
| | | // 金额去除千分位 |
| | | delcommafy(num) { |
| | |
| | | display: none !important; |
| | | } |
| | | .web-display-inline { |
| | | display: inline-block !important; |
| | | display: inline-table !important; |
| | | } |
| | | </style> |