<template>
  <transition name="dialog-fade">
    <el-dialog
      v-if="showDialog"
      :title="dialogTitle"
      class="add-group-com"
      :visible.sync="showDialog"
      width="400px"
      @close="closeDialog(0)"
    >
      <el-form
        ref="formInfo"
        :model="formInfo"
        class="demo-form-inline"
        label-width="100px"
        :rules="rules"
      >
        <el-form-item label="站点名称：" prop="watchName">
          <el-input v-model="formInfo.watchName"></el-input>
        </el-form-item>
         <el-form-item label="站点编号：" prop="watchName">
          <el-input v-model="formInfo.watchName"></el-input>
        </el-form-item>
         <el-form-item label="选择模板：" prop="region">
            <el-select v-model="formInfo.region" placeholder="请选择">
              <el-option label="选择模板1" value="1"></el-option>
              <el-option label="选择模板2" value="2"></el-option>
            </el-select>
          </el-form-item>
      
        <div style="text-align: right">
          <el-button type="primary" @click="submitForm('formInfo')"
            >保存</el-button
          >
        </div>
      </el-form>
    </el-dialog>
  </transition>
</template>
<script>

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

</style>