copyPerformanceDialog.vue 7.35 KB
<!-- 复制绩效方案弹窗 -->
<template>
  <div>
    <d2-dialog title="复制绩效方案"
              :is-visible.sync="copyPerformanceVisible"
              width="70%"
              btn-ok-label="确定"
              @confirmDialog="handleConfirm"
              @closeDialog="handleCancel"
              class="carSeries">
      <slot />
      <el-row class="tableCon">
        <div class="tableBox">
          <el-table ref="seletingTable"
                    :data="selectingData"
                    height="320px"
                    class="table"
                    border
                    @select="handleChange"
                    @select-all="handleAll">
            <el-table-column type="selection" :selectable="selectable" width="55" align="center" />
            <el-table-column label="序号"
                                     align="center"
                                     type="index"
                                     width="55" />
            <el-table-column
              prop="merchantName"
              label="门店名称"
              :show-overflow-tooltip="true"
              align="center">
            </el-table-column>
            <el-table-column 
              prop="merchantId"
              label="商户号"
              :show-overflow-tooltip="true"
              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="selectedBox">
          <div class="title">
            <div class="title_txt">已选</div>
            <div class="title_btn" @click="clearSelect">清空</div>
          </div>
          <div class="content">
            <div class="item" v-for="(subItem, subIdx) in selectedData" :key="subIdx">
              <div class="item_txt"><span>{{ `${subItem.merchantName}${subItem.merchantId}` }}</span></div>
              <div class="del_item" @click="delItem(subItem)"><i class="el-icon-error"></i></div>
            </div>
          </div>
        </div>
      </el-row>
    </d2-dialog>
  </div>
</template>
<script>
import { deepClone } from '@/common/util'
export default {
  name: 'CarSeriesDialog',
  data() {
    return {
      selectedData: [],
      selectingData: [],
      // 分页
      total: 0,
      currentPage: 1,
      pageSize: 10,
      curId: '',
      isVisible: false
    }
  },

  props: {
    copyPerformanceVisible: {
      type: Boolean,
      default: false
    },
    performanceMerchantApi: {
      type: Function,
      default: () => { }
    },
    performanceMerchantSearchForm: {
      type: Object,
      default: () => { }
    },
    copySelectedData: {
      type: Object,
      default: () => {}
    }
  },

  mounted() {
    this.getSelectingList()
  },

  methods: {
    selectable(row) {
      if (row.merchantId == this.copySelectedData?.merchantId) {
        return false
      } else {
        return true
      }
    },

    getSelectingList() {
      let params = deepClone(this.performanceMerchantSearchForm)
      this.performanceMerchantApi({
        ...params,
        currentPage: this.currentPage,
        pageSize: this.pageSize
      }).then(res => {
        this.selectingData = res.list || []
        this.total = res.total
        this.$nextTick(() => {
          this.recoverySelection()
        })
      })
    },
    recoverySelection() {
      var exitIds = this.selectedData.map((item) => item.merchantId)
      this.selectingData.forEach((item) => {
        exitIds.includes(item.merchantId) &&
          this.$refs.seletingTable.toggleRowSelection(item, true)
      })
    },
    handleChange(selection, row) {
      var addOrDelete = !!selection.find(
        (item) => item.merchantId === row.merchantId
      )
      addOrDelete
        ? this.selectedData.push(row)
        : (this.selectedData = this.selectedData.filter(
          (item) => item.merchantId !== row.merchantId
        ))
    },
    handleAll(selection) {
      this.selectingData.forEach((item) => {
        var isExit = this.selectedData.findIndex(
          (subItem) => subItem.merchantId === item.merchantId
        )
        if (selection.length && isExit === -1 && item.merchantId != this.copySelectedData?.merchantId) {
          this.selectedData.push(item)
        } else if (!selection.length && isExit !== -1) {
          this.selectedData.splice(isExit, 1)
        }
      })
    },
    clearSelect() {
      this.selectedData = []
      this.$refs.seletingTable.clearSelection()
    },
    delItem(row) {
      this.selectedData = this.selectedData.filter(item => item.merchantId !== row.merchantId)
      const obj = this.selectingData.find(v => v.merchantId == row.merchantId)
      if (obj) this.$refs.seletingTable.toggleRowSelection(obj)
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.getSelectingList()
    },
    handleConfirm() {
      if (!this.selectedData?.length) return this.$message.warning('请选择门店')
      if (this.selectedData?.length > 10) return this.$message.warning('最多选择十家门店')
      this.$emit('handleConfirm', this.selectedData)
    },
    handleCancel() {
      this.$emit('handleCancel')
    }
  }
}

</script>
<style lang="scss" scoped>
.carSeries .table {
  margin: 0 auto 20px !important;
  width: 100%;
}
.carSeries .tableCon {
  margin-top: 20px;
  display: flex;
  .tableBox {
    flex: 2;
  }
  .selectedBox{
    flex: 1;
    height: 320px;
    border: 1px solid #E5E5E5;
    margin-left: 10px;
    .title{
      height: 38px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 8px 0 16px;
      border-bottom: 1px solid #E5E5E5;
      .title_txt{
        font-size: 16px;
        font-weight: 600;
        color: #333333;
      }
      .title_btn{
        cursor: pointer;
        font-size: 14px;
        color: #185EFE;
      }
    }
    .content{
      padding: 16px 10px;
      height: calc(100% - 75px);
      overflow-y: scroll;
      .item{
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 32px;
        color: #666666;
        padding: 0 8px;
        .del_item{
          cursor: pointer;
        }
      }
      .item:hover{
        background: #F6F9FF;
      }
    }
  }
}
.service-service .carSeries .el-table .cell,
.d2-form .carSeries .el-table .cell {
  line-height: 26px !important;
}
.service-service .carSeries .el-table--medium td,
.d2-form .carSeries .el-table--medium td {
  padding: 6px 8px !important;
}
.carSeries .red {
  color: red;
}
.carSeries .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;
}
.text_hide{
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
::v-deep .text_hide p{
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin: 0;
}
::v-deep .el-radio__original {
  display: none !important;
}

::v-deep .el-radio:focus:not(.is-focus):not(:active):not(.is-disabled)
  .el-radio__inner {
  box-shadow: none !important;
}
</style>