<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      label-width="78px"
    >
      <el-form-item label="教师" prop="applyName">
        <el-input
          v-model="queryParams.applyName"
          placeholder="请输入教师"
          clearable
        />
      </el-form-item>
      <el-form-item label="实验时间" prop="time">
        <el-date-picker
          v-model="queryParams.startTime"
          type="date"
          placeholder="选择"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
        <el-date-picker
          v-model="queryParams.endTime"
          type="date"
          placeholder="选择"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="实验分类">
        <el-select
          v-model="queryParams.experimentClassify"
          placeholder="请选择"
          clearable
        >
          <el-option
            v-for="dict in dict.type.experiment_classify"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="实验名称">
        <el-input
          v-model="queryParams.experimentName"
          placeholder="请输入"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="getList"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-table border v-loading="loading" :data="tableData" stripe>
      <el-table-column
        fixed="left"
        label="序号"
        type="index"
        width="55"
        align="center"
      />
      <el-table-column label="学科" align="center" prop="sub">
        <template slot-scope="{ row }">
          <div>{{ selectDictLabel(dict.type.lab_sub, row.sub) }}</div>
        </template>
      </el-table-column>
      <el-table-column label="学年" align="center" prop="schoolYear" />
      <el-table-column label="级部" align="center" prop="grade" />
      <el-table-column label="班级" align="center" prop="className" />
      <el-table-column label="实验时间" align="center" prop="experimentTime" />
      <el-table-column label="实验名称" align="center" prop="experimentName" />
      <el-table-column
        label="实验分类"
        align="center"
        prop="experimentClassify"
      >
        <template slot-scope="{ row }">
          <div>
            {{
              selectDictLabel(
                dict.type.experiment_classify,
                row.experimentClassify
              )
            }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="实验室" align="center" prop="labName" />
      <el-table-column
        label="实验用品"
        align="center"
        prop="experimentUseGoods"
      />
      <el-table-column label="章节内容" align="center" prop="chapterContent" />
      <el-table-column label="教师" align="center" prop="applyName" />
      <el-table-column label="附件" align="center" prop="schoolAccessoryList">
        <template slot-scope="scope">
          <div
            v-for="(accessory, index) in scope.row.accessoryList"
            :key="index"
          >
            <a :href="baseUrl + accessory.accessoryUrl" target="_blank">{{
              accessory.accessoryName
            }}</a>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      ref="pageBlock"
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getList } from "@/api/smartSchool/laboratoryManagement/experimentalRecords";
export default {
  dicts: ["experiment_classify", "lab_sub"],
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        applyName: "",
        startTime: "",
        endTime: "",
        experimentClassify: "",
      },
      loading: false,
      total: 0,
      tableData: [],
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    //获取列表数据
    getList() {
      getList(this.queryParams).then((response) => {
        this.tableData = response.rows;
        console.log(this.tableData);
        this.tableData = response.rows.map((item) => {
          item.accessoryList = item.schoolAccessoryList; // 将附件信息赋值给accessoryList属性
          return item;
        });
        this.total = response.total;
        this.loading = false;
      });
    },
    //重置
    resetQuery() {
      (this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        applyName: "",
        startTime: "",
        endTime: "",
        experimentClassify: "",
      }),
        this.getList();
    },
  },
};
</script>

<style lang="scss" scoped>
.yearChoose {
  width: 130px;
}
</style>
