selectMember.vue 10.4 KB
<template>
  <div class="member-wrapper">
    <div class="member-left">
      <div class="member-title">
        预选
        <span>仅筛选有外部客户联系人的成员</span>
      </div>
      <div class="member-content">
        <el-form :inline="true" class="member-form" :model="searchForm" @submit.native.prevent>
          <el-form-item label="所在门店/部门" style="margin-bottom: 0;">
            <el-popover
              ref="popover"
              placement="bottom"
              width="215"
              trigger="click"
              v-model="popoverVisible"
              @show="onShowPopover"
              @hide="onHidePopover"
            >
              <el-tree
                class="select-tree"
                :data="treeData"
                :props="defaultProps"
                default-expand-all
                @node-click="handleNodeClick"
              ></el-tree>
              <el-input
                v-model="searchForm.department"
                slot="reference"
                :size="size"
                readonly
                placeholder="请选择所在门店/部门"
                :class="{ 'rotate': popoverVisible }"
                suffix-icon="el-icon-arrow-down"
                @keyup.enter.native="search"
              ></el-input>
            </el-popover>
          </el-form-item>
          <el-form-item label="姓名" style="margin-bottom: 0;">
            <el-input
              :size="size"
              v-model.trim="searchForm.name"
              @keyup.enter.native="search"
              clearable
              placeholder="请输入姓名搜索"
            ></el-input>
          </el-form-item>
          <!-- <el-form-item>
          <el-checkbox v-model="searchForm.checked">仅看跟进专员</el-checkbox>
          </el-form-item>-->
          <el-form-item style="margin-bottom: 0;">
            <el-button type="primary" :size="size" @click="search">查询</el-button>
          </el-form-item>
        </el-form>
        <div class="table-content">
          <GLTable
            :key="key"
            v-loading="loading"
            ref="empTable"
            :tableData="tableEmpData"
            :tableParams="tableParams"
            :hasNum="false"
            :hasPage="false"
            :noDataImg="url"
            @selectionTable="selectionTable"
            @row-click="rowClick"
          >
            <div slot="staffName" slot-scope="scope">
              <span>{{scope.scope.staffName}}</span>
              <span class="staff-title" v-show="scope.scope.staffTitle">{{scope.scope.staffTitle}}</span>
            </div>
          </GLTable>
        </div>
      </div>
      <!-- <div class="member-checked">
        <el-checkbox v-model="searchForm.checked">仅看跟进专员</el-checkbox>
      </div>-->
    </div>
    <div class="member-right">
      <div class="member-title">已选</div>
      <div class="member-name">成员名称({{innerTags.length}}项)</div>
      <div class="input-tag-wrapper">
        <div class="tag-box">
          <el-tag
            v-for="(tag, idx) in innerTags"
            :key="idx"
            type="info"
            closable
            :disable-transitions="false"
            @close="remove(tag)"
          >
            <!-- <i class="el-icon-user-solid"></i> -->
                                <img class="headPortrait" src="@/assets/headPortrait.png" />
            {{ tag.staffName }}
          </el-tag>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import url from '@/assets/empty.png'
