HandsontableGridWrap.js
7.8 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
import React,{PropTypes} from 'react';
import cx from 'classnames';
import s from './handsontableGridWrap.scss';
const socialGridHead = [
{employee_no:'员工编号',employee_name:'姓名',pay_city:'社保缴纳地',pay_type:'社保缴纳类型',insurance_base:'社保基数',insurance_company_sum:'社保公司缴纳',
insurance_person_sum:'社保个人缴纳',endowment_company_ratio:'养老',endowment_company_amount:'',endowment_person_ratio:'',endowment_person_amount:'',medical_company_ratio:'医疗',medical_company_amount:'',medical_person_ratio:'',medical_person_amount:'',
unemployment_company_ratio:'失业',unemployment_company_amount:'',unemployment_person_ratio:'',unemployment_person_amount:'',maternity_company_ratio:'生育',maternity_company_amount:'',maternity_person_ratio:'',maternity_person_amount:'',injury_company_ratio:'工伤',injury_company_amount:'',injury_person_ratio:'',injury_person_amount:'',
housing_fund_company_ratio:'公积金',housing_fund_company_amount:'',housing_fund_person_ratio:'',housing_fund_person_amount:'',supplement_insurance_company_amount:'社保补缴',supplement_insurance_person_amount:'',supplement_housing_fund_company_amount:'公积金补缴',supplement_housing_fund_person_amount:''},
{employee_no:'',employee_name:'',pay_city:'',pay_type:'',insurance_base:'',insurance_company_sum:'',
insurance_person_sum:'',endowment_company_ratio:'公司缴纳比例',endowment_company_amount:'公司缴纳',endowment_person_ratio:'个人缴纳比例',endowment_person_amount:'个人缴纳',medical_company_ratio:'公司缴纳比例',medical_company_amount:'公司缴纳',
medical_person_ratio:'个人缴纳比例',medical_person_amount:'个人缴纳',
unemployment_company_ratio:'公司缴纳比例',unemployment_company_amount:'公司缴纳',unemployment_person_ratio:'个人缴纳比例',unemployment_person_amount:'个人缴纳',maternity_company_ratio:'公司缴纳比例',maternity_company_amount:'公司缴纳',maternity_person_ratio:'个人缴纳比例',maternity_person_amount:'个人缴纳',
injury_company_ratio:'公司缴纳比例',injury_company_amount:'公司缴纳',injury_person_ratio:'个人缴纳比例',injury_person_amount:'个人缴纳',housing_fund_company_ratio:'公司缴纳比例',housing_fund_company_amount:'公司缴纳',housing_fund_person_ratio:'个人缴纳比例',housing_fund_person_amount:'个人缴纳',
supplement_insurance_company_amount:'公司补缴',supplement_insurance_person_amount:'个人补缴',supplement_housing_fund_company_amount:'公司补缴',supplement_housing_fund_person_amount:'个人补缴'}
];
const getColHeaders=(columns)=>{
let colHeaders=[];
columns.map((col)=>{
colHeaders.push(col.name);
})
return colHeaders;
}
const getColumns=(columns)=>{
let cols=[];
columns.map((col)=>{
cols.push({
editor: false,
data:col.column_no
});
});
return cols;
}
const compare = function (obj1, obj2) {
var val1 = obj1.column_no;
var val2 = obj2.column_no;
if (val1 < val2) {
return -1;
} else if (val1 > val2) {
return 1;
} else {
return 0;
}
}
class HandsontableGridWrap extends React.Component {
constructor (props, context) {
super(props, context);
}
static propTypes={
onChange: PropTypes.func,
choices:PropTypes.array,
value:PropTypes.oneOfType([
PropTypes.string,
PropTypes.array
]),
placeholder:PropTypes.string,
name:PropTypes.string,
multi:PropTypes.bool,
error:PropTypes.bool,
disabled:PropTypes.bool,
labelKey:PropTypes.string,
valueKey:PropTypes.string,
style:PropTypes.object,
id:PropTypes.string
}
static defaultProps = {
style:{
width:'100%',
minHeight: '100px',
resize:'vertical',
overflow:'auto'
},
id:'custom_grid'
}
componentDidMount(){
const self=this;
let {costData={},columns=[],id}=self.props;
let container = document.getElementById(id);
let {data=[],hidden_columns=[],hidden_rows=[],merge_cells=[]}=costData;
console.log(costData) ;
if('social_grid'==id){
data=socialGridHead.concat(data);
merge_cells= [
{row:0, col: 7, rowspan: 1, colspan:4},
{row:0, col: 11, rowspan:1, colspan: 4},
{row:0, col: 15, rowspan:1, colspan: 4},
{row:0, col: 19, rowspan:1, colspan: 4},
{row:0, col: 23, rowspan:1, colspan: 4},
{row:0, col: 27, rowspan:1, colspan: 4},
{row:0, col: 31, rowspan:1, colspan: 2},
{row:0, col: 33, rowspan:1, colspan: 2},
{row:0, col: 0, rowspan:2, colspan: 1},
{row:0, col: 1, rowspan:2, colspan: 1},
{row:0, col: 2, rowspan:2, colspan: 1},
{row:0, col: 3, rowspan:2, colspan: 1},
{row:0, col: 4, rowspan:2, colspan: 1},
{row:0, col: 5, rowspan:2, colspan: 1},
{row:0, col: 6, rowspan:2, colspan: 1}
];
}
let options={
data:data,
stretchH:'all',
fixedRowsTop: 0,
manualColumnResize: true,
manualRowResize: true,
manualColumnMove: true,
columnSorting: true,
sortIndicator: true,
manualColumnResize: true,
fixedColumnsLeft: 0,
outsideClickDeselects: false,
filters: true,
mergeCells: merge_cells,
hiddenColumns: {
columns: [],
indicators: true
},
hiddenRows: {
rows: [],
indicators: true
},
search: true,
copyPaste:false
}
if(!columns){
}else{
columns=columns.sort(compare);
options['colHeaders']=getColHeaders(columns);
options['rowHeaders']=true;
options['columns']=getColumns(columns);
}
self.grid = new Handsontable(container,options);
}
componentWillReceiveProps(nextProps){
}
componentWillUnmount(){
this.grid.destroy();
}
render(){
const {style,id}=this.props;
return(
<div style={style} className={cx(s.handsontable_grid_wrap)}>
<div id={id} style={{height:'100%',width:'100%'}}></div>
</div>
)
}
}
export class CostGridWrap extends React.Component {
constructor (props, context) {
super(props, context);
}
static propTypes={
onChange: PropTypes.func,
choices:PropTypes.array,
value:PropTypes.oneOfType([
PropTypes.string,
PropTypes.array
]),
placeholder:PropTypes.string,
name:PropTypes.string,
multi:PropTypes.bool,
error:PropTypes.bool,
disabled:PropTypes.bool,
labelKey:PropTypes.string,
valueKey:PropTypes.string,
style:PropTypes.object,
id:PropTypes.string
}
static defaultProps = {
style:{
width:'100%',
minHeight: '220px',
resize:'vertical',
overflow:'auto'
},
id:'custom_grid'
}
componentDidMount(){
const self=this;
let {costData={},columns=[],id,myData}=self.props;
let container = document.getElementById(id);
if(myData){
costData=myData;
}
const {data=[],hidden_columns=[],hidden_rows=[],merge_cells=[]}=costData;
let options={
data:data,
stretchH:'all',
fixedRowsTop: 0,
manualColumnResize: true,
manualRowResize: true,
manualColumnMove: true,
columnSorting: true,
sortIndicator: true,
manualColumnResize: true,
fixedColumnsLeft: 0,
outsideClickDeselects: false,
filters: true,
mergeCells: merge_cells,
hiddenColumns: {
columns: [],
indicators: true
},
hiddenRows: {
rows: [],
indicators: true
},
search: true,
copyPaste:false
}
if(!columns){
}else{
columns=columns.sort(compare);
options['colHeaders']=getColHeaders(columns);
options['rowHeaders']=true;
options['columns']=getColumns(columns);
}
self.grid = new Handsontable(container,options);
}
componentWillReceiveProps(nextProps){
}
componentWillUnmount(){
this.grid.destroy();
}
render(){
const {style,id}=this.props;
return(
<div style={style} className={cx(s.handsontable_grid_wrap)}>
<div id={id} style={{height:'100%',width:'100%'}}></div>
</div>
)
}
}
export default HandsontableGridWrap;