|
|
'use strict';
|
|
|
|
|
|
import ReactNative from 'react-native';
|
|
|
import {Platform} from 'react-native';
|
|
|
import BrandService from '../../services/BrandService';
|
|
|
import {Record, List, Map} from 'immutable';
|
|
|
import Pinyin from '../../../common/utils/pinyin';
|
...
|
...
|
@@ -414,18 +415,34 @@ export function searchHistory() { |
|
|
};
|
|
|
}
|
|
|
|
|
|
export function insertSearchHistory(keyword) {
|
|
|
export function insertSearchHistory(data) {
|
|
|
return (dispatch, getState) => {
|
|
|
ReactNative.NativeModules.YH_ClassifyHelper.insertSearchHistory(keyword)
|
|
|
.then(data => {
|
|
|
dispatch({
|
|
|
type: INSERT_BRAND_SEARCH_HISTORY,
|
|
|
payload: parseSearchHistory(data)
|
|
|
});
|
|
|
})
|
|
|
.catch(error => {
|
|
|
//兼容IOS只需要搜索关键字,android需要整个data数据
|
|
|
if (Platform.OS === 'ios') {
|
|
|
let brandName = data.brand_name ? data.brand_name : '';
|
|
|
ReactNative.NativeModules.YH_ClassifyHelper.insertSearchHistory(brandName)
|
|
|
.then(data => {
|
|
|
dispatch({
|
|
|
type: INSERT_BRAND_SEARCH_HISTORY,
|
|
|
payload: parseSearchHistory(data)
|
|
|
});
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
else{
|
|
|
ReactNative.NativeModules.YH_ClassifyHelper.insertSearchHistory(data)
|
|
|
.then(data => {
|
|
|
dispatch({
|
|
|
type: INSERT_BRAND_SEARCH_HISTORY,
|
|
|
payload: parseSearchHistory(data)
|
|
|
});
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
|
...
|
...
|
@@ -447,7 +464,13 @@ export function clearSearchHistory() { |
|
|
function parseSearchHistory(data) {
|
|
|
let list = [];
|
|
|
data.map((item, i) => {
|
|
|
list.push({keyword: item});
|
|
|
//兼容IOS只需要搜索关键字,android需要整个data数据
|
|
|
if (Platform.OS === 'ios') {
|
|
|
list.push({keyword: item});
|
|
|
}
|
|
|
else{
|
|
|
list.push({keyword: item.brand_name, androiddata: item});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return list;
|
...
|
...
|
|