<template>
	<view>
		<view class="js_dialog" :class="is_show?'showCont':''" id="iosDialog2">
			<view class="weui-mask" @click="hideModal"></view>
			<view class="weui-dialog">
				<view class="weui-dialog__hd">
					<text class="weui-dialog__title">提示</text>
				</view>
				<view class="weui-dialog__bd">{{obj.content}}</view>
				<view class="weui-dialog__ft">
					<view hover-class="weui-dialog__btn_cl" @click="hideModal"
						class="weui-dialog__btn weui-dialog__btn_default">
						{{cancelText}}
					</view>
					<button hover-class="weui-dialog__btn_cl" :data-tel="mobile" open-type="getPhoneNumber"
						@getphonenumber="onGetphoneNumber" class="weui-dialog__btn weui-dialog__btn_primary">
						{{confirmText}}
					</button>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		props: {
			obj: {
				type: Object,
				default: {
					content: null,
					href: null,
					showCancel: false,
				}
			},

			title: {
				type: String,
				default: "温馨提示"
			},

			cancelText: {
				type: String,
				default: "取消"
			},

			confirmText: {
				type: String,
				default: "马上完善"
			},
		},

		computed: {
			...mapState(['is_show'])
		},

		data() {
			return {
				is_hide: false,
			}
		},
		
		methods: {
			showModal(e) {
				this.$store.state.is_show = false;
			},
			hideModal(e) {
				this.$store.state.is_show = false;
			},
			// 微信成为会员
			onGetphoneNumber(e) {
				let userInfo=uni.getStorageSync("userInfo"), 
				    store_id=uni.getStorageSync("store_id");
				if (e.detail.errMsg == "getPhoneNumber:ok") {
					this.$http.request('xcx/Jiemi', {
						id:userInfo.id,
						data: e.detail.encryptedData,
						iv: e.detail.iv,
						sessionKey: uni.getStorageSync('user_xcx_info').session_key,
						store_id: store_id,
					}, "", "", true).then(res => {
						this.phoneNumber = res.data.phoneNumber;
						uni.setStorageSync('phone', res.data.phoneNumber);
						uni.showModal({
							title: '授权成功',
							content: '享受更多优惠！',
							showCancel: false,
							cancelText: '',
							confirmText: '确定',
							success: res => {	
								let subscribe = uni.getStorageSync('balance_subscribe');
								this.$store.state.is_show = false;
								uni.requestSubscribeMessage({
									tmplIds: [subscribe.member_tid],
									success: (r) => {
									},
									complete: (r) => {
										this.menber_info();
									}
								})
							},
							fail: () => {},
							complete: () => {}
						});
					})
				} else {
					uni.showToast({
						title: "授权失败,请重新授权",
						icon: 'none'
					})
				}
			},
			// 成为会员,更新用户信息
			menber_info() {
				let userInfo = uni.getStorageSync('userInfo');
				this.$http.request('xcx/userinfo', {
					id: userInfo.id,
				}, "", "", true).then(res => {	
					if (res.code == "200"&&res.data.mobile) {
						this.$store.commit("SET_USER_INFO",res.data) 
						// uni.setStorageSync('userInfo', res.data);
						// uni.switchTab({
						// 	url:"../pages/my/my"
						// })
                        console.log(411111)
                         this.$emit("success",res.data); 
					}
				}).catch((res) => {
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				});
			},
			
		},
	}
