<template>
    <el-dialog
      :title="dialogTitle"
      v-model="dialogVisible"
      width="400px"
      @close="closeDialog(0)"
       @open="open"
    >
      <el-form
        ref="formInfo"
        :model="form"
        class="demo-form-inline"
        label-width="100px"
        :rules="rules"
      >
        <el-form-item label="分组名称：" prop="watchName">
          <el-input v-model="form.watchName"  ></el-input>
        </el-form-item>
      
        <div style="text-align: right">
          <el-button type="primary" @click="submitForm('formInfo')"
            >保存</el-button
          >
        </div>
      </el-form>
    </el-dialog>
</template>
<script>

export default {
  name: "AddGroupCom",
  props: {
    dialogTitle: {
      type: String,
      default: "新建分组",
    },
    itemInfo: {
      type: Object,
      default: function () {
        return {};
      },
    },
  },
  data() {
    return {
       checked: true,
      showDialog: false,
      formInfo: JSON.parse(JSON.stringify(this.itemInfo)),
      rules: {
        watchName: [
          // required  是否为必填项， trigger:表单验证的触发时机，失去焦点进行验证
          { required: true, message: "请输入分组名称", trigger: "blur" },
          {
            min: 3,
            max: 6,
            message: "用户名长度在 3 到 6 个字符",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    roleValid(rule, value, callback) {
      if (value.length === 0) {
        callback(new Error("不能为空"));
      } else {
        callback();
      }
    },

    // 保存操作
    submitForm(formName) {
      const params = Object.assign(this.formInfo, {});
      params
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // 走保存请求
          this.$message({
            message: "操作成功！",
            type: "success",
          });
          this.closeDialog(1);
        } else {
          return false;
        }
      });
    },
    // 关闭弹框
    closeDialog(flag) {
      this.$refs["formInfo"].resetFields();
      this.showDialog = false;
      this.$emit("closeDialog", flag);
    },
  },
};
</script>
 
<style scoped lang="scss">


</style>