<template>
	<view>
		<u-overlay :show="ishow">
			<view class="dialog">
				<view class="dialog-top">
					<view class="dialog-title">
						<view>
							<view class="">
								辉南渣土车运输
							</view>
							<view class="" style="font-weight: 400; font-size:30rpx;margin-top: 20rpx;">
								V{{newVersion}}
							</view>
						</view>
					</view>
				</view>
				<view class="dialog-bottom">
					<view class="textBox">
						<uqrcode ref="uqrcode" canvas-id="qrcode" :value="appUrl" :options="{ margin: 10 }"></uqrcode>
						<view style="color: #FC5536;margin-top: 37rpx;">浏览器扫描二维码下载APP</view>
						<view style="color: #FC5536;">仅支持安卓手机下载应用</view>
					</view>
					<u-button class="dialog-button" @click="saveImage"
						color="linear-gradient(to top, #F59A02, #FFD334 )" shape="circle" type="warning" text="">
						保存图片
					</u-button>
				</view>
				<view class="update-close" @tap="close(true)">
					<u-icon size="66" color="#ffffff" name="close-circle"></u-icon>
				</view>
			</view>
		</u-overlay>
	</view>
</template>

<script>
	import {
		versionList
	} from "../../api/company/my.js"
	export default {
		name: 'HomeHint',
		props: {
			show: {
				type: Boolean,
				default: "",
			}
		},
		data() {
			return {
				appUrl: '',
				ishow: false,
				version: null,
				newVersion: null,
				userId: this.$store.state.user.userId,
				// url: ''
			}
		},
		methods: {
			// 保存二维码
			saveImage() {
				// uqrcode为组件的ref名称，为了保证方法调用成功，请在 complete 事件返回success=true后调用。
				this.$refs.uqrcode.save({
					success: () => {
						uni.showToast({
							icon: 'success',
							title: '保存成功'
						});
					}
				});
			},
			close(is) {
				if (is) {
					this.$emit('close', true)
				} else {
					this.$emit('close')
				}

			},
			// 获取版本信息
			getVersion() {
				//#ifdef APP-PLUS
				// 获取本地应用资源版本号
				plus.runtime.getProperty(plus.runtime.appid, (info) => {
					console.log(JSON.stringify(info));
					this.version = info.version
					console.log(this.version);
				})
				//#endif
			},
			getVersionList() {
				let obj = {}
				obj.versionNo = 'admin'
				obj.userId = ''
				console.log(obj);
				versionList(obj).then(res => {
					console.log('版本', res);
					this.appUrl = res.data.url
					this.newVersion = res.data.versionNo
					// this.versionCode = info.versionCode ;
				})
			}
		},
		mounted() {
			this.getVersion()
		},
		watch: {
			show: {
				handler(value) {
					this.ishow = value;
				},
				immediate: true, //设置为 true 时，第一次进入页面时即监听
				deep: true, // 深度监听父组件传过来对象变化 
			},
			version(newVal) {
				if (newVal) {
					this.getVersionList()
				}
			}
		},
	}
</script>

<style lang="scss" scoped>
	.dialog {
		position: fixed;
		width: 80%;
		/* height: 462rpx; */
		padding: 0 0 20rpx 0;
		background: rgba(255, 255, 255, 0.75);
		border: 2rpx solid #77A8FF;
		box-shadow: 0rpx 0rpx 24rpx 6rpx rgba(109, 160, 251, 0.6);
		border-radius: 28rpx;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
	}

	.dialog-top {
		position: relative;
		height: 338rpx;
		top: -90rpx;
		width: 100%;
		background: url('@/static/images/tooltip5.png');
		background-size: 100% 100%;
	}

	.dialog-title {
		text-align: center;
		position: absolute;
		bottom: 31rpx;
		left: 50%;
		transform: translate(-50%);
		font-weight: bold;
		color: #2F4173;
		font-size: 34rpx;
	}

	.dialog-bottom {
		/* width: 542rpx; */
		/* height: 200rpx; */
		/* position: absolute; */
		/* bottom: 15rpx; */
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: -70rpx;

	}

	.textBox {
		font-size: 30rpx;
		font-weight: bold;
		color: #485B93;
		line-height: 60rpx;
		text-align: center;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.dialog-button {
		width: 238rpx;
		height: 75rpx;
		margin-top: 42rpx;
		margin-bottom: 42rpx;
		font-size: 28rpx;
		font-weight: bold;
	}


	.update-close {
		position: absolute;
		text-align: center;
		left: 50%;
		transform: translate(-50%);
		bottom: -100rpx;
	}
</style>
