<template>
	<view class="content">
		<my-baseNar />
		<!-- 核销员首页 -->
		<view class="myInfoInit">
			<view class="myInfoImg">
				<image class="init_image" :src="userInfo.avatar" mode=""></image>
			</view>
			<view class="myInfoInitInfo">
				<view class="myInfoInitInfoTop">
					<view class="myInfoInitInfoTop-name">
						{{userInfo.username}}
					</view>
					<view class="myInfoInitInfoTop-back">
						<u-button class="loginOutbtn" @click="userLoginout" text="退出登录" shape="circle"
							color="#fbf2f1"></u-button>
					</view>
				</view>
			</view>
		</view>
		<view class="sscanCode">
			<view class="sscanCodeTitle">
				<u-icon size='24' name="http://amy.yyinhong.cn/uploads/wximg/dp.png"></u-icon>
				<span>{{userInfo.store_name}}</span>
			</view>
			<view class="sscanCodeContent">
				<view class="sscanCodeContentInit" @click="gotoProductInfo">
					<u-icon size='24' name="http://amy.yyinhong.cn/uploads/wximg/scan.png"></u-icon> <span
						class="scanCodeName">扫码核销</span>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: {}
			}
		},
		onShow() {
			this.getUserInfo();
		},
		methods: {
			//获取用户信息
			getUserInfo() {
				this.$request('/merchant-info', 'GET', {}).then(res => {
					console.log('请求成功')
					this.userInfo = res.data;
				}).catch(err => {
					uni.showToast({
						icon: 'error',
						title: '' + err.message
					})
				})
			},
			userLoginout() {
				this.$request('/logout', 'GET', {}).then(res => {
					uni.showToast({
						icon: 'success',
						title: '退出登录成功',
						complete() {
							uni.reLaunch({
								url: '/pages/login/login'
							})
						}
					})
				}).catch(err => {
					uni.showToast({
						icon: 'error',
						title: '' + err.message
					})
				})
			},
			gotoProductInfo() {
				uni.scanCode({
					success: function(res) {
						// console.log('条码类型：' + res.scanType);
						// console.log('条码内容：' + res.result);
						// 微信小程序
						if (res.errMsg == "scanCode:ok") {
							// 扫描到的信息
							// console.log(res.result);
							uni.navigateTo({
								url: '/pageSub/pages/verificationDetails/verificationDetails?num=' +
									res.result
							})
						} else {
							uni.showToast({
								icon: 'none',
								title: '未识别到二维码，请重新尝试！',
							})
						}
					}
				});

			}
		}
	}
</script>
<style lang="scss" scoped>
	.content {
		width: 100vw;
		height: 100vh;
		background: linear-gradient(to bottom, #f3d4d7, #f8f8f8, #ffffff);
	}

	.myInfoInit {
		margin: 30rpx;
		width: calc(100% - 60rpx);
		padding: 30rpx 0;
		display: flex;
		flex-direction: row;
		align-items: center;

		.myInfoImg {
			height: 120rpx;
			width: 120rpx;
			background-color: #FFFFFF;
			border-radius: 120rpx;
			overflow: hidden;
		}

		.myInfoInitInfo {
			width: calc(100% - 140rpx);
			margin-left: 20rpx;
			height: 72rpx;
			display: flex;
			flex-direction: row;
			align-items: center;

			.myInfoInitInfoTop {
				width: 100%;
				height: 60rpx;
				line-height: 60rpx;
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: space-between;

				.myInfoInitInfoTop-name {
					flex: 1;
					font-size: 40rpx;
					color: #333333;
					font-weight: 600;
				}

				.myInfoInitInfoTop-back {
					width: 200rpx;
					font-size: 24rpx;
					font-weight: 600;
					display: flex;
					flex-direction: row-reverse;
					align-items: center;
				}
			}
		}
	}

	.sscanCode {
		width: calc(100% - 120rpx);
		min-height: 104rpx;
		padding: 30rpx;
		margin: 0 30rpx;
		margin-top: 20rpx;
		border-radius: 24rpx;
		background-color: #ffffff;
	}

	.verificationCode {
		color: #D3195E;
		margin-left: 10rpx;
	}

	.sscanCodeTitle {
		display: flex;
		flex-direction: row;
		align-items: center;
		width: 100%;
		height: 60rpx;
		font-size: 30rpx;
		color: #000;
	}

	.sscanCodeContent {
		width: 100%;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		flex-wrap: wrap;
	}

	.sscanCodeContentInit {
		width: 100%;
		height: 94rpx;
		padding: 20rpx;
		background-color: #fafafa;
		border-radius: 16rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;

		.scanCodeName {
			font-size: 32rpx;
			color: #333333;
			margin-left: 20rpx;
		}

	}

	::v-deep .u-button__text {
		color: #F6588D;
	}
</style>