<template>
	<text :style="ciystyle" v-if="user>0">
		<text style="font-size:0.7em;" v-if="!usrinfo" @tap.stop="getname">No.</text>
		<text @tap.stop="getname">{{showtxt}}</text>
		<button class="btn def smm" style="margin-left:1em;" @tap.stop="showinfo">成员详情</button>
	</text>
	<text :style="ciystyle" v-else>
		<text style="color:var(--bg6)">暂无</text>
	</text>
</template>

<style scoped>
</style>

<script>
	//支持本地缓存，自动翻译
	export default {
		props: {
			user: {
				type: [String, Number],
				default: 0
			},
			ciystyle: {
				type: [String, Object],
				default: ''
			},
		},
		data() {
			return {
				usrinfo: null
			};
		},
		watch: {},
		computed: {
			showtxt() {
				if (this.usrinfo)
					return this.usrinfo.name;
				return this.user;
			},
		},
		mounted() {
			this.usrinfo = this.getstorage('d' + this.user);
			if (!this.usrinfo)
				this.getuserinfo();
		},
		methods: {
			async getuserinfo() {
				if (this.usrinfo) {
					if (this.usrinfo._times > this.tostamp())
						return;
				}
				const app = getApp();
				app.globalData.mqfunc.push({
					name: 'userinfo_' + this.user,
					func: 'dao.userinfo_get',
					data: {
						id: this.user,
					},
					callback: retjson => {
						if (retjson.code != 1)
							return;
						retjson.user._times = this.tostamp() + 60;
						this.setstorage('d' + this.user, retjson.user);
						this.usrinfo = retjson.user;
					}
				});
			},
			async getname() {
				this.getuserinfo();
			},
			async showinfo() {
				await this.getuserinfo();
				this.gourl('/pages/me/user_show', '', this.usrinfo, 'userinfo');
			},
		}
	}
</script>