<template>
  <transition name="dialog-fade">
    <el-dialog
      v-if="showDialog"
      :title="dialogTitle"
      class="dialog-component"
      v-model="showDialog"
      width="640px"
      @close="closeDialog(0)"
    >
      <el-form
        ref="formInfo"
        :model="formInfo"
        class="demo-form-inline"
        label-width="100px"
        :rules="rules"
      >
        <el-form-item label="账号：" prop="accountNumber">
          <el-input v-model="formInfo.accountNumber"></el-input>
        </el-form-item>
        <el-form-item label="用户名：" prop="userName">
          <el-input v-model="formInfo.userName"></el-input>
        </el-form-item>
        <el-form-item label="手机号码：" prop="phone">
          <el-input v-model="formInfo.phone"></el-input>
        </el-form-item>
         <el-form-item label="告警短信" prop="phone">
          <el-checkbox v-model="checked1" label="接收"></el-checkbox>
        </el-form-item>
       

       
        <br />
        <br />
        <br />
        <div style="text-align: right">
          <el-button @click="closeDialog(0)">取消</el-button>
          <el-button type="primary" @click="submitForm('formInfo')"
            >确定</el-button
          >
        </div>
      </el-form>
    </el-dialog>
  </transition>
</template>

<script>




export default {
  name: "DialogComponent",
  props: {
    dialogTitle: {
      type: String,
      default: "新增",
    },
    itemInfo: {
      type: Object,
      default: function () {
        return {};
      },
    },
  },
  data() {
    return {
      showDialog: false,
      formInfo: JSON.parse(JSON.stringify(this.itemInfo)),
      options: [
        {
          value: "选项1",
          label: "站点一",
        },
        {
          value: "选项2",
          label: "站点二",
        },
        {
          value: "选项3",
          label: "站点三",
        },
        {
          value: "选项4",
          label: "站点四",
        },
        {
          value: "选项5",
          label: "站点五",
        },
      ],

      rules: {
        accountNumber: [
          // required  是否为必填项， trigger:表单验证的触发时机，失去焦点进行验证
          { required: true, message: "请输入账号", trigger: "blur" },
          {
            min: 3,
            max: 6,
            message: "用户名长度在 3 到 6 个字符",
            trigger: "blur",
          },
        ],
        userName: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          {
            min: 3,
            max: 6,
            message: "用户名长度在 3 到 6 个字符",
            trigger: "blur",
          },
        ],
        phone: [
          { required: false, 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) {
      alert(1)
      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">
.el-input,
.el-select {
  width: 240px;
}
</style>