var g_filters = {
	//-- 判断是不是有等级价 --
	is_has_rank: function (rank_switch, item) {
		if (!rank_switch) return false;
		if (item.cardprice1 || item.cardprice2 || item.cardprice3) { return true }
		return false;
	},

	//-- 判断,不是等级会员时候，要显示的最低等级价和名称 --
	get_card_price: function (goods, all_card, type) {
		var price1 = parseFloat(goods['cardprice1']);
		var price2 = parseFloat(goods['cardprice2']);
		var price3 = parseFloat(goods['cardprice3']);
		if (!all_card) {
			if (type == 0) return 0;
			return "";
		}

		var arr = [];
		var min_price = 0;
		var min_name = "";

		var min_price = null;
		var min_name = null;
		//---设置对应的价格名字----	   
		for (var i = 0; i < 3; i++) {
			var vl = all_card[i];
			if (!vl) continue;
			if (vl['CorrPrice'] == "Price1" && price1 > 0) {
				if (min_price == null) {
					min_price = price1; min_name = vl['CardName'];
				}
				else if (price1 < min_price) {
					min_price = price1; min_name = vl['CardName'];
				}
			}
			if (vl['CorrPrice'] == "Price2" && price2 > 0) {
				if (min_price == null) {
					min_price = price2; min_name = vl['CardName'];
				}
				else if (price2 < min_price) {
					min_price = price2; min_name = vl['CardName'];
				}
			}

			if (vl['CorrPrice'] == "Price3" && price3 > 0) {
				if (min_price == null) {
					min_price = price3; min_name = vl['CardName'];
				}
				else if (price3 < min_price) {
					min_price = price3; min_name = vl['CardName'];
				}
			}

		}
		if (min_price == null) {
			if (type == 0) return 0;
			return "";
		}

		//if(type==0) return arr.length;
		//--进行排序,升序---
		/*---
		arr.sort(function(a,b){
					 if (a.price < b.price) {
					   return -1;
					 } else if (a.fee == b.fee) {
					   return 0;
					 } else {
					   return 1;
					 }
		})--*/
		//-- 获取最下价钱，和相应的卡的名称 --		  
		//min_price=min.price;
		//min_name=min.name;				   
		if (type == 0) return min_price.toFixed(2);
		if (min_name.length > 7) min_name = min_name.substring(0, 8);
		return min_name;
	},


	get_goods_url: function (item) {

		var url1 = "/pages/goods/goodsInfo/goodsInfo?goods_id=" + item.goods_id + "&prom_id=" + item.prom_id + "&prom_type="+item.prom_type
		//  预售活动
		if (item.prom_type == 8) {
			url1 = "/packageC/pages/presell/goodsInfo/goodsInfo?goods_id=" + item.goods_id + "&prom_id=" + item.prom_id
		}
		// 如果是幸运购活动商品
		if (item.prom_type == 9) {
			url1 = "/packageC/pages/luckyGo/luckyGo_goodsInfo/luckyGo_goodsInfo?goods_id=" + item.goods_id + "&group_id=" + item.prom_id
		}

		if ([1,2,6].indexOf(item.prom_type)>-1 && item.prom_id > 0) {
			url1 = "/pages/goods/goodsInfo/goodsInfo?goods_id=" + item.goods_id + "&prom_id=" + item.prom_id + "&prom_type="+item.prom_type;
		}


		return url1;
	}
}

module.exports = {
	is_has_rank: g_filters.is_has_rank,
	get_card_price: g_filters.get_card_price,
	get_goods_url: g_filters.get_goods_url
}