<template>
  <div class="tema">
    <div class="top">
      <p>团队管理</p>
      <el-button type="primary" @click="addUser()" v-if="tool.checkAuth($route.name,'insert')">
        <img src="@/assets/add.png" alt="" style="vertical-align:middle">
        新建账号
        </el-button>
    </div>
    <team-item :teamData="teamData" v-if="tool.checkAuth($route.name,'read') && teamData.length != 0">
      <template v-slot:icon="scope">
        <img src="@/assets/edit.png" alt="" @click.stop="editTargetFun(scope.data)" slot="icon" v-if="tool.checkAuth($route.name,'update')">
      </template>
      <template v-slot:remove="scope">
        <remove-team :teamData="scope.data" v-if="tool.checkAuth($route.name,'delete')"></remove-team>
      </template>
    </team-item>
    <el-empty description="暂无数据" v-else></el-empty>
    <add-user ref="addUser" :editTarget="editTarget"></add-user>
  </div>
</template>

<script>
import AddUser from '@/SManagement/user/team-manage/components/AddUser'
import TeamItem from '@/SManagement/user/team-manage/components/TeamItem'
import RemoveTeam from '@/SManagement/user/team-manage/components/RemoveTeam'
export default {
  name: 'TeamManage',
  data () {
    return {
      param: {
          "classname": "sale.team.team",
          "method": "query_teamList",
          "content": {
              "pageNumber": 1,
              "pageSize": 999999,
              "where": {
                  "condition": ""
              }
          }
      },
      teamData:[],
      //编辑的目标
      editTarget:''
    };
  },
  components: {
    AddUser,
    TeamItem,
    RemoveTeam
  },
  computed: {
  },
  watch: {
  },
  created() {
    this.getTeamData()
  },
  methods: {
    addUser() {
      this.$refs.addUser.dialogVisible = true
      this.editTarget = ''
      this.$refs.addUser.param.content.sa_agent_hrid = '0'
      this.$nextTick(() => {
        this.$refs.addUser.$refs.formInfo.resetFields()
      })
    },
    async getTeamData() {
      let res = await this.$api.requested(this.param)
      this.teamData = res.data
    },
    editTargetFun(data) {
      this.editTarget = data
      this.$refs.addUser.dialogVisible = true
    }
  },
};
</script>

<style scoped>
*{
  box-sizing: border-box;
}
  .tema {
    width: 100%;
    min-height: 100%;
    background: #ffffff;
    position: relative;
  }
  .tema .top {
    display: flex;
    justify-content: space-between;
    padding: 16px 16px 9px 0;
    margin-left: 16px;
    border-bottom: 1px solid #DDDDDD;
    align-items: center;
  }
  .tema .top p {
    font-size: 16px;
    font-weight: bold;
    color: #333333;
  }
  .el-empty {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%,-50%);
  }
</style>
