export default {
	shopName(){
		return "";
	},
	clearUri(url){
		var userInfo = uni.getStorageSync("user_data");
		if(!userInfo){
			uni.showLoading({
				title:"加载中..."
			});
			setTimeout(function(){
				uni.hideLoading();
				uni.$u.route({
					url:'/pages/user/user',
					type:"switchTab",
					animationType:"slide-in-bottom"
				});
			},800);
			return ;
		}
		uni.$u.route({
			url:url,
			animationType:"slide-in-bottom",
			animationDuration:300
		});
	},
	jumpUri(url,type,param){
		var userInfo = uni.getStorageSync("user_data");
		var cacheShop = this.shopId();
		if(!userInfo){
			setTimeout(function(){
				uni.hideLoading();
				uni.$u.route({
					url:'/pages/user/login?store='+cacheShop,
					type:"navigateTo",
					animationType:"slide-in-bottom"
				});
			},800);
			return ;
		}
		if(type == 1 && !userInfo){
			uni.showToast({
				title:"请先登录",
				icon:"none"
			});
			return true;
		}
		uni.$u.route(url,param);
	},
	//判断是否登录
	navTo: function(url,param) {
		uni.$u.route(url,param);
	},
	//判断是否登录
	isLogin: function() {
		return uni.getStorageSync("user") ? true : false
	},
	
	/**
	 * 操作成功提示框
	 * @param {*} msg 
	 * @param {*} callback 
	 * @param {*} icon 
	 */
	showSuccess(msg,icon,callback){
		// #ifdef APP-PLUS
		plus.nativeUI.toast(msg);
		// #endif
		// #ifdef MP
		uni.showToast({
			title: msg,
			icon: icon?icon:'none',
			mask: true,
			duration: 1500,
			success() {
				callback && (setTimeout(function() {
					callback();
				}, 1500));
			}
		});
		// #endif
	},

	/**
	 * 操作错误提示
	 * @param {*} msg 
	 * @param {*} showCancel 
	 * @param {*} callback 
	 * @param {*} title 
	 */
	showError(msg,callback,title = "友情提示",showCancel = true){
		uni.showModal({
			title: title,
			content: msg,
			showCancel: showCancel,
			success(res) {
				callback && callback(res);
			}
		});
	},
	
	showConfirm(msg,callback,title,yes,cancel){
		plus.nativeUI.confirm(msg, function(e){
				callback && callback(e);
			},
			{"title":title,"buttons":[yes?yes:"确定",cancel?cancel:"取消"]}
		);
	},
	
	showSysAlert(msg,callback,title,showCancel){
		plus.nativeUI.alert(msg,callback,title,showCancel);
	},
	showSysMsg(msg){
		plus.nativeUI.toast(msg);
	},
	/**
	 * loading
	 * @param {Object} msg
	 * @param {Object} callback
	 */
	loading(msg,callback){
		uni.showLoading({
			title:msg ?? '请求中...',
			mask:true,
			success(res) {
				callback && callback(res);
			}
		})
	},
	hideLoad(){
		uni.hideLoading();
	},
	formatDate(value) {
		const data = new Date(value);
		const month = data.getMonth() + 1;
		const day = data.getDate();
		const year = data.getFullYear();
		const hours = data.getHours();
		const minutes = data.getMinutes();
		const seconds = data.getSeconds();
		const formattedTime = `${year}-${month}-${day}`;
		// const formattedTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
		return formattedTime;
	},
	formatMoney(num) {
		if (num == 0) return "￥0.00";
		return Intl.NumberFormat("zh-CN", {
			style: "currency",
			currency: "CNY",
			minimumFractionDigits: 2,
			maximumFractionDigits: 2,
		}).format(num / 100);
	}
}