toChinesNum .js文件
/**
* 将数字转成中文大写
* @params num
*/
export function toChinesNum(num) {
let changeNum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九']; //changeNum[0] = "零"
let unit = ["", "十", "百", "千", "万"];
num = parseInt(num);
let getWan = (temp) => {
let strArr = temp.toString().split("").reverse();
let newNum = "";
for (var i = 0; i < strArr.length; i++) {
newNum = (i == 0 && strArr[i] == 0 ? "" : (i > 0 && strArr[i] == 0 && strArr[i - 1] == 0 ? "" : changeNum[strArr[i]] + (strArr[i] == 0 ? unit[0] : unit[i]))) + newNum;
}
return newNum;
}
let overWan = Math.floor(num / 10000);
let noWan = num % 10000;
if (noWan.toString().length < 4) noWan = "0" + noWan;
return overWan ? getWan(overWan) + "万" + getWan(noWan) : getWan(num);
}
<template>
<div class="level-top-nav-page">
<router-link
v-for="(item, index) in list"
:key="index"
class="vaccine-module"
:to="{name: 'clinicList', query: {vaccineId: item.id}}"
>
</router-link>
</div>
</template>
<script>
import { toChinesNum } from "@/utils/toChinesNum ";
data() {
return {
list: [],
}
},
methods: {
onLoad() {
const vm = this;
vaccineIconPageList({
page: vm.page,
listRows: vm.listRows
}).then(res => {
let data = res.data.list;
for (let i = 0;i < data.length;i++) {
这里使用
data[i].times = toChinesNum(data[i].times) + '针次';
vm.list.push(data[i]);
}
});
},
}
}
</script>