<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="文件名称" prop="fileName">
        <el-input
          v-model="queryParams.fileName"
          v-no-whitespace
          placeholder="请输入文件名称"
          maxlength="60"
          show-word-limit
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <el-table-column
        type="index"
        width="55"
        label="序号"
        align="center"
        :index="indexContinuous(queryParams.pageNum, queryParams.pageSize)"
      />
      <el-table-column label="文件名称" align="center" prop="fileName" />
      <el-table-column label="文件大小" align="center" prop="fileSize" />
      <el-table-column label="文件类型" align="center" prop="fileType" />
      <el-table-column label="申请时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleView(scope.row)"
          >查看</el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            @click="handleDel(scope.row)"-->
<!--          >删除</el-button>-->
          <el-button
            size="mini"
            type="text"
            @click="handleAuditRecord(scope.row)"
            v-hasPermi="['system:audit:query']"
          >审核记录
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog title="文件预览" :visible.sync="open" width="90%" append-to-body>
      <div style="width: 100%;height:720px">
        <bns-kkFile-preview :items="fileList"></bns-kkFile-preview>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import BnsKkFilePreview from '@/components/pro-tabs/bns-kkFile-preview.vue'
import {getEnterFileList} from '@/api/pro/cons/materialList'
import { encryptCBC } from '@/utils/aescbc'
import { indexContinuous } from '@/utils/bonus'

export default {
  name: "Post",
  components: { 'bns-kkFile-preview': BnsKkFilePreview },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工程表格数据
      list: [
        {
          fileName: '文件名称',
          fileSize: '文件大小',
          fileType: '文件类型',
          createTime: '申请时间',
        }
      ],
      items:{},
      fileList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type:'1',
        fileName: undefined,
        proId: this.$store.state.user.thisIds.proId,
        consUuid: this.$store.state.user.thisIds.consUuid,
        supUuid: this.$store.state.user.thisIds.supUuid,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    indexContinuous,
    /** 查询工程列表 */
    getList() {
      this.loading = true;
      getEnterFileList(this.queryParams).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        equipName: undefined,
        postSort: 0,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.proId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.fileList = {
        filePreviewUrl: row.filePath,
        fileName: row.fileName,
      }
      this.open = true;
    },

    /** 审核记录按钮操作 */
    handleAuditRecord(row) {
      this.$router.push("/flow/auditRecord/" + encryptCBC(JSON.stringify({
        taskId: row.taskId,
        checkType:'2'
      })));
    },
    /** 删除按钮操作 */
    handleDel(row) {

    },
  }
};
</script>
