activateDia.vue 9.7 KB
<template>
  <div>
    <GLDialog :mode="'big'" class="gl-form-min" bigTitle="选择激活员工" :visible.sync="dialogActivateVisible" @close="clearStaff">
      <el-form :inline="true" class="member-form" :model="searchForm" @submit.native.prevent>
        <el-form-item label="员工姓名:">
          <el-input v-model="searchForm.staffName" :size="size" placeholder="输入关键字搜索"></el-input>
        </el-form-item>
        <el-form-item label="启用状态:">
          <el-select v-model="searchForm.openJoinStatus" placeholder="全部" :size="size">
            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" :size="size" class="gap8" @click="findNotActiveStaff">查询</el-button>
          <el-button plain :size="size" class="btn-three" @click="resetSearch">重置</el-button>
        </el-form-item>
      </el-form>
      <div class="member-wrapper">
        <div class="member-left">
          <div class="member-title">员工列表</div>
          <div class="member-content">
            <div class="table-content" style="max-height: 456px;">
              <GLTable :hasPage="false" v-loading="loading" ref="activateTable" :tableData="tableActiveData" :tableParams="tableParams" :noDataImg="url" @selectionTable="selectionTable" @row-click="rowClick">
                <div slot="openJoinStatusString" class="dot" slot-scope="scope">
                  <div :class="status[scope.scope.openJoinStatusString]"></div>
                  <span v-if="scope.scope.openJoinStatusString == '未开启'">未开启</span>
                  <span v-if="scope.scope.openJoinStatusString == '已开启'">已开启</span>
                  <span v-if="scope.scope.openJoinStatusString == '未授权'">未授权</span>
                </div>
              </GLTable>
            </div>
          </div>
        </div>
        <div class="member-right">
          <div class="member-title">已选列表</div>
          <div class="member-context">
            <div class="member-name">已选({{ innerTags.length }}项)</div>
            <el-button type="text" @click="clearStaff">清空</el-button>
          </div>
          <div class="input-tag-wrapper">
            <div class="tag-box">
              <el-tag v-for="tag in innerTags" :key="tag.userId" type="info" closable :disable-transitions="false" @close="remove(tag)">
                {{ tag.staffName }}
              </el-tag>
            </div>
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="closeDia">取 消</el-button>
        <el-button size="small" type="primary" @click="activeStaff" :loading="butLoading">确 定</el-button>
      </span>
    </GLDialog>
  </div>
</template>

