<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="90px"
    >
      <kindergarten
        @kinbatlist="kinbatlist"
        style="display: inline; padding: 20px 0 20px 0"
      ></kindergarten>
      <el-form-item label="报告名称" prop="reportName">
        <el-input
          v-model="queryParams.reportName"
          placeholder="请输入报告名称"
          style="width: 230px"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报告编号" prop="reportCode">
        <el-input
          v-model="queryParams.reportCode"
          placeholder="请输入报告编号"
          clearable
          style="width: 230px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="checkTime">
        <el-input
          v-model="queryParams.reportName"
          style="width: 230px"
          placeholder="请输入报告名称"
          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-table v-loading="loading" :data="kindergartenCheckReportList">
      <el-table-column
        label="幼儿园名称"
        align="center"
        prop="kindergartenName"
      />
      <el-table-column label="批次名称" align="center" prop="batchName" />
      <el-table-column label="报告名称" align="center" prop="reportName" />
      <el-table-column label="报告编号" align="center" prop="reportCode" />
      <el-table-column label="审核人" align="center" prop="checkUserId" />
      <el-table-column label="审核状态" align="center" prop="checkStatus">
        <template slot-scope="scope">
          {{ scope.row.checkStatus == 0 ? "未审核" : "" }}
          {{ scope.row.checkStatus == 1 ? "已审核" : "" }}
        </template>
      </el-table-column>
      <el-table-column
        label="审核时间"
        align="center"
        prop="checkTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="lookhand(scope.row)"
            >预览</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:kindergartenCheckReport:edit']"
            >审核</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-download"
            @click="handleExport(scope.row)"
            v-hasPermi="['system:kindergartenCheckReport:export']"
            >下载</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="title"
      :visible.sync="open"
      width="1200px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="审批状态" prop="checkStatus">
          <el-radio-group v-model="form.checkStatus">
            <el-radio :label="0">未审批</el-radio>
            <el-radio :label="1">已审批</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="报告内容" prop="reportName">
          <iframe
            ref="pdfCotainer"
            :src="pdfurl"
            width="1000px"
            height="550px"
          ></iframe>
        </el-form-item>
        <!-- <el-form-item label="幼儿园名称" prop="kindergartenName">
          <el-input v-model="form.kindergartenName" />
        </el-form-item>
        <el-form-item label="批次名称" prop="batchCode">
          <el-input v-model="form.batchCode" />
        </el-form-item>
        <el-form-item label="报告编号" prop="reportCode">
          <el-input v-model="form.reportCode" placeholder="请输入报告编号" />
        </el-form-item>
        <el-form-item label="报告名称" prop="reportName">
          <el-input v-model="form.reportName" placeholder="请输入报告名称" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog
      title="预览"
      :visible.sync="openiframe"
      width="1050px"
      append-to-body
    >
      <div style="height: 600px">
        <iframe
          ref="pdfCotainer"
          :src="pdfurl"
          width="1000px"
          height="600px"
        ></iframe>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="openiframe = false">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listKindergartenCheckReport,
  getKindergartenCheckReport,
  addKindergartenCheckReport,
  updateKindergartenCheckReport,
  report,
} from "@/api/system/kindergartenCheckReport";
import kindergarten from "../../assembly/kindergarten.vue";

export default {
  components: { kindergarten },
  name: "KindergartenCheckReport",
  data() {
    return {
      // 遮罩层
      loading: true,
      openiframe: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 幼儿园检测报告表格数据
      kindergartenCheckReportList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        kindergartenId: null,
        batchCode: null,
        reportCode: null,
        reportName: null,
        physicalSynthAnalysis: null,
        downloadAddress: null,
        motionLibraryId: null,
        checkUserId: null,
        checkTime: null,
        checkStatus: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      pdfurl: null,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询幼儿园检测报告列表 */
    getList() {
      this.loading = true;
      listKindergartenCheckReport(this.queryParams).then((response) => {
        this.kindergartenCheckReportList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        kindergartenId: null,
        batchCode: null,
        reportCode: null,
        reportName: null,
        physicalSynthAnalysis: null,
        downloadAddress: null,
        motionLibraryId: null,
        checkUserId: null,
        checkTime: null,
        checkStatus: 0,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      console.log(this.queryParams);
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      report(row.id).then((res) => {
        this.pdfurl = window.URL.createObjectURL(res);
        // window.open(this.pdfurl);
      });
      getKindergartenCheckReport(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改幼儿园检测报告审批状态";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateKindergartenCheckReport(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addKindergartenCheckReport(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    //预览
    lookhand(item) {
      report(item.id).then((res) => {
        this.pdfurl = window.URL.createObjectURL(res);
        this.openiframe = true;
        // window.open(this.pdfurl);
      });
    },
    /** 导出按钮操作 */
    handleExport(row) {
      // report(row.id).then((res) => {
      //   console.log(res);
      // });
      this.download(
        `/system/kindergartenCheckReport/download/report?id=${row.id}`,
        {},
        `幼儿园检测报告.pdf`
      );
    },
    kinbatlist(kindergartenId, batchCode) {
      console.log(kindergartenId, batchCode);
    },
  },
};
</script>
<style scoped='scss'>
::v-deep .el-form {
  display: inline;
}
</style>
