<template>
	<view style="background-color: #EBF4F7;letter-spacing: 1rpx;">
		<view :style="{paddingTop: vuex_custom_bar_height +40+ 'rpx'}"
			style="background: linear-gradient(50deg, #034EF9 0%, #05ACFF 99%);height: 400rpx;">

			<view class="tn-flex tn-flex-center tn-flex-col-center" style="padding: 30rpx;width: 100%;">
				<view v-if="login">
					<image :src="apiImgUrl+userInfo.photo_image"
						style="width: 100rpx;height: 100rpx;border-radius: 50%;"></image>
				</view>
				<view v-if="!login">
					<image src="/static/def.png" style="width: 100rpx;height: 100rpx;border-radius: 50%;"></image>
				</view>
				<view style="width: 100%;">
					<view v-if="login" class="tn-flex tn-flex-col-center tn-flex-row-between">
						<view style="margin-left: 20rpx;color: #fff">
							<view style="font-size: 35rpx;">{{ userInfo.nikename }}</view>
							<view style="font-size: 24rpx;margin-top: 10rpx;" v-if="userInfo.status==1">接口返回商会+职位</view>
						</view>
						<!--						<view @click="tn('/pages/index/my_edit')">-->
						<!--							<image src="/static/ico13.png" style="width: 40rpx ;" mode="widthFix"></image>-->
						<!--						</view>-->
					</view>
					<view v-if="!login" class="tn-flex tn-flex-col-center tn-flex-row-between">
						<view style="margin-left: 20rpx;color: #fff">
							<tn-button @click="loginMod = true">点击登陆</tn-button>
						</view>
						<!--            <view @click="tn('/pages/index/my_edit')">-->
						<!--              <image src="/static/ico13.png" style="width: 40rpx ;" mode="widthFix"></image>-->
						<!--            </view>-->
					</view>
				</view>
			</view>
		</view>
		<view>
			<view style="padding: 30rpx;margin-top:-115rpx;background-color: transparent;">
				<view class="tn-flex tn-flex-center tn-flex-col-center tn-flex-row-between"
					style="text-align: center;padding: 30rpx;background-color: #FFF;border-radius: 20rpx;box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(12,0,5,0.1);">
					<view @click="tn('/pages/index/pizz_info?id='+userInfo.association_id)">
						<view>
							<image src="/static/ico5.png" style="width: 50rpx;height: 50rpx;"></image>
						</view>
						<view style="margin-top: 10rpx;">
							<text>所在商/协会</text>
						</view>
					</view>
					<view @click="tn('/pages/index/events_my')">
						<view>
							<image src="/static/ico1.png" style="width: 50rpx;height: 50rpx;"></image>
						</view>
						<view style="margin-top: 10rpx;">
							<text>参与活动</text>
						</view>
					</view>
					<view @click="tn('/pages/index/my_desc')">
						<view>
							<image src="/static/02_2.png" style="width: 50rpx;height: 50rpx;"></image>
						</view>
						<view style="margin-top: 10rpx;">
							<text>协会服务</text>
						</view>
					</view>
					<view @click="tn('/pages/index/my_card?id='+userInfo.member_id)">
						<view>
							<image src="/static/ico6.png" style="width: 50rpx;height: 50rpx;"></image>
						</view>
						<view style="margin-top: 10rpx;">
							<text>我的名片</text>
						</view>
					</view>
				</view>
			</view>
			<view style="background-color: #fff;">
				<view style="padding:0px 20rpx;">
					<!--					<tn-list-cell :arrow="true" @click="tn('/pages/index/my_pizz')">-->
					<!--						<view class="tn-flex tn-flex-center tn-flex-col-center">-->
					<!--							<image src="/static/ico7.png" style="width: 50rpx;height: 50rpx"></image>-->
					<!--							<view style="margin-left: 20rpx;">所在商/协会</view>-->
					<!--						</view>-->
					<!--					</tn-list-cell>-->
					<tn-list-cell :arrow="true" @click="tn('/pages/index/my_apply')">
						<view class="tn-flex tn-flex-center tn-flex-col-center">
							<image src="/static/ico8.png" style="width: 50rpx;height: 50rpx"></image>
							<view style="margin-left: 20rpx;">入会申请记录</view>
						</view>
					</tn-list-cell>
					<tn-list-cell :arrow="true" @click="tn('/pages/index/my_msg')">
						<view class="tn-flex tn-flex-center tn-flex-col-center">
							<image src="/static/ico9.png" style="width: 50rpx;height: 50rpx"></image>
							<view style="margin-left: 20rpx;">我的消息</view>
						</view>
					</tn-list-cell>
					<!--					<tn-list-cell :arrow="true" @click="tn('/pages/index/my_assist')">-->
					<!--						<view class="tn-flex tn-flex-center tn-flex-col-center">-->
					<!--							<image src="/static/ico10.png" style="width: 50rpx;height: 50rpx"></image>-->
					<!--							<view style="margin-left: 20rpx;">常见问题</view>-->
					<!--						</view>-->
					<!--					</tn-list-cell>-->

					<tn-list-cell :arrow="true" @click="tn('/pages/index/my_idea')">
						<view class="tn-flex tn-flex-center tn-flex-col-center">
							<image src="/static/ico12.png" style="width: 50rpx;height: 50rpx"></image>
							<view style="margin-left: 20rpx;">意见反馈</view>
						</view>
					</tn-list-cell>
					<tn-list-cell :arrow="true" @click="loginAut">
						<view class="tn-flex tn-flex-center tn-flex-col-center">
							<image src="/static/ico11.png" style="width: 50rpx;height: 50rpx"></image>
							<view style="margin-left: 20rpx;">退出帐号</view>
						</view>
					</tn-list-cell>
				</view>
			</view>
		</view>
		<tn-modal v-model="loginMod" :custom="true">
			<view class="custom-modal-content">
				<view style="text-align: center;font-size: 34rpx;">会员登陆</view>
				<view class="text">
					<tn-form ref="form" :labelWidth="120">
						<tn-form-item label="手机号" prop="phone">
							<tn-input v-model="loginData.phone" />
						</tn-form-item>
						<tn-form-item label="密码" prop="password">
							<tn-input v-model="loginData.password" type="password" />
						</tn-form-item>
					</tn-form>
					<view style="text-align: center;margin-top: 30rpx;">
						<tn-button backgroundColor="#E6E6E6" fontColor="#ffffff"
							@click="loginMod = false">取消</tn-button>
						<tn-button backgroundColor="tn-bg-blue" fontColor="tn-color-white" style="margin-left: 30rpx"
							@click="submitLogin">确定
						</tn-button>
					</view>
				</view>
			</view>
		</tn-modal>
	</view>
