const isEmpty = function(obj) {
	if (obj == null) return true;
	if (typeof obj !== 'object') return false;
	return JSON.stringify(obj) === '{}';
};
const status = function(value, state) {
	var status = '未生成'
	if (state == 'SUCCESS') {
		switch (value) {
			case 'NONE':
				status = '未生成'
				break
			case 'PENDING':
				status = '等待'
				break
			case 'GENERATING':
				status = '生成中...'
				break
			case 'SUCCESS':
				status = '生成成功'
				break
			case 'FAILED':
				status = '生成失败'
				break
		}
	} else {
		switch (state) {
			case 'FAILED':
				status = '生成失败'
				break
			case 'GENERATING':
				status = '生成中...'
				break
			case 'NONE':
				status = '未生成'
				break
		}
	}
	return status
};
const orderStatus = function(value) {
	var statusStr = '已完成'
	switch (value) {
		case 'PENDING':
			statusStr = '等待'
			break
		case 'COMPLETE':
			statusStr = '已完成'
			break
		case 'FULL_REFUND':
			statusStr = '全额退款'
			break
		case 'CORRECTION1_REFUND':
			statusStr = '补正1次退款'
			break
		case 'CORRECTION2_REFUND':
			statusStr = '补正2次退款'
			break
	}
	return statusStr
};
const proType = function(value) {
	// PROJ:项目、AGENT:代理、FULL_REFUND:全额退款、CORRECTION1_REFUND:补正1次退款、CORRECTION2_REFUND:补正2次退款
	var str = '项目创建'
	switch (value) {
		case 'PROJ':
			str = '项目创建'
			break
		case 'AGENT':
			str = '代理'
			break
		case 'FULL_REFUND':
			str = "全额退款"
			break
		case 'CORRECTION1_REFUND':
			str = '补正1次退款'
			break
		case 'CORRECTION2_REFUND':
			str = '补正2次退款'
			break
	}
	return str

}
const boderStyle = function(value) {
	var str = 'tickets-yellow' // tickets-gray  tickets-green
	switch (value) {
		case '1': //可用
			str = 'tickets-yellow'
			break
		case '2': //已经使用
			str = 'tickets-gray'
			break
		case '3': //不可用
			str = 'tickets-green'
			break
	}
	return str
}
const fontColor = function(value) {
	var str = 'font-yellow' // tickets-gray  tickets-green
	switch (value) {
		case '1': //可用
			str = 'font-yellow'
			break
		case '2': //已经使用
			str = 'font-gray'
			break
		case '3': //不可用
			str = 'font-green'
			break
	}
	return str
}
const timeSplit = function(value) {
	var regex = new RegExp('-', 'g');
	return value.replace(regex, '.');
}
const objIsEmpty = function(obj) {
	if (obj === undefined) {
		return true;
	}
	if (obj === null) {
		return true;
	}
	return Object.keys(obj).length === 0;
}
var moneyTxt = function(size, fontSize, price) {
	const formattedStr =
		'<span style="font-size:' + size + 'px;">￥</span><span style="font-size:' + fontSize + 'px;">' + price +
		'</span>';
	return formattedStr
}
var phoneNum = function(str, startLength, endLength, replaceStr) {
	if (str == null || str == '') return ''
	if (str.length <= startLength + endLength) {
		return str;
	}
	return str.slice(0, startLength) + replaceStr + str.slice(str.length - endLength);
}

var repairStatusColor = function(status) {
	var color = 'repair-status-yellow'
	switch (status) {
		case 'PENDING':
			color = 'repair-status-yellow'
			break
		case 'APPROVED':
			color = 'repair-status-green'
			break
		case 'REJECTED':
			color = 'repair-status-red'
			break
		case 'CANCELED':
			color = 'repair-status-gray'
			break
	}
	return color
}
var repairStatus = function(status) {
	var str = '待审核'
	switch (status) {
		case 'PENDING':
			str = '待审核'
			break
		case 'APPROVED':
			str = '已通过'
			break
		case 'REJECTED':
			str = '未通过'
			break
		case 'CANCELED':
			str = '已取消'
			break
	}
	return str
}
var repairType = function(type) {
	var str = '未知'
	switch (type) {
		case 'CORRECTION1':
			str = '一次补正'
			break
		case 'CORRECTION2':
			str = '二次补正'
			break
	}
	return str
}
var repairKind = function(kind) {
	var str = '未知'
	switch (kind) {
		case 'CODE':
			str = '代码'
			break
		case 'MANUAL':
			str = '操作手册'
			break
		case 'ALL':
			str = '代码+操作手册'
			break
	}
	return str
}

