index.vue 6.09 KB
<!-- 关联门店弹窗 -->
<template>
  <d2-dialog title="选择车型" :is-visible.sync="relateStoreVisible" width="1075px" btn-ok-label="确定" @confirmDialog="handleRelateStoreConfirm" @closeDialog="handleRelateStoreClose" class="relateStore">
    <el-form :model="storeSearchForm" ref="relate" :inline="true">
      <el-form-item label="品牌名称:">
        <el-input v-model.trim="storeSearchForm.brandName" placeholder="品牌名称" max-length="20" @keydown.native="handleStoreInput" clearable />
      </el-form-item>
      <el-form-item label="子品牌名称:">
        <el-input v-model.trim="storeSearchForm.childName" placeholder="子品牌名称" max-length="20" @keydown.native="handleStoreInput" clearable />
      </el-form-item>
      <el-form-item label="车系名称:">
        <el-input v-model.trim="storeSearchForm.seriesName" placeholder="车系名称" max-length="20" @keydown.native="handleStoreInput" clearable />
      </el-form-item>
      <el-button type="primary" @click="handleCurrentChange(1)">搜索</el-button>
    </el-form>
    <div class="tableCon">
      <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" />
          <el-table-column label="序号" type="index" width="70" align="center"></el-table-column>
          <el-table-column prop="brandName" label="品牌名称" align="center"></el-table-column>
          <el-table-column prop="childName" label="子品牌名称" align="center"></el-table-column>
          <el-table-column prop="vehicleSeriesName" label="车系名称" align="center"></el-table-column>
        </el-table>
        <el-pagination class="pagination" small background @current-change="handleCurrentChange" :current-page.sync="currentPage" :page-size="pageSize" layout="total, prev, pager, next" :total="total" />
      </div>
      <div class="tableRight">
        <el-table :data="selectedData" border height="464px">
          <el-table-column prop="brandName" label="品牌名称" align="center"></el-table-column>
          <el-table-column prop="childName" label="子品牌名称" align="center"></el-table-column>
          <el-table-column prop="vehicleSeriesName" label="车系名称" align="center"></el-table-column>
          <el-table-column label="删除" align="center" width="80px">
            <template slot-scope="scope">
              <el-button class="el-icon-delete" @click="handleDelete(scope.row)" type="text" />
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </d2-dialog>
</template>

<script>
// import { getBrandList } from "@api/contentManager"
import D2Dialog from '@/components/d2-dialog'
export default {
  name: 'RelateStoreDialog',
  components: {
    D2Dialog
  },
  data() {
    return {
      selectedData: [],
      selectingData: [],
      // 分页
      total: 0,
      currentPage: 1,
      pageSize: 20,
      storeSearchForm: {
        brandName: '',
        childName: '',
        seriesName: ''
      }
    }
  },

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

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

  methods: {
    recoverySelection() {
      var exitIds = this.selectedData.map(item => item.vehicleSeriesId)
      this.selectingData.forEach(item => {
        exitIds.includes(item.vehicleSeriesId) && this.$refs.seletingTable.toggleRowSelection(item, true)
      })
    },
    getSelectingList() {
      this.$apis.serviceConfig
        .carSeriesPage({
          ...this.storeSearchForm,
          currentPage: this.currentPage,
          pageSize: this.pageSize
        })
        .then(res => {
          this.selectingData = res.list.map(item => {
            item.vehicleSeriesId = item.seriesId
            item.vehicleSeriesName = item.seriesName
            return item
          })
          this.total = res.total
          this.$nextTick(() => {
            this.recoverySelection()
          })
        })
    },
    handleChange(selection, row) {
      var addOrDelete = !!selection.find(item => item.vehicleSeriesId === row.vehicleSeriesId)
      addOrDelete ? this.selectedData.push(row) : (this.selectedData = this.selectedData.filter(item => item.vehicleSeriesId !== row.vehicleSeriesId))
    },
    handleAll(selection) {
      this.selectingData.forEach(item => {
        var isExit = this.selectedData.findIndex(subItem => subItem.vehicleSeriesId === item.vehicleSeriesId)
        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.vehicleSeriesId !== row.vehicleSeriesId)
      const obj = this.selectingData.find(v => v.vehicleSeriesId == row.vehicleSeriesId)
      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" scoped >
.relateStore .table {
  margin: 0 auto 20px !important;
}
.tableCon {
  width: 100%;
  margin-top: 20px;
  display: flex;
  justify-content: space-between;
  .tableBox {
    // flex: 1;
    width: 500px !important;
  }
  .tableRight {
    box-sizing: border-box;
    // flex: 1;
    width: 500px !important;
    // margin-left: 35px;
    // width: 300px !important;
  }
}
.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;
}
</style>