为InputRender增加format参数,货币数字格式转换
This commit is contained in:
parent
f9e5c299f1
commit
e0e550f360
|
@ -10,4 +10,5 @@
|
|||
| value | render的值 | string | 无 |
|
||||
| isclickTrigger | 是否使用点击触发编辑状态 | boolean | false |
|
||||
| onChange | 当值发生改变的时候触发的方法 | Function | 无 |
|
||||
| format | Currency:货币数字; | string | 无 |
|
||||
|
||||
|
|
|
@ -25,9 +25,39 @@ export default class InputRender extends Component {
|
|||
this.check();
|
||||
}
|
||||
};
|
||||
//货币的格式化方法
|
||||
formatCurrency = money => {
|
||||
if (money && money != null && !!Number(money)) {
|
||||
money = String(money);
|
||||
let left = money.split(".")[0],
|
||||
right = money.split(".")[1];
|
||||
right = right
|
||||
? right.length >= 2 ? "." + right.substr(0, 2) : "." + right + "0"
|
||||
: ".00";
|
||||
let temp = left
|
||||
.split("")
|
||||
.reverse()
|
||||
.join("")
|
||||
.match(/(\d{1,3})/g);
|
||||
return (
|
||||
(Number(money) < 0 ? "-" : "") +
|
||||
temp
|
||||
.join(",")
|
||||
.split("")
|
||||
.reverse()
|
||||
.join("") +
|
||||
right
|
||||
);
|
||||
} else if (money === 0) {
|
||||
//注意===在这里的使用,如果传入的money为0,if中会将其判定为boolean类型,故而要另外做===判断
|
||||
return "0.00";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
render() {
|
||||
const { value, editable } = this.state;
|
||||
let { isclickTrigger } = this.props;
|
||||
let { value, editable } = this.state;
|
||||
let { isclickTrigger,format } = this.props;
|
||||
let cellContent = "";
|
||||
if (editable) {
|
||||
cellContent = isclickTrigger ? (
|
||||
|
@ -55,6 +85,9 @@ export default class InputRender extends Component {
|
|||
</div>
|
||||
);
|
||||
} else {
|
||||
if(format && format === "Currency"){
|
||||
value = this.formatCurrency(value);
|
||||
}
|
||||
cellContent = isclickTrigger ? (
|
||||
<div className="editable-cell-text-wrapper" onClick={this.edit}>
|
||||
{value || " "}
|
||||
|
|
Loading…
Reference in New Issue