var payType = function(type) {
	// 充值1|支出2|提现3|系统扣款4|订单收入5|付款6)
	var typeStr = '支出'
	switch (type) {
		case 1:
			typeStr = '充值'
			break
		case 2:
			typeStr = '支出'
			break
		case 3:
			typeStr = '提现'
			break
		case 4:
			typeStr = '系统\n扣款'
			break
		case 5:
			typeStr = '订单\n收入'
			break
		case 6:
			typeStr = '付款'
			break
	}
	return typeStr
}
var payTypeColor = function(type) {
	var typeColr = 'type-g'
	switch (type) {
		case 1:
		case 3:
		case 5:
			typeColr = 'type-g'
			break
		case 2:
		case 4:
		case 6:
			typeColr = 'type-z'
			break
	}
	return typeColr
}

// 充值1|支出2|提现3|系统扣款4|订单收入5|付款6)
var payTypeFontSize = function(type) {
	var fSize = 'size-32'
	switch (type) {
		case 1:
		case 2:
		case 3:
		case 6:
			fSize = 'size-32'
			break
		case 4:
		case 5:
			fSize = 'size-24'
			break
	}
	return fSize
}
var payTypeSign = function(type) {
	var typeStr = '-'
	switch (type) {
		case 1:
		case 5:
			typeStr = '+'
			break
		case 2:
		case 3:
		case 4:
		case 6:
			typeStr = '-'
			break
	}
	return typeStr
}
var invoiceStatusColor = function(status) {
	var str = 'col-yellow'
	// -1:用户取消,0:开票失败,1:开票中,2:开票完成
	switch (status) {
		case '-1':
			str = 'col-gray'
			break
		case '0':
			str = 'col-red'
			break
		case '1':
			str = 'col-yellow'
			break
		case '2':
			str = 'col-green'
			break

	}
	return str
}
var invoiceStatus = function(status) {
	var str = '待审核'
	// -1:用户取消,0:开票失败,1:开票中,2:开票完成
	switch (status) {
		case '-1':
			str = '已取消'
			break
		case '0':
			str = '未通过'
			break
		case '1':
			str = '待审核'
			break
		case '2':
			str = '完成'
			break
	}
	return str
}
var payWay = function(way) {
	var wayClass = 'pay-wx'
	switch (way) {
		case '微信':
			wayClass = 'pay-wx'
			break
		case '支付宝':
			wayClass = 'pay-alipay'
			break
		case '对公转账':
			wayClass = 'pay-public'
			break
		case '百度':
			wayClass = 'pay-bd'
			break
	}
	return wayClass
}
var includes = function(str, target) {
	return str && str.indexOf(target) !== -1;
}
// 订单状态0:取消订单,1:待付款,2:待填写资料,3:过户中,4:平台下证	
var goodsOrderStatus = function(status) {
	var str = '已取消'
	switch (status) {
		case '0':
			str = '已取消'
			break
		case '1':
			str = '待付款'
			break
		case '2':
			str = '写资料'
			break
		case '3':
			str = '过户中'
			break
		case '4':
			str = '已下证'
			break
	}
	return str
}

var goodsStatus = function(check, status, orderStatus) {
	check = '' + check;
	status = '' + status;
	orderStatus = '' + orderStatus;
	var orderStatusMap = {
		'1': '待付款',
		'2': '待填写资料',
		'3': '过户中',
		'4': '过户完成'
	};
	if (orderStatusMap[orderStatus]) {
		return orderStatusMap[orderStatus];
	}
	var checkStatusMap = {
		'': '未提交',
		'0': '审核未通过',
		'1': '审核中'
	};
	if (checkStatusMap[check]) {
		return checkStatusMap[check];
	}
	if (check == '2') {
		return status == '1' ? '已上架' : '未上架';
	}
	return '未提交';
}
var goodsOrderColor = function(status) {
	var str = 'col-gray'
	switch (status) {
		case '0':
			str = 'col-gray'
			break
		case '1':
		case '2':
		case '3':
			str = 'col-primary'
			break
		case '4':
			str = 'col-green'
			break
	}
	return str
}
//判断是否是图片
var isImg = function(filename) {
	var input = filename.trim();
	var hasDot = input.indexOf('.') !== -1;
	var extension = hasDot ?
		input.substring(input.lastIndexOf('.') + 1).toLowerCase() :
		input.toLowerCase();
	var imageExtensions = [
		'jpg', 'jpeg', 'png', 'gif', 'bmp',
		'webp', 'svg', 'ico', 'tiff', 'tif'
	];
	return imageExtensions.indexOf(extension) !== -1;
};
export {
	isEmpty,
	status,
	orderStatus,
	proType,
	boderStyle,
	fontColor,
	timeSplit,
	objIsEmpty,
	moneyTxt,
	phoneNum,
	repairStatusColor,
	repairKind,
	repairType,
	repairStatus,
	payTypeColor,
	payType,
	payTypeFontSize,
	payTypeSign,
	invoiceStatusColor,
	invoiceStatus,
	payWay,
	includes,
	goodsOrderStatus,
	goodsOrderColor,
	goodsStatus,
	isImg
}