<template>
	<view class="_dbg" :style="sty" @tap.stop="showdbglist" v-if="bshow && me.id>0 && dbgs">
		<view class="_dbgbg">
		</view>
		<view class="_dbgtxt">
			{{me.id}}<br />
			{{me.name}}
		</view>
	</view>
</template>

<style scoped>
	._dbg {
		top: 25em;
		position: fixed;
		width: 4em;
		height: 4em;
		z-index: 10000000;
		transition: right 0.5s;
	}

	._dbgbg {
		position: relative;
		border: 1px solid #9412cc11;
		background:#ffffff;
		width: 100%;
		height: 100%;
		border-radius: 50%;
	}

	._dbgtxt {
		position: absolute;
		width: 100%;
		height: 100%;
		text-align: center;
		padding: 0 0.3em;
		line-height: 1.3em;
		text-shadow: 1px 1px #ffffff, -1px -1px #ffffff, -1px 1px #ffffff, 1px -1px #ffffff;
		top: 0.7em;
		left: 0;
		font-size: 0.8em;
		color: #000000;
	}
</style>

<script>
	export default {
		props: {},
		data() {
			return {
				sty:{right: '-0.3rem'},
				dbgs: null,
				bshow: true
			};
		},
		watch: {},
		computed: {},
		mounted() {
			this.me = this.getme();
			this.dbgs = this.getstorage('_dbgs');
		},
		methods: {
			async chguser(item) {
				var retjson = await this.callfunc({
					func: 'login.debug_chguser',
					data: {
						code: item.data.user
					}
				});
				if (retjson.code != 1)
					return this.alert(retjson.errmsg);
				this.me = this.objdeepmerge(this.me, retjson.me);
				getApp().setuserstorage(retjson);
				var page = this.com_getpage();
				page.me = this.me;
				if (page.dbgcallback)
					page.dbgcallback();
			},
			async mehide(item) {
				this.bshow = false;
				if (item.data > 0) {
					setTimeout(() => {
						this.bshow = true;
					}, item.data);
				}
			},
			async meusr(item) {
				var btn = await this.inputmsg({
					title: '用户ID',
					ele: 'input'
				}, [{
					name: '添加',
					btn: 'add'
				}, {
					name: '删除',
					btn: 'del',
					cls: 'dag'
				}, {
					name: '取消',
					btn: 'cancel',
					cls: 'def'
				}]);
				if (btn.btn == 'cancel')
					return;
				if (!btn.text)
					return this.toast('请填写用户ID');
				var retjson = await this.callfunc({
					func: 'login.debug_opuser',
					data: btn
				});
				if (retjson.code != 1)
					return this.alert(retjson.errmsg);
				if (btn.btn == 'add') {
					this.dbgs.push(retjson.data);
				} else {
					var idx = this.arrayfind(this.dbgs, btn.text, 'user');
					if (idx > -1)
						this.dbgs.splice(idx, 1);
				}
				this.setstorage('_dbgs', this.dbgs);
			},
			async showdbglist() {
				var items = [];
				for (var i = 0; i < this.dbgs.length; i++) {
					items.push({
						func: 'chguser',
						name: this.dbgs[i].name,
						sub: this.dbgs[i].user,
						data: this.dbgs[i]
					});
				}
				items.push({
					br: true
				});
				items.push({
					func: 'mehide',
					name: '消失5秒',
					style: 'color:var(--warn6)',
					data: 5000
				});
				items.push({
					func: 'mehide',
					name: '永久隐藏',
					style: 'color:var(--dag6)',
					data: 0
				});
				items.push({
					func: 'meusr',
					name: '增删用户',
					style: 'color:var(--man6)',
					data: 0
				});
				this.sty.right = '-3.3rem';
				this.popmenu({
					rowcount: 3,
					items,
					closecb: () => {
						this.sty.right = '-0.3rem';
					}
				});
			},
		}
	}
</script>