import Vue from 'vue'
import { config } from '@/config/config'

//保留两位小数
Vue.filter('keepTwoNum',function(val){
	let value = Number(val)
	return value.toFixed(2)
})


//链接加时间戳
Vue.filter("timestamp", function(link) {	
		return link + '?t=' + new Date().getTime();
});


//截取第一张照片且判断是否有图片，没有图片按照传递类型随机输出
Vue.filter("firstImg",function(arr,sizeType,imgType){
	let img;
	//图片类型判断
	if(arr){
		if(arr instanceof Array){
			img = arr[0]
		}else{
			img = arr.split(',')[0]
		}
	}else if(!arr){
		//如果没有图片则随机输出一张
		// if(imgType === 'farmer'){
		// 	const farmerList = ['carbon2/farmer/1.png','carbon2/farmer/2.png']
		// 	img = farmerList[Math.floor(Math.random() * farmerList.length)];
		// }
		img = '/static/img/inbuild.png'
	}
	// return config.imgUrl + img;
	return img;
});

Vue.filter("miniImg",function(img,quality){
	return img+'?imageMogr2/quality/'+quality
});
