<template>
  <div class="detail_contain">
    <p class="now_page_title">
      权限管理 / 角色管理 /
      <span>{{
        $route.path.indexOf("edit") !== -1
          ? "角色类型"
          : $route.path.indexOf("add") !== -1
          ? "新增角色"
          : "分配权限"
      }}</span>
    </p>
    <div class="info_contain">
      <p v-if="$route.path.indexOf('allot') !== -1" class="borerd">
        <span></span>基本信息
      </p>
      <el-form ref="form" :rules="rules" :model="form" label-width="0px">
        <el-form-item prop="name">
          <p class="formname">角色名称：</p>
          <el-input v-model="form.name"></el-input>
        </el-form-item>

        <el-form-item prop="desc">
          <p class="formname">角色描述：</p>
          <el-input type="textarea" v-model="form.desc"></el-input>
        </el-form-item>

        <el-form-item prop="person">
          <p class="formname">登记人：</p>
          <el-input v-model="form.person" disabled></el-input>
        </el-form-item>

        <el-form-item prop="date">
          <p class="formname">登记日期：</p>
          <el-input v-model="form.date" disabled></el-input>
        </el-form-item>

        <el-form-item class="bottom-btn">
          <el-button type="primary" @click="onSubmit('form')" class="right"
            >保存</el-button
          >
          <el-button class="right">取消</el-button>
        </el-form-item>
      </el-form>

      <p v-if="$route.path.indexOf('allot') !== -1" class="borerd">
        <span></span>菜单权限
      </p>
      <div
        v-if="$route.path.indexOf('allot') !== -1"
        style="margin-bottom:100px;margin-top:20px;"
      >
        <menu-permission
          :data="permissionData"
          @change="changePermissions"
        ></menu-permission>
      </div>
    </div>
  </div>
</template>

