Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(customer-profile-board): COMPONENTS-145 #224

Merged
merged 1 commit into from
Oct 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});
});
});