<template>
  <el-dialog title="反馈建议" :visible.sync="showSuggest" width="45%" @close="onClose">
    <el-form size="mini" ref="form" :model="form" label-width="80px" :rules="rules">
      <el-form-item label="姓名" prop="sugName">
        <el-input v-model="form.sugName" placeholder="请输入姓名"></el-input>
      </el-form-item>
      <el-form-item label="手机号" prop="sugMobile">
        <el-input v-model="form.sugMobile" placeholder="输入手机号，以便于接收建议的反馈"></el-input>
      </el-form-item>
      <el-form-item label="建议内容" prop="sugContent">
        <el-input type="textarea" v-model="form.sugContent" placeholder="请输入您的建议" :rows="5"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="closeDialog()">取 消</el-button>
      <el-button size="mini" type="primary" @click="submitSuggest()">提 交</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  name: "demo",
  props: {
    // 是否显示
    showSuggest: {
      type: Boolean,
      require: true,
      default: false
    }
  },
  components: {},
  data() {
    return {
      form: { sugName: "", sugMobile: "", sugContent: "" },
      rules: {
        sugName: [{ required: true, message: "请输入姓名", trigger: "blur" }],
        sugContent: [
          { required: true, message: "请输入建议内容", trigger: "blur" }
        ]
      }
    };
  },
  computed: {},
  methods: {
    closeDialog() {
      this.$emit("closeSuggest");
    },
    submitSuggest() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.$axios
            .post("/api/excel/suggest", this.form)
            .then(res => {
              const { data } = res;
              if (data.success) {
                this.$message.success("意见反馈成功，我会尽快处理");

                this.closeDialog();
              } else {
                this.$message.error("出现了一些错误，十分抱歉");
              }
            })
            .catch(err => {
              console.log(err);
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    onClose() {
      this.$refs.form.clearValidate();
      this.$refs.form.resetFields();
    }
  },
  created() {},
  mounted() {}
};
</script> 

<style scoped>
</style>
