tableDialog.vue 5.12 KB
<!-- 关联门店弹窗 -->
<template>
  <d2-dialog :title="title" :noCancel="true" :is-visible.sync="relateStoreVisible" width="50%" btn-ok-label="确定"
    @confirmDialog="handleRelateStoreConfirm" @closeDialog="handleRelateStoreClose" class="relateStore">
    <slot />
    <el-row class="tableCon">
      <div class="tableBox">
        <!--  height="300px" -->
        <el-table ref="seletingTable" :data="selectingData" class="table" border
          v-loading="$store.state.d2admin.loading.value" height="300px">
          <el-table-column label="序号" type="index" align="center" width="60">
            <template slot-scope="scope">{{ scope.$index + 1 }}</template>
          </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>
        <!-- <el-pagination small background @current-change="handleCurrentChange" :current-page.sync="pageNum"
          :page-size="pageSize" layout="total, prev, pager, next" :total="total" /> -->
      </div>
    </el-row>
  </d2-dialog>
</template>

<script>
export default {
  name: "SelectEmployees",
  data() {
    return {
      selectedData: [],
      selectingData: [],
      // 分页
      total: 0,
      pageNum: 1,
      pageSize: 10
    }
  },

  props: {
    title: {
      type: String,
      default: "驻店员工"
    },
    relateStoreVisible: {
      type: Boolean,
      default: false
    },
    storeApi: {
      type: Function,
      default: () => { }
    },
    storeSelected: {
      type: Array,
      default: () => []
    },
    storeSearchForm: {
      type: Object,
      default: () => { }
    },
    merchantIds: {
      type: Array,
      default: () => []
    }
  },

  mounted() {
    this.selectedData = this.storeSelected
    this.getSelectingList()
    console.log(this.selectedData, "---------")
  },

  methods: {
    recoverySelection() {
      var exitIds = this.selectedData.map((item) => item.staffUuid)
      this.selectingData.forEach((item) => {
        exitIds.includes(item.staffUuid) &&
          this.$refs.seletingTable.toggleRowSelection(item, true)
      })
    },
    getSelectingList() {
      console.log(this.storeSearchForm, "this.storeSearchForm")
      this.storeApi({
        ...this.storeSearchForm,
        pageNum: this.pageNum,
        pageSize: this.pageSize
        // merchantNoList: this.merchantIds
      }).then((res) => {
        // res?.forEach((val) => {
        // 账户中心门店返回商户号字段是merchantNo
        //   if (val.merchantNo) val.merchantId = Number(val.merchantNo)
        //   val?.sceneList?.forEach((subVal) => {
        //     if (subVal.scene == this.selectedScene) {
        //       val.yqMerchantId = subVal?.yqMerchant?.merchantId || "-"
        //       val.yqMerchantName = subVal?.yqMerchant?.merchantName || "-"
        //     }
        //   })
        // })
        this.selectingData = res.list
        this.total = res.total
        this.$nextTick(() => {
          this.recoverySelection()
        })
      })
    },
    handleChange(selection, row) {
      var addOrDelete = !!selection.find(
        (item) => item.staffUuid === row.staffUuid
      )
      addOrDelete
        ? this.selectedData.push(row)
        : (this.selectedData = this.selectedData.filter(
          (item) => item.staffUuid !== row.staffUuid
        ))
    },
    handleAll(selection) {
      this.selectingData.forEach((item) => {
        var isExit = this.selectedData.findIndex(
          (subItem) => subItem.staffUuid === item.staffUuid
        )
        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.staffUuid !== row.staffUuid
      )
      const obj = this.selectingData.find((v) => v.staffUuid == row.staffUuid)
      this.$refs.seletingTable.toggleRowSelection(obj)
    },
    handleCurrentChange(val) {
      this.pageNum = val
      this.getSelectingList()
    },
    handleRelateStoreConfirm() {
      this.$emit("handleRelateStoreConfirm", this.selectedData)
    },
    handleRelateStoreClose() {
      this.$emit("handleRelateStoreClose")
    }
  }
}
</script>
<style lang="scss">
.relateStore .table {
  margin: 0 auto 20px !important;
  width: 98%;
}

.relateStore .tableCon {
  margin-top: 20px;
  display: flex;

  .tableBox {
    flex: 1;
  }
}

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

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

.relateStore .red {
  color: red;
}

.relateStore .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>