Commit e79feb43 by 胡悦

修改数字为汉字

1 parent 0b274454
...@@ -33,11 +33,7 @@ ...@@ -33,11 +33,7 @@
<img class="wheat" :src="getImageUrl('wheat')" alt="" /> <img class="wheat" :src="getImageUrl('wheat')" alt="" />
<div class="price-title"> <div class="price-title">
为团队助力开单,{{ 为团队助力开单,{{
data.upgradeCount == 1 data.upgradeCount == "一" ? "首单金额" : `第${data.upgradeCount}笔`
? "首单金额"
: data.upgradeCount <= 10
? `第${numberObj[data.upgradeCount]}笔`
: `第${data.upgradeCount}笔`
}} }}
</div> </div>
<div class="price-number">{{ data.newsInfo!.totalPrice }}元</div> <div class="price-number">{{ data.newsInfo!.totalPrice }}元</div>
...@@ -76,15 +72,15 @@ const global: any = inject("global"); ...@@ -76,15 +72,15 @@ const global: any = inject("global");
let query: Params = {}; let query: Params = {};
const numberObj = { const numberObj = {
0: 0, 0: 0,
2: "贰", 2: "二",
3: "叁", 3: "三",
4: "肆", 4: "四",
5: "伍", 5: "五",
6: "陆", 6: "六",
7: "柒", 7: "七",
8: "捌", 8: "八",
9: "玖", 9: "九",
10: "拾", 10: "十",
}; };
const data = reactive<Partial<DataInfo>>({ const data = reactive<Partial<DataInfo>>({
newsInfo: <NewsInfo>{ newsInfo: <NewsInfo>{
...@@ -97,12 +93,68 @@ const getInfo = async () => { ...@@ -97,12 +93,68 @@ const getInfo = async () => {
"dj.api.smarcarlife.staffDayReport.getSaPersonalGoodNewsData", "dj.api.smarcarlife.staffDayReport.getSaPersonalGoodNewsData",
query query
); );
data.upgradeCount = data.newsInfo?.staff?.upgradeCount; data.upgradeCount = convertToChinaNum(data.newsInfo?.staff?.upgradeCount);
}; };
/**
* 功能:获取图片地址
* 参数:name:图片名称
* path:图片在服务器上的路径
*/
const getImageUrl = (name: any, path = "dj") => { const getImageUrl = (name: any, path = "dj") => {
return new URL(`./${path}/${name}.png?v=${global.version}`, global.$imgUrl) return new URL(`./${path}/${name}.png?v=${global.version}`, global.$imgUrl)
.href; .href;
}; };
// 数字转汉字
const convertToChinaNum = (num: any) => {
var arr1 = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
var arr2 = [
"",
"十",
"百",
"千",
"万",
"十",
"百",
"千",
"亿",
"十",
"百",
"千",
"万",
"十",
"百",
"千",
"亿",
];
if (!num || isNaN(num)) {
return "零";
}
var english = num.toString().split("");
var result = "";
for (var i = 0; i < english.length; i++) {
var des_i = english.length - 1 - i; //倒序排列设值
result = arr2[i] + result;
var arr1_index = english[des_i];
result = arr1[arr1_index] + result;
}
//将【零千、零百】换成【零】 【十零】换成【十】
result = result.replace(/零(千|百|十)/g, "零").replace(/十零/g, "十");
//合并中间多个零为一个零
result = result.replace(/零+/g, "零");
//将【零亿】换成【亿】【零万】换成【万】
result = result.replace(/零亿/g, "亿").replace(/零万/g, "万");
//将【亿万】换成【亿】
result = result.replace(/亿万/g, "亿");
//移除末尾的零
result = result.replace(/零+$/, "");
//将【零一十】换成【零十】
//result = result.replace(/零一十/g, '零十');//貌似正规读法是零一十
//将【一十】换成【十】
result = result.replace(/^一十/g, "十");
return result;
};
onMounted(() => { onMounted(() => {
if (route.query) { if (route.query) {
query = route.query; query = route.query;
......
...@@ -11,7 +11,8 @@ export interface Params { ...@@ -11,7 +11,8 @@ export interface Params {
export interface DataInfo { export interface DataInfo {
newsInfo: NewsInfo; newsInfo: NewsInfo;
upgradeCount: number; upgradeCount: number | string
;
} }
export interface NewsInfo { export interface NewsInfo {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!