<template>
  <el-dialog ref="diaFrom" v-dialogDrag title="查看档案详情" :close-on-click-modal="false" :visible.sync="daStatus"
    width="85%" top="10px" :before-close="cancel">
    <div v-for="(item, key) in Alltable" :key="key" class="wholeTable">
      <el-table v-loading="item.tableLoading" :data="item.tableData" fit border ref="tableForEach"
        :max-height="Alltable.length==1?600:510" @row-click="editCurrentApplicationApproval($event, item, key)"
        tooltip-effect="dark">
        <el-table-column label="原文数量" width="90" align="center"
          v-if="(Alltable.length===3 && key===2)||(Alltable.length===1)||(Alltable.length===2)">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="handleContents(scope.row, item, key)">{{
                    scope.row.archive_file_num ? scope.row.archive_file_num : 0
                }}</el-button>
          </template>
        </el-table-column>
        <el-table-column v-for="(ele, index) in JSON.parse(item.tableShow)" :key="index" :prop="ele.columnName"
          :min-width="ele.width" :label="ele.columnChnName" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span v-if="ele.columnName === 'fonds_no'">
              {{ (fondsList.filter(f => f.fondscode === scope.row[ele.columnName])[0] || {}).codeName }}
            </span>
            <span v-if="ele.columnName !== 'fonds_no'">{{ scope.row[ele.columnName] }}</span>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination v-if="item.hasOwnProperty('pagination')" @current-change="handleCurrentChange($event, item, key)"
        @size-change="handleSizeChange($event, item, key)" layout="total, prev, pager, next, sizes"
        :page-size="item.pagination.pageSize" :page-sizes="[10, 20, 30, 50]" :current-page="item.pagination.pageNum"
        :total="item.pagination.total">
      </el-pagination>
      <!-- 原文弹窗 -->
    </div>
    <drawer-tem ref="original" :treeRow="treeRow" :drawer='drawer' :actions='actions' :catalogueType='catalogueType'
      @handleClose="cancelDrawer" />
  </el-dialog>
</template>
<script>
  import DrawerTem from "@/components/DrawerTem"
  import {
    getOneTable
  } from "@/api/archives-management/fileManagement/notStoredArchives"
  export default {
    props: {
      daStatus: {
        type: Boolean,
        default: () => false,
      },
      Alltable: {
        type: Array,
        default: () => [],
      },
      fondsList: {
        type: Array,
        default: () => [],
      },
    },
    data() {
      return {
        treeRow: {},
        drawer: false,
        actions: "",
        catalogueType: false,
        tableOneClickRow: {},
        tableTwoClickRow: {}
      }
    },
    components: {
      DrawerTem,
    },
    methods: {
      cancel() {
        this.$emit("cancel")
      },
      editCurrentApplicationApproval(val, item, key) {
        if (key === 0) {
          this.tableOneClickRow = val
          if (this.Alltable.length === 3) {
            this.Alltable[2].tableData = []
          }
        } else if (key === 1) {
          this.tableTwoClickRow = val
        }
        // this.clickSearch(key + 1)
        // this.tableOneClickRow = val
        // this.$refs.tableForEach[key].clearSelection();
        // this.$refs.tableForEach[key].toggleRowSelection(val);
        this.$emit("getData", key + 1, val.id)

      },
      //每页换个数
      handleSizeChange(val, item, key) {
        // console.log(item)
        item.pagination.pageSize = val;
        item.pagination.pageNum = 1;
        this.$emit("getData", key, item.tableData[0].pid)
        console.log(val, 999)
      },
      //   //换页
      handleCurrentChange(val, item, key) {
        item.pagination.pageNum = val;
        this.$emit("getData", key, item.tableData[0].pid)
        console.log(val, 999)
      },
      //点击原文
      cancelDrawer() {
        this.drawer = false
      },
      handleContents(val, item, key) {
        this.treeRow = val;
        this.$refs.original.archiveNum = val.archive_file_num ?
          val.archive_file_num :
          0;
        // console.log(this.$refs.original, 7778)
        this.$refs.original.oriTable = item;
        // console.log(this.$refs.original.oriTable, 8887)
        this.$refs.original.orirow = val;
        this.$refs.original.orikey = key;
        let params = {
          commonMap: {
            funcTypeCode: "file",
            tableName: item.tableName,
          },
          conditionMap: {
            rec_id: val.id,
            file_status: 1,
          },
          orderBy: "order by  page_no  asc",
          limit: "1000",
          page: "1",
        };
        this.$refs.original.params = params;
        this.actions = this.prefix + "/point-strategy/v/ajjnOriginBatch/uploadSimpleFilesAnjuan?recId=" +
          val.id +
          "&fondscode=" +
          val.fonds_no +
          "&tableName=" +
          item.tableName
        getOneTable(params).then((res) => {
          //原文表
          this.$refs.original.tableDataOrigin = res.body.list;
        }).then(res => {
          params.conditionMap.file_status = 2;
          getOneTable(params).then((res) => {
            //原文回收站表
            this.$refs.original.backData = res.body.list;
          });
        })
        this.$refs.original.picUrl = "";
        this.$refs.original.videoSrc = "";
        this.$refs.original.activeName = "1"
        this.drawer = true
      },
    }
  }

</script>
<style lang="scss" scoped>
  .wholeTable {
    padding: 10px 20px;
  }

</style>
