<template>
	<view class="download-item">
		<view class="download-info" @click="govideo">
			<view class="info">
				
				<view class="download-name">{{ item.name }}</view>
				<view class="download-size">{{ changeSize(item.size) }}</view>
				<view class="download-time">{{ changeTime(item.time) }}</view>
			</view>
			<view v-show="canDelete" class="download-delete">
				<view @click.stop="deleteFile">删除</view>
			</view>
		</view>
	</view>
</template>

<script>
	import fileManager from "@/utils/fileManager.js";
	export default {
		components: {
		},
		props: {
            item: {},
		},
		data() {
		  return {
		    canDelete: false,
		  };
		},
		methods: {
			govideo(){
				const filename = this.item.name
				let underscoreIndex = filename.lastIndexOf("_");
				let dotMp4Index = filename.indexOf(".mp4");
				
				if (underscoreIndex !== -1 && dotMp4Index !== -1 && dotMp4Index > underscoreIndex) {
				    let extractedText = filename.substring(underscoreIndex + 1, dotMp4Index);
				    console.log(extractedText); // 输出：66279
					 this.openVideo(extractedText)
				} else {
				    console.log("未找到下划线或'.mp4'，或者位置顺序不正确。");
				}
			
			},
			showDelete(isDelete) {
				this.canDelete = isDelete
			},
			deleteFile() {
						        console.log(this.item);
						        this.$emit("DeleteFile", this.item.fullPath,this.item.localPath)
						},
			/*文件大小转换*/
			changeSize(size) {
			  var num;
			  if (size / 1024 <= 1024) {
			    num = size / 1024;
			    return num.toFixed(2) + "KB";
			  }
			  if (size / 1024 > 1024 && size / 1024 <= 1024 * 1024) {
			    num = size / 1024 / 1024;
			    return num.toFixed(2) + "M";
			  }
			  if (size / 1024 > 1024 * 1024) {
			    num = size / 1024 / 1024 / 1024;
			    return num.toFixed(2) + "G";
			  }
			},
			changeTime(time) {
				return time
			}
		}
	};
</script>

<style lang="scss">
	.download-item {
		padding: 10px 15px;
		display: flex;
		align-items: center;
				
		.download-info {
			padding: 10px 10px;
			background-color: #171929;
			border-radius: 6px;
			box-shadow: 0 1px 3px rgba(0,0,0,0.2);
			display: flex;
			align-items: center;
			overflow: hidden;
			flex: 1;
			
			.download-delete {
				// flex: 0 0 20%;
				// overflow: hidden;
				// background-color: #456;
				color: red;
			}
			
			.info {
				flex: 1 1 0%;
				overflow: hidden;
				
				.download-name {
					font-size: 16px;
					                    width: 540rpx;
					font-weight: 600;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					color: #fff;
				}
				
				.download-size {
					font-size: 14px;
					font-weight: 600;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					color: #fff;
				}
				
				.download-time {
					padding-top: 5px;
					font-size: 12px;
					font-weight: 500;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					color: #999999;
				}
			}
		}
	}
</style>