screenSubActions.js
1.85 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
'use strict';
import ReactNative from 'react-native';
import Utils from '../../utils/Utils';
const {
SET_DATASOURCE_SUB,
SET_SELECT_ITEM,
} = require('../../constants/actionTypes').default;
export function updateDataSource(data) {
if (!data) {
return;
}
let key = data?data.key:'';
let json = data;
if (key == 'brand') {
json = processData(data);
}
return {
type: SET_DATASOURCE_SUB,
payload: json
};
}
export function setSelectItem(json) {
return {
type: SET_SELECT_ITEM,
payload: json
};
}
export function selectItem(data) {
return (dispatch, getState) => {
let {app, screenSub} = getState();
let {filterSub} = screenSub;
let payload = parseList(data,filterSub);
dispatch(setSelectItem(payload));
};
}
function parseList(data,filterSub) {
let list = filterSub&&filterSub.list?filterSub.list.toJS():[];
for (var i = 0; i < list.length; i++) {
let item = list[i];
item.isSelect = false;
if (item.name == data.name) {
item.isSelect = true;
}
}
return list;
}
function processData(data){
let list = data?data.list:[];
let latterObject={};
let newObject={};
let keys = [];
let allObj = {};
let specialList = [];
list.forEach((item, i) => {
let key = item.brand_alif?item.brand_alif:item.name;
if (Utils.isContains(key,'全部') || Utils.isContains(key,'所有')) {
allObj = item;
}else if (!regChar(key) || key.length > 1) {
specialList.push(item);
} else{
if (!latterObject[key]) {
latterObject[key] = [];
keys.push(key);
}
latterObject[key].push(item);
}
});
keys.sort();
keys.forEach((item, i) => {
newObject[item] = latterObject[item];
});
data.list = newObject;
data.keyList = keys;
data.allObj = allObj;
data.specialList = specialList;
return data;
}
function regChar(value){
var reg= /^[A-Za-z]+$/;
if (reg.test(value)) {
return true;
}
return false;
}