<script>
import url from '@/assets/empty.png'
const status = {
  未开启: 'dot3',
  已开启: 'dot2',
  未授权: 'dot3'
}
const options = [
  {
    value: 0,
    label: '未开启'
  },
  {
    value: 1,
    label: '已开启'
  },
  {
    value: 2,
    label: '未授权'
  }
]
export default {
  name: 'ActivateDia',
  props: ['selectData'],
  data() {
    return {
      url: url,
      butLoading: false,
      searchForm: {
        staffName: '',
        openJoinStatus: ''
      },
      checked: '',
      treeData: [],
      options: options,
      status,
      dialogActivateVisible: false,
      defaultProps: {
        children: 'children',
        label: 'departmentName'
      },
      loading: false,
      // 表格参数
      tableParams: {
        checkSelectKey: 'id',
        checkSelectVal: [],
        listName: 'list',
        // 行数据的key
        mutiSelectUniqueKey: 'id',
        // 多选ref的名称
        mutiSelectName: 'salelist',
        tableColumns: [
          {
            label: '员工姓名',
            prop: 'staffName'
          },
          {
            label: '员工手机号',
            prop: 'staffPhone'
          },
          {
            label: '部门',
            prop: 'departmentName'
          },
          {
            label: '启用状态',
            prop: 'openJoinStatusString',
            addHtml: 'openJoinStatusString'
          }
        ]
      },
      // 未激活员工表信息
      tableActiveData: [],
      innerTags: [],
      // 账号信息
      activeInfo: {}
    }
  },
  mounted() {},
  methods: {
    init(row) {
      this.activeInfo = row
      this.dialogActivateVisible = true
      this.findNotActiveStaff()
    },
    selectionTable(val) {
      this.innerTags = val
    },
    // 清空搜索条件
    resetSearch() {
      this.searchForm = {
        staffName: '',
        openJoinStatus: ''
      }
      this.findNotActiveStaff()
    },
    findNotActiveStaff() {
      const { corpId, merchantId } = this.activeInfo
      var params = {
        ...JSON.parse(JSON.stringify(this.searchForm)),
        corpId,
        merchantId
      }
      this.loading = true
      this.$apis.accountConfig.findNotActiveStaff(params).then(res => {
        if (res.code == 0) {
          this.tableActiveData = res.data
          this.loading = false
        } else {
          this.loading = false
          this.$message({
            message: res.message,
            type: 'error',
            customClass: 'global-messageZindex'
          })
        }
      })
    },
    handleNodeClick(data) {
      this.searchForm.department = data.departmentName
      this.currentTreeData = data
      this.onHidePopover()
    },
    remove(item) {
      this.$refs.activateTable.$refs.salelistMutiTable.toggleRowSelection(item)
    },
    rowClick(row) {
      this.$refs.activateTable.$refs.salelistMutiTable.toggleRowSelection(row)
    },
    // 激活员工
    activeStaff() {
      if (!this.innerTags.length) {
        this.$message({
          message: '未选中员工,无法激活',
          type: 'error',
          customClass: 'global-messageZindex'
        })
        return
      }
      var userIdList = []
      this.innerTags.forEach(item => {
        userIdList.push(item.userId)
      })
      const { merchantId, corpId } = this.activeInfo
      var params = {
        corpId,
        merchantId,
        userIdList
      }
      this.butLoading = true
      this.$apis.accountConfig.activeAccount(params).then(res => {
        if (res.code == '0') {
          this.butLoading = false
          this.dialogActivateVisible = false
          var txt = '<p>已激活&nbsp;' + `${res.data ? res.data : 0}` + '&nbsp;个</p>'
          this.$confirm(txt, '提示', {
            confirmButtonText: '我知道了',
            dangerouslyUseHTMLString: true,
            showCancelButton: false,
            confirmButtonClass: 'confirmbtn',
            type: 'success',
            customClass: 'gl-message-box confirm-btn',
            callback: action => {
              if (res.data && res.data > 0) {
                this.$emit('activeStaff')
              }
            }
          })
        } else {
          this.butLoading = false
          this.$message.error(res.message)
        }
      })
    },
    // 清空右侧选择员工
    clearStaff() {
      this.$refs.activateTable.$refs.salelistMutiTable.clearSelection()
      this.innerTags = []
    },
    // 关闭弹窗
    closeDia() {
      this.clearStaff()
      this.dialogActivateVisible = false
    }
  }
}
</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: 400;
    line-height: 22px;
    margin-bottom: 6px;
    span {
      display: inline-block;
      padding-left: 5px;
      font-size: 12px;
      color: #999;
      font-size: 500;
    }
  }
  .member-left {
    width: 70%;

    .member-content {
      border: 1px solid #eee;
      .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: 30%;
    margin-left: 14px;
    .member-context {
      display: flex;
      justify-content: space-between;
      padding: 11px 8px 11px 16px;
      border: 1px solid #eee;
      .member-name {
        font-size: 14px;
        color: #333;
        line-height: 20px;
      }
    }
  }
}
.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% - 72px);
  display: flex;
  align-items: center;
  max-height: 500px;
  overflow: auto;
  // margin-bottom: 10px;
  i {
    color: #75acff;
    margin-right: 3px;
    font-size: 14px;
  }
  /deep/ input {
    outline: none !important;
    border: none !important;
  }
  /deep/ .el-input {
    min-width: 150px;
    width: auto;
    flex: 1;
  }
  /deep/ .el-tag--info {
    background: #fafbfe;
    border-radius: 4px;
    border: 1px solid #e8e8ea;
  }
}
.el-tag {
  margin-right: 10px;
  line-height: 22px;
  margin-bottom: 5px;
  height: 24px;
}
.global-messageZindex {
  z-index: 3000 !important;
}
</style>