<template>
  <div class="companyAddress-wrap common-set-wrap">
    <nav-crumb :navpath="navpath"></nav-crumb>
    <div class="right-content">
      <div class="right-box">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
          <el-form-item label="管理员角色" prop="name" class="">
            <el-input v-model="ruleForm.name" disabled placeholder="" class="w-380"></el-input>
          </el-form-item>
          <el-form-item label="选择人员" prop="name" class="">
            <div class="flex w-380 flex-wrap">
              <template v-for="(item,index) in ruleForm.peopleList">
                <div class="people-cell">
                  <img :src="item.img"/>
                  <p>{{item.name}}</p>
                  <i class="el-icon-circle-close" @click.stop="delField(index,item,ruleForm.peopleList)"></i>
                </div>
              </template>
              <div class="people-cell">
                <span class="add-icon" @click.stop="showDialogLayer('people')"><i class="el-icon-plus"></i></span>
              </div>
            </div>
          </el-form-item>
          <el-form-item label="选择管理范围" prop="name" class="m-b-0">
            <div class="flex w-380 flex-wrap">
              <template v-for="(item,index) in ruleForm.departList">
                <el-tag class="depart-cell">{{item.name}} <i class="el-icon-circle-close" @click.stop="delField(index,item,ruleForm.departList)"></i></el-tag>
              </template>
              <el-button class="el-tag m-l-8 depart-cell" @click.stop="showDialogLayer('depart')"><i class="el-icon-plus"></i>添加字段</el-button>
            </div>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <vue-gic-footer></vue-gic-footer>
  </div>
</template>
<script>
import navCrumb from '@/components/nav/nav.vue';

import strLength from '@/common/js/strlen';
import showMsg from '@/common/js/showmsg';
import errMsg  from '@/common/js/error';
import { _debounce } from "@/common/js/public";
import { getRequest, postRequest, postJson, postForm } from '@/api/api';
export default {
  name: "addAdminRole",
  data() {

    return {
      // 面包屑参数
      navpath: [
        {
          name: '首页',
          path: '/index',
          relocation: true
        },
        {
          name: '设置',
          path: '/companyAddress'
        },
        {
          name: '设置子管理员',
          path: '/setChildAdmin'
        },
        {
          name: '添加成员',
          path: ''
        }
      ],

      ruleForm: {
        name: '企业管理员',
        peopleList: [
          {
            id: '1',
            name: '张三',
            img: 'http://thirdwx.qlogo.cn/mmopen/j7nX4OeBsXRNyvh6micCywssVEYCaWiaicUZq5Vn2zWktWLAyRvEAH7icQmUhLze8rrQYpM5ptwZ2RL7cX0icyBbiavhYFNTIZhibKu/0'
          }
        ],
        departList: [
          {
            id: '1',
            name: '张三',
          }
        ]
      },
      rules: {

      }

    }
  },
  computed: {

  },
  methods: {
    /**
     * 保存
     */
    submitForm: _debounce(function(formName) {
      const that = this;
      that.$refs[formName].validate((valid) => {
        console.log(valid)
        if (valid) {

        } else {
          return false;
        }
      });
    },500),

    /**
     * 保存---api
     */
    postSave() {
      const that = this;

    },

    /**
     * 删除字段
     */
    delField(index,item,list) {
      const that = this
      that.$alert('确定要删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
      }).then(({ value }) => {
        list.splice(index,1)
      }).catch(() => {

      });
    },

    /**
     * 弹窗显示事件
     */
    showDialogLayer() {
      const that = this

      console.log(1)
    },

  },
  mounted() {

  },
  components: {
    navCrumb
  }
}

</script>
<style lang="less" scoped>
.border-box {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

/* display */
.inline-block {
  display: inline-block;
}

.block {
  display: block;
}

.top {
  vertical-align: top;
}

.middle {
  vertical-align: middle;
}

/* flex */
.flex {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
}

.flex-1 {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  -ms-flex: 1;
  flex: 1;
}

.flex-column {
  -webkit-flex-direction: column;
  -moz-flex-direction: column;
  -ms-flex-direction: column;
  -o-flex-direction: column;
  flex-direction: column;
}

.flex-row {
  -webkit-flex-direction: row;
  -moz-flex-direction: row;
  -ms-flex-direction: row;
  -o-flex-direction: row;
  flex-direction: row;
}

.flex-align-center {
  -webkit-box-align: center;
  -webkit-align-items: center;
  -ms-flex-align: center;
  align-items: center;
}

.flex-pack-center {
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  -ms-flex-pack: center;
  justify-content: center;
}

.flex-between {
  -webkit-justify-content: space-between;
  justify-content: space-between;
}

.flex-wrap {
  -webkit-flex-wrap: wrap;
  -moz-flex-wrap: wrap;
  -ms-flex-wrap: wrap;
  -o-flex-wrap: wrap;
  flex-wrap: wrap;
}

.right-content {
  /*width: 100%;*/
  padding: 24px;
  min-height: calc(100% - 240px);

  .right-box {
    background: #fff;
    padding: 24px;
    min-height: 500px;

    h2 {
      font-size: 16px;
      color: #303133;
    }

    p {
      font-size: 14px;
      color: #909399;
    }

    .m-t-24 {
      margin-top: 24px;
    }

    .m-b-0 {
      margin-bottom: 0;
    }

    .w-380 {
      width: 380px;
    }

    .people-cell {
      position: relative;
      margin-right: 24px;
      img {
        width: 40px;
        height: 40px;
        border-radius: 4px;
      }

      .el-icon-circle-close {
        position: absolute;
        top: -10px;
        right: -10px;
        font-size: 16px;
        color: #808995;
        cursor: pointer;
      }
    }

    .depart-cell {
      position: relative;
      margin: 0 24px 24px 0;

      .el-icon-circle-close {
        position: absolute;
        top: -10px;
        right: -10px;
        font-size: 16px;
        color: #808995;
        cursor: pointer;
      }
    }

    .add-icon {
      display: block;
      width: 40px;
      height: 40px;
      line-height: 40px;
      text-align: center;
      border-radius: 50%;
      border: 1px dashed #C0CCDA;
      cursor: pointer;
      i {
        font-size: 16px;
        color: #8C939D;
      }
    }
  }
}
</style>
