<template>
	<view class="body">
		<!-- 公共组件-每个页面必须引入 -->
		<public-module></public-module>

		<block v-for="(item,index) in list" :key="index">
			<my-list-item :item="item" :index="index" @authModal="authModal" @weixinMsg="weixinMsg"
				@zhifubaoMsg="zhifubaoMsg" :someData="status"></my-list-item>
		</block>
		<button class="my-3 mt-4 mx-3 dis a-c j-c btn" type="primary" @tap="logout">退出登录</button>
		<auth-Modal :authShow="authShow" @btnClick="authShow=false" @maskClick="authShow=false"></auth-Modal>
	</view>
</template>

<script>
	import {
		mapState
	} from "vuex"
	import {
		mapMutations
	} from "vuex"
	import authModal from '@/components/modules/user/authModal.vue'; //实名认证弹窗
	import myListItem from "@/components/modules/my/my-list-item.vue";
	export default {
		components: {
			myListItem,
			authModal
		},
		data() {
			return {
				authShow: false,
				list: [{
						icon: "",
						name: "账号管理",
						clicktype: "navigateTo",
						url: "/pages/set/safe",
						auth: true
					},
					// {
					// 	icon: "",
					// 	name: "实名认证",
					// 	clicktype: "auth",
					// 	text: "",
					// 	borderColor: "",
					// 	backColor: "",
					// 	url: ""
					// },
					{
						icon: "",
						name: "微信绑定",
						clicktype: "weixin",
						url: "",
						text: '未绑定',
					},
					{
						icon: "",
						name: "支付宝绑定",
						clicktype: "zhifubao",
						url: "",
						text: '未绑定',
					},
					// {
					// 	icon: "",
					// 	name: "清除缓存",
					// 	clicktype: "clear",
					// 	url: "",
					// },
					// {
					// 	icon: "",
					// 	name: "常见问题",
					// 	clicktype: "navigateTo",
					// 	url: "/pages/set/question",
					// 	auth: true
					// },
					{
						icon: "",
						name: "关于合伙人",
						clicktype: "navigateTo",
						url: "/pages/set/about",
						text: "",
						auth: false
					},
				],
				status: {
					weixinstatus: false,
					zhifubaostatus: false,
				}
			}
		},
		computed: {
			...mapState(['userInfo'])
		},
	// mounted() {
	// 	this.bindingStatus();
	// 		this.isBindAlipay();
	// },
		onLoad() {
			// #ifdef APP
			this.bindingStatus();
			this.isBindAlipay();
			//#endif
			if (this.userInfo.sysUser.status == '0' && this.userInfo.sysUser.managementSource == '2') {
				if (this.userInfo.sysUser.factorVerify == '2') {
					this.list[1].text = '实名认证失败';
					this.list[1].borderColor = '#FF0000';
					this.list[1].backColor = '#FFE2E2';
					this.lsit[1].url = '/pages/user/authInfo';
				} else {
					this.list[1].text = '未认证';
					this.list[1].borderColor = '#0052FF';
					this.list[1].backColor = '#DDE8FF';
				}
			} else if (this.userInfo.sysUser.status == '8') {
				this.list[1].text = '待补充资料';
				this.list[1].borderColor = '#FFB800';
				this.list[1].backColor = '#FFF3D3';
				this.lsit[1].url = '/pages/user/practitionerInfo';
			} else if (this.userInfo.sysUser.status == '3') {
				this.list[1].text = '审核不通过';
				this.list[1].borderColor = '#FF0000';
				this.list[1].backColor = '#FFE2E2';
				this.lsit[1].url = '/pages/user/practitionerInfo';
			} else if (this.userInfo.sysUser.status == '2') {
				this.list[1].text = '资料审核中';
				this.list[1].borderColor = '#FFB800';
				this.list[1].backColor = '#FFF3D3';
				this.lsit[1].url = '/pages/user/authResult1';
			} else if (this.userInfo.sysUser.status == '1') {
				this.list[1].text = '已认证';
				this.list[1].borderColor = '#0052FF';
				this.list[1].backColor = '#DDE8FF';
			}
		},
		async onShow() {
			// #ifdef APP
			let args = plus.runtime.arguments;
			if (args) {
				plus.runtime.arguments = null; //进入之后就把urlscheme清空要不然下一次oushow时还会执行
				// 处理args参数，如直达到某新页面等
				//通过code请求获取user_id
				var authCode = args.split("=")[1];
				if (authCode != undefined && authCode != "" && authCode != null) {
					let res = await this.$http.post("/APPPartner/bindAlipay", {
						code: authCode,
					})
					if (res.code == '200') {
						uni.showToast({
							title: res.msg,
							icon: "success"
						});
						this.isBindAlipay();
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						});
					}
				}
			}
			//#endif
		},
		methods: {
			...mapMutations(['emptyUserInfo']),
			logout() {
				this.emptyUserInfo();
				setTimeout(() => {
					uni.reLaunch({
						url: "/pages/login/login"
					})
					return true;
				}, 500);
			},
			authModal(res) {
				this.authShow = res;
			},
			//微信绑定查询
			async bindingStatus() {
				let res = await this.$http.get("/APPPartner/checkBindWechat")
				if (res.code == '200') {
					this.list[2].text = "已绑定"
					this.status.weixinstatus = true;
				} else {
					this.status.weixinstatus = false;
				}
			},
			//支付宝绑定查询
			async isBindAlipay() {
				let res = await this.$http.get("/APPPartner/checkBindAlipay")
				if (res.code == '200') {
					this.list[3].text = "已绑定"
					this.status.zhifubaostatus = true;
				} else {
					this.status.zhifubaostatus = false;
				}
			},
			weixinMsg(res) {
				if (res.code == '200') {
					uni.showToast({
						title: res.msg,
						icon: "success"
					});
					this.bindingStatus();
				} else {
					uni.showToast({
						title: res.msg,
						icon: "none"
					});
				}
			},
			zhifubaoMsg(res) {
				if (res.code == '200') {
					uni.showToast({
						title: res.msg,
						icon: "success"
					});
					this.isBindAlipay();
				} else {
					uni.showToast({
						title: res.msg,
						icon: "none"
					});
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.btn {
		background: #fff;
		border-radius: 4px;
		border: 1px solid #343EEF;
		color: #343EEF;
		font-size: 32rpx;
	}
</style>