relateStoreDialog.vue 3.06 KB
<!-- 关联门店弹窗 -->
<template>
  <d2-dialog
    title="关联门店"
    :isVisible.sync="relateStoreVisible"
    width="70%"
    btnOkLabel="关联"
    @closeDialog="handleRelateStoreClose"
    class="relateStore"
  >
    <el-row>
      <el-col :span="12">
        <el-table
          ref="seletingTable"
          :data="selectingData"
          height="500px"
          class="table"
          border
          @select="handleChange"
          @select-all="handleAll"
        >
          <el-table-column
            type="selection"
            width="55"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="confValue"
            label="门店名称"
          ></el-table-column>
        </el-table>
        <el-pagination
          small
          background
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="10"
          layout="total, prev, pager, next"
          :total="total"
        ></el-pagination>
      </el-col>
      <el-col :span="12">
        <el-table
          :data="selectedData"
          class="table"
          border
          height="500px"
        >
          <el-table-column
            prop="confValue"
            label="门店名称"
          ></el-table-column>
        </el-table>
      </el-col>
    </el-row>
  </d2-dialog>
</template>

<script>
export default {
  name: 'relateStoreDialog',
  data() {
    return {
      selectedData: [],
      selectingData: [{
        confId: 1,
        confValue: '广州上策贸易有限公司'
      }, {
        confId: 2,
        confValue: '广州上策贸易有限公司2'
      }, {
        confId: 3,
        confValue: '广州上策贸易有限公司3'
      }, {
        confId: 4,
        confValue: '广州上策贸易有限公司4'
      }],
      // 分页
      total: 100,
      currentPage: 1
    }
  },

  props: {
    relateStoreVisible: {
      type: Boolean,
      default: false
    }
  },

  mounted() { },

  methods: {
    handleChange(selection, row) {
      var addOrDelete = !!selection.find(item => item.confId === row.confId)
      addOrDelete
        ? this.selectedData.push(row)
        : (this.selectedData = this.selectedData.filter(item => item.confId !== row.confId))
    },
    handleAll(selection) {
      this.selectingData.forEach(item => {
        var isExit = this.selectedData.findIndex(subItem => subItem.confId === item.confId)
        if (selection.length && (isExit === -1)) {
          this.selectedData.push(item)
        } else if (!selection.length && (isExit !== -1)) {
          this.selectedData.splice(isExit, 1)
        }
      })
    },
    handleCurrentChange(val) {
      this.currentPage = val
      console.log(this.currentPage)
      // 调接口
    },
    handleRelateStoreClose() {
      this.$emit('handleRelateStoreClose')
    }
  }
}

</script>
<style>
.relateStore .table {
  margin: 0 auto 20px !important;
  width: 98%;
}
.relateStore .el-table .cell {
  line-height: 20px !important;
}
.relateStore .el-table .cell {
  padding: 0 8px !important;
}
</style>