<template>
  <div class="page_newGrouping">
    <div class="newGroupingTitle">
      <i class="iconfont icon-zuojiantou jiantou" @click="$router.go(-1)"></i>
      <span class="titleName">新增分组</span>
    </div>
    <div class="infoBox">
      <van-field v-model="name" required label="分组名称" placeholder="请输入" />
    </div>
    <div class="save" @click="saveGroup">保存</div>
  </div>
</template>

<script>
import { saveGroup } from "@/api/patient/patient";
export default {
  data() {
    return {
      show: false,
      name: "",
      active: 0
    };
  },
  methods: {
    saveGroup() {
      if (this.name === "") {
        this.$toast("请输入分组名");
        return false;
      }
      const params = {
        name: this.name
      };
      saveGroup(params).then(response => {
        if (response.data.state === 1) {
          var group = response.data.data.group;
          this.$toast("保存成功");
          this.$router.push("/configurecenter?active=" + this.active);
        } else {
          this.$toast("分组名称已存在!");
        }
      });
    },
    toReturn() {
      this.$router.push("/configurecenter?active=" + this.active);
    }
  },
  created() {
    this.active = parseInt(this.$route.query.active);
    localStorage.setItem("test", this.active);
  }
};
</script>

<style lang="scss" scoped>
.page_newGrouping {
  height: 100%;
  overflow: hidden;
  overflow-y: auto;
  background: #fafafa;
  .newGroupingTitle {
    background: #fff;
    padding: 0 1.125rem;
    height: 3.125rem;
    display: flex;
    align-items: center;
  }
  .jiantou {
    font-size: 1.5rem;
    font-weight: 600;
    margin-right: 7rem;
  }
  .titleName {
    font-size: 1.125rem;
    font-weight: 600;
  }
  .infoBox {
    margin-top: 1rem;

    .van-cell__value {
      display: flex;
      align-items: center;
    }
  }
  .save {
    width: 19.25rem;
    height: 2.875rem;
    margin: 0 auto;
    background: rgba(51, 138, 251, 1);
    box-shadow: 0px 1px 12px 0px rgba(51, 138, 251, 1);
    border-radius: 1.4375rem;
    text-align: center;
    line-height: 2.875rem;
    color: #fff;
    margin-top: 2.875rem;
  }
}
</style>
<style lang="scss">
.infoBox {
  .van-cell__value {
    display: flex;
    align-items: center;
  }
}
</style>
