<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2020-03-16 09:59:39
 * @LastEditors: 无尘
 * @LastEditTime: 2020-12-14 17:11:36
 -->
<template>
  <div class="daily-set-wrap ">
    <div class="daily-set-content border-box" v-if="isManager">
      <div class="company-title m-b-20 m-t-26 flex flex-space-between flex-align-center">
        <div role="alert" class="el-alert el-alert--info">
          <i class="el-alert__icon el-icon-info"></i>
          <div class="el-alert__content">
            <span class="el-alert__title"
              >1.好办管理后台管理员需在企业微信后台添加，<el-button type="text" @click="goto" style=" font-size: 13px;">详情请见</el-button>
              <br />
              2.企业微信后台新增管理员后，请点击右侧【刷新】按钮刷新企业成员，否则不会同步到好办管理员列表。
            </span>
          </div>
        </div>
        <el-button v-if="$getButtonLimit($buttonCode.refreshAdminList)" :limit-code="$buttonCode.refreshAdminList" type="primary" @click="refresh">刷新</el-button>
      </div>
      <el-table :data="roleList" style="margin-top:20px">
        <el-table-column prop="userName" label="姓名"> </el-table-column>
        <el-table-column prop="userPhone" label="手机号"> </el-table-column>
        <el-table-column prop="departmentName" label="部门"> </el-table-column>
      </el-table>
    </div>
    <not-manager v-else></not-manager>
  </div>
</template>
<script>
import { getRequest } from '@/api/api';
// import { _debounce } from '@/common/js/public';
import showMsg from '@/common/js/showmsg';
import errMsg from '@/common/js/error';
import NotManager from '../business/not-manager.vue';
export default {
  props: {},
  comments: { NotManager },
  data() {
    return {
      wxEnterpriseId: sessionStorage.getItem('userInfos') ? JSON.parse(sessionStorage.getItem('userInfos')).wxEnterpriseId : '',

      roleList: [],
      isManager: false
    };
  },
  methods: {
    /**
     * 跳转
     */
    changeRoute() {
      this.$router.push('/contactsList');
    },
    goto() {
      window.open('https://www.yuque.com/docs/share/89a899fe-caae-41b3-86ea-2435a8066418?#');
    },
    /**
     * 展开/折叠
     */
    changeToggle(item) {
      item.expand = item.expand ? false : true;
    },
    /**
     * 获取数据
     */
    getData(val) {
      let para = {
        wxEnterpriseId: this.wxEnterpriseId
      };
      getRequest('/haoban-manage3-web/admin-list', para)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            if (!!resData.result && resData.result.length) {
              resData.result.forEach(ele => {
                ele.expand = false;
              });
            }
            this.roleList = [];
            resData.result.forEach(i => {
              if (i.roleUser.length) {
                this.roleList = this.roleList.concat(i.roleUser);
              }
            });
          }
          this.isManager = resData.errorCode != 10030;
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          this.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },
    refresh() {
      getRequest('/haoban-manage3-web/sync-qywx', {}).then(res => {
        showMsg.showmsg('刷新成功', 'success');
        this.getData();
      });
    }
  },
  watch: {},
  mounted() {
    const that = this;
    that.getData();
  },
  components: { NotManager }
};
</script>
<style type="text/scss" lang="scss" scoped>
.bg-ebecf0 {
  background: #ebecf0;
}
.color-c0c4cc {
  display: inline-block;
  line-height: 34px;
  padding-left: 10px;
  color: #c0c4cc;
}
.condition-tips {
  display: inline-block;
  vertical-align: middle;
  line-height: 32px;
}
.p-l-30 {
  padding-left: 30px;
}
.p-l-40 {
  padding-left: 40px;
}
.p-l-55 {
  padding-left: 55px;
}
.p-l-85 {
  padding-left: 85px;
}
.m-l-20 {
  margin-left: 20px;
}
.line-50 {
  height: 50px;
  line-height: 50px;
}
.el-alert--info {
  width: 720px;
  font-size: 14px;
  color: #606266;
  background: rgba(240, 245, 255, 1);
  border-radius: 2px;
  border: 1px solid rgba(133, 165, 255, 1);
}
.el-icon-info {
  width: 12px;
  font-size: 12px;
  color: #2f54eb;
  margin-top: -17px;
}
.table-condition {
  /* min-width: 1200px; */
}
.admin-table-body {
  .admin-thead {
    width: 100%;
    height: 48px;
    line-height: 48px;
  }
  .row-th {
    height: 48px;
    line-height: 48px;
  }
  .el-row {
    font-size: 14px;
    border-bottom: 1px solid #dcdfe6;
    overflow: hidden;
    &.border-set {
      border-bottom: 0px solid #dcdfe6;
      .el-col {
        position: relative;
        border-bottom: 1px solid #dcdfe6;
        &::after {
          content: ' ';
          position: absolute;
          left: 0px;
          bottom: 0;
          width: 100%;
          height: 50px;
          border-bottom: 1px solid #dcdfe6;
          z-index: 1;
        }
        &.line-one {
          &::after {
            content: ' ';
            position: absolute;
            left: 55px;
            bottom: 0;
            width: calc(100% - 55px);
            height: 50px;
            border-bottom: 1px solid #dcdfe6;
            z-index: 1;
          }
        }
      }
    }
    .hide-border {
      position: relative;
      &::after {
        content: ' ';
        position: absolute;
        left: 0;
        bottom: 0;
        width: 55px;
        height: 1px;
        background: #fff;
        z-index: 1;
      }
    }
  }
}
.daily-set-wrap {
  height: 100%;
  .daily-set-content {
    padding: 20px;
    .table-condition-left {
    }
  }
  .el-form {
    .el-form-item {
      margin-bottom: 4px;
    }
    >>> .el-form-item__label {
      color: #606266;
    }
  }
  .depart-item-content {
    width: 213px;
    height: 32px;
    overflow: hidden;
    white-space: nowrap;
    border-radius: 4px;
    border: 1px solid #dcdfe6;
    cursor: pointer;
  }
  .item-cell-select {
    >>> .el-select__tags {
      white-space: nowrap;
      overflow: hidden;
    }
  }
  .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;
    }
  }
}
</style>
