<template>
	<div class="doc">
		<view class="box">
			<u-badge :value="value.length">


			</u-badge>
		</view>

		<u-button :plain="true" :hairline="true" v-if="type != 'view'" size='mini' text="上传"
			@click="handleUpload"></u-button>
		<u-button :plain="true" :hairline="true" v-else size='mini' text="查看" @click="handleUpload"></u-button>
	</div>
</template>

<script>
	export default {
		name: 'index',

		model: {
			prop: 'value',
			event: 'updateVal'
		},
		props: {
			type: {
				type: String,
				default: ''
			},
			value: {
				type: Array,
				default: () => {
					return [];
				}
			}
		},
		data() {
			return {
				selectVal: ''
			};
		},
		watch: {
			value: {
				handler(newVal) {

					this.selectVal = newVal || [];
				},
				immediate: true
			}
		},
		created() {
			uni.$off('getFiles')
			uni.$on('getFiles', (id) => {
				this.getFiles(id)
			})
		},
		destroyed() {
			uni.$off('getFiles')
		},
		methods: {
			handleUpload() {
				uni.navigateTo({
					url: '/pages/doc/docList?fileId=' + JSON.stringify(this.selectVal)
				})
			},
			getFiles(val = []) {
				this.$emit('updateVal', val);
			}
		}
	};
</script>

<style scoped lang="scss">
	.doc {
		position: relative;

		.box {
			position: absolute;
			right: -20rpx;
			top: -15rpx;
			width: 40rpx;
			z-index: 999;
		}

		uni-button {
			width: 100rpx;
			// height: 50rpx;
			margin-left: 10rpx;
			margin-right: 0;
			color: #fff !important;
			border: none;
			background: #157a2c !important;

		}
	}
</style>