selectEmp.vue 6.06 KB
<template>
  <div class="select-emp-panel">
    <div class="scrm-p10 emp-tree-panel">
      <div class="popper-arrow"></div>
      <div class="emp-scroll-panel" :style="{
          height: treeHeight + 'px'
        }">
        <div class="tree-title">所在门店/部门</div>
        <el-tree
          v-loading="loading"
          :data="listTree"
          :expand-on-click-node="false"
          highlight-current
          :props="defaultProps"
          @node-click="handleNodeClick"
        ></el-tree>
      </div>
    </div>
    <el-col
      class="scrm-p10 emp-table-panel"
      :style="{
        height: treeHeight + 20 + 'px'
      }"
    >
      <GLTable
        v-loading="loading"
        ref="saleTable"
        :tableData="tableEmpData"
        :tableParams="tableParams"
        :hasNum="false"
        :hasPage="false"
        @selectionTable="selectionTable"
      ></GLTable>
    </el-col>
  </div>
</template>
<script>
export default {
  name: 'selectEmp',
  props: ['selectData', 'islord'],
  data() {
    return {
      treeHeight: 0,
      staffName: '',
      listTree: [],
      defaultProps: {
        children: 'children',
        label: 'departmentName'
      },
      // 表格参数
      tableParams: {
        checkSelectKey: 'id',
        checkSelectVal: [],
        listName: 'list',
        // 行数据的key
        mutiSelectUniqueKey: 'id',
        // 多选ref的名称
        mutiSelectName: 'salelist',
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        tableColumns: [
          {
            label: '姓名',
            prop: 'staffName'
          },
          {
            label: '职务',
            prop: 'staffTitle'
          }
        ]
      },
      tableEmpData: [],
      currentArr: [],
      loading: true
    }
  },
  methods: {
    selectionTable(val) {
      this.$emit('selectTable', val)
    },
    listDepartmentTree() {
      const params = { merchantId: 10001001, addChildrensFlag: true }
      if (this.islord) {
        params.islord = this.islord
      }
      params.isHavCustomer = true
      this.$apis.customerTransform.listDepartmentTree(params).then(res => {
        this.listTree = res
        this.loading = false
        if (this.listTree.length) {
          this.listTree[0].entmicroStaffResponses = this.getEmployee(this.listTree)
          this.currentArr = this.$common.utils.deepClone(this.listTree[0].entmicroStaffResponses)
        }
        if (this.selectData && this.selectData.length) {
          this.selectData.forEach(i => {
            const row = this.getEmployee(this.listTree).find(j => j.id == i.staffId)
            this.clearSelect(row)
          })
        }
        this.$nextTick(() => {
          document.getElementsByClassName('el-tree-node__expand-icon')[0].click()
          document.getElementsByClassName('el-tree-node__content')[0].click()
        })
      })
    },
    clearSelect(row) {
      this.$refs.saleTable.$refs.salelistMutiTable.toggleRowSelection(row)
    },
    clearSelection() {
      this.$refs.saleTable.$refs.salelistMutiTable.clearSelection()
    },
    handleNodeClick(data) {
      this.departmentId = data.id
      this.tableEmpData = data.entmicroStaffResponses
      // this.currentArr = this.$common.utils.deepClone(data.entmicroStaffResponses)
      // this.listEntmicroStaff()
    },
    getEmployee(d, arr = []) {
      d.forEach(i => {
        if (i.entmicroStaffResponses) {
          i.entmicroStaffResponses.forEach(j => {
            const flag = arr.find(m => m.id == j.id)
            if (!flag) {
              arr.push(j)
            }
          })
        }
        if (i.children) {
          this.getEmployee(i.children, arr)
        }
      })
      return arr
    },
    searchTable(search) {
      const arr = []
      if (this.currentArr && this.currentArr.length != 0) {
        this.currentArr.forEach(item => {
          if (item.staffName.indexOf(search) != -1) {
            arr.push(item)
          }
        })
      }
      this.tableEmpData = arr
    }
    // listEntmicroStaff(staffName) {
    //   let params = {
    //     departmentId: this.departmentId,
    //     staffName: staffName ? staffName : this.staffName,
    //     merchantid: this.$globalState.session.merchantId
    //   }
    //   this.$apis.emp.listEntmicroStaff(params).then(res => {
    //     this.tableEmpData = res
    //   })
    // }
  },
  mounted() {
    let clientHeight = document.documentElement.clientHeight
    this.treeHeight = clientHeight - 650
    this.listDepartmentTree()
  }
}
</script> 
<style scoped lang="scss">
.select-emp-panel {
  display: flex;
  .emp-tree-panel {
    margin-top: 10px;
    width: 200px;
    position: relative;
    background: #ffffff;
    box-shadow: 0px 2px 12px 0px rgba(0, 0, 0, 0.06);
    border: 1px solid #e4e7ed;
    .emp-scroll-panel {
      min-height: 200px;
      overflow: auto;
      box-sizing: border-box;
    }
    .popper-arrow {
      border-top-width: 0;
      border-width: 6px;
      position: absolute;
      top: -12px;
      left: 30px;
      display: block;
      width: 0;
      height: 0;
      border-color: transparent;
      border-style: solid;
      border-bottom-color: #e4e7ed;
      &:after {
        content: ' ';
        border-width: 6px;
        top: 1px;
        margin-left: -6px;
        border-top-width: 0;
        position: absolute;
        display: block;
        width: 0;
        height: 0;
        border-color: transparent;
        border-style: solid;
        border-bottom-color: #fff;
      }
    }
  }
  .emp-table-panel {
    flex: 1;
    min-height: 200px;
    overflow: auto;
    margin-top: 10px;
    background: #ffffff;
    box-shadow: 0px 2px 12px 0px rgba(0, 0, 0, 0.06);
    border: 1px solid #e4e7ed;
    /deep/ .el-checkbox__input.is-disabled .el-checkbox__inner {
      background-color: #999999;
    }
  }
  .emp-tree-panel {
    margin-right: 10px;
    font-size: 15px;
    /deep/ .el-tree-node:focus > .el-tree-node__content {
      color: #5850ff;
      background: #f2f5fa;
    }
  }
  .tree-title {
    font-size: 16px;
    font-weight: 500;
    color: #333333;
    line-height: 14px;
    padding: 10px;
  }
}
</style>