<template>
	<view>
		<cu-custom bgColor="bg-gradual-blueness" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">法律法规</block>
		</cu-custom>
		<view class="cu-bar search bg-white">
			<view class="search-form radius">
				<text class="cuIcon-search"></text>
				<input  v-model="KEYWORDS" placeholder="请输入关键字"></input>
			</view>
			<view class="action">
				<button class="cu-btn bg-green shadow-blur radius" @click="getQuery()">搜索</button>
			</view>
		</view>
		<view>

      <collapse v-if="accordion" @goToDetail="goToDetail" v-for="item in accordion" :key="item.id" :item="item"></collapse>

      <view v-if="varList" class="vi-card">
        <view class="vi-card-items" v-for="(item,index) of varList" :key="index">
          <view class="vi-card-title">
            {{item.NAME}}
          </view>
          <view class="vi-card-content">
            <text v-if="item.extension_name == '.docx' || item.extension_name == '.doc'">文件属性：文档</text>
            <text v-else-if="item.extension_name == '.xls' || item.extension_name == '.xlsx'">文件属性：表格</text>
            <text v-else-if="item.extension_name == '.ppt' || item.extension_name == '.pptx'">文件属性：幻灯片</text>
            <text v-else-if="item.extension_name == '.pdf'">文件属性：PDF</text>
            <text v-else>文件属性：</text>
            <text>上传日期：{{item.CTIME | formatDate}}</text>
          </view>
          <view class="vi-card-foot">
            <button class="cu-btn bg-blue sm"  @click="$noMultipleClicks(downloadFile,item.FILEPATH)"><text class="cuIcon-pulldown"></text>下载</button>
            <button
                class="cu-btn bg-cyan sm" @click="$noMultipleClicks(showFile,item)">
              <text class="cuIcon-playfill"></text> 预览
            </button>
          </view>
        </view>
      </view>
		</view>
			<!-- <view class="cu-tabbar-height"></view> -->
	</view>
</template>

<script>
	import {
		basePath,corpinfoId,loginSession,formatDate,loginUser,baseImgPath
	} from '@/common/tool.js';
	import collapse from "@/components/collapse/collapse.vue"
	export default {
		components: {collapse},
		data() {
			return {
				accordion: [],
        noClick:true,
        varList: [],
				KEYWORDS:'',
			}
		},
    filters: {
      formatDate(time) {
        if(time){
          var subStr=new RegExp('-','ig');//创建正则表达式对象,不区分大小写,全局查找
          time=time.replace(subStr,"/");//把'is'替换为空字符串
        }
        let date = new Date(time)
        return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
      }
    },
		onLoad() {
			this.getData()
		},
		methods: {
			change(e) {},
			goToDetail(item){
				if(item.id === '' || item.id === undefined){
          item.id = item.MFOLDER_ID
        }
				uni.navigateTo({
					url: '/pages/basics/study-files/study-detail?PARENT_ID='+item.id
				})
			},
			getQuery(){	//搜索按钮事件
				var _this = this;
				_this.showCount = -1;
				_this.currentPage = 1;
				_this.list = [];
				_this.isEnd = false;
				_this.getData();
			},
			getData(){
				var _this = this;
				uni.showLoading({
					title:"加载中..."
				});//加载中动画
				uni.request({
					url: basePath +'/app/mfolderStipulate/appListTree',
					method: 'POST',
					dataType: 'json',
					header: {
						'Content-type':'application/x-www-form-urlencoded'
					},
					data: {
						CORPINFO_ID:loginUser.CORPINFO_ID,
						USER_ID:loginUser.USER_ID,
						KEYWORDS:_this.KEYWORDS,
					},
					success: (res) => {
            if(res.data.zTreeNodes){
              uni.hideLoading();//结束加载中动画
              _this.accordion = JSON.parse(res.data.zTreeNodes)
              _this.varList = []
            } else {
              uni.hideLoading();//结束加载中动画
              _this.varList = res.data.varList.filter(item => item.FILEPATH)
              _this.accordion = []
            }

					}
				})
			},
      downloadFile(e){
        var url=baseImgPath + e ;
        var url2 = encodeURI(url);
        plus.runtime.openURL(url2, function(res) {
        });
      },
      showFile(item){
        uni.showLoading({
          title:"加载中..."
        });//加载中动画
        uni.downloadFile({
          url:baseImgPath+item.FILEPATH,
          success:(res)=>{
            uni.hideLoading();//结束加载中动画
            uni.openDocument({
              filePath:res.tempFilePath,
              success:function(){
              }
            })
          }
        })
      }
		}
	}
</script>

<style>

</style>
