<template>
  <Base-dialog
    title="操作提示："
    :disabledBtn="disabledBtn"
    :isShow.sync="isShow"
    @submit="submitForm"
    @close="close"
  >
    <el-form
      :model="formData"
      ref="formData"
      label-width="80px"
      label-position="right"
    >
      <el-form-item
        label="作弊原因"
        prop="cheating_reason"
        :rules="[
          {
            required: true,
            message: '请填写作弊原因',
            trigger: ['blur', 'change'],
          },
        ]"
      >
        <el-input
          v-model="formData.cheating_reason"
          type="textarea"
          :rows="4"
          placeholder="请输入作弊原因"
        ></el-input>
      </el-form-item>
      <ul style="padding-left: 80px">
        <li
          class="li_sty"
          @click="uploadText(item.label)"
          v-for="(item, index) in msgTitle"
          :key="index"
        >
          {{ item.label }}
        </li>
      </ul>
    </el-form>
  </Base-dialog>
</template>

<script>
export default {
  props: {
    vidBoxHours: {
      type: Boolean,
      default: false,
    },
    disabledBtn: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      msgTitle: [
        { label: "学习拍照异常", value: 1 },
        {
          label: "学习拍照太黑无法识别人像，请确保拍照光线充足并拍到全脸",
          value: 2,
        },
        {
          label: "学习拍照太模糊无法识别人像，请确保拍照光线充足并拍到全脸",
          value: 3,
        },
        {
          label: "学习拍照人像不全无法识别，请确保拍照光线充足并拍到全脸",
          value: 4,
        },
      ],
      formData: {
        cheating_reason: "",
      },
    };
  },
  methods: {
    submitForm() {
      this.$refs.formData.validate((valid) => {
        if (valid) {
          this.$emit("submit", this.formData.cheating_reason);
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    uploadText(msg) {
      this.formData.cheating_reason = msg;
    },
    close() {
      this.$emit("close");
    },
  },
  computed: {
    isShow: {
      get() {
        return this.vidBoxHours;
      },
      set(val) {
        this.$emit("update:vidBoxHours", false);
      },
    },
  },
  watch: {
    vidBoxHours(val) {
      if (val === false) {
        this.uploadText("");
      } else {
        this.$nextTick(() => {
          this.$refs.formData.clearValidate();
        });
      }
    },
  },
};
</script>

<style  lang="less" scoped>
.li_sty {
  cursor: pointer;
  transition: all 0.3s;
  background-color: #eee;
  padding: 0px 10px;
  margin-bottom: 6px;
  font-size: 12px;
  line-height: 26px;
  display: table;
  &:hover {
    box-shadow: 0px 0px 4px 2px rgba(0, 0, 0, 0.2);
  }
}
</style>