<style lang="scss">
.addclass {
  .el-input,
  button {
    width: 500px;
  }
}
</style>
<template>
  <section class="addclass">
    <p>内容管理 > 栏目管理 > 新增栏目</p>
    <div class="content">
      <el-form label-width="80px">
        <el-form-item label="栏目名称">
          <el-input placeholder="栏目名称" v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="排序字段">
          <el-input placeholder="排序字段" v-model="form.order"></el-input>
        </el-form-item>
        <el-form-item label=" ">
          <el-button @click="save" type="primary">保存</el-button>
        </el-form-item>
      </el-form>
    </div>
  </section>
</template>
<script>
export default {
  components: {},
  data() {
    return {
      form: { name: "" }
    };
  },
  methods: {
    getData() {
      this.$api.getContentById({ id: this.form.id }).then(res => {
        this.form = res.data.data;
      });
    },
    save() {
      var parm = this.form;
      if (parm.id) {
        this.$api.editContent(parm).then(res => {
          if (res.data.code == 0) {
            this.$message({ message: "修改成功！", type: "success" });
            this.$router.push({ path: "/content" });
          } else {
            this.$message.error(res.data.message);
          }
        });
      } else {
        this.$api.addContent(parm).then(res => {
          if (res.data.code == 0) {
            this.$message({ message: "添加成功！", type: "success" });
            this.$router.push({ path: "/content" });
          } else {
            this.$message.error(res.data.message);
          }
        });
      }
    }
  },
  created() {
    if (this.$route.query.id) {
      this.form.id = this.$route.query.id;
      this.id = this.$route.query.id;
      this.getData();
    }
  }
};
</script>





