<template>
  <div class="exam-wrapper">
    <el-tabs v-model="activeName">
      <el-tab-pane label="题库管理" name="题库管理">
        <div class="add-question-bank-wrapper">
          <el-button type="primary" @click="addQuestionBank">添加题库</el-button>
        </div>
        <div class="tools-search-question-bank-wrapper">
          <el-select
            v-model="searchType"
            placeholder="所属分类"
          >
            <el-option
              v-for="item in questionTypeOption"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
          <el-input v-model="inputSearchName" style="width: 480px;margin-left: 20px;" placeholder="请输入名称" />
          <el-button style="margin-left: 20px;">搜索</el-button>
        </div>
        <div class="table-wrapper">
          <el-table
            :data="tableData"
          >
            <el-table-column
              prop="title"
              label="名称"
            />
            <el-table-column
              label="包含内容"
            >
              <template
                slot-scope="scope"
              >
                <div>试卷:&nbsp;{{ scope.row.testerSum }}&nbsp;&nbsp;题目: {{ scope.row.subjectSum }}</div>
              </template>
            </el-table-column>
            <el-table-column
              label="分类"
              prop="type"
            />
            <el-table-column
              label="操作"
            >
              <template slot-scope="scope">
                <el-button @click="jumpToManage(scope.row)">管理</el-button>
                <el-button @click="showEditDialog(scope.row)">编辑</el-button>
                <el-button @click="deleteEditDialog">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-tab-pane>
      <el-tab-pane label="题库分类管理" name="题库分类管理">
        <div class="edit-question-bank-wrapper">
          <el-button type="primary" @click="addTypeDialog">添加分类</el-button>
        </div>
        <div class="edit-type-table-wrapper">
          <el-table
            :data="tableTypeData"
          >
            <el-table-column
              prop="title"
              label="名称"
            />
            <el-table-column
              label="包含内容"
            >
              <template slot-scope="scope">
                <div>题库:&nbsp;{{ scope.row.questionSum }}</div>
              </template>
            </el-table-column>
            <el-table-column
              label="操作"
            >
              <template slot-scope="scope">
                <el-button @click="showEditTypeDialog">编辑</el-button>
                <el-button @click="deleteType(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-tab-pane>
    </el-tabs>
    <el-dialog
      title="创建题库"
      :visible.sync="addFormDialogShow"
    >
      <el-form
        ref="addform"
        :model="formInfo"
        label-width="120px"
        :rules="rules"
      >
        <el-form-item label="名称" prop="title">
          <el-input v-model="formInfo.title" />
        </el-form-item>
        <el-form-item label="分类" prop="type">
          <el-select
            v-model="formInfo.type"
            placeholder="所属分类"
          >
            <el-option
              v-for="item in questionTypeOption"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button type="info" @click="cancelAddForm">取消</el-button>
        <el-button type="success" @click="submitAddForm">提交</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="编辑题库"
      :visible.sync="editFormDialogShow"
    >
      <el-form
        ref="editform"
        :model="editFormInfo"
        label-width="120px"
        :rules="rules"
      >
        <el-form-item label="名称" prop="title">
          <el-input v-model="editFormInfo.title" />
        </el-form-item>
        <el-form-item label="分类" prop="type">
          <el-select
            v-model="editFormInfo.type"
            placeholder="所属分类"
          >
            <el-option
              v-for="item in questionTypeOption"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button type="info" @click="cancelEditForm">取消</el-button>
        <el-button type="success" @click="submitEditForm">提交</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="添加分类"
      :visible.sync="addTypeFormDialog"
    >
      <el-form
        ref="addTypeform"
        :model="typeFormInfo"
        label-width="120px"
        :rules="rules"
      >
        <el-form-item label="名称" prop="title">
          <el-input v-model="typeFormInfo.title" />
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button>取消</el-button>
        <el-button>提交</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="编辑分类"
      :visible.sync="editTypeFormDialog"
    >
      <el-form
        ref="editTypeform"
        :model="editTypeFormInfo"
        label-width="120px"
        :rules="typeRules"
      >
        <el-form-item label="名称" prop="title">
          <el-input v-model="editTypeFormInfo.title" />
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="cancelEditType">取消</el-button>
        <el-button @click="submitEditType">提交</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// import axiosFile from '@/utils/requestfile.js'
export default {
  data() {
    return {
      activeName: '题库管理',
      questionTypeOption: [
        {
          label: '视频问题回答',
          value: '视频问题回答'
        },
        {
          label: '安全生产培训',
          value: '安全生产培训'
        },
        {
          label: '职业卫生培训',
          value: '职业卫生培训'
        }
      ],
      searchType: '',
      inputSearchName: '',
      tableData: [
        {
          title: '大学习、大培训、大考试',
          type: '大学习、大培训、大考试',
          testerSum: 10,
          subjectSum: 10
        },
        {
          title: '放射诊疗防护',
          type: '放射诊疗防护',
          testerSum: 8,
          subjectSum: 8
        },
        {
          title: '职业卫生视频验证',
          type: '职业卫生视频验证',
          testerSum: 2,
          subjectSum: 4
        }
      ],
      addFormDialogShow: false,
      formInfo: {
        title: '',
        type: ''
      },
      rules: {
        title: [
          {
            required: true,
            message: '请输入名称',
            trigger: 'blur'
          }
        ],
        type: [
          {
            required: true,
            message: '请输入课程类型',
            trigger: 'change'
          }
        ]
      },
      editFormDialogShow: false,
      editFormInfo: {
        title: '',
        type: ''
      },
      tableTypeData: [
        {
          title: '视频问题回答',
          questionSum: 1
        },
        {
          title: '放射诊疗防护',
          questionSum: 1
        },
        {
          title: '职业卫生培训',
          questionSum: 3
        }
      ],
      addTypeFormDialog: false,
      typeFormInfo: {
        title: ''
      },
      typeRules: {
        title: [
          {
            required: true,
            message: '请输入名称',
            trigger: 'blur'
          }
        ]
      },
      editTypeFormDialog: false,
      editTypeFormInfo: {
        title: ''
      }
    }
  },
  methods: {
    addQuestionBank() {
      this.addFormDialogShow = true
    },
    cancelAddForm() {
      this.addFormDialogShow = false
      this.formInfo.title = ''
      this.formInfo.type = ''
    },
    submitAddForm() {
      // 提交 axios
    },
    cancelEditForm() {
      this.editFormDialogShow = false
    },
    submitEditForm() {
      // axios
    },
    showEditDialog(row) {
      this.editFormDialogShow = true
    },
    deleteEditDialog() {
      this.$confirm('此操作将永久删除题库, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '删除成功'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    deleteType(row) {
      // row
      // 删除类型
      this.$confirm('此操作将永久删除类型，是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'message',
          message: '删除成功'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    cancelEditType() {
      this.editTypeFormDialog = false
    },
    submitEditType() {
      // 提交编辑类型
      //
    },
    showEditTypeDialog() {
      //
      this.editTypeFormDialog = true
    },
    addTypeDialog() {
      // 添加分类对话框
      this.addTypeFormDialog = true
    },
    jumpToManage(row) {
      // console.log(row)
      this.$router.push({
        path: '/train/exam/manage/44444'
      })
    }
  }
}
</script>

<style lang="scss">
  .add-question-bank-wrapper {
    position: absolute;
    right: 20px;
    top: 0;
  }
  .tools-search-question-bank-wrapper {
    display: flex;
    margin-bottom: 20px;
    margin-top: 40px;
  }
  .edit-question-bank-wrapper {
    display: flex;
    justify-content: flex-end;
    padding-right: 20px;
  }
</style>
