<template>
  <view class="work-container">
    <u-collapse
        @change="change"
        @close="close"
        @open="open"
    >
      <u-collapse-item v-if="item.parentId != 0" v-for="item in deptList"
          :title="item.deptName"
          :name="item.deptId"
      >

        <text class="u-collapse-content" v-for="subitem in item.list">

          {{ subitem.nickName }} {{ subitem.phonenumber }} {{ subitem.createTime }}

        </text>
      </u-collapse-item>

    </u-collapse>
  </view>
</template>

<script>
import authObj from '@/plugins/auth.js';
import {getDeptList,getUserListByDept} from '@/api/user/user';
export default {
    data() {
      return {
        current: 0,
        swiperDotIndex: 0,
        deptList:[],
        deptMap :{}
      }
    },
  onLoad(){
    this.getDeptList();
  },
    methods: {
      change(item){
        console.log(item)
      },
      getUser(dept){
        let id = dept.deptId;
        getUserListByDept(id).then(res=>{
          debugger;
          dept.list = res.rows;
        });
      },
      getDeptList(){
        getDeptList().then(res=>{
          this.deptList = res.data;
          for (let i = 0; i < this.deptList.length; i++) {
              let dept = this.deptList[i];
              this.deptMap[dept.deptId]  = dept;
          }
        });
      },
      open(deptId){
        let dept = this.deptMap[deptId]
        if(dept.list == null){
          this.getUser(dept);
        }
      },
      close(item){

      },
    }
  }
</script>

<style lang="scss">
  /* #ifndef APP-NVUE */
  page {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    background-color: #fff;
    min-height: 100%;
    height: auto;
  }

  view {
    font-size: 14px;
    line-height: inherit;
  }

  /* #endif */

  .text {
    text-align: center;
    font-size: 26rpx;
    margin-top: 10rpx;
  }

  .grid-item-box {
    flex: 1;
    /* #ifndef APP-NVUE */
    display: flex;
    /* #endif */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 15px 0;
  }

  .uni-margin-wrap {
    width: 690rpx;
    width: 100%;
    ;
  }

  .swiper {
    height: 300rpx;
  }

  .swiper-box {
    height: 150px;
  }

  .swiper-item {
    /* #ifndef APP-NVUE */
    display: flex;
    /* #endif */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    height: 300rpx;
    line-height: 300rpx;
  }

  @media screen and (min-width: 500px) {
    .uni-swiper-dot-box {
      width: 400px;
      /* #ifndef APP-NVUE */
      margin: 0 auto;
      /* #endif */
      margin-top: 8px;
    }

    .image {
      width: 100%;
    }
  }
</style>
