|
|
/*
|
|
|
* @Author: Targaryen
|
|
|
* @Date: 2016-06-02 15:50:47
|
|
|
* @Last Modified by: Targaryen
|
|
|
* @Last Modified time: 2016-06-02 16:05:54
|
|
|
*/
|
|
|
|
|
|
'use strict';
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
/**
|
|
|
* 处理用于筛选的 URL
|
|
|
* @param {[type]} originParam [description]
|
|
|
* @param {[type]} newParam [description]
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
|
|
exports.handleFilterUrl = (originParam, newParam) => {
|
|
|
let dest = '?';
|
|
|
let tempOriginParam = {};
|
|
|
|
|
|
// 创建 originParam、newParam 键的数组
|
|
|
let originParamArray = _.keys(originParam);
|
|
|
let newParamArray = _.keys(newParam);
|
|
|
|
|
|
// 判断参数是否已经存在
|
|
|
let isExist = !_.isEmpty(_.find(originParamArray, function(o) {
|
|
|
return o === newParamArray[0];
|
|
|
}));
|
|
|
|
|
|
if (isExist) {
|
|
|
tempOriginParam = Object.assign(tempOriginParam, originParam);
|
|
|
|
|
|
_.forEach(newParam, function(value, key) {
|
|
|
tempOriginParam[key] = value;
|
|
|
});
|
|
|
} else {
|
|
|
tempOriginParam = Object.assign(tempOriginParam, originParam, newParam);
|
|
|
}
|
|
|
|
|
|
_.forEach(tempOriginParam, function(value, key) {
|
|
|
dest = dest + key + '=' + value + '&';
|
|
|
});
|
|
|
|
|
|
return _.trim(dest, '&');
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 处理选中数据
|
|
|
* @param {[type]} params [description]
|
|
|
* @param {[type]} origin [description]
|
|
|
* @param {[type]} param [description]
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
|
|
exports.handleCheckedData = (params, origin, param) => {
|
|
|
var dest = [];
|
|
|
|
|
|
// 品牌选中数据
|
|
|
if (!_.isEmpty(origin)) {
|
|
|
_.forEach(origin, (value) => {
|
|
|
if (value.checked) {
|
|
|
let checked = {};
|
|
|
|
|
|
checked.name = value.name;
|
|
|
|
|
|
let tempParam = {};
|
|
|
|
|
|
tempParam[param] = '';
|
|
|
// checked.href = handleFilterUrl(params, tempParam);
|
|
|
|
|
|
dest.push(checked);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return dest;
|
|
|
}; |
...
|
...
|
|