<script>
import { getRole } from "@/utils/common";
import menuPermission from "@/components/menu-permission";
export default {
  props: {},
  components: {
    menuPermission,
  },
  data() {
    return {
      form: {
        name: "",
        desc: "",
        person: "",
        date: "",
      },
      now_user: 2, //0：普通用户，1：组织管理员，2：超级管理员
      permissionData: [
        {
          name: "权限管理1",
          selected: false,
          value: 1,
          children: [
            {
              name: "权限管理1-1",
              selected: false,
              value: 11,
              children: [
                {
                  name: "权限管理1-1-1",
                  selected: false,
                  value: 111,
                  children: [
                    {
                      name: "权限管理1-1-1-1",
                      selected: false,
                      value: 1111,
                    },
                    {
                      name: "权限管理1-1-1-2",
                      selected: false,
                      value: 1112,
                    },
                    {
                      name: "权限管理1-1-1-3",
                      selected: false,
                      value: 1113,
                    },
                  ],
                },
              ],
            },
            {
              name: "权限管理1-2",
              selected: false,
              value: 12,
              children: [
                {
                  name: "权限管理1-2-1",
                  selected: false,
                  value: 121,
                  children: [
                    {
                      name: "权限管理1-2-1-1",
                      selected: false,
                      value: 1211,
                    },
                    {
                      name: "权限管理1-2-1-2",
                      selected: false,
                      value: 1212,
                    },
                    {
                      name: "权限管理1-2-1-3",
                      selected: false,
                      value: 1213,
                    },
                  ],
                },
              ],
            },
          ],
        },
        {
          name: "权限管理2",
          selected: false,
          value: 2,
          children: [
            {
              name: "权限管理2-1",
              selected: false,
              value: 21,
              children: [
                {
                  name: "权限管理2-1-1",
                  selected: false,
                  value: 211,
                  children: [
                    {
                      name: "权限管理2-1-1-1",
                      selected: false,
                      value: 2111,
                    },
                    {
                      name: "权限管理2-1-1-2",
                      selected: false,
                      value: 2112,
                    },
                    {
                      name: "权限管理2-1-1-3",
                      selected: false,
                      value: 2113,
                    },
                  ],
                },
              ],
            },
            {
              name: "权限管理2-2",
              selected: false,
              value: 22,
              children: [
                {
                  name: "权限管理2-2-1",
                  selected: false,
                  value: 221,
                  children: [
                    {
                      name: "权限管理2-2-1-1",
                      selected: false,
                      value: 2211,
                    },
                    {
                      name: "权限管理2-2-1-2",
                      selected: false,
                      value: 2212,
                    },
                    {
                      name: "权限管理2-2-1-3",
                      selected: false,
                      value: 2213,
                    },
                  ],
                },
              ],
            },
          ],
        },
        {
          name: "权限管理3",
          selected: false,
          value: 3,
          children: [
            {
              name: "权限管理3-1",
              selected: false,
              value: 31,
              children: [
                {
                  name: "权限管理3-1-1",
                  selected: false,
                  value: 311,
                  children: [
                    {
                      name: "权限管理3-1-1-1",
                      selected: false,
                      value: 3111,
                    },
                    {
                      name: "权限管理3-1-1-2",
                      selected: false,
                      value: 3112,
                    },
                    {
                      name: "权限管理3-1-1-3",
                      selected: false,
                      value: 3113,
                    },
                  ],
                },
              ],
            },
            {
              name: "权限管理3-2",
              selected: false,
              value: 32,
              children: [
                {
                  name: "权限管理3-2-1",
                  selected: false,
                  value: 321,
                },
              ],
            },
          ],
        },
        {
          name: "权限管理4",
          selected: false,
          value: 4,
          children: [
            {
              name: "权限管理4-1",
              selected: false,
              value: 41,
            },
            {
              name: "权限管理4-2",
              selected: false,
              value: 42,
            },
          ],
        },
      ],
      rules: {
        name: [{ required: true, message: "请输入角色名称", trigger: "blur" }],
        desc: [
          { required: true, message: "请输入角色描述", trigger: "blur" },
          { max: 200, message: "长度小于200个字符", trigger: "blur" },
        ],
      },
    };
  },
  watch: {},
  computed: {},
  created() {
    this.now_user = this.$store.state.role;
    getRole().then((data) => {
      this.now_user = data;
      this.$store.commit("rolefun", data);
      this.now_page();
    });
    console.log(this.$route);
  },
  mounted() {},
  methods: {
    onSubmit(formName) {
      console.log("submit!");
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    now_page() {
      if (this.$route.path.indexOf("edit") !== -1) {
        this.getInfo();
      }
      if (this.$route.path.indexOf("allot") !== -1) {
        this.getInfo();
      }
    },
    getInfo() {
      console.log("111");
    },
    changePermissions(values) {
      console.log(values);
    },
  },
};
</script>

<style>
.info_contain .el-input__inner {
  background-color: #f7f8f9;
  width: 1022px;
}
.info_contain .el-textarea__inner {
  background-color: #f7f8f9;
  width: 1022px;
}
.info_contain .el-input.is-disabled .el-input__inner {
  background-color: #e3e4e6;
}
</style>

<style scoped>
.detail_contain {
  width: 100%;
  padding: 0 20px;
  height: calc(100% - 55px);
}
.info_contain {
  padding: 25px 20px;
  background-color: #fff;
  width: 100%;
  box-shadow: 0px 3px 6px 0px #f4f7fc;
  border-radius: 12px;
  min-height: calc(100% - 20px);
  margin-bottom: 20px;
  position: relative;
}
.now_page_title {
  margin: 15px 0;
  color: #898d9e;
}
.now_page_title span {
  color: #242c43;
}
.formname {
  color: #58617a;
}
.right {
  float: right;
  margin-left: 20px;
}
.removepic {
  display: inline-block;
  margin-top: -40px;
  float: left;
  margin-left: 180px;
  width: 76px;
  height: 32px;
  background-color: #495feb;
  border-radius: 8px;
  line-height: 32px;
  text-align: center;
  color: #e6ebfe;
  cursor: pointer;
}
.edit_change {
  width: 100%;
  border-bottom: 2px solid #f4f7fc;
  overflow: hidden;
}
.edit_change_box {
  width: 163px;
  height: 48px;
  line-height: 48px;
  background-color: #e3e5ef;
  border-radius: 8px;
  color: #8890a7;
  text-align: center;
  float: left;
  margin-right: 20px;
  font-weight: 600;
  margin-bottom: 25px;
  font-size: 16px;
  cursor: pointer;
}
.edit_change_box img {
  vertical-align: -3px;
  margin-right: 5px;
}
.safe_title {
  width: 100%;
  height: 65px;
  line-height: 65px;
  border-bottom: 2px solid #f4f7fc;
}
.safe_select {
  float: left;
  width: auto;
  margin-right: 40px;
  height: 65px;
  cursor: pointer;
}
.safe_box_select {
  padding: 30px 10px 10px 10px;
  width: 100%;
  height: 100%;
}
.openbgc {
  width: 56px;
  height: 23px;
  background-image: url("~@/assets/imgs/btn_on_hov.png");
  background-size: contain;
  cursor: pointer;
}
.formtitle {
  color: #58617a;
  margin: 15px 0;
}

.savebtn {
  position: absolute;
  right: 20px;
  bottom: 20px;
  width: 278px;
  overflow: hidden;
}
.btnsty {
  width: 124px;
  height: 44px;
  line-height: 44px;
  background-color: rgba(195, 202, 248, 0.5);
  border-radius: 8px;
  color: rgba(15, 38, 131, 1);
  text-align: center;
  float: left;
  margin-right: 30px;
  cursor: pointer;
}
.savebtn .btnsty:nth-last-of-type(1) {
  margin-right: 0px;
  background-color: rgba(15, 38, 131, 1);
  color: rgba(248, 249, 253, 1);
}

.bottom-btn {
  position: absolute;
  bottom: 20px;
  right: 50px;
}
.borerd {
  color: #58617a;
  font-size: 16px;
}
.borerd span {
  display: inline-block;
  width: 4px;
  height: 16px;
  background-color: #515fe7;
  border-radius: 2px;
  margin-right: 10px;
  vertical-align: -2px;
}
</style>
