// 自定义filter
export function myFilter(value, options, key = "label") {
	if (options && options instanceof Array) {
		let arr = options.filter(item => item.value === value)
		if (arr.length) {
			return arr[0] && arr[0][key]
		} else {
			return value
		}
	} else {
		return value
	}
}

// showToast
export function showToast(title, mask = true) {
	uni.showToast({
		title,
		icon: 'none',
		mask,
		duration: 2000
	})
}

let localtionshowModal = null

export function showModal({
	content = "是否执行？",
	showCancel = true,
	success,
	fail
}) {
	if (localtionshowModal) {
		return false;
	}
	localtionshowModal = setTimeout(() => {
		uni.showModal({
			content: content,
			confirmText: '确认',
			cancelText: '取消',
			showCancel: showCancel,
			success,
			complete: () => {
				clearTimeout(localtionshowModal);
				localtionshowModal = null;
			}
		});
	}, 1);
}

export function setNeedRefresh() {
	var pages = getCurrentPages();
	if (pages.length >= 2) {
		var page = pages[pages.length - 2];
		page.needRefresh = true
	}
}
