<template>
  <div class="app-container">
    <div style="margin-top:3%">  
    <div class="readme">正在考试中，考试时间 50 分钟</div>
    <div class="djs">距离考试结束还有{{ time }}</div>
    </div>

    <el-row>
      <h4 class="h4">更换件列表</h4>

      <el-table
      :data="tableData"  border
      style="text-align:center;margin-top:1%;"
      max-height="550">
      <el-table-column
        prop="name"
        label="更换件类型"
        >
        <template slot-scope="scope">
          <el-input v-model="scope.row.address" ></el-input>
        </template>
      </el-table-column>

      <el-table-column
        prop="number"
        label="状态">
        <template slot-scope="scope">
          <el-input v-model="scope.row.address" ></el-input>
        </template>
      </el-table-column>
      <el-table-column
        prop="reason"
        label="申请时间" >
        <template slot-scope="scope">
          <el-input v-model="scope.row.address" ></el-input>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作">
        <template slot-scope="scope">
          <el-button
            @click.native.prevent="AddRow(scope.$index, tableData)"
            type="text"
            size="small">
            追加
          </el-button>
          <el-button
            @click.native.prevent="deleteRow(scope.$index, tableData)"
            type="text"
            size="small">
            移除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-row>

  <el-row>
    <h4 class="h4">维修报告列表</h4>
    <el-table
      :data="tableData1"  border
      style="text-align:center;margin-top:1%;"
      max-height="550">
      <el-table-column
        prop="name"
        label="故障现象">
        <template slot-scope="scope">
          <el-input v-model="scope.row.address" ></el-input>
        </template>
      </el-table-column>
      <el-table-column
        prop="number"
        label="可能原因">
        <template slot-scope="scope">
          <el-input v-model="scope.row.address" ></el-input>
        </template>
      </el-table-column>
      <el-table-column
        prop="reason"
        label="故障部位" >
        <template slot-scope="scope">
          <el-input v-model="scope.row.address" ></el-input>
        </template>
      </el-table-column>
      <el-table-column
        prop="reason"
        label="排除方法" >
        <template slot-scope="scope">
          <el-input v-model="scope.row.address" ></el-input>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作">
        <template slot-scope="scope">
          <el-button
            @click.native.prevent="AddRow1(scope.$index, tableData1)"
            type="text"
            size="small">
            追加
          </el-button>
          <el-button
            @click.native.prevent="deleteRow1(scope.$index, tableData1)"
            type="text"
            size="small">
            移除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-row>
  <el-form ref="elForm" :model="formData" :rules="rules" size="medium"  style="margin-top: 1%;text-align: center;">
    <el-form-item label="修复结论" prop="field101">
      <el-select v-model="formData.field101" placeholder="请选择修复结论" clearable :style="{width: '95%'}">
        <el-option v-for="(item, index) in field101Options" :key="index" :label="item.label"
          :value="item.value" :disabled="item.disabled"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item size="large">
        <el-button type="primary" @click="submitForm" style="width: 8%;">交卷</el-button>
    </el-form-item>
  </el-form>
  </div>
</template>

<style>
.readme {
  margin-top:2%;
  text-align: center;
  line-height:8px;
  font-size:22px;
}
.djs {
  margin-top:2%;
  text-align: center;
  line-height:8px;
  font-size:22px;
  color:red;
  margin-bottom: 3%;
}
</style>

<script>
import { examStudentAnswering,examStudentSubmit } from "@/api/sim/exam";
export default {
  name: "exam2",
  data() {
    return {
      duration: 0, // 假设倒计时1800秒
      examId:'',
      tableData: [{
        name: '1111',
        number: '',
        reason: ''
      }, {
        name: '2222',
        number: '',
        reason: ''
      }],

      tableData1: [{
        name: '',
        number: '',
        reason: '',
        reason: ''
      }, {
        name: '',
        number: '',
        reason: '',
        reason: ''
      }],
      formData: {
        field101: undefined,
      },
      rules: {
        field101: [{
          required: true,
          message: '请选择下拉选择',
          trigger: 'change'
        }],
      },
      field101Options: [{
        "label": "选项一",
        "value": 1
      }, {
        "label": "选项二",
        "value": 2
      }, {
        "label": "选项三",
        "value": 3
      }],
       // 遮罩层
      loading: true,
      // 分页信息
      total: 0,
      pageNum: 1,
      pageSize: 10,
      // 选中角色编号
      roleIds:[],
      // 角色信息
      roles: [],
      // 用户信息
      form: {},
      // 列信息
      columns: [
        { key: 0, label: `更换件类型`, visible: true },
        { key: 1, label: `状态`, visible: true },
        { key: 2, label: `申请时间`, visible: true },
      ],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      const examId = this.$route.params.examId;
      examStudentAnswering(examId).then(response => {
          console.log(response);          
          this.duration = 3000000/1000;
      });
    },
    deleteRow(index, rows) {
      console.log(index+"@@@@")
      console.log(rows+"####")
      rows.splice(index, 1);
    },
    AddRow(index, rows) {
      const newRow = {
        name: '',
        number: '',
        reason: '',
      };
      this.tableData.push(newRow); // 追加新行
    },
    deleteRow1(index, rows) {
      console.log(index+"@@@@")
      console.log(rows+"####")
      rows.splice(index, 1);
    },
    AddRow1(index, rows) {
      const newRow = {
        name: '',
        number: '',
        reason: '',
      };
      this.tableData1.push(newRow); // 追加新行
    },
    /** 单击选中行数据 */
    clickRow(row) {
      this.$refs.table.toggleRowSelection(row);
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.roleIds = selection.map((item) => item.roleId);
    },
    // 保存选中的数据编号
    getRowKey(row) {
      return row.roleId;
    },
    /** 提交按钮 */
    submitForm() {
      const examId = this.$route.params.examId;
      examStudentSubmit(examId).then(response => {
        if(response.code='200'){
          this.$router.push("/people/exam-exam3/examid/" + examId);
        }
      });
      // this.$router.push("/people/exam-exam3/examid/1");
      // this.$router.push("/exam/exam");
    },
    /** 关闭按钮 */
    close() {
      const obj = { path: "/system/user" };
      this.$tab.closeOpenPage(obj);
    },
  },
  computed: {
    time() {
      let minutes = Math.floor((this.duration % 3600) / 60);
      let seconds = this.duration % 60;
      return `${minutes}分${seconds}秒`;
    },
  },
  mounted() {
    let timer = setInterval(() => {
      this.duration--;
      if (this.duration <= 0) {
        clearInterval(timer);
      }
    }, 1000);
  },

};
</script>