<template>
  <div class="app-container">
    <div style="margin-top:3%">  
    <div class="readme">正在练习中，考试时间 30 分钟</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 { listUser } from "@/api/system/user";

export default {
  name: "AuthRole",
  data() {
    return {
      duration: 1800, // 假设倒计时1800秒
      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() {
    const userId = this.$route.params && this.$route.params.userId;
    if (userId) {
      this.loading = true;
      getAuthRole(userId).then((response) => {
        this.form = response.user;
        this.roles = response.roles;
        this.total = this.roles.length;
        this.$nextTick(() => {
          this.roles.forEach((row) => {
            if (row.flag) {
              // this.$refs.table.toggleRowSelection(row);
            }
          });
        });
        this.loading = false;
      });
    }
  },
  methods: {
    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); // 追加新行
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.roleIds = selection.map((item) => item.roleId);
    },
    // 保存选中的数据编号
    getRowKey(row) {
      return row.roleId;
    },
    /** 提交按钮 */
    submitForm() {
      const userId = this.form.userId;
      // const roleIds = this.roleIds.join(",");
    //   updateAuthRole({ userId: userId, roleIds: roleIds }).then((response) => {
    //     this.$modal.msgSuccess("授权成功");
    //     this.close();
    //   });
       this.$router.push("/people/train-train3/trainid/5");
    },
    /** 关闭按钮 */
    close() {
      const obj = { path: "/system/user" };
      this.$tab.closeOpenPage(obj);
    },
  },
  computed: {
      time() {
        //let hours = Math.floor(this.duration / 3600);
        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>