<template>
  <el-dialog title="选择题型" :visible="visible" width="380px" top="38vh" :show-close="false" @close="dialogClose">
    <el-cascader
      v-model="type"
      size="medium"
      :options="questionTypeOption"
      :show-all-levels="false"
      :props="{ expandTrigger: 'hover' }"
      popper-class="select-question-type"
    />
    <template slot="footer">
      <el-button size="medium" @click="dialogClose">取消</el-button>
      <el-button type="primary" size="medium" @click="confirm">确定</el-button>
    </template>
  </el-dialog>
</template>

<script>
import { questionTypeOption, questionDataList } from '@/views/exercise_questions/data/questionType';

export default {
  name: 'SelectQuestionType',
  props: {
    visible: {
      type: Boolean,
      required: true,
    },
  },
  data() {
    return {
      questionTypeOption,
      type: ['base', 'select'],
    };
  },
  methods: {
    dialogClose() {
      this.$emit('update:visible', false);
    },
    confirm() {
      this.$emit('update:visible', false);
      let type = this.type[this.type.length - 1];
      this.$emit('addQuestionToExercise', type, type === 'select' ? 'single' : '', questionDataList[type]);
    },
  },
};
</script>

<style lang="scss" scoped>
.el-dialog {
  :deep &__header {
    padding: 40px 40px 0;
  }

  :deep &__body {
    padding: 24px 40px;
  }

  :deep &__footer {
    display: flex;
    padding: 0 40px 40px;

    .el-button {
      flex: 1;
    }
  }

  .el-cascader {
    width: 100%;

    :deep .el-input__inner {
      height: 48px;
      font-size: 16px;
      font-weight: bold;
      line-height: 48px;
      color: #000;
    }
  }
}
</style>

<style lang="scss">
.select-question-type {
  .el-cascader-menu {
    min-width: 150px;
    color: $font-color;
  }

  .el-cascader-node {
    height: 36px;
    line-height: 36px;
  }

  .el-cascader-menu__wrap {
    height: 318px;
  }
}
</style>
