<template>
	<view>
		<scroll-view scroll-y class="page">
			<cu-custom bgColor="bg-cyan"><block slot="content">首页</block></cu-custom>
			<view class="photoView">
				<view class="photoImage">
					<open-data type="userAvatarUrl"></open-data>
				</view>
			</view>
			<view style="padding-top:20%;">
				<view class='text-center margin-bottom text-lg  text-grey'>请扫描人员二维码进行配置</view>
			</view>
			<view class="padding flex flex-direction" style="padding-top: 40%;">
				<button class="cu-btn bg-cyan margin-tb-sm lg" @click="buttonClick">扫码配置</button>
			</view>
			<view class="cu-tabbar-height"></view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
			}
		},
		created(){
		},
		methods: {
			buttonClick() {
				let that = this;
				uni.scanCode({
					success: function (res) {
						let code = res.result;
						uni.request({
							url: 'https://mwapi.opmonitor.com/?c=app_api&a=getNewConfigQrcodeType',
							data: {code: code},
							header: {
								'Content-type': 'application/json'
							},
							success: function(res){
								// console.info(res.data.data)
								if(res.data.data.type === "error"){
									uni.showModal({
										title: '提示',
										content: '不存在的医废二维码',
										success: function(res){
											if(res.confirm) {
												uni.navigateTo({
													url: "/pages/index/index"
												})
											}else if (res.cancal){
												uni.navigateTo({
													url: "/pages/index/index"
												})
											}
										}
									})
								}else if(res.data.data.type === "user"){
									uni.navigateTo({
										url: "/pages/component/postByUser?qrcode="+res.data.data.qrcode
									})
								}
							},
							fail: () => {
								console.info('小程序域名不正确，请检查域名的正确性')
							}
						})
					},
					fail: () => {
						console.info('调用照相功能失败！！！')
					}
				})
			}
		}
	}
</script>

<style>
	.page {
		width: 100vw;
		height: 100Vh;
	}
	
	.photoView {
		padding-top: 150rpx;
		position: relative;
		color: #fff;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	.photoImage {
		overflow:hidden;
		display: block;
		width: 200rpx;
		height: 200rpx;
		margin: 20rpx;
		border-radius: 50%;
		border: 2px solid #fff;
		box-shadow: 3px 3px 10px rgba(0, 0, 0, 0.2);
	}
</style>
