You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.3 KiB
69 lines
1.3 KiB
<!--
|
|
* @Author: ch
|
|
* @Date: 2022-04-21 09:54:15
|
|
* @LastEditors: ch
|
|
* @LastEditTime: 2022-04-21 10:59:21
|
|
* @Description: file content
|
|
-->
|
|
<template>
|
|
<view class="ui-money">
|
|
<text v-if="prefix" class="ui-money--prefix">¥</text>
|
|
<text class="ui-money--price">{{moneyStr}}</text>
|
|
<text v-if="flaot && suffix" class="ui-money--suffix">.{{moneyArr[1]}}</text>
|
|
</view>
|
|
</template>
|
|
<script>
|
|
export default {
|
|
props : {
|
|
money : {
|
|
type : Number | String,
|
|
default : '0'
|
|
},
|
|
flaot : {
|
|
type : Boolean,
|
|
default : false
|
|
},
|
|
prefix : {
|
|
type : Boolean,
|
|
default : false
|
|
},
|
|
suffix : {
|
|
type : Boolean,
|
|
default : false
|
|
}
|
|
},
|
|
computed : {
|
|
moneyStr (){
|
|
let priceStr = '',
|
|
intNum = this.moneyArr[0],
|
|
floatNum = this.moneyArr[1];
|
|
// 前缀不需要缩小显示
|
|
if(!this.prefix){
|
|
priceStr = `¥${intNum}`;
|
|
}else{
|
|
priceStr = intNum;
|
|
}
|
|
// 后缀不需要缩小显示
|
|
if(!this.suffix){
|
|
priceStr += floatNum ? `.${floatNum}` : '';
|
|
}
|
|
return priceStr;
|
|
},
|
|
moneyArr (){
|
|
let moneyArr = this.money.toString().split('.');
|
|
// 如果需要补0 则整数时补00
|
|
if(this.flaot){
|
|
if(!moneyArr[1]){
|
|
moneyArr[1] = '00';
|
|
}else if(moneyArr[1] < 10){
|
|
moneyArr[1] = `0${moneyArr[1]}`;
|
|
}
|
|
}
|
|
return moneyArr;
|
|
}
|
|
|
|
}
|
|
}
|
|
</script>
|
|
<style lang="scss" scoped>
|
|
</style> |