import { useScrollStore } from "@/stores/scroll";
// import UniHelper from "../utils/UniHelper";
import  { YcBase64, YcReg, YcStorage, YcStringUtil, YcUniapp, Yc } from "@ycxxkj/uniapp";
import { deviceHelper } from "../data/device";
const ycxxkj = { YcBase64, YcReg, YcStorage, YcStringUtil, YcUniapp, Yc };
const Page = {
	SUCCESS_CODE: 0,
	setTitle: (title: string = "核销端") => {
		uni.setNavigationBarTitle({ title });
	},
	getVersion: () => {
		// @ts-ignore
		// const version = __VERSION__ as string;
		let version = "copyright © 1.0.3";
		return version;
	},
	switch(url: string) {
		uni.switchTab({
			url
		});
	},
	goBack(delta: number = 1) {
		uni.navigateBack({
			delta
		});
	},
	goto: (url: string) => {
		console.log("#debug#🚀 ~ file: Page.ts:30 ~ goto url:", url);
		uni.navigateTo({
			url
		});
	},
	relauch(url: string) {
		uni.reLaunch({
			url
		});
	},
	redirect(url: string) {
		uni.redirectTo({ url });
	},
	isLogin() {
		let token = ycxxkj.YcStorage.get("token");
		if (token) {
			return true;
		}
		return false;
	},
	onPageScroll(e: any) {
		const store = useScrollStore();
		// console.log("onPageScroll:e", e, store);
		store.setTop(e.scrollTop);
		let pages = getCurrentPages();
		let curPage = pages[pages.length - 1];
		curPage.$vm.scrollTop = e.scrollTop;
		// console.log("curPage.$vm.scrollTop", curPage.$vm, curPage.$vm.scrollTop);
	},
	test() {
		console.log("onLoad yc is", ycxxkj);
	},
	showVal(val: any, def: string | number = "-", suffix: string = ""): string | number | any {
		if (!val && val !== 0 && val !== "0") {
			return def;
		}
		return val + suffix;
	},
	/**
	 * 格式化金额 ，由分转为元，并保留2位小数
	 * @param val
	 * @returns
	 */
	priceFormat(val: string | number) {
		let price = Number(val);
		if (isNaN(price)) {
			price = 0;
		}
		return (price / 100).toFixed(2);
	},
	deviceHelper,
	...ycxxkj
	// ...UniHelper
};
console.log("#debug#🚀 ~ file: Page.ts:81 ~ Page.url:", Page.url);
console.log("#debug#🚀 ~ file: Page.ts:81 ~ Page.url:", Page.url);
console.log("#debug#🚀 ~ file: Page.ts:81 ~ Page.url:", Page.url);
export default Page;
