<template>
	<view>
		<scroll-view scroll-y class="page">
			<cu-custom bgColor="bg-gradual-pink" :isBack="true"><block slot="backText">返回</block><block slot="content">交接卡绑定</block></cu-custom>
			<view class="photoView">
				<image src="/static/headPhoto.jpg" class="photoImage"></image>
			</view>
			<view class="padding flex flex-direction" style="padding-top: 800rpx;">
				<button class="cu-btn bg-blue margin-tb-sm lg" @click="buttonClick">扫描交接卡</button>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				code: 'https://opmonitor.com/qrc/r060001ull'
			}
		},
		mounted() {
			uni.request({
				url: 'https://lekapi.opmonitor.com/?c=app_api&a=getIsBindHandCard',
				data: {openid: getApp().globalData.openid},
				header: {
					'Content-type': 'application/json'
				},
				success: function(res){
					if(res.data.data === 'success'){
						uni.reLaunch({
							url: "/pages/plugin/handCardCode"
						})
					}else if(res.data.data === 'failure'){
						console.info('请进行交接卡绑定工作')
					}
				},
				fail: () => {
					console.info('小程序域名不正确，请检查域名正确性')
				}
			})
		},
		methods: {
			buttonClick() {
				let that = this;
				uni.request({
					url: 'https://lekapi.opmonitor.com/?c=app_api&a=getBindHandCardInfo',
					data: {code: that.code,openid: getApp().globalData.openid},
					header: {
						'Content-type': 'application/json'
					},
					success: function(res){
						if(res.data.data.msg === 'success'){
							uni.reLaunch({
								url: "/pages/plugin/handCardCode"
							})
						}else{
							uni.showModal({
								title: '提示',
								content: '扫描交接码失败',
								success: function(res){
									if(res.confirm) {
										uni.reLaunch({
											url: "/pages/plugin/handCard"
										})
									}else if (res.cancal){
										uni.reLaunch({
											url: "/pages/plugin/handCard"
										})
									}
								}
							})
						}
					},
					fail: () => {
						console.info('小程序域名不正确，请检查域名的正确性')
					}
				})
			}
		}
	}
</script>

<style>
	.page {
		width: 100vw;
		height: 100Vh;
	}
	.photoView {
		text-align: center;
		padding-top: 50rpx;
	}
	.photoImage {
		width: 200rpx;
		height: 200rpx;
		border-radius: 50%;
	}
</style>
