<template>
	<view >
		<cu-custom ref="cuCustom" bgColor="bg-gradual-blueness" :isBack="true" :isRingt="true" :backUrl="backUrl">
			<block slot="backText">返回</block>
			<block slot="content">学习详细</block>
		</cu-custom>

		<view class="sdetail">
			<view class="svideol" >
				<view class="sitem">
					<view class="sleft">
						<text class="text-blue cuIcon-newsfill mr10"></text>
						<text @click="$noMultipleClicks(studyData,index)" class="text-title">{{pd.TITLE}}</text>
					</view>
				</view>
			</view>
			<view class="cu-tabbar-height"></view>
		</view>
	</view>
</template>

<script>
	import {
		basePath,
		corpinfoId,
		baseImgPath,
		loginUser
	} from '@/common/tool.js';
	export default {
		data() {
			return {
				baseImgPath: baseImgPath,
				backUrl: '/pages/application/onlinexxks/my-tasks',
				loading: false,
				noClick: true,
				COURSEWARE_ID:'',
				TEMPSTUDYUSERS_ID: '',
				pd: {}, // 数据,
			}
		},
		async onLoad(event) {
			this.TEMPSTUDYUSERS_ID = event.TEMPSTUDYUSERS_ID
			this.COURSEWARE_ID = event.COURSEWARE_ID
			await this.getData()
			this.$forceUpdate()
		},
		methods: {
			getData() {
				return new Promise((resolve, reject) => {
					var _this = this;
					uni.showLoading({
						title: '请稍候'
					})
					uni.request({
						url: basePath + '/app/studysection/goEdit',
						method: 'POST',
						dataType: 'json',
						header: {
							'Content-type': 'application/x-www-form-urlencoded'
						},
						data: {
							STUDYSECTION_ID: this.COURSEWARE_ID,
              CORPINFO_ID:loginUser.CORPINFO_ID,
              USER_ID:loginUser.USER_ID,
						},
						success: (res) => {
							if ("success" == res.data.result) {
								uni.hideLoading();
								_this.pd = res.data.pd;
							} else {
								uni.showToast({
									icon: 'none',
									title: res.data.message,
									duration: 2000
								});
							}
							resolve(true)
						}
					})
				})
			},
			studyData() {
				uni.showLoading({
					title: "加载中..."
				}); //加载中动画
				uni.downloadFile({
					url: baseImgPath + this.pd.FILEPATH,
					success: (res) => {
						uni.hideLoading(); //结束加载中动画
						uni.openDocument({
							filePath: res.tempFilePath,
							success: function(res) {
								// console.log(res)
							}
						})
					}
				})
				uni.request({
					url: basePath + '/app/tempstudy/edit',
					method: 'POST',
					dataType: 'json',
					header: {
						'Content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						TEMPSTUDYUSERS_ID: this.TEMPSTUDYUSERS_ID,
            CORPINFO_ID:loginUser.CORPINFO_ID,
            USER_ID:loginUser.USER_ID,
					}
				})
			},
			BackPage() {
				uni.redirectTo({
					url: '/pages/application/onlinexxks/my-curriculum',
				})
			}
		}
	}
</script>

<style>
</style>
