<template>
  <el-dialog
    title="档案选择"
    v-if="showFlag"
    :visible.sync="showFlag"
    :modal="false"
    width="80%"
    center
  >
    <el-row>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table
      v-loading="loading"
      :data="fileList"
      @current-change="handleCurrent"
      @row-dblclick="handleRowDbClick"
    >
      <el-table-column width="50" align="center">
        <template v-slot="scope">
          <el-radio
            v-model="selectedArchivesId"
            :label="scope.row.id"
            @change="handleRowChange(scope.row)"
            >{{ "" }}</el-radio
          >
        </template>
      </el-table-column>
      <el-table-column label="档案类型" align="center" prop="type">
        <template v-slot="scope">
          <dict-tag
            :type="DICT_TYPE.ARCHIVES_FILE_TYPE"
            :value="scope.row.type"
          />
        </template>
      </el-table-column>
      <el-table-column label="档案位置" align="center" prop="position" />
      <el-table-column label="全宗号" align="center" prop="caseNum" />
      <el-table-column label="目录号" align="center" prop="catalogNum" />
      <el-table-column label="案卷号" align="center" prop="filesNum" />
      <el-table-column label="保存期限" align="center" prop="timeLimit">
      </el-table-column>
      <el-table-column label="鉴定人" align="center" prop="userName" />
      <el-table-column label="业务实体" align="center" prop="company" />
      <el-table-column label="鉴定日期" align="center" prop="date" width="180">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.date) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="鉴定结果" align="center" prop="result">
        <template v-slot="scope">
          <span>{{ scope.row.result == 0 ? "销毁" : "延长期限" }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirmSelect">确 定</el-button>
      <el-button @click="showFlag = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { getAuthenticatePage } from "@/api/fileAuth/authenticate";
export default {
  name: "FileSelect",
  data() {
    return {
      showFlag: false,
      selectedArchivesId: undefined,
      selectedRow: undefined,
      // 遮罩层
      loading: true,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 档案数据
      fileList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        result: "1",
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      getAuthenticatePage(this.queryParams).then((response) => {
        this.fileList = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleCurrent(row) {
      if (row) {
        this.selectedRow = row;
      }
    },
    //行双击选中
    handleRowDbClick(row) {
      if (row) {
        this.selectedRow = row;
        this.$emit("onSelected", this.selectedRow);
        this.showFlag = false;
      }
    },
    // 单选选中数据
    handleRowChange(row) {
      if (row) {
        this.selectedRow = row;
      }
    },
    //确定选中
    confirmSelect() {
      if (this.selectedArchivesId == null || this.selectedArchivesId == 0) {
        this.$notify({
          title: "提示",
          type: "warning",
          message: "请至少选择一条数据!",
        });
        return;
      }
      this.$emit("onSelected", this.selectedRow);
      this.showFlag = false;
    },
  },
};
</script>
