<template>
	<view class="page-view">
		<top-return :color="'#FFF'" text="作业列表"></top-return>

		<view class="bg-box2"></view>

		<!-- 页面标题内容 -->
		<view class="top-box">
			<view class="flex-baseline">
				<view class="info-title" style="margin-left: 0;">{{dayTime.split('月')[0]}}</view>
				<view class="info-subtitle">月</view>
				<view class="info-title">{{dayTime.split('月')[1]}}</view>
				<view class="info-subtitle">日</view>
				<view class="info-subtitle" style="margin-left: 20rpx;">已完成</view>
				<view class="info-title">{{value}}%</view>
			</view>
			<view class="flex-baseline">
				<view class="data-subtitle" style="margin-left: 0;">孩子今日共</view>
				<view class="data-title">{{workData.length}}</view>
				<view class="data-subtitle">份作业</view>
			</view>
		</view>

		<view class="card-view">
			<view class="card-item" v-for="(item,index) in workData" :key="index" @click="navWorkReport(index)">
				<view class="card-title">
					<view class="t-icon t-icon-workicon">
					</view>
					<view class="YS-title" style="font-size: 45rpx;">{{item.work.name}}</view>
					<view
						:class="[item.work.progress === 'finish'?'t-icon t-icon-yiwancheng1':'t-icon t-icon-jinhangzhong-copy1','state-seal']">
					</view>
				</view>
				<view class="card-info">
					<view class="flex-baseline">
						<view class="info-type">布置老师:</view>
						<view class="YS-title" style="margin-left: 10rpx;">{{item.work.creatorId}}</view>
						<view class="info-type" style="margin-left: 20rpx;">截止时间:</view>
						<view class="YS-title" style="margin-left: 10rpx;">
							{{$timeStampToTime(item.work.endTime)}}
						</view>
					</view>
					<view class="flex-row" style="margin-top: 20rpx;">
						<u-parse class="YS-title" style="font-size: 30rpx;" :content="item.work.description"
							:selectable="true"></u-parse>
					</view>
				</view>
				<!-- 正文 -->
				<view class="content-box">
					<view class="title-box"
						:style="{backgroundColor: item.work.progress === 'finish'? '#23b46c': '#f9c752' }">
						<view class="title-text">作业附件</view>
					</view>
					<view v-for="(attachment,i) in item.work.attachments" :key="i">
						<view class="attachment-box">
							<view v-if="attachment.type == 'word'" class="t-icon t-icon-WORD"></view>
							<view v-if="attachment.type == 'excel'" class="t-icon t-icon-ECEL"></view>
							<view v-if="attachment.type == 'pdf'" class="t-icon t-icon-PDF"></view>
							<view v-if="attachment.type == 'image'" class="t-icon t-icon-tupianziliao"></view>
							<view v-if="attachment.type == 'ppt'" class="t-icon t-icon-PPT"></view>
							<view class="attachment-info" style="margin-left: 20rpx;">
								<view class="content-detail">文件名: {{attachment.name}}</view>
								<view class="content-subtitle">文件大小: {{fixNum(attachment.size/8/1024)}}KB</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		computed: {
			...mapState('m_children', ['workData'])
		},
		data() {
			return {
				value: '',
				dayTime: ''
			}
		},
		onLoad(parameter) {
			this.value = parameter.value
			this.dayTime = (new Date()).format('M-d').replace('-', '月')
		},
		methods: {
			fixNum(num) {
				return num.toFixed(2)
			},
			navWorkReport(index) {
				uni.navigateTo({
					url: `/subpkg/datalist/workReport?index=${index}`
				})
			}
		}
	}
</script>

<style lang="scss">
	@import 'data_pages.scss';
	@import 'top_info.scss';

	.attachment-box {
		display: flex;
		margin-bottom: 20rpx;
		align-items: center;
		padding: 6rpx 20rpx;
		background-color: #FFF;
		border-radius: 10rpx;

		.t-icon {
			width: 60rpx;
			height: 60rpx;
		}

		.attachment-info {
			display: flex;
			flex-direction: column;
			margin: 20rpx 50rpx;
		}
	}
</style>
