index.vue 4.35 KB
<template>
  <div class="square-main" v-loading="loading">
    <el-dialog title="选择跟进专员" :visible.sync="dialogVisible" width="50%" :before-close="handleClose">
      <el-form :inline="true" :model="tableSearchForm">
        <el-form-item size="small" label="员工">
          <el-input v-model="tableSearchForm.staffName" placeholder="请输入员工姓名"></el-input>
        </el-form-item>
        <el-form-item size="small" class="emp-form-btn">
          <el-button type="primary" @click="handleSearch">查询</el-button>
        </el-form-item>
      </el-form>
      <GLTable v-if="dialogVisible" ref="table" :layout="layout" :tableData="tableData" :tableTotal="tableTotal" :pageConf="pageConf" :tableParams="tableParams" @refreshTable="handleSearch" @selectionTable="selectionTable"></GLTable>
      <span slot="footer" class="dialog-footer">
        <a class="dialog-jump" @click="jumpUrl">新增专员</a>
        <el-button size="small" @click="handleCancel">取 消</el-button>
        <el-button size="small" type="primary" @click.native="handleSelect">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { utils } from 'glsx-common'
import util from '@/utils/util'
export default {
  name: 'selectEmp',
  data() {
    return {
      loading: false,
      dialogVisible: false,
      tableSearchForm: {},
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
      tableParams: {
        listName: 'data',
        tableOption: false,
        // 行数据的key
        mutiSelectUniqueKey: 'id',
        // 多选ref的名称
        mutiSelectName: 'salelist',
        tableColumns: [
          {
            label: '姓名',
            prop: 'staffName'
          },
          {
            label: '部门',
            prop: 'departmentName'
          },
          {
            label: '跟进专员类型',
            prop: 'followerTypeName'
          }
        ]
      },
      layout: 'sizes, prev, pager, next, jumper, ->, total',
      tableData: [],
      tableTotal: 0,
      selectItem: [],
      selectEmp: []
    }
  },
  methods: {
    jumpUrl() {
      util.openTab(location.origin + '/settings/followUp/index')
    },
    getFollower() {
      var params = {
        ...JSON.parse(JSON.stringify(this.tableSearchForm)),
        pageSize: this.$refs.table.page.pageSize,
        pageNum: this.$refs.table.page.pageNum
      }
      this.$apis.helpCard.getFollower(params).then(res => {
        this.tableData = res.data
        this.tableTotal = res.count
        this.tableData.forEach(item => {
          this.selectEmp.forEach((itm, index) => {
            if (itm.staffId == item.id) {
              this.$refs.table.$refs.salelistMutiTable.toggleRowSelection(item)
              this.selectEmp.splice(index, 1)
            }
          })
        })
      })
    },
    init(item) {
      this.tableSearchForm = {}
      this.selectEmp = JSON.parse(JSON.stringify(item))
      this.dialogVisible = true
      this.$nextTick(() => {
        this.$refs.table.page.pageNum = 1
        this.getFollower()
      })
    },
    handleSearch() {
      this.getFollower()
    },
    selectionTable(val) {
      this.selectItem = val
    },
    handleClose() {
      this.handleCancel()
    },
    handleCancel: utils.debounce(function() {
      this.dialogVisible = false
      this.$refs.table.$refs.salelistMutiTable.clearSelection()
    }, 300),
    handleSelect: utils.debounce(function() {
      this.loading = true
      let selectEmp = this.selectEmp.map(item => {
        return {
          id: item.staffId,
          staffName: item.staffName
        }
      })
      const selectItem = this.selectItem.concat(selectEmp)
      if (selectItem.length == 0) {
        this.$message.error('请选择员工')
        return
      }
      this.loading = false
      this.dialogVisible = false
      this.$emit('selectTable', this.selectItem.concat(selectEmp))
      this.$refs.table.$refs.salelistMutiTable.clearSelection()
    }, 300)
  }
}
</script>
<style lang="scss" scoped>
.emp-form-btn {
  margin-left: 20px;
}
.dialog-jump {
  color: #5850ff;
  float: left;
  line-height: 24px;
  text-decoration: underline;
  cursor: pointer;
}
.square-main {
  /deep/ {
    .el-table {
      height: 40vh;
      overflow-y: auto;
    }
    .el-table::before {
      left: 0;
      bottom: 0;
      width: 100%;
      height: 0px;
    }
  }
}
</style>