<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 class="dy-list">
        <view v-for="(item,index) of varList" :data-id="item.MFOLDER_ID" class="dy-list-item p201 arrow" @click=goToDetail(item)>
          <view class="dy-subtitle">
            <text>{{item.NAME}}</text>
          </view>
        </view>
      </view>
		</view>
			<!-- <view class="cu-tabbar-height"></view> -->
	</view>
</template>

<script>
  import { decryptAes } from "@/common/aesUtil";
	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: [],
        varList: [],
				KEYWORDS:'',
			}
		},
		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
				// })
				uni.downloadFile({
				  url: baseImgPath + item.FILEPATH,
				  success: function (res) {
				    var filePath = res.tempFilePath;
				    uni.openDocument({
				      filePath: filePath,
				      showMenu: true,
				      success: function (res) {
				        console.log('打开文档成功');
				      }
				    });
				  }
				});
			},
			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) => {
            res.data = decryptAes(res.data);
            if(res.data.zTreeNodes){
              uni.hideLoading();//结束加载中动画
              _this.accordion = res.data.varList
              _this.varList = []
            } else {
              uni.hideLoading();//结束加载中动画
              _this.varList = res.data.varList
              _this.accordion = []
            }

					}
				})
			},
		}
	}
</script>

<style>

</style>
