Skip to content

Instantly share code, notes, and snippets.

@youzipi
Last active March 23, 2017 07:27
Show Gist options
  • Save youzipi/5101d414abf83eed2535b2dfe16442b3 to your computer and use it in GitHub Desktop.
Save youzipi/5101d414abf83eed2535b2dfe16442b3 to your computer and use it in GitHub Desktop.
lodash-bala
var areas = _.chain(nodes)
.filter(function (node) {
switch (node.id[0]) {
case 'p': // 省 是全选状态
return isFullCheck(node);
case 'c': // 市 是全选状态 and 上级(省)是半选
return isFullCheck(node)
&& !isFullCheck(node.getParentNode());
case 'd': // 区县 是全选状态 and 上级(市)是半选
return !isFullCheck(node.getParentNode());
}
})
.map(function (node) {
return _.zipObject(['level', 'id'], [levelArea[node.level], node.id.substring(1)]);
// ex: {level:'p',id:'1100000000'}
})
.groupBy('level')
.value();
var getIds = fp.map('id'); // 可以返回 [],不需要defaultIds
// var defaultIds = function (ids) {
// return getIds(ids) || []
// };
var provinceIds = getIds(areas['p']);
var cityIds = getIds(areas['c']);
var districtIds = getIds(areas['d']);
// 添加套装:计算套装中商品的最低总价 和最高总价
var calPrice = fp.reduce(
function (sum, a) {
return sum + parseInt(
_.multiply($(a).text(), $(a).parents('td').next().text())
)
}, 0);
var minSumPrice = calPrice($('.minPrice'));
var maxSumPrice = calPrice($('.maxPrice'));
fp.flow(
fp.replace(/[\[\]]/g, ''),
fp.split(','),
fp.map(_.trim)
)('[a,b,c, d]')
// output: ['a','b','c','d']
var getIds = fp.map('id'); // 可以返回 [],不需要defaultIds
// var defaultIds = function (ids) {
// return getIds(ids) || []
// };
var provinceIds = getIds(areas['p']);
var cityIds = getIds(areas['c']);
var districtIds = getIds(areas['d']);
var calPrice = fp.reduce(
function (sum, a) {
return sum + parseInt(
_.multiply($(a).text(), $(a).parents('td').next().text())
)
}, 0);
var minSumPrice = calPrice($('.minPrice'));
var maxSumPrice = calPrice($('.maxPrice'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment