relateStoreDialog.vue 6.36 KB
<!-- 关联门店弹窗 -->
<template>
  <GLDialog title="关联门店" :visible.sync="relateStoreVisible" okText="关联" @onOk="handleRelateStoreConfirm" @onCancel="handleRelateStoreClose" class="relateStore">
    <slot />
    <el-row class="tableCon">
      <!-- <el-col :span="12"> -->
      <div class="tableBox">
        <el-table ref="seletingTable" :data="selectingData" height="464px" class="table" border @select="handleChange" @select-all="handleAll">
          <el-table-column type="selection" width="55" align="center" :selectable="selectable" />
          <el-table-column v-if="sourcePage != 'serviceStore'" prop="yqMerchantName" label="园区店名称" align="center">
            <template slot-scope="scope">
              <span :class="{ red: !scope.row.isSetUpgradeSettleRule && needTip.includes(sourcePage) }">{{ scope.row.yqMerchantName }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="merchantName" label="4S店名称" align="center">
            <template slot-scope="scope">
              <span :class="{ red: !scope.row.isSetUpgradeSettleRule && needTip.includes(sourcePage) }">{{ scope.row.merchantName }}</span>
              <el-tooltip v-if="!scope.row.isSetUpgradeSettleRule" popper-class="tooltip-class" effect="dark" content="该门店无配置财务分润规则,无法关联!" placement="top">
                <span v-if="!scope.row.isSetUpgradeSettleRule && needTip.includes(sourcePage)" class="tip-icon">?</span>
              </el-tooltip>
            </template>
          </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>
      <!-- </el-col> -->
      <!-- <el-col :span="12"> -->
      <el-table :data="selectedData" class="table tableBox" border height="464px">
        <el-table-column v-if="sourcePage != 'serviceStore'" prop="yqMerchantName" label="园区店名称" align="center" />
        <el-table-column prop="merchantName" label="4S店名称" align="center" />
        <el-table-column label="删除" align="center" width="50px">
          <template slot-scope="scope">
            <el-button class="el-icon-delete" @click="handleDelete(scope.row)" type="text" />
          </template>
        </el-table-column>
      </el-table>
      <!-- </el-col> -->
    </el-row>
  </GLDialog>
</template>

<script>
export default {
  name: 'RelateStoreDialog',
  data() {
    return {
      selectedData: [],
      selectingData: [],
      needTip: ['editProduct'],
      // 分页
      total: 0,
      currentPage: 1,
      pageSize: 20
    }
  },

  props: {
    relateStoreVisible: {
      type: Boolean,
      default: false
    },
    // 页面来源
    sourcePage: {
      type: String,
      default: ''
    },
    storeApi: {
      type: Function,
      default: () => {}
    },
    storeSelected: {
      type: Array,
      default: () => []
    },
    storeSearchForm: {
      type: Object,
      default: () => {}
    }
    // 去掉表格中某些字段
    // noTableField: {
    //   type: Array,
    //   default: () => []
    // }
  },

  mounted() {
    this.selectedData = this.storeSelected
    this.getSelectingList()
  },

  methods: {
    selectable(row, index) {
      var isSelect = row.hasOwnProperty('beServed') ? !row.beServed : true
      if (this.sourcePage === 'editProduct') {
        // 不能选的判断
        // console.log('??')
        isSelect = row.isSetUpgradeSettleRule
      }
      return isSelect
    },
    recoverySelection() {
      var exitIds = this.selectedData.map(item => item.merchantId)
      this.selectingData.forEach(item => {
        exitIds.includes(item.merchantId) && this.$refs.seletingTable.toggleRowSelection(item, true)
      })
    },
    getSelectingList() {
      this.storeApi({
        ...this.storeSearchForm,
        currentPage: this.currentPage,
        pageSize: this.pageSize
      }).then(res => {
        res.list = res.list.map(item => {
          let yqMerchant = item?.sceneList[0]?.yqMerchant || {}
          // console.log(yqMerchant)
          item = {
            yqMerchantName: yqMerchant?.merchantName,
            yqMerchantId: yqMerchant?.merchantId,
            ...item
          }
          return item
        })
        this.selectingData = res.list
        this.total = res.total
        this.$nextTick(() => {
          this.recoverySelection()
        })
      })
    },
    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)
        var isServed = item.hasOwnProperty('beServed') ? item.beServed : false
        if (selection.length && isExit === -1 && !isServed) {
          this.selectedData.push(item)
        } else if (!selection.length && isExit !== -1) {
          this.selectedData.splice(isExit, 1)
        }
      })
    },
    handleDelete(row) {
      this.selectedData = this.selectedData.filter(item => item.merchantId !== row.merchantId)
      this.$refs.seletingTable.toggleRowSelection(row)
    },
    handleCurrentChange(val) {
      this.currentPage = 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 {
  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>