<template>
	<view class="container">
		<!-- #ifdef H5 -->
		<view style="color: #fff;">
			<tn-nav-bar backgroundColor="#26B3A0" :bottomShadow="false" @rightClick="jumpScoreRed">支付状态
				<!-- 	<template slot="right">
					课程购买记录
				</template> -->
			</tn-nav-bar>
			<view :style="{ height: tobheight + 'px' }"></view>
		</view>
		<!-- #endif -->


		<view class="content">
			<view class="topIcon">
				<!-- <image src="../../../static/posImg.png" mode=""></image> -->
				<icon type="success" size="54" color="#26B3A0" />
				<view class="txt">
					支付成功
				</view>
			</view>
			<view class="btn" @click="handleShowRes">
				{{resShow?'收起学习资料':'查看学习资料'}}
			</view>

			<view class="res" v-if="resShow&&this.detail.content">
				<view class="inner" v-for="(i,index) in this.detail.content" @click="downLoad(i)">
					<text style="text-decoration: underline;">
						{{'学习资料'+(index+1)}}</text><text>{{i.slice(i.lastIndexOf('.'))}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		courseDetail
	} from '@/api/score/index.js'
	import {
		downLoad2
	} from '@/utils/download2.js'
	export default {
		components: {},
		data() {
			return {
				detail: {},

				tobheight: 45,
				resShow: false
			};
		},
		computed: {

		},
		watch: {

		},
		async onLoad(o) {
			let res = await courseDetail({
				course_id: o.id
			})
			if (res.code == 0) {
				this.detail = res.data
			}
			console.log('支付成功--课程详情返回值', res);
		},
		onReady() {

		},
		onShow() {

		},
		onUnload() {

		},
		methods: {
			handleShowRes() {
				this.resShow = !this.resShow
			},


			downLoad(fileName) {
				if (fileName.endsWith('.mp4') || fileName.endsWith('.pdf')) {
					let plat = uni.getSystemInfoSync().platform
					if (plat == 'android' || plat == 'ios') {
						console.log("plat == 'android' || plat == 'ios'");
						window.open(
							fileName
						)
					} else {
						downLoad2(fileName, this.detail.course.name + '-学习资料', 'video/mp4')
					}
				} else {
					window.open(
						fileName
					)
				}
			},

			goPay() {
				uni.navigateTo({
					url: '/pages/index/scorePaySuc/index'
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	@import './index.scss';
</style>