BatchWorkListPriceUpdate.js
8.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/**
* 此组件用于生产工单列表批量更新价格 by pm 20210518
*/
/* eslint-disable no-undef,import/first,prefer-destructuring,jsx-a11y/alt-text */
import React, { Component } from 'react';
import { Input, message, Radio } from 'antd';
import styles from '../../index.less';
import * as commonBusiness from '../Common/commonBusiness';
import * as commonServices from '../../services/services'; /* 服务类 */
import * as commonConfig from '../../utils/config';
import * as commonUtils from '../../utils/utils';
import * as commonFunc from '../Common/commonFunc';
import AntdDraggableModal from '../Common/AntdDraggableModal';
export default class BatchWorkListPriceUpdate extends Component {
/** 构造函数 */
constructor(props) {
super(props);
this.state = {
radioValue: 1,
};
this.formatOk = -1;
}
handleBtnSave = () => {
const {
reportData, reportDelData, reportConfig,
} = this.props;
const data = [];
if (!commonBusiness.validateTable(reportConfig, reportData)) {
return;
}
data.push(commonBusiness.mergeData('report', 'sysreport', reportData, reportDelData));
this.handleSaveData({ data, sClientType: '1', optName: commonFunc.showMessage(app.commonConst, 'priceSaveSucess') });
};
handleSaveData = async (params) => {
const {
token, sModelsId, masterData,
} = this.props;
const returnData = await commonBusiness.saveData({ token, value: params, sModelsId });
if (returnData.code === 1) {
this.props.onSaveState({
enabled: false, currentId: masterData.sId,
});
this.getReportData();
} else {
this.props.getServiceError(returnData);
}
};
handleOk = async () => {
const {
sModelsId, app, slaveConfig, slaveSelectedRowKeys, slaveFilterCondition,
} = this.props;
const { radioValue } = this.state;
const dProductPrice = document.getElementById('dProductPriceNew').value;
const dFlowRate = document.getElementById('dFlowRate').value; /* 上浮比率 */
if (this.formatOk > -1) {
message.warning(commonFunc.showMessage(app.commonConst, 'DecimalOut'));
return;
}
/* 勾选行文本框作为单价的参数 */
let dNProductPrice = 0;
let dFloatRate = 0;
/* 数据参数 */
const value = {
sProName: 'Sp_System_BatchWorkListPriceMoney',
paramsMap: {
sFormGuid: sModelsId, sSrcGuid: slaveSelectedRowKeys,
},
};
if (radioValue === 1) { /* 上浮比率 */
dFloatRate = dFlowRate;
value.paramsMap.dFloatRate = dFloatRate;
} else if (radioValue === 2) {
dNProductPrice = dProductPrice;
value.paramsMap.dNProductPrice = dNProductPrice;
}
const url = `${commonConfig.server_host}business/updatePriceBatch?sModelsId=${sModelsId}`;
const returnData = (await commonServices.postValueService(app.token, value, url)).data;
if (returnData.code === 1) { /* 成功 */
message.success(commonFunc.showMessage(app.commonConst, 'priceSaveSucess') + returnData.msg);
document.getElementById('dProductPriceNew').value = '';
document.getElementById('dFlowRate').value = '';
this.props.onGetData(slaveConfig, slaveFilterCondition);
} else { /* 失败 */
this.props.getServiceError({ msg: commonFunc.showMessage(app.commonConst, 'priceSaveSucess') + returnData.msg });
}
this.props.onSaveState({
visibleBatchWorkListPriceUpdate: false,
enabled: false,
});
};
handleCancel = () => {
this.props.onSaveState({
visibleBatchWorkListPriceUpdate: false,
enabled: false,
});
};
handleRadioChange = (e) => {
this.setState({
radioValue: e.target.value,
});
};
handleChange = (name) => {
const { slaveConfig, app } = this.props;
const dPprice = this.props.getFloatNum('dProductPrice'); /* 获取系统设定小数位 */
const priceValue = document.getElementById('dProductPriceNew').value;
const iNewIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sName === 'dProductPrice');
if (iNewIndex > -1 && (commonUtils.isNotEmptyObject(slaveConfig.gdsconfigformslave[iNewIndex].sMaxValue) || commonUtils.isNotEmptyObject(slaveConfig.gdsconfigformslave[iNewIndex].sMinValue))) {
const product = slaveConfig.gdsconfigformslave[iNewIndex];
document.getElementById('dProductMoneyNew').value = 0;
if (commonUtils.isNotEmptyObject(product.sMaxValue) && parseFloat(product.sMaxValue, dPprice) < parseFloat(priceValue, dPprice)) {
message.warning(commonFunc.showMessage(app.commonConst, 'maxValue') + product.sMaxValue);
}
if (commonUtils.isNotEmptyObject(product.sMinValue) && parseFloat(product.sMinValue, dPprice) < parseFloat(priceValue, dPprice)) {
message.warning(commonFunc.showMessage(app.commonConst, 'minValue') + product.sMinValue);
}
} else {
const rep = /\d+\.(\d*)/;
if (name === 'dProductPriceNew') {
const pointRep = priceValue.match(rep); /* 匹配小数,若为整数,则为空 */
const point = priceValue.replace(rep, '$1');/* 通过正则表达式获取小数位后长度 */
if (isNaN(priceValue)) {
this.formatOk = 1;
message.warning(commonFunc.showMessage(app.commonConst, 'formatCheck'));
return;
}
if (pointRep !== null && point.length > dPprice) {
this.formatOk = 1;
document.getElementById('dProductMoneyNew').value = 0;
message.warning(commonFunc.showMessage(app.commonConst, 'maxPointLength') + dPprice);
} else if (pointRep === null && priceValue.length > 9) { /* 整数超9位 */
message.warning(`${commonFunc.showMessage(app.commonConst, 'maxIntegerLength')}9`);
this.formatOk = 1;
} else {
this.formatOk = -1;/* 确定时,输入规则正常标志 */
}
}
if (name === 'dFlowRate') {
const dFlowRate = document.getElementById('dFlowRate').value; /* 上浮比率 */
const pointRep = dFlowRate.match(rep); /* 匹配小数,若为整数,则为空 */
const point = dFlowRate.replace(rep, '$1');/* 通过正则表达式获取小数位后长度 */
if (isNaN(dFlowRate)) {
this.formatOk = 1;
message.warning(commonFunc.showMessage(app.commonConst, 'formatCheck'));
return;
}
if (pointRep !== null && point.length > dPprice) {
this.formatOk = 1;
message.warning(commonFunc.showMessage(app.commonConst, 'maxPointLength') + dPprice);
} else {
this.formatOk = -1;/* 确定时,输入规则正常标志 */
}
}
}
};
/** 渲染 */
render() {
const {
batchPriceWorkListUpdateData, visibleBatchWorkListPriceUpdate, app,
} = this.props;
const priceBatchUpdate = commonFunc.showMessage(app.commonConst, 'workPriceBatchUpdate');/* 价格批量更新 */
const sOrderMoney = commonFunc.showMessage(app.commonConst, 'sOrderMoney');/* 订货单价标题 */
const sFlowRate = commonFunc.showMessage(app.commonConst, 'sFlowRate');/* 浮动比率%标题 */
return (
<div className={styles.toolBar}>
{ visibleBatchWorkListPriceUpdate ?
<AntdDraggableModal
title={priceBatchUpdate}
visible={visibleBatchWorkListPriceUpdate}
onOk={this.handleOk}
onCancel={this.handleCancel}
destroyOnClose
body={{ width: '400px' }}
>
<div className="priceUpdatelist">
{
batchPriceWorkListUpdateData !== undefined ?
<div style={{ marginBottom: 16 }}>
<Radio.Group name="radiogroup" onChange={this.handleRadioChange} value={this.state.radioValue}>
<Radio style={{ height: '38px', lineHeight: '36px' }} value={1}> <Input id="dFlowRate" disabled={this.state.radioValue === 2} bordered addonBefore={sFlowRate} onChange={this.handleChange.bind(this, 'dFlowRate')} /> </Radio> <br />
<Radio style={{ height: '38px', lineHeight: '36px' }} value={2}> <Input id="dProductPriceNew" disabled={this.state.radioValue === 1} bordered addonBefore={`${sOrderMoney} `} onChange={this.handleChange.bind(this, 'dProductPrice')} /></Radio>
</Radio.Group>
</div>
: null }
</div>
</AntdDraggableModal>
: '' }
</div>
);
}
}