index.vue 6.87 KB
<!-- 关联门店弹窗 -->
<template>
  <d2-dialog title="选择员工" :is-visible.sync="relateStoreVisible" width="1280px" btn-ok-label="确定"
    @confirmDialog="handleRelateStoreConfirm" @closeDialog="handleRelateStoreClose" class="relateEmp">
    <el-row class="tableCon">
      <div class="tableBox">
        <div class="tableHeader">选择员工</div>
        <div class="tableBody">
          <el-form :model="storeSearchForm" ref="relate" :inline="true">
            <el-form-item label="员工名称:">
              <el-input v-model.trim="storeSearchForm.staffName" placeholder="请输入员工名称" max-length="20" clearable />
            </el-form-item>
            <el-form-item label="员工手机号:">
              <el-input v-model.trim="storeSearchForm.staffPhone" placeholder="请输入手机号" max-length="11" type="number"
                clearable />
            </el-form-item>
            <div class="text-align: right;">
              <el-button type="primary" @click="handleCurrentChange(1)">搜索</el-button>
            </div>
          </el-form>
        </div>
        <el-table ref="seletingTable" :data="selectingData" height="264px" class="table" border @select="handleChange"
          @select-all="handleAll">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column prop="staffName" label="员工名称" align="center">
          </el-table-column>
          <el-table-column prop="staffPhone" label="手机号" align="center">
          </el-table-column>
        </el-table>
        <el-pagination small background @current-change="handleCurrentChange" :current-page.sync="currentPage"
          :page-size="pageSize" layout="total, prev, pager, next" :total="total" />
      </div>
      <div class="tableBox">
        <div class="tableHeader">
          已选员工
          <a @click="handleClear" class="clear-btn"> 清空 </a>
        </div>
        <div class="tableBody">
          <el-table class="table" :data="selectedData" border height="364px">
            <el-table-column type="index" label="序号" width="50">
            </el-table-column>
            <el-table-column prop="staffName" label="员工名称" align="center">
            </el-table-column>
            <el-table-column prop="staffPhone" label="手机号" align="center">
            </el-table-column>
            <el-table-column label="操作" align="center" width="50px">
              <template slot-scope="scope">
                <el-button @click="handleDelete(scope.row)" type="text">
                  删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </el-row>
  </d2-dialog>
</template>

<script>
import { staffBaseInfoPageList } from "@api/contentManager"
export default {
  name: "RelateStoreDialog",
  data() {
    return {
      selectedData: [],
      selectingData: [],
      // 分页
      total: 0,
      currentPage: 1,
      pageSize: 20,
      storeSearchForm: {}
    }
  },

  props: {
    relateStoreVisible: {
      type: Boolean,
      default: false
    },
    storeSelected: {
      type: Array,
      default: () => []
    }
  },

  mounted() { },
  watch: {
    relateStoreVisible: {
      handler(val) {
        if (val) {
          this.selectedData = this.storeSelected
          console.log(this.selectedData, "---------")
          this.recoverySelection()
        }
      },
      deep: true
    }
  },
  methods: {
    handleDelete(row) {
      this.selectedData = this.selectedData.filter((item) => item.id !== row.id)
      const obj = this.selectingData.find((v) => v.id == row.id)
      this.$refs.seletingTable.toggleRowSelection(obj)
    },
    handleClear() {
      this.selectedData = []
      this.$refs.seletingTable.clearSelection()
    },
    recoverySelection() {
      var exitIds = this.selectedData.map((item) => item.id)
      this.selectingData.forEach((item) => {
        exitIds.includes(item.id) &&
          this.$refs.seletingTable &&
          this.$refs.seletingTable.toggleRowSelection(item, true)
      })
    },
    getSelectingList() {
      staffBaseInfoPageList({
        ...this.storeSearchForm,
        currentPage: this.currentPage,
        pageSize: this.pageSize
      }).then((res) => {
        this.selectingData = res.list
        this.total = res.total
        this.$nextTick(() => {
          this.recoverySelection()
        })
      })
    },
    handleChange(selection, row) {
      var addOrDelete = !!selection.find((item) => item.id === row.id)
      addOrDelete
        ? this.selectedData.push(row)
        : (this.selectedData = this.selectedData.filter(
          (item) => item.id !== row.id
        ))
    },
    handleAll(selection) {
      this.selectingData.forEach((item) => {
        var isExit = this.selectedData.findIndex(
          (subItem) => subItem.id === item.id
        )
        if (selection.length && isExit === -1) {
          this.selectedData.push(item)
        } else if (!selection.length && isExit !== -1) {
          this.selectedData.splice(isExit, 1)
        }
      })
    },
    handleDelete(row) {
      this.selectedData = this.selectedData.filter((item) => item.id !== row.id)
      const obj = this.selectingData.find((v) => v.id == row.id)
      if (obj) this.$refs.seletingTable.toggleRowSelection(obj)
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.getSelectingList()
    },
    handleRelateStoreConfirm() {
      this.$emit("handleRelateStoreConfirm", this.selectedData)
    },
    handleRelateStoreClose() {
      this.$emit("handleRelateStoreClose")
    }
  }
}
</script>
<style lang="scss">
.relateEmp .tableCon {
  display: flex;
  gap: 10px;

  .tableBox {
    width: calc(50% - 10px);
    border: 1px solid #e5e5e5;

    .tableHeader {
      opacity: 1;
      background: #f5f5f5;
      padding: 10px 16px;
      color: #333333;
      display: flex;
      font-size: 14px;
      justify-content: space-between;

      .clear-btn {
        color: #409eff;
        cursor: pointer;
      }
    }

    .tableBody {
      padding: 16px;

      .tab-box {
        margin-bottom: -20px;

        .el-tabs__nav-wrap {
          &::after {
            display: none;
          }
        }
      }

      .el-input {
        width: 170px;
      }

      .el-range-editor--medium.el-input__inner {
        width: 300px !important;
      }
    }
  }
}

.service-store .relateEmp .el-table .cell,
.d2-form .relateEmp .el-table .cell {
  line-height: 26px !important;
}

.service-store .relateEmp .el-table--medium td,
.d2-form .relateEmp .el-table--medium td {
  padding: 6px 8px !important;
}

.relateEmp .red {
  color: red;
}

.relateEmp .tip-icon {
  position: absolute;
  display: inline-block;
  height: 10px;
  width: 10px;
  line-height: 10px;
  color: #ffffff;
  background-color: red;
  border: 1px solid red;
  border-radius: 50%;
  cursor: pointer;
  font-size: 6px;
  margin-left: 2px;
}
</style>