<template>
	<view>
		<mescroll-empty :option="option" @emptyclick="$navigateTo('/pages/login/login')" v-if="isEmpty">
		</mescroll-empty>
		<view class="file-list" v-else>
			<view class="file-item" v-for="(item,index) in tableData" :key="index" @click="clickFolder(item)">
				<view class="file-image">
					<image class="image" src="/static/image/datacenter/folder.png" mode="aspectFill"></image>
				</view>
				<view class="file-content">
					<view class="title">{{item.name}}</view>
					<view class="sub">{{item.createDate || '-'}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		generateFileNodeProject,
		getProjectDirList
	} from '@/request/api/datacenter.js'
	import {
		projectPermission
	} from '@/uitls/datacenter'
	export default {
		data() {
			return {
				option: {
					tip: '暂未加入项目'
				},
				tableData: [],
				parentId: '',
				isEmpty: true
			}
		},
		onShow() {
			this.isEmpty = true;
			if (!uni.getStorageSync('token')) {
				this.option = {
					tip: '暂未登录',
					btnText: '点击登录'
				}
			} else if (!this.$store.getters.project.id) {
				this.option = {
					tip: '暂未加入项目'
				}
			} else {
				this.initProjectDir();
				this.isEmpty = false;
			}
		},
		methods: {
			initProjectDir() {
				generateFileNodeProject(this.$store.getters.project.id).then(res => {
					if (res.code === 200) {
						this.tableData = res.data.sort((a, b) => b.directory - a.directory);
					}
				});
			},
			clickFolder(item) {
				if (!item.directory) return;
				projectPermission({
					id: item.id,
					oldPermission: item.permissions,
					type: 'access',
					name: item.name,
					folderList: [item.name]
				}, () => {
					this.$navigateTo('/pages/file/file?parentId=' + item.id + '&title=' + item.name)
				});
			}
		}
	}
</script>

<style lang="scss">
	.file-list {
		padding: 30rpx;

		.file-item {
			display: flex;
			padding: 20rpx;
			background: #fff;
			display: flex;
			align-items: center;
			border-radius: 16rpx;
			box-shadow: 0px 1px 12px rgba(3, 3, 3, 0.08);
			margin-bottom: 30rpx;

			.file-image {
				width: 100rpx;
				height: 80rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				margin-right: 30rpx;
			}

			.title {
				font-size: 32rpx;
				font-weight: 600;
				margin-bottom: 10rpx;
			}

			.sub {
				font-weight: 300;
				font-size: 24rpx;
				margin-top: 10rpx;
				color: $uni-secondary-color;
			}

		}
	}
</style>