module.exports = {

	//新物业图片预览type值为图片类型键名。001视频002图片
	imgClick(index, list, type) {
		let imgArr = JSON.parse(JSON.stringify(list));
		// console.log(imgArr)
		// console.log(this.$fileHost)
		let arr = [];
		let current = index;
		imgArr.map(item => {
			if (type && type != '') {
				if (item[type] == '002') {
					if (item.url) {
						arr.push(item.url)
					} else {
						arr.push(item)
					}
				}
			} else {
				arr.push(item)
			}

		})

		for (let i = 0; i < index + 1; i++) {
			if (imgArr[i][type] == '001') {
				current--
			}
		}
		console.log(arr)
		uni.previewImage({
			current: current,
			urls: arr
		});
	},

	//新物业图片预览type值为图片类型键名。002视频001图片
	videoList(index, list, type) {
		let imgArr = JSON.parse(JSON.stringify(list));

		let arr = [];
		let current = index;
		// imgArr.map(item => {
		// 	if (item[type] == '002') {
		// 		if (item.url) {
		// 			let obj = {
		// 				faceImg: item.faceImg,
		// 				url: item.url,
		// 				resourceType: '002'
		// 			}
		// 			arr.push(obj)
		// 		} else {
		// 			let obj = {
		// 				faceImg: item.faceImg,
		// 				url: item,
		// 				resourceType: '002'
		// 			}
		// 			arr.push(obj)
		// 		}
		// 	}
		// })

		// for (let i = 0; i < index + 1; i++) {
		// 	if (imgArr[i][type] == '001') {
		// 		current--
		// 	}
		// }
		// console.log(arr)
		uni.setStorageSync("previewList", imgArr)
		uni.setStorageSync("previewIndex", index)
		uni.navigateTo({
			url: `/pages/swiperPreview/swiperPreview`
		})
		// return msg
	},

	formatPhone(e) {
        if (this.$isNull(e)) return
		var tel = e;
		tel = "" + tel;
		var newTel = tel.substr(0, 3) + "****" + tel.substr(7)
		return newTel
	},
	formatName(e) {
		if (this.$isNull(e)) return
		if (e != null || e != undefined) {
			var name = e;
			if (name.length > 1) {
				name = "" + name;
				var newName = name.substr(0, 1) + "*" + name.substr(2,name.length-1)
				return newName
			} 
			
			else {
				return name
			}

		} else {
			return e
		}



	},
    //姓名星号-只留首尾
    formatNameAll(name) {
        if (this.$isNull(name)) return
        let newStr;
        if (name.length === 2) {
            newStr = name.substr(0, 1) + '*';
        } else if (name.length > 2) {
            let seat = ''
            for(let i = 0; i < name.length - 2; i++){
                seat += '*'
            }
            newStr = name.substr(0, 1) + seat + name.substr(-1, 1);
        } else {
            newStr = name;
        }
        return newStr;
    },
	timefilter(type, value) {
        if (this.$isNull(value)) return
        var newDate = ""
        if (String(value).indexOf("-") != -1) {
            newDate = new Date(value.replace(/-/g, "/"))
        } else {
            newDate = new Date(Number(value))
        }
        var hours = newDate.getHours().toString()
        var minutes = newDate.getMinutes().toString()
        var seconds = newDate.getSeconds().toString()

        var year = newDate.getFullYear().toString();
        var month = (newDate.getMonth() + 1).toString();
        var day = (newDate.getDate()).toString();
        if (month.length == 1) {
            month = "0" + month;
        }
        if (day.length == 1) {
            day = "0" + day;
        }
        if (hours.length == 1) {
            hours = "0" + hours;
        }
        if (minutes.length == 1) {
            minutes = "0" + minutes;
        }
        if (seconds.length == 1) {
            seconds = "0" + seconds;
        }
        if (type == 'YY-MM-DD HH:MM:SS') {
            return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
        } else if (type == 'HH:MM') {
            return hours + ':' + minutes
        } else if (type == 'HH:MM:SS') {
            return hours + ':' + minutes + ':' + seconds
        } else if (type == 'YY-MM-DD') {
            return year + '-' + month + '-' + day
        } else if (type == 'YY-MM-DD HH:MM') {
            return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes
        } else if (type == 'MM-DD HH:MM') {
            return month + '-' + day + ' ' + hours + ':' + minutes
        } else if (type == '年月日 HH:MM:SS') {
            return year + '年' + month + '月' + day + '日 ' + hours + ':' + minutes + ':' + seconds
        } else if (type == 'YY/MM/DD') {
			return year + '/' + month + '/' + day
		} 

    },
    
	isNull(param) {
		if (typeof param == "boolean") {
			return false;
		}
		if (param == null || param == undefined || param == '' || param.length == 0) {
			return true;
		}
		return false;
	},
    //比较时间 (endDate是否大于beginDate)
    isBefore(beginValue,endValue) {
        if(this.$isNull(beginValue)) return false;
        if(this.$isNull(endValue)) return false;
        
        let beginDate = ""
        let endDate = ""

        if (String(beginValue).indexOf("-") != -1) {
			beginDate = new Date(beginValue.replace(/-/g, "/"))
		} else {
			beginDate = new Date(beginValue)
		}
        if (String(endValue).indexOf("-") != -1) {
			endDate = new Date(endValue.replace(/-/g, "/"))
		} else {
			endDate = new Date(endValue)
		}

        var begin = beginDate.getTime();
        var end = endDate.getTime();
        if ( end > begin) {
            return true;
        }else{
            return false;
        }
    },
}
