<template>
	<view>
		<view class="home-list-item d-flex a-center j-sb animated fadeIn fast" hover-class="home-list-hover"
			@tap="clickevent">
			<view class="d-flex a-center">
				<view v-if="item.icon" class="icon iconfont" :class="['icon-'+item.icon]"></view> {{item.name}}
			</view>
			<view class="d-flex a-center j-center rightText">
				{{item.text}}
				<view class="icon iconfont" :class="{'icon-youjiantou':!item.data}">{{item.data || ''}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	const PACKAGE_INFO_KEY = '__package_info__'
	export default {

		data() {
			return {}
		},
		props: {
			item: Object,
			index: Number,
			someData: {
				type: Boolean,
				default: null,
			},
		},
		methods: {
			clickevent() {
				switch (this.item.clicktype) {
					case "navigateTo":
						if (this.item.url) {
							let option = {
								url: this.item.url
							};
							if (this.item.auth) {
								return this.navigate(option, 'navigateTo', true);
							}
							uni.navigateTo(option);
						}
						break;
					case "switchTab":
						if (this.item.url) {
							let option = {
								url: this.item.url
							};
							if (this.item.auth) {
								return this.navigate(option, 'switchTab', true);
							}
							uni.switchTab(option);
						}
						break;
					case "clear":
						uni.showModal({
							title: '提示',
							content: '是否要清除缓存？',
							confirmText: '立刻清除',
							success: res => {
								if (res.confirm) {
									uni.showToast({
										title: '清除缓存成功！',
										icon: "none"
									});
								}
							},
						});
						break;
					case "weixin":
						if (this.someData) {
							uni.showToast({
								title: '已绑定',
								icon: 'none'
							});
						} else {
							this.bindother();
						}
						break;

					case "nothing":
						uni.showToast({
							title: '更新中...',
							icon: 'none'
						});
						break;

				}
			},
			// 绑定第三方登录
			bindother() {
				uni.login({
					provider: 'weixin',
					onlyAuthorize: true,
					success: (res) => {
						this.codeRes(res.code)
					},
					fail: (err) => {
						uni.showToast({
							title: '绑定失败',
							icon: "none"
						});
					}
				});

			},
			async codeRes(code) {
				let res = await this.$http.post("/wechat/bind", {
					code: code,
				})
				this.$emit('weixinMsg', res);
			},
		}
	}
</script>

<style scoped>
	.home-list-item {
		padding: 20upx;
		border-top: 1upx solid #F4F4F4;
		border-bottom: 1upx solid #F4F4F4;
	}

	.home-list-item>view:first-child {
		color: #333333;
	}

	.home-list-item>view:first-child>view {
		margin-right: 10upx;
		font-size: 32upx;
	}

	.home-list-item>view:last-child {
		color: #CCCCCC;
	}

	.home-list-hover {
		background: #f4f4f4;
	}

	.rightText {
		font-size: 30upx;
	}

	.icon {
		margin-left: 10upx;
		font-size: 24upx;
	}
</style>