Skip to content

Commit

Permalink
fix(customer-profile-board): COMPONENTS-145 (#224)
Browse files Browse the repository at this point in the history
【列表模式】RFM指标平均发货到确认收货间隔”、“平均每次购买金额”、“平均每次购买件数”、”平均每次购买间隔“小数点后需要保留两位
  • Loading branch information
DiscipleD authored and arzyu committed Oct 26, 2016
1 parent b2e0b3a commit 3fc313f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
17 changes: 10 additions & 7 deletions src/components/customer-profile-board/CustomerAttributeSetting.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ const consumer = {
name: '第一次购买金额',
defaultValue: '-',
unit: ' 元',
currency: true,
fixed: 2,
editable: false
}, {
attribute: 'trade_first_interval',
Expand All @@ -293,7 +293,7 @@ const consumer = {
name: '最后一次购买金额',
defaultValue: '-',
unit: ' 元',
currency: true,
fixed: 2,
editable: false,
isInListMode: true
}, {
Expand All @@ -319,7 +319,7 @@ const consumer = {
name: '累计购买金额',
defaultValue: '-',
unit: ' 元',
currency: true,
fixed: 2,
editable: false,
isInListMode: true
}, {
Expand All @@ -333,20 +333,22 @@ const consumer = {
name: '平均每次购买金额',
defaultValue: '-',
unit: ' 元',
currency: true,
fixed: 2,
editable: false,
isInListMode: true
}, {
attribute: 'trade_avg_item_num',
name: '平均每次购买件数',
defaultValue: '-',
unit: ' 件',
fixed: 0,
editable: false
}, {
attribute: 'trade_avg_buy_interval',
name: '平均每次购买间隔',
defaultValue: '-',
unit: ' 天',
fixed: 0,
editable: false
}, {
attribute: 'trade_refund_count',
Expand All @@ -359,27 +361,28 @@ const consumer = {
name: '退款金额',
defaultValue: '-',
unit: ' 元',
currency: true,
fixed: 2,
editable: false
}, {
attribute: 'trade_avg_confirm_interval',
name: '平均发货到确认收货间隔',
defaultValue: '-',
unit: ' 天',
fixed: 0,
editable: false
}, {
attribute: 'trade_max_amount',
name: '最大单笔订单购买金额',
defaultValue: '-',
unit: ' 元',
currency: true,
fixed: 2,
editable: false
}, {
attribute: 'trade_order_discount_fee',
name: '订单级优惠费用',
defaultValue: '-',
unit: ' 元',
currency: true,
fixed: 2,
editable: false
}]
}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class CustomerProfileBoardService {
if (attribute.valueMap) {
return attribute.valueMap[dataMapping[attribute.attribute]];
} else {
return (attribute.currency ? this.formatCurrencyNumber(dataMapping[attribute.attribute]) : dataMapping[attribute.attribute]) + attribute.unit;
return (typeof attribute.fixed !== 'undefined' ? this.formatNumber(dataMapping[attribute.attribute], attribute.fixed) : dataMapping[attribute.attribute]) + attribute.unit;
}
} else {
if (attribute.valueMap) {
Expand All @@ -289,10 +289,11 @@ class CustomerProfileBoardService {

/**
* format currency number
* @param {number} number
* @returns {number} number
* @param {Number} number
* @param {number} fixed
* @returns {string} number
*/
formatCurrencyNumber(number, fixed = 2) {
formatNumber(number, fixed = 2) {
number = parseFloat(number);
if (!number) number = 0;
return number.toFixed(fixed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ describe('CustomerProfileBoard', () => {
name: '最后一次购买金额',
defaultValue: '0.00 元',
unit: ' 元',
currency: true,
fixed: 2,
editable: false,
isInListMode: true
};
Expand Down Expand Up @@ -364,13 +364,13 @@ describe('CustomerProfileBoard', () => {
assert.deepEqual(customerProfileBoardService.getAttributeValue(attribute2, {}), attribute2.valueMap[attribute2.defaultValue]);
});

it('formatCurrencyNumber', () => {
it('formatNumber', () => {
const customerProfileBoardService = new CustomerProfileBoardService();
assert.strictEqual(customerProfileBoardService.formatCurrencyNumber('a'), '0.00');
assert.strictEqual(customerProfileBoardService.formatCurrencyNumber('0'), '0.00');
assert.strictEqual(customerProfileBoardService.formatCurrencyNumber(0), '0.00');
assert.strictEqual(customerProfileBoardService.formatCurrencyNumber(11.1), '11.10');
assert.strictEqual(customerProfileBoardService.formatCurrencyNumber(123.456), '123.46');
assert.strictEqual(customerProfileBoardService.formatNumber('a'), '0.00');
assert.strictEqual(customerProfileBoardService.formatNumber('0'), '0.00');
assert.strictEqual(customerProfileBoardService.formatNumber(0), '0.00');
assert.strictEqual(customerProfileBoardService.formatNumber(11.1), '11.10');
assert.strictEqual(customerProfileBoardService.formatNumber(123.456), '123.46');
});
});
});

0 comments on commit 3fc313f

Please sign in to comment.