/* 
  添加等级
  author:zsy
  date:2023-7-30
 */
<template>
  <div class="add-level">
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="地址名称" prop="levelname">
        <el-input v-model="ruleForm.levelname"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')"
          >提交</el-button
        >
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {addLevel} from '@/api/level'
export default {
  
  data() {
    return {
      ruleForm: {
        levelname: "",
      },
      rules: {
        levelname: [
          { required: true, message: "请输入地址名称", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    /* 提交功能 */
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          addLevel({
            levelname: this.ruleForm.levelname
          })
            .then((res) => {
              this.$message({
                message: "提交成功",
                type: "success",
              });
              this.$refs[formName].resetFields();
              this.$router.push("/level/levelList");
            })
            .catch((err) => {
              console.log(err);
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    /* 重置 */
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style scoped>
.add-level {
  width: 70%;
  margin: 100px auto 0;
}
</style>