step1.vue 2.42 KB
<template>
	<view>
		<!-- 报名须知 -->
		<view class="title-left-border">报名须知</view>

		<view class="flexRow">
			<label>附件下载:</label>
			<view>
				<text class="underLine text-danger" @click="downLoad(config.trainUrl_api+activity?.signNoticeAttachment?.url)">《报名须知》</text>
			</view>
		</view>
		<view class="flexRow" @click="changeAgree">
			<uni-icons type="checkbox-filled" v-if="agree" color="#C5161E" size="20"></uni-icons>
			<uni-icons type="checkbox" color="#bbbbbb" v-else size="20"></uni-icons>
			<view>我确认已经仔细阅读报名须知</view>
		</view>
	</view>

	<view class="fixedBottom">
		<button class="btn" @click="next" :class="agree?'btn-red':'btn-gary'">阅读并同意</button>
	</view>
</template>

<script setup>
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import {
		ref,
		reactive,
		toRefs
	} from 'vue'
	import * as train from '@/training/train.js'
	import config from '@/config.js';
	const emit = defineEmits(['next'])
	const agree = ref(false)
	defineProps({
		activity: {
			type: Object,
			default: () => {}
		}
	})

	function changeAgree() {
		if (agree.value) {
			agree.value = false
		} else {
			agree.value = true
		}
	}

	function downLoad(url) {
		console.log(url)
		// url = url.replace("http://", "https://")
		uni.showLoading({
			title: '下载中'
		});
		uni.downloadFile({
			url: url,
			success: function(res) {
				uni.hideLoading();
				console.log(res)
				var filePath = res.tempFilePath;
				uni.showLoading({
					title: '正在打开'
				});
				uni.openDocument({
					filePath: filePath,
					showMenu: true,
					success: function(res) {
						uni.hideLoading();
					},
					fail: function(err) {
						uni.hideLoading();
						uni.showToast({
							title: '打开失败',
							icon: 'none',
							duration: 2000
						});
					}
				});
			},
			fail: function(error) {
				console.log(error)
				uni.hideLoading();
				uni.showToast({
					title: `下载失败`,
					icon: 'none',
					duration: 2000
				});
			}
		});
	}

	function next() {
		if (agree.value) {
			emit('next')
		} else {
			uni.showToast({
				title: `请确认报名须知`,
				icon: 'none'
			})
		}
	}
</script>

<style scoped lang="scss">
	.flexRow {margin: 30rpx 0 0;align-items: center;
		display: flex;font-size: 28rpx;
		label{color: #999;}
		view{margin-left: 20rpx;}
	}
</style>