lodash#multiply JavaScript Examples
The following examples show how to use
lodash#multiply.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RateForm.js From hzero-front with Apache License 2.0 | 4 votes |
render() {
const { form, initData, title, anchor, modalVisible, onCancel, confirmLoading } = this.props;
const { getFieldDecorator } = form;
const { rateMethodCode, tenantId } = this.state;
const {
fromCurrencyCode,
fromCurrencyName,
toCurrencyCode,
toCurrencyName,
rateTypeCode,
rateTypeName,
rateDate,
rate,
enabledFlag = 1,
} = initData;
const validStartDate = (_, date, callback) => {
const end = form.getFieldsValue().endDate;
const start = moment(date).unix();
if (!!end && start > moment(end).unix()) {
callback(
intl.get('hzero.common.validation.date.after', {
startDate: intl.get('hpfm.rate.model.rate.startDate').d('起始时间'),
endDate: intl.get('hpfm.rate.model.rate.endDate').d('结束时间'),
})
);
} else {
callback();
}
};
const validDate = (_, date, callback) => {
const start = form.getFieldsValue().startDate;
const end = moment(date).unix();
if (!!start && end < moment(start).unix()) {
callback(intl.get('hpfm.rate.view.validation.data').d('结束时间不能早于起始时间'));
} else {
callback();
}
};
return (
<Modal
destroyOnClose
title={title}
width={520}
wrapClassName={`ant-modal-sidebar-${anchor}`}
transitionName={`move-${anchor}`}
visible={modalVisible}
onOk={this.saveBtn}
onCancel={onCancel}
confirmLoading={confirmLoading}
okText={intl.get('hzero.common.button.ok').d('确定')}
cancelText={intl.get('hzero.common.button.cancel').d('取消')}
>
<Form>
<FormItem
{...MODAL_FORM_ITEM_LAYOUT}
label={intl.get('hpfm.rate.model.rate.fromCurrencyCode').d('币种代码')}
>
{getFieldDecorator('fromCurrencyCode', {
initialValue: fromCurrencyCode,
rules: [
{
type: 'string',
required: true,
message: intl.get('hzero.common.validation.notNull', {
name: intl.get('hpfm.rate.model.rate.fromCurrencyCode').d('币种代码'),
}),
},
{
validator: (rule, value, callback) => {
if (value && form.getFieldValue('toCurrencyCode') === value) {
callback(
new Error(
intl.get('hpfm.rate.view.validation.notSame').d('不能选择相同的币种代码')
)
);
} else {
callback();
}
},
},
],
})(
<Lov
disabled={!!fromCurrencyCode}
textValue={initData.fromCurrencyCode || ''}
code="HPFM.CURRENCY"
queryParams={{ tenantId, enabledFlag: 1 }}
onChange={(text, record) => {
form.setFieldsValue({ fromCurrencyName: record && record.currencyName });
}}
/>
)}
</FormItem>
<FormItem
{...MODAL_FORM_ITEM_LAYOUT}
label={intl.get('hpfm.rate.model.rate.fromCurrencyName').d('币种名称')}
>
{getFieldDecorator('fromCurrencyName', {
initialValue: fromCurrencyName,
rules: [
{
type: 'string',
required: true,
message: intl.get('hzero.common.validation.notNull', {
name: intl.get('hpfm.rate.model.rate.fromCurrencyName').d('币种名称'),
}),
},
],
})(<Input disabled />)}
</FormItem>
<FormItem
{...MODAL_FORM_ITEM_LAYOUT}
label={intl.get('hpfm.rate.model.rate.toCurrencyCode').d('兑换币种代码')}
>
{getFieldDecorator('toCurrencyCode', {
initialValue: toCurrencyCode,
rules: [
{
type: 'string',
required: true,
message: intl.get('hzero.common.validation.notNull', {
name: intl.get('hpfm.rate.model.rate.toCurrencyCode').d('兑换币种代码'),
}),
},
{
validator: (rule, value, callback) => {
if (value && form.getFieldValue('fromCurrencyCode') === value) {
callback(
new Error(
intl.get('hpfm.rate.view.validation.notSame').d('不能选择相同的币种代码')
)
);
} else {
callback();
}
},
},
],
})(
<Lov
disabled={!!toCurrencyCode}
textValue={toCurrencyCode}
code="HPFM.CURRENCY"
queryParams={{ tenantId, enabledFlag: 1 }}
onChange={(text, record) => {
form.setFieldsValue({ toCurrencyName: record.currencyName });
}}
/>
)}
</FormItem>
<FormItem
{...MODAL_FORM_ITEM_LAYOUT}
label={intl.get('hpfm.rate.model.rate.toCurrencyName').d('兑换币种名称')}
>
{getFieldDecorator('toCurrencyName', {
initialValue: toCurrencyName,
rules: [
{
type: 'string',
required: true,
message: intl.get('hzero.common.validation.notNull', {
name: intl.get('hpfm.rate.model.rate.toCurrencyName').d('兑换币种名称'),
}),
},
],
})(<Input disabled />)}
</FormItem>
<FormItem
{...MODAL_FORM_ITEM_LAYOUT}
label={intl.get('hpfm.rate.model.rate.rateTypeName').d('汇率类型')}
>
{getFieldDecorator('rateTypeCode', {
initialValue: rateTypeCode,
rules: [
{
type: 'string',
required: true,
message: intl.get('hzero.common.validation.notNull', {
name: intl.get('hpfm.rate.model.rate.rateTypeName').d('汇率类型'),
}),
},
],
})(
<Lov
allowClear={false}
disabled={!!rateTypeCode}
textValue={rateTypeName}
code="HPFM.EXCHANGE_RATE_TYPE"
queryParams={{ tenantId, enabledFlag: 1 }}
onChange={(text, record) => {
this.setState({
rateMethodCode: record.rateMethodCode,
});
}}
/>
)}
</FormItem>
{form.getFieldValue('rateTypeCode') === 'Current Rate' ? (
<FormItem
{...MODAL_FORM_ITEM_LAYOUT}
label={intl.get('hpfm.rate.model.rate.rateValue').d('汇率')}
>
{getFieldDecorator('rateValue', {
rules: [
{
type: 'string',
required: true,
message: intl.get('hzero.common.validation.notNull', {
name: intl.get('hpfm.rate.model.rate.rateValue').d('汇率'),
}),
},
],
})(<Input disabled />)}
</FormItem>
) : (
''
)}
{rateDate && (
<FormItem
{...MODAL_FORM_ITEM_LAYOUT}
label={intl.get('hpfm.rate.model.rate.rateDate').d('兑换日期')}
>
{getFieldDecorator('rateDate', {
initialValue: rateDate ? moment(rateDate, DEFAULT_DATE_FORMAT) : '',
})(
<DatePicker
placeholder=""
style={{ width: '100%' }}
disabled
format={getDateFormat()}
/>
)}
</FormItem>
)}
{rateMethodCode === 'FR' ? (
<FormItem
{...MODAL_FORM_ITEM_LAYOUT}
label={intl.get('hpfm.rate.model.rate.startDate').d('起始时间')}
>
{getFieldDecorator('startDate', {
initialValue: rateDate ? moment(rateDate, DEFAULT_DATE_FORMAT) : '',
rules: [
{
type: 'object',
required: true,
message: intl.get('hzero.common.validation.notNull', {
name: intl.get('hpfm.rate.model.rate.startDate').d('起始时间'),
}),
},
{
validator: validStartDate,
},
],
})(
<DatePicker
placeholder=""
style={{ width: '100%' }}
disabledDate={current => {
return (
(current && moment(current).subtract(-1, 'days') < moment().endOf('day')) ||
moment(current).subtract(30, 'days') > moment().endOf('day')
);
}}
disabled={form.getFieldValue('rateTypeCode') === 'Current Rate' || !!rateDate}
format={getDateFormat()}
/>
)}
</FormItem>
) : (
''
)}
{rateMethodCode === 'FR' && (
<FormItem
{...MODAL_FORM_ITEM_LAYOUT}
label={intl.get('hpfm.rate.model.rate.endDate').d('结束时间')}
>
{getFieldDecorator('endDate', {
initialValue: rateDate ? moment(rateDate, DEFAULT_DATE_FORMAT) : '',
rules: [
{
type: 'object',
required: true,
message: intl.get('hzero.common.validation.notNull', {
name: intl.get('hpfm.rate.model.rate.endDate').d('结束时间'),
}),
},
{
validator: validDate,
},
],
})(
<DatePicker
placeholder=""
style={{ width: '100%' }}
disabled={form.getFieldValue('rateTypeCode') === 'Current Rate' || !!rateDate}
disabledDate={current => {
return (
(current && moment(current).subtract(-1, 'days') < moment().endOf('day')) ||
moment(current).subtract(30, 'days') > moment().endOf('day')
);
}}
format={getDateFormat()}
/>
)}
</FormItem>
)}
<FormItem
{...MODAL_FORM_ITEM_LAYOUT}
label={intl.get('hpfm.rate.model.rate.currencyNumber').d('货币数量')}
>
{getFieldDecorator('currencyNumber', {
initialValue: rate ? '1' : '',
rules: [
{
required: true,
message: intl.get('hzero.common.validation.notNull', {
name: intl.get('hpfm.rate.model.rate.currencyNumber').d('货币数量'),
}),
},
{
pattern: /^[0-9]*$/,
message: intl.get('hpfm.rate.validation.digital').d('只能输入数字'),
},
{
validator: (rule, value, callback) => {
if (value > 0) {
callback();
} else {
callback(
new Error(
intl
.get('hpfm.rate.view.validation.correctCurrencyNum')
.d('请输入正确的货币数量')
)
);
}
},
},
],
})(<InputNumber precision={0} min={0} style={{ width: '100%' }} />)}
</FormItem>
<FormItem
{...MODAL_FORM_ITEM_LAYOUT}
label={intl.get('hpfm.rate.model.rate.exchangeNumber').d('兑换数量')}
>
{getFieldDecorator('exchangeNumber', {
initialValue: rate ? round(multiply(1, rate), 8).toString() : '',
rules: [
{
required: true,
message: intl.get('hzero.common.validation.notNull', {
name: intl.get('hpfm.rate.model.rate.exchangeNumber').d('兑换数量'),
}),
},
{
validator: (rule, value, callback) => {
if (value > 0) {
callback();
} else {
callback(
new Error(
intl
.get('hpfm.rate.view.validation.correctExchangeNum')
.d('请输入正确的兑换数量')
)
);
}
},
},
],
})(<InputNumber precision={8} step={0.00000001} min={0} style={{ width: '100%' }} />)}
</FormItem>
<FormItem
{...MODAL_FORM_ITEM_LAYOUT}
label={intl.get('hzero.common.status.enable').d('启用')}
>
{getFieldDecorator('enabledFlag', {
initialValue: enabledFlag,
})(<Switch />)}
</FormItem>
</Form>
</Modal>
);
}
Example #2
Source File: index.js From hzero-front with Apache License 2.0 | 4 votes |
render() {
const {
match,
initLoading,
updateLoading,
createLoading,
organizationId,
crossRateLoading,
rate: { rateList = [], modalVisible, rateMethodList, pagination = {} },
} = this.props;
const { crossRate, rateFormData } = this.state;
const title = rateFormData.exchangeRateId
? intl.get('hpfm.rate.view.message.edit').d('编辑汇率定义')
: intl.get('hpfm.rate.view.message.create').d('新建汇率定义');
const rateFormProps = {
title,
rateMethodList,
modalVisible,
anchor: 'right',
confirmLoading: updateLoading || createLoading,
onCancel: this.hideModal,
onHandleAdd: this.handleAdd,
initData: rateFormData,
};
const crossRateProps = {
crossRate,
anchor: 'right',
confirmLoading: crossRateLoading,
onCancelDrawer: this.setCrossRateDrawer,
onSaveCrossRate: this.saveCrossRate,
};
const columns = [
{
title: intl.get('hpfm.rate.model.rate.fromCurrencyCode').d('币种代码'),
width: 120,
dataIndex: 'fromCurrencyCode',
},
{
title: intl.get('hpfm.rate.model.rate.fromCurrencyName').d('币种名称'),
dataIndex: 'fromCurrencyName',
minWidth: 200,
},
{
title: intl.get('hpfm.rate.model.rate.toCurrencyCode').d('兑换币种代码'),
width: 120,
dataIndex: 'toCurrencyCode',
},
{
title: intl.get('hpfm.rate.model.rate.toCurrencyName').d('兑换币种名称'),
dataIndex: 'toCurrencyName',
minWidth: 200,
},
{
title: intl.get('hpfm.rate.model.rate.rateTypeName').d('汇率类型'),
key: 'rateTypeName',
width: 100,
dataIndex: 'rateTypeName',
},
{
title: intl.get('hpfm.rate.model.rate.rateDate').d('兑换日期'),
width: 150,
dataIndex: 'rateDate',
render: (text) => {
return <span>{moment(text).format(getDateFormat())}</span>;
},
},
{
title: intl.get('hpfm.rate.model.rate.currencyNumber').d('货币数量'),
width: 100,
dataIndex: 'currencyNumber',
render: () => {
return <span>1</span>;
},
},
{
title: intl.get('hpfm.rate.model.rate.exchangeNumber').d('兑换数量'),
width: 100,
dataIndex: 'exchangeNumber',
render: (text, record) => {
return <span>{round(multiply(1, record.rate), 8)}</span>;
},
},
{
title: intl.get('hzero.common.status').d('状态'),
width: 100,
dataIndex: 'enabledFlag',
render: enableRender,
},
{
title: intl.get('hzero.common.button.action').d('操作'),
width: 80,
fixed: 'right',
render: (text, record) => {
const operators = [
{
key: 'edit',
ele: (
<ButtonPermission
type="text"
permissionList={[
{
code: `${match.path}.button.edit`,
type: 'button',
meaning: '汇率定义-编辑',
},
]}
onClick={() => this.handleUpdateRate(record)}
>
{intl.get('hzero.common.button.edit').d('编辑')}
</ButtonPermission>
),
len: 2,
title: intl.get('hzero.common.button.edit').d('编辑'),
},
];
return operatorRender(operators, record);
},
},
];
return (
<React.Fragment>
<Header title={intl.get('hpfm.rate.view.message.title').d('汇率定义')}>
<ButtonPermission
icon="plus"
type="primary"
permissionList={[
{
code: `${match.path}.button.create`,
type: 'button',
meaning: '汇率定义-新建',
},
]}
onClick={this.showModal}
>
{intl.get('hzero.common.button.create').d('新建')}
</ButtonPermission>
<ExcelExport
exportAsync
requestUrl={`${HZERO_PLATFORM}/v1/${
isTenantRoleLevel()
? `${organizationId}/exchange-rates/export`
: 'exchange-rates/export'
}`}
queryParams={this.getSearchFormData}
/>
<ButtonPermission
permissionList={[
{
code: `${match.path}.button.createCrossRate`,
type: 'button',
meaning: '汇率定义-生成交叉汇率',
},
]}
onClick={() => this.setCrossRateDrawer(true)}
>
{intl.get('hpfm.rate.view.rate.createCrossRate').d('生成交叉汇率')}
</ButtonPermission>
</Header>
<Content>
<div className="table-list-search">{this.renderFilterForm()}</div>
<Table
bordered
rowKey="exchangeRateId"
loading={initLoading}
dataSource={rateList}
columns={columns}
scroll={{ x: tableScrollWidth(columns) }}
pagination={pagination}
onChange={this.handleStandardTableChange}
/>
<RateForm {...rateFormProps} />
<CrossRateDrawer {...crossRateProps} />
</Content>
</React.Fragment>
);
}