export default {
  name: 'SelectMember',
  props: ['selectData', 'followData'],
  data() {
    return {
      url: url,
      searchForm: {},
      treeData: [],
      defaultProps: {
        children: 'children',
        label: 'departmentName'
      },
      popoverVisible: false,
      loading: false,
      // 表格参数
      tableParams: {
        checkSelectKey: 'id',
        checkSelectVal: [],
        listName: 'list',
        // 行数据的key
        mutiSelectUniqueKey: 'id',
        // 多选ref的名称
        mutiSelectName: 'salelist',
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        tableColumns: [
          {
            label: '姓名',
            prop: 'staffName',
            addHtml: 'staffName'
          },
          {
            label: '所在门店/部门',
            prop: 'departmentName'
          }
        ]
      },
      tableEmpData: [],
      allTreeData: [],
      currentTreeData: [],
      innerTags: [],
      key: new Date()
    }
  },
  mounted() {
    this.listDepartmentTree()
    
  },
  methods: {
    selectionTable(val) {
      this.innerTags = val
    },
    // 清空搜索条件
    resetSearch() {
      this.searchForm = {}
      this.tableEmpData = this.allTreeData
    },
    // 显示时触发
    onShowPopover() {
      this.popoverVisible = true
    },
    // 隐藏时触发
    onHidePopover() {
      this.popoverVisible = false
    },
    listDepartmentTree() {
      const params = { addChildrensFlag: true }
      if (this.islord) {
        // 是否群主
        params.islord = this.islord
      }
      this.loading = true
      params.isHavCustomer = true
      this.$apis.groupGuest.listDepartmentTree(params).then(res => {
        this.loading = false
        if (res) {
          this.tableEmpData = this.getEmployee(res)
          this.allTreeData = this.getEmployee(res)
          this.currentTreeData = this.getEmployee(res)
          this.treeData = res
          this.tableEmpData.length ? (this.$refs.empTable.tableHeightValues = '250px') : this.$refs.empTable.setTableHeightFun()
          if (this.selectData && this.selectData.length) {
            this.selectData.forEach(item => {
              this.$refs.empTable.$refs.salelistMutiTable.toggleRowSelection(item)
            })
          }
          if (this.followData) this.tableParams.checkSelectVal = this.followData
          // this.key = new Date()
        } else {
          this.treeData = []
        }
      })
    },
    handleNodeClick(data) {
      this.searchForm.department = data.departmentName
      this.currentTreeData = data
      this.onHidePopover()
    },
    getEmployee(d, arr = []) {
      d.reverse().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
    },
    search() {
      this.tableEmpData = []
      const data = this.currentTreeData
      const keyword = this.searchForm.name
      let arr = []
      if (data instanceof Array) {
        data.forEach(i => {
          if (i.staffName.indexOf(keyword) != -1) {
            this.tableEmpData.push(i)
          }
        })
      } else if (data instanceof Object) {
        if (data.entmicroStaffResponses) {
          if (keyword) {
            data.entmicroStaffResponses.forEach(i => {
              if (i.staffName.indexOf(keyword) != -1) {
                this.tableEmpData.push(i)
              }
            })
          } else {
            this.tableEmpData = this.tableEmpData.concat(data.entmicroStaffResponses)
          }
        }
        if (data.children) {
          data.children.forEach(i => {
            if (i.entmicroStaffResponses) {
              i.entmicroStaffResponses.forEach(j => {
                if (keyword) {
                  if (j.staffName.indexOf(keyword) != -1) {
                    const flag = this.tableEmpData.find(m => m.id == j.id)
                    if (!flag) {
                      this.tableEmpData.push(j)
                    }
                  }
                } else {
                  const flag = this.tableEmpData.find(m => m.id == j.id)
                  if (!flag) {
                    this.tableEmpData.push(j)
                  }
                }
              })
            }
          })
        }
      }
    },
    remove(item) {
      this.$refs.empTable.$refs.salelistMutiTable.toggleRowSelection(item)
    },
    rowClick(row) {
      if (this.followData.find(i => i == row.id)) return
      this.$refs.empTable.$refs.salelistMutiTable.toggleRowSelection(row)
    }
  }
}
</script>

<style lang="scss">
.el-input.el-input--suffix.rotate .el-input__suffix .el-icon-arrow-down {
  transform: rotate(-180deg);
}
.select-tree {
  max-height: 400px;
  overflow-y: scroll;
}
.staff-title {
  position: relative;
  font-size: 12px;
  padding: 0 10px;
  line-height: 12px;
  color: #999;
  &::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 5px;
    transform: translateY(-50%);
    display: inline-block;
    width: 1px;
    height: 12px;
    background-color: #999;
  }
}
.member-wrapper {
  display: flex;
  .member-title {
    font-size: 16px;
    font-weight: 500;
    line-height: 22px;
    margin-bottom: 6px;
    span {
      display: inline-block;
      padding-left: 5px;
      font-size: 12px;
      color: #999;
    }
  }
  .member-left {
    width: 800px;

    .member-content {
      border: 1px solid #eee;
      .member-form {
        padding: 10px 20px;
      }
      .table-content {
        max-height: 456px;
        overflow: auto;
        border: 1px solid #eee;
      }
    }
    .member-checked {
      text-align: right;
      margin-top: 10px;
    }
  }
  .member-right {
    width: 286px;
    margin-left: 14px;
    .member-name {
      font-size: 14px;
      color: #333;
      line-height: 20px;
      padding: 18px;
      border: 1px solid #eee;
    }
  }
}
.tag-box {
  height: 100%;
}
.input-tag-wrapper {
  position: relative;
  font-size: 14px;
  border: 1px solid #eee;
  border-top: none;
  box-sizing: border-box;
  color: #606266;
  display: inline-block;
  padding: 8px 10px;
  line-height: 32px;
  transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  width: 100%;
  height: calc(100% - 86px);
  display: flex;
  align-items: center;
  max-height: 500px;
  overflow: auto;
  // margin-bottom: 10px;
  i {
    color: #75acff;
    margin-right: 3px;
    font-size: 14px;
  }
  /deep/ input {
    /* input { */
    /* background-color: red!important;  调试用的样式 */
    outline: none !important;
    border: none !important;
  }
  /deep/ .el-input {
    min-width: 150px;
    width: auto;
    flex: 1;
  }
}
.el-tag {
  margin-right: 10px;
  line-height: 22px;
  margin-bottom: 5px;
  height: 24px;
}
</style>