<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-08-14 16:51:07
 * @LastEditors: 无尘
 * @LastEditTime: 2020-09-08 15:26:31
 -->
<!--
通讯录部门
<contact-tree :item-data="itemData" v-model="itemData" ></contact-tree>

import contactTree from '/components/company/contact-tree.vue';
-->
<template>
  <ul class="">
    <!-- <draggable :list="itemData" class="wx-component" :options="rightOption" @input="emitter" @change="changeData"> -->
    <li class="contact-li" v-for="(item, index) in itemData" :key="index + 'gic'">
      <div :class="['li-cell cursor-pointer', departObj.departmentId == item.departmentId ? 'li-cell-active' : '']" @click="toggleExpand(item)">
        <div class="li-cell-p" :style="{ 'margin-left': item.level * 20 + 'px' }">
          <span :class="['font-12 color-606266', item.isStore == 1 || !item.hasSonNode ? 'color-fff' : '', item.expand ? 'el-icon-caret-bottom' : 'el-icon-caret-right']"></span><span v-if="item.loading" class="el-tree-node__loading-icon el-icon-loading"></span><span :class="['font-14 p-r-10 iconfont  iconqiye-tianchong', !!item.loading ? '' : 'p-l-10', departObj.departmentId == item.departmentId ? 'color-2f54eb' : 'color-dedfe6']"></span><span class="font-14 color-606266 span-departName">{{ item.departmentName }}</span>
        </div>
      </div>
      <li-row v-if="item.expand" :depart-obj="departObj" :item-data="item.children" @getSelectData="getSelectData"></li-row><!-- v-show="!!item.children.length && item.expand" -->
    </li>
    <!-- </draggable> -->
  </ul>
</template>
<script>
export default {
  name: 'LiRow',
  components: {
  },
  props: {
    value: {
      type: [ Object, Array ],
      default() {
        return [];
      }
    },
    itemData: {
      type: [ Object, Array ],
      default() {
        return [];
      }
    },
    // 选中节点
    departObj: {
      type: Object,
      default() {
        return {
          departmentId: '',
          departmentName: '',
          wxDepartmentId: '',
          parentId: '',
          isStore: '',
          staffCount: '',
          bindFlag: '',
          loading: false
        };
      }
    }
  },
  data() {
    return {
      rightOption: {
        group: {
          name: 'people',
          pull: true,
          put: true
        },
        sort: true
      }
    };
  },
  methods: {
    /**
     * @description: 改变数组数据
     * @param {Array} value
     * @author: 无尘
     */
    emitter(value) {
      this.$emit('input', value);
    },
    /**
     * @description: 展开或者关闭下级
     * @param {Object} item
     * @author: 无尘
     */
    async toggleExpand(item) {
      const that = this;
      // console.log(item);
      item.expand = item.expand ? false : true;
      if (item.isStore == 0 && !item.children.length) {
        item.loading = true;
        // item.children = await that.getChildData(item);
        item.loading = false;
      }

      that.$emit('getSelectData', item);
      that.$forceUpdate();
    },
    /**
     * @description: 获取选中部门/门店数据
     * @param {Object} obj
     * @author: 无尘
     */
    getSelectData(obj) {
      const that = this;
      that.selectData = obj;
      that.$emit('getSelectData', obj);
    },
  }
};
</script>
<style lang="less" scoped>
.li-cell {
  min-height: 26px;
  line-height: 26px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  .color-606266 {
    &.color-fff {
      color: #fff;
    }
  }
  &.li-cell-active {
    background: #f4f6fe;
    .span-departName {
      color: #2f54eb;
    }
    .iconqiye-tianchong {
      color: #2f54eb;
    }
    .color-606266 {
      &.color-fff {
        color: #f4f6fe;
      }
    }
  }
}
.contact-li {
  .li-cell {
    &:hover {
      background: #f4f6fe;
      .span-departName {
        color: #303133;
      }
      .color-606266 {
        &.color-fff {
          color: #f4f6fe;
        }
      }
    }
  }
}

.w-110 {
  width: 110px;
}

.w-320 {
  width: 320px;
}

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

.child-row {
  padding-left: 10px;
}
</style>
