<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 {}
		},
		methods: {
			buttonClick() {
				let that = this;
				uni.scanCode({
					success: function (res) {
						let code = res.result;
						uni.request({
							url: 'https://lekapi.opmonitor.com/?c=app_api&a=getQrcodeType',
							data: {code: code},
							header: {
								'Content-type': 'application/json'
							},
							success: function(res){
								if(res.data.data.type === "error"){
									uni.showModal({
										title: '提示',
										content: '不存在的医废二维码',
										success: function(res){
											if(res.confirm) {
												uni.reLaunch({
													url: "/pages/component/home"
												})
											}else if (res.cancal){
												uni.navigateTo({
													url: "/pages/component/home"
												})
											}
										}
									})
								}else if(res.data.data.type === "bag"){
									uni.navigateTo({
										url: "/pages/component/traceDetailsByMedical?id="+res.data.data.id
									})
								}else if(res.data.data.type === "box"){
									uni.navigateTo({
										url: "/pages/component/traceDetailsByBox?id="+res.data.data.id
									})
								}else if(res.data.data.type === "dept"){
									uni.navigateTo({
										url: "/pages/component/traceDetailsByDept?id="+res.data.data.id
									})
								}
							},
							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>
