selectLord.vue 9.24 KB
<template>
  <div class="member-wrapper">
    <div class="member-left">
      <div class="member-title">
        预选
        <span>共{{ chatGroupCount }}个群聊,{{ tableEmpData.length }}个群主成员</span>
      </div>
      <div class="member-content">
        <el-form :inline="true" class="member-form" :model="searchForm" @submit.native.prevent>
          <el-form-item style="margin-bottom: 0">
            <span class="lord-label" slot="label">所在门店/部门</span>
            <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 style="width: 215px" 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.lordName" @keyup.enter.native="search" clearable placeholder="请输入姓名搜索"></el-input>
          </el-form-item>
          <el-form-item style="margin-bottom: 0">
            <span class="lord-label" slot="label">跟进专员类型</span>
            <el-select v-model="searchForm.followerId" style="width: 215px" :size="size" placeholder="请选择">
              <el-option v-for="item in followTypeList" :key="item.id" :label="item.followName" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <!-- <el-form-item>
          <el-checkbox v-model="searchForm.checked">仅看跟进专员</el-checkbox>
          </el-form-item>-->
          <el-form-item label style="margin-bottom: 0; margin-left: 40px">
            <el-button :size="size" @click="handleReset">重置</el-button>
            <el-button type="primary" :size="size" @click="search">搜索</el-button>
          </el-form-item>
        </el-form>
        <div class="table-content" style="max-height: 456px">
          <GLTable 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>
    <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>
            {{ tag.staffName }}
          </el-tag>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import url from '@/assets/empty.png'
export default {
  name: 'SelectLord',
  props: ['selectData'],
  data() {
    return {
      url: url,
      searchForm: {},
      checked: '',
      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'
          },
          {
            label: '跟进专员类型',
            prop: 'followerTypeName',
            formatter: cellValue => {
              return cellValue.followerTypeName ? cellValue.followerTypeName : '-'
            }
          },
          {
            label: '群数量',
            prop: 'chatCount'
          }
        ]
      },
      tableEmpData: [],
      allTreeData: [],
      currentTreeData: [],
      innerTags: [],
      followTypeList: [],
      chatGroupCount: 0
    }
  },
  mounted() {
    this.getFindLordGroup({}, true)
    this.getFollowerType()
    this.listDepartmentTree()
  },
  methods: {
    selectionTable(val) {
      this.innerTags = val
    },
    // 清空搜索条件
    resetSearch() {
      this.searchForm = {}
      this.tableEmpData = this.allTreeData
    },
    // 显示时触发
    onShowPopover() {
      this.popoverVisible = true
    },
    // 隐藏时触发
    onHidePopover() {
      this.popoverVisible = false
    },
    getFindLordGroup(params, isFirst) {
      this.$apis.customerTransform.findLordGroup(params).then(res => {
        this.loading = false
        if (res) {
          this.tableEmpData = res
          this.tableEmpData.map(item => (this.chatGroupCount += item.chatCount))
          this.$refs.empTable.tableHeightValues = this.tableEmpData.length ? '' : '230px'
          if (isFirst && this.selectData && this.selectData.length) {
            this.selectData.forEach(item => {
              this.$refs.empTable.$refs.salelistMutiTable.toggleRowSelection(item)
            })
          }
        } else {
          this.treeData = []
        }
      })
    },
    listDepartmentTree() {
      const params = { addChildrensFlag: true }
      params.islord = true
      this.$apis.customerTransform.listDepartmentTree(params).then(res => {
        this.treeData = res
      })
    },
    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.getFindLordGroup(this.searchForm)
    },
    remove(item) {
      this.$refs.empTable.$refs.salelistMutiTable.toggleRowSelection(item)
    },
    rowClick(row) {
      this.$refs.empTable.$refs.salelistMutiTable.toggleRowSelection(row)
    },
    getFollowerType() {
      this.$apis.customerTransform.followerType({}).then(res => {
        this.followTypeList = res
      })
    },
    handleReset() {
      this.searchForm = {}
      this.search()
    }
  }
}
</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;
  }
}
.lord-label {
  display: inline-block;
  width: 110px;
}
.member-wrapper {
  display: flex;
  .member-title {
    font-size: 16px;
    font-weight: 600;
    line-height: 22px;
    margin-bottom: 6px;
    span {
      display: inline-block;
      padding-left: 5px;
      font-size: 12px;
      color: #999;
      font-weight: 500;
    }
  }
  .member-left {
    width: calc(100% - 286px);

    .member-content {
      border: 1px solid #eee;
      border-bottom: none;
      .member-form {
        padding: 10px 20px;
      }
      .table-content {
        max-height: 456px;
        overflow: auto;
        border-top: 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>