export function isCardNo(card) {
	// 身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X 
	var reg =
		/(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/;
	if (reg.test(card) === false) {
		console.log(card);
		return false;

	}
	return true
}


export function getMoneyStyle(value = 0) {
	if (typeof value == 'string') {
		value = (+value).toFixed(2)
	}
	if (typeof value == 'number') {
		value = value.toFixed(2)
	}
	// 将字符串转为数组
	let n = value.split("");
	// 反转数组并复制循环处理
	let arr = n.reverse().map(function(e, ind, ar) {
		// 判断当前下标是否为3的整数倍数且不为最后一个下标
		if (ind % 3 == 0 && ind / 3 > 1 && ind != ar.length) {
			return e + ','
		} else {
			return e
		}
	})
	// 反转数组回复原来排序并合并回字符串
	arr = arr.reverse().join('')
	return arr;
}
// 倒计时计算
// 计算倒计时时间
export function timeComputed(time) {
	// 获取当前时间
	let actTime = (new Date()).getTime();
	// 获取到期时间
	let stopTime = time - actTime;
	let daytime = Math.floor(stopTime / 24 / 3600 / 1000)
	// 判断是否小于0
	if (stopTime < 0) {
		stopTime = stopTime * -1
	}
	let day = daytime; //获取剩余小时数
	let hours = Math.floor((stopTime / 1000 / 60 / 60) % 24); //获取剩余小时数
	let minutes = Math.floor((stopTime / 1000 / 60) % 60); //获取分钟
	let seconds = Math.floor((stopTime / 1000) % 60); //获取秒数
	return {
		day, //倒计时天数
		hours, //倒计时小时数
		minutes, //倒计时分钟数
		seconds //倒计时秒数
	}
}
//处理文章详情页
export function deconstructArticle(data) {
	if (data) {
		data = data.replace(/<img/g, '<img style="width: 100% !important;height:auto"').replace(
			/<p>\S*<img/g, '<p style="line-height: 0;"><img');
	}
	return data;
}
// 调用打开地图方法
export function openMap(e) {
	var that = this
	return new Promise((resolve, reject) => {
		uni.getSetting({
			success(res) {
				console.log(res);
				//这里判断是否有地位权限
				if (!res.authSetting['scope.userLocation']) {
					uni.showModal({
						title: '提示',
						content: '请求获取位置权限',
						success: function(res) {
							if (res.confirm == false) {
								// 授权失败
								reject()
								return false;
							}
							uni.openSetting({
								success(res) {
									console.log(res);
									//如果再次拒绝则返回页面并提示
									if (!res.authSetting['scope.userLocation']) {
										uni.showToast({
											title: '此功能需获取位置信息,请重新设置',
											duration: 3000,
											icon: 'none'
										})
									} else {
										//允许授权,调用地图
										resolve()
									}
								},
								fail(e) {
									console.log(e);
								}
							})
						}
					})
				} else {
					//如果有定位权限,调用地图
					resolve()
				}
			}
		})
	
	})
}