<template>
	<view>
		<van-dialog  title="请登录"
		show-cancel-button="true"
		:show="show"
		@cancel="cancelDialog" @confirm="confirmOrder"
		confirm-button-open-type="getUserInfo"	
		confirm-button-color = "#323232"	
		>
		</van-dialog>
			<!-- <button @click="wxlogion"   open-type="getUserInfo">请点击授权</button> -->
	</view>
	
</template>

<script>
	import {
		mapMutations,mapState
	} from 'vuex'
	export default {
		props:{
		  showdialog:{
		    default: false,
		    type: Boolean
		  }
		},
		 data() {
			return{
				show: false
			}
		},
		watch:{
			'showdialog':function(val) {
				if(val) {
					this.show = true;
				}else {
					this.show = false;
				}
			}
		},
		methods:{
			...mapMutations(['login','showDialog']),
			cancelDialog() {
				this.$msg('登录失败');
				this.login();
				this.$emit('cancelDiaolog')
				this.showDialog(false);
			},
			confirmOrder() {
				this.wxlogion();
			},
			wxlogion() {
				let  that = this;
				    uni.getUserInfo({
					     success(res) {
							 that.login(res.userInfo);
							 that.showDialog(true);
							 that.$emit('confirmDiaolog');
							 that.$msg("登录成功")
					     },
					     fail(res) {
						    console.log(res);
							that.$msg("登录失败")
					     }
				    })
			}
		}
	}
</script>

<style>
</style>
