<template>
<div>
<!--使用elementUI输入框插件-->
<!--阿拉伯值输入框-->
<el-input-number v-model="a" controls-position="right" :min="0"></el-input-number>
<!--输入框中转中文-->
<el-input v-model.trim="NumberToChinese"></el-input>
</div>
</template>
<script>
export default {
name: "num",
data(){
return{
a:0,// 阿拉伯整数
b:"",// 大写
}
},
computed:{
// 价格转大写
NumberToChinese(){
let m = this.a;
const unit = ["仟", "佰", "拾", "", "仟", "佰", "拾", "", "角", "分"]
m *= 100;
m += "";
var length = m.length;
var result = "";
for (var i = 0; i < length; i++) {
if (i == 2) {
result = "元" + result;
} else if (i == 6) {
result = "万" + result;
}
if (m.charAt(length - i - 1) == 0) {
if (i != 0 && i != 1) {
if (result.charAt(0) != '零' && result.charAt(0) != '元' && result.charAt(0) != '万') {
result = "零" + result;
}
}
continue;
}
let A = null;
const A_ = m.charAt(length - i - 1);
if(A_==="0"){
A = "零";
}else if(A_==="1"){
A = "壹";
}else if(A_==="2"){
A = "贰";
}else if(A_==="3"){
A = "叁";
}else if(A_==="4"){
A = "肆";
}else if(A_==="5"){
A = "伍";
}else if(A_==="6"){
A = "陆";
}else if(A_==="7"){
A = "柒";
}else if(A_==="8"){
A = "捌";
}else if(A_==="9"){
A = "玖";
}
result = A + unit[unit.length - i - 1] + result;
}
result += result.charAt(result.length - 1) == '元' ? "整" : "";
this.b = result;
return result;
},
}
}
</script>