</script>
<style>
	.iosDialog2 {
		position: fixed;
		left: 0;
		top: 0;
		background-color: rgba(0, 0, 0, 0.5);
		width: 100%;
		height: 100%;
		z-index: 999;
	}

	.js_dialog {
		display: none;
	}

	/*定义样式*/
	page .showCont {
		display: block;
		/* animation: showPopUp 0.5s; */
		/* animation-fill-mode: forwards; */
	}

	page .hiddenCont {
		display: none;
		/* animation: hiddenPopUp 0.5s; */
		/* animation-fill-mode: forwards; */
	}

	/*定义动画*/
	@keyframes showPopUp {
		0% {
			opacity: 0;
			z-index: 999;
		}

		100% {
			opacity: 1;
			z-index: 999;

		}
	}

	@keyframes hiddenPopUp {
		0% {
			opacity: 0;
			z-index: 999;
		}

		100% {
			opacity: 1;
			display: none;
			z-index: 999;
		}
	}

	.weui-mask {
		position: fixed;
		top: 0;
		right: 0;
		left: 0;
		bottom: 0;
		background: rgba(0, 0, 0, 0.6);
		z-index: 999;
	}

	.weui-dialog {
		position: fixed;
		width: 600rpx;
		margin: 0 auto;
		top: 50%;
		left: 16px;
		right: 16px;
		-webkit-transform: translate(0, -50%);
		transform: translate(0, -50%);
		background-color: #fff;
		text-align: center;
		border-radius: 12px;
		overflow: hidden;
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		-webkit-flex-direction: column;
		-webkit-box-orient: vertical;
		-webkit-box-direction: normal;
		flex-direction: column;
		max-height: 90%;
		z-index: 999;
	}

	.weui-dialog__hd {
		padding: 64rpx 48rpx 32rpx;
	}

	.weui-dialog__title {
		font-weight: 700;
		font-size: 34rrpx;
		line-height: 1.4;
	}

	.weui-dialog__bd:first-child {
		min-height: 40px;
		padding: 32px 24px 0;
		font-weight: 700;
		color: rgba(0, 0, 0, 0.9);
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		-webkit-flex-direction: column;
		-webkit-box-orient: vertical;
		-webkit-box-direction: normal;
		flex-direction: column;
		-webkit-box-pack: center;
		-webkit-justify-content: center;
		justify-content: center;
	}

	.weui-dialog__bd {
		/* overflow-y: auto; */
		-webkit-overflow-scrolling: touch;
		padding: 0 24px;
		margin-bottom: 32px;
		font-size: 17px;
		line-height: 1.4;
		word-wrap: break-word;
		-webkit-hyphens: auto;
		hyphens: auto;
		color: rgba(0, 0, 0, 0.5);
	}

	.weui-dialog__ft {
		position: relative;
		line-height: 56px;
		min-height: 56px;
		font-size: 17px;
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
	}

	.weui-dialog__btn {
		display: block;
		-webkit-box-flex: 1;
		-webkit-flex: 1;
		flex: 1;
		color: #576b95;
		font-weight: 700;
		text-decoration: none;
		-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
		position: relative;
	}

	.weui-dialog__btn:after {
		content: " ";
		position: absolute;
		left: 0;
		top: 0;
		width: 1px;
		bottom: 0;
		border-left: 1px solid rgba(0, 0, 0, 0.1);
		border-left: 1px solid
			/* var(--weui-DIALOG-LINE-COLOR) */
		;
		color: rgba(0, 0, 0, 0.1);
		/* color: var(--weui-DIALOG-LINE-COLOR); */
		-webkit-transform-origin: 0 0;
		transform-origin: 0 0;
		-webkit-transform: scaleX(0.5);
		transform: scaleX(0.5);
	}

	.weui-dialog__ft:after {
		content: " ";
		position: absolute;
		left: 0;
		top: 0;
		right: 0;
		height: 1px;
		border-top: 1px solid rgba(0, 0, 0, 0.1);
		color: rgba(0, 0, 0, 0.1);
		-webkit-transform-origin: 0 0;
		transform-origin: 0 0;
		-webkit-transform: scaleY(0.5);
		transform: scaleY(0.5);
	}

	.weui-dialog__btn_default {
		color: rgba(0, 0, 0, 0.9);
	}

	.weui-dialog__btn_cl {
		background: #F1F1F1;
	}

	/* 去除button默认样式 */

	.weui-dialog__ft button::after {
		border: none;

	}

	.weui-dialog__ft button {
		background-color: transparent;

		padding-left: 0;

		padding-right: 0;

		line-height: inherit;

	}

   .weui-dialog__ft button {
		border-radius: 0;

	}
</style>
