selectFollow.vue 5.08 KB
<template>
  <div class="square-main" v-loading="loading">
    <GLDialog title="选择跟进专员" :visible.sync="dialogVisible">
      <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">
          <el-button type="primary" @click="handleSearch">查询</el-button>
        </el-form-item>
      </el-form>
      <div class="table-box">
        <GLTable :key="key" v-if="dialogVisible" ref="followTable" :layout="layout" :tableData="tableData" :hasNum="false" :tableTotal="tableTotal" :pageConf="pageConf" :tableParams="tableParams" @refreshTable="handleSearch" @selectionTable="selectionTable" @row-click="rowClick"></GLTable>
        <div class="form-tips">必须配置至少1个跟进专员</div>
      </div>
      <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>
    </GLDialog>
  </div>
</template>

<script>
import { utils } from 'glsx-common'
import util from '@/utils/util'
export default {
  name: 'SelectFollow',
  data() {
    return {
      loading: false,
      dialogVisible: false,
      tableSearchForm: {},
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
      tableParams: {
        listName: 'data',
        tableOption: false,
        // 行数据的key
        mutiSelectUniqueKey: 'id',
        checkSelectKey: 'id',
        checkSelectVal: [],
        // 多选ref的名称
        mutiSelectName: 'salelist',
        tableColumns: [
          {
            label: '姓名',
            prop: 'staffName'
          },
          {
            label: '部门',
            prop: 'departmentName'
          },
          {
            label: '跟进专员类型',
            prop: 'followerTypeName'
          }
        ]
      },
      layout: 'total',
      tableData: [],
      tableTotal: 0,
      selectItem: [],
      selectEmp: [],
      checkSelect: [],
      key: new Date()
    }
  },
  methods: {
    jumpUrl() {
      util.openUrl(location.origin + '/settings/followUp/index')
    },
    getFollower() {
      var params = {
        ...JSON.parse(JSON.stringify(this.tableSearchForm)),
        pageSize: this.$refs.followTable.page.pageSize,
        pageNum: this.$refs.followTable.page.pageNum
      }
      this.$apis.groupGuest.getFollower(params).then(res => {
        this.tableData = res.data
        this.tableTotal = res.count
        if (res.count > 10) {
          this.layout = 'total, pager'
        }
        this.tableData.forEach(item => {
          this.selectEmp.forEach((itm, index) => {
            if (itm.staffId == item.id) {
              this.$refs.followTable.$refs.salelistMutiTable.toggleRowSelection(item)
              this.selectEmp.splice(index, 1)
            }
          })
          if (this.checkSelect) this.tableParams.checkSelectVal = this.checkSelect
        })
      })
    },
    init(item, checkMember) {
      this.checkSelect = checkMember
      this.tableSearchForm = {}
      this.selectEmp = JSON.parse(JSON.stringify(item))
      this.dialogVisible = true
      this.$nextTick(() => {
        this.$refs.followTable.page.pageNum = 1
        this.getFollower()
      })
    },
    handleSearch() {
      this.getFollower()
    },
    selectionTable(val) {
      this.selectItem = val
    },
    handleClose() {
      this.handleCancel()
    },
    rowClick(row) {
      if (this.checkSelect.find(i => i == row.id)) return
      this.$refs.followTable.$refs.salelistMutiTable.toggleRowSelection(row)
    },
    handleCancel: utils.debounce(function() {
      this.dialogVisible = false
      this.$refs.followTable.$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.followTable.$refs.salelistMutiTable.clearSelection()
    }, 300)
  }
}
</script>

<style lang="scss" scoped>
@import '@/styles/variables.scss';
.dialog-jump {
  color: $btnBlue;
  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;
    }
  }
}
.form-tips {
  position: absolute;
  bottom: 0;
  right: 0;
  font-size: 12px;
  color: #999;
  line-height: 32px;
}
.table-box {
  position: relative;
}
</style>