</template>

<script>
	import {
		getUserIndex,
		loginDo
	} from "@/util/api";
	import store from "@/store";

	export default {
		data() {
			return {
				topCurrent: 0,
				login: false,
				loginMod: false,
				userInfo: {},
				apiImgUrl: this.$store.state.imgUrl,
				loginData: {
					openid: '',
					phone: '',
					password: '',
					association_id: store.state.Gid
				},
			}
		},
		mounted() {
			var uid = uni.getStorageSync('uid');
			console.log(uid);
			if (uid) {
				this.getUserInfo(uid);
			}
		},
		methods: {
			getUserInfo(uid) {
				getUserIndex({
						member_id: uid
					})
					.then(res => {
						console.log(res);
						if (res.code == 1) {
							this.userInfo = res.data;
							this.login = true;
						}
					})
					.catch(error => {
						uni.showToast({
							title: error,
							icon: 'none',
							duration: 2000
						});
					})
			},
			submitLogin() {
				this.loginData.openid = uni.getStorageSync('openid');
				loginDo(this.loginData)
					.then(res => {
						console.log(res);
						if (res.code == 1) {
							uni.showToast({
								title: '登陆成功！',
								icon: 'none',
								duration: 2000
							});
							uni.setStorageSync('uid', res.data.id);
							this.userInfo = res.data;
							this.login = true;
							this.loginMod = false;
						} else {
							uni.showToast({
								title: '帐号或密码错误！',
								icon: 'none',
								duration: 2000
							});
						}
					})
					.catch(error => {
						uni.showToast({
							title: error,
							icon: 'none',
							duration: 2000
						});
					})
			},
			loginAut() {
				var that = this;
				uni.showModal({
					title: '提示',
					content: '确定要退出吗？',
					success: function(res) {
						if (res.confirm) {
							uni.removeStorageSync('uid');
							that.login = false;
						}
					}
				});
			},
			tn(e) {
				var uid = uni.getStorageSync('uid');
				if (!uid) {
					this.loginMod = true;
					return;
				}
				uni.navigateTo({
					url: e
				})
			}
		}
	}
</script>

<style>

</style>