selectChannel.vue 4.73 KB
<template>
  <div class="square-main">
    <GLDialog title="选择渠道" :visible.sync="dialogVisible" @onOk="handleSelect" @onCancel="handleCancel" mode="big">
      <div class="square-tabel">
        <div class="square-tabel-select">
          <GLTable ref="table" :hasPage="false" :tableData="tableData" :tableTotal="tableTotal" :tableParams="tableParams" @refreshTable="handleSearch" @selectionTable="selectionTable"></GLTable>
        </div>
        <div class="square-tabel-selected">
          <div class="selected-title">已选渠道</div>
          <div class="selected-panel">
            <div class="selected-item" v-for="(item, index) in selectedList" :key="index">
              <div :title="item.codeName">
                <span :style="{ background: colorList[index] }"></span>
                {{ item.codeName }}
              </div>
              <img src="@/assets/img/channel/del.png" @click="delTag(item)" />
            </div>
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="handleCancel">取 消</el-button>
        <el-button size="small" type="primary" @click="handleSelect">确 定</el-button>
      </span>
    </GLDialog>
  </div>
</template>

<script>
import { utils } from 'glsx-common'
export default {
  name: 'selectEmp',
  data() {
    return {
      dialogVisible: false,
      tableSearchForm: {},
      tableParams: {
        listName: 'data',
        tableOption: false,
        // 行数据的key
        mutiSelectUniqueKey: 'id',
        // 多选ref的名称
        mutiSelectName: 'salelist',
        tableColumns: [
          {
            label: '渠道名称',
            prop: 'codeName'
          },
          {
            label: '备注',
            prop: 'codeRemark'
          }
        ]
      },
      tableData: [],
      tableTotal: 0,
      selectItem: [],
      selectCode: [],
      selectedList: []
    }
  },
  props: {
    colorList: {
      type: Array
    }
  },
  methods: {
    getFollower() {
      var params = {
        pageSize: 1000,
        pageNum: 1
      }
      this.$apis.channel.listChannelCodeByPage(params).then(res => {
        console.log(res)
        this.tableData = res.data
        this.tableTotal = res.count
        this.tableData.forEach(item => {
          this.selectCode.forEach((itm, index) => {
            if (itm.codeState == item.codeState) {
              this.$refs.table.$refs.salelistMutiTable.toggleRowSelection(item)
            }
          })
        })
      })
    },
    init(codeId) {
      this.selectCode = JSON.parse(JSON.stringify(codeId))
      this.selectedList = []
      this.dialogVisible = true
      this.$nextTick(() => {
        this.getFollower()
      })
    },
    handleSearch() {
      this.getFollower()
    },
    selectionTable(val) {
      this.selectedList = val
    },
    delTag(item) {
      this.$refs.table.$refs.salelistMutiTable.toggleRowSelection(item)
    },
    handleCancel() {
      this.dialogVisible = false
      this.$refs.table.$refs.salelistMutiTable.clearSelection()
    },
    handleSelect: utils.debounce(function() {
      if (this.selectedList.length == 0) {
        this.$message.error('请选择渠道')
        return
      }
      if (this.selectedList.length > 8) {
        this.$message.error('最多选择8个渠道数据')
        return
      }
      this.dialogVisible = false
      this.$emit('selectTable', this.selectedList)
      this.$refs.table.$refs.salelistMutiTable.clearSelection()
    }, 300)
  }
}
</script>

<style lang="scss" scoped>
.square-main {
  .square-tabel {
    display: flex;
    &-select {
      flex: 1;
    }
    &-selected {
      width: 320px;
      margin-left: 20px;
      .selected-title {
        background: #f4f6fc;
        color: #333333;
        line-height: 20px;
        padding: 16px 20px;
        font-weight: 600;
      }
      .selected-panel {
        padding: 0px 20px;
        .selected-item {
          font-size: 14px;
          font-weight: 400;
          color: #333333;
          line-height: 30px;
          display: flex;
          align-items: center;
          justify-content: space-between;
          div {
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
          }
          span {
            vertical-align: middle;
            display: inline-block;
            width: 12px;
            height: 2px;
            margin-right: 10px;
          }
          img {
            width: 16px;
            height: 16px;
            cursor: pointer;
          }
        }
      }
    }
  }
  /deep/ {
    .el-table {
      height: 50vh;
      overflow-y: auto;
    }
    .el-table::before {
      left: 0;
      bottom: 0;
      width: 100%;
      height: 0px;
    }
  }
}
</style>