<template>
	<view class="">
		<uni-menubar title="文件管理" />
		<tm-search v-model="param.keyword" color="blue" @confirm="getfileList"></tm-search>
		<tm-sticky>
			<tm-tabs color="blue" @change="tabClick" v-model="activeIndex" :list="list" range-key="name"
				align="left"></tm-tabs>
		</tm-sticky>
		<view v-if="list.length>0">
			<tm-grouplist title="文件列表" title-theme="blue">
				<view v-for="(item,index) in fileList" :key="index">
					<tm-listitem @click="fileDetail(item)" :title="`${item.name}(${item.ext})`"
						:label="item.update_time" left-icon="icon-folder-fill" left-icon-color="blue" show-left-icon
						show-right-icon>
						<template v-slot:left>
							<tm-icons color="orange" name="icon-folder-fill" size="40"></tm-icons>
						</template>
						<template v-slot:rightValue>
							<view v-if="item.is_edit">
								我的<text v-if="item.showc==0">(私有)</text><text v-if="item.showc==1">(公开)</text>
							</view>
							<view v-else>公共</view>
						</template>
					</tm-listitem>
				</view>
			</tm-grouplist>
		</view>
		<tm-flotbutton v-if="user.card_id>0" @click="uploadFile" label="添加" :show-text="true" color="bg-gradient-blue-accent">
		</tm-flotbutton>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				activeIndex: 0,
				list: [{
					'name': '全部',
					'id': 0
				}],
				fileList: [],
				pid: 0,
				param:{
					cate_id:0,
					keyword:'',
				}
			}
		},
		computed: {
			user() {
				return this.$tm.vx.state().user.userInfo || {}
			}
		},
		onLoad () {
			this.getFileClass()
			this.getfileList()
			// uni.$once('refresh',this.getfileList(0))
			this.getfileList(0)
		},
		methods: {
			fileDetail(item) {
				uni.navigateTo({
					url: "/pages/file/fileDetail?fileId=" + item.id + "&card_id=" + uni.getStorageSync('card_id')
				})
			},
			getFileClass() {
				this.$tm.request.post('file/cate').then(res => {
					this.list = [...this.list, ...res.data]
				})
			},
			getfileList() {
				this.$tm.request.post('file/list', this.param).then(res => {
					this.fileList = res.data
				})
			},
			tabClick(e) {
				this.activeIndex = e
				this.param.cate_id = this.list[e].id
				this.getfileList()
			},
			uploadFile() {
				// console.log(this.pid)
				uni.navigateTo({
					url: '/pages/file/uploadFile?pid=' + this.pid
				})
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>
