Skip to content

Commit ab7a19a

Browse files
committed
feat(Price): 新增 l-decimal-class 和 l-dot-class 外部样式类
l-dot-class 覆盖小数点样式 l-decimal-class 覆盖小数部分样式 close #943
1 parent a4bc701 commit ab7a19a

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

src/price/index.js

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Component({
44
/**
55
* 组件的属性列表
66
*/
7-
externalClasses: ['l-deleted-class', 'l-unit-class', 'l-value-class', 'l-class'],
7+
externalClasses: ['l-deleted-class', 'l-unit-class', 'l-value-class', 'l-class', 'l-decimal-class', 'l-dot-class'],
88
behaviors: [validator],
99
properties: {
1010
unit: {
@@ -51,7 +51,16 @@ Component({
5151
* 组件的初始数据
5252
*/
5353
data: {
54-
54+
// 价格整数部分
55+
priceInteger: {
56+
type: String,
57+
value: '0'
58+
},
59+
// 价格小数部分
60+
priceDecimal: {
61+
type: String,
62+
value: '00'
63+
}
5564
},
5665

5766
observers: {
@@ -65,18 +74,35 @@ Component({
6574
*/
6675
methods: {
6776
reserveNumber() {
77+
this.setData({
78+
priceInteger: null,
79+
priceDecimal: null
80+
});
6881
const countToNumber = Number(this.data.value);
6982
const isText = isNaN(Number(countToNumber)) || (this.data.mode === 'text');
7083
if (!isText && this.data.autofix) {
7184
const result = countToNumber.toFixed(this.data.reserveDigit);
85+
const price = result.toString().split('.');
86+
this._setPrice(price);
87+
} else {
88+
const price = this.data.value.split('.');
89+
this._setPrice(price);
90+
}
91+
},
92+
93+
_setPrice(price) {
94+
if (price.length === 1) {
7295
this.setData({
73-
result
96+
priceInteger: price[0]
7497
});
75-
} else {
98+
}else if(price.length === 2){
7699
this.setData({
77-
result: this.data.value
100+
priceInteger: price[0],
101+
priceDecimal: price[1]
78102
});
103+
}else{
104+
throw 'price 格式有误,请仔细检查!';
79105
}
80106
}
81107
}
82-
});
108+
});

src/price/index.wxml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
<!-- unit -->
33
<text class="l-unit-class" style="color: {{unitColor?unitColor:color}}; font-size: {{unitSize?unitSize:size}}rpx; font-weight: {{unitBold?unitBold:bold}}">{{unit}}</text>
44
<!-- count -->
5-
<text class="l-value-class" style="color: {{valueColor?valueColor:color}}; font-size: {{valueSize?valueSize:size}}rpx; font-weight: {{valueBold?valueBold:bold}}">{{result}}</text>
6-
</view>
5+
<text class="l-value-class" style="color: {{valueColor?valueColor:color}}; font-size: {{valueSize?valueSize:size}}rpx; font-weight: {{valueBold?valueBold:bold}}">{{priceInteger}}<text class="l-dot-class">{{priceDecimal?'.':''}}</text><text class="l-decimal-class">{{priceDecimal?priceDecimal:''}}</text></text>
6+
</view>

0 commit comments

Comments
 (0)