selectCrowd.vue 7.27 KB
<!--
 * @Description: 
 * @Author: huyue
 * @Date: 2022-05-24 18:18:53
 * @LastEditors: huyue
 * @LastEditTime: 2022-06-09 17:55:40
-->
<template>
  <div>
    <el-dialog :title="'人群筛选'" :visible.sync="crowdVisible">
      <div class="member-wrapper">
        <div class="member-left">
          <div class="member-title">
            人群列表
          </div>
          <div class="member-content">
            <el-form :inline="true" class="member-form" :model="searchForm" @submit.native.prevent>
              <el-form-item label="人群名称" style="margin-bottom: 0" size="small">
                <el-input :size="size" v-model.trim="searchForm.keyword" @keyup.enter.native="search" clearable
                  placeholder="请输入关键字搜索"></el-input>
              </el-form-item>
              <el-form-item label style="margin-bottom: 0;margin-left:10px" size="small">
                <el-button type="primary" :size="size" @click="search">搜索</el-button>
              </el-form-item>
            </el-form>
            <div class="table-content">
              <GLTable v-loading="loading" ref="crowdTable" :tableData="tableData" @refreshTable="search"
                :tableTotal="tableTotal" :layout="layout" :tableParams="crowdTableParams" :hasNum="true"
                :pageConf="pageConf" :noDataImg="url" @selectionTable="selectionTable" @row-click="rowClick"></GLTable>
            </div>
          </div>
        </div>
        <div class="member-right">
          <div class="member-title">已选</div>
          <div class="member-name">人群({{ innerTags.length }}项)</div>
          <div class="input-tag-wrapper">
            <div class="tag-box">
              <el-tag v-for="(tag, idx) in innerTags" :key="idx" type="info" closable :disable-transitions="false"
                @close="remove(tag)">
                {{ tag.crowdName }}
              </el-tag>
            </div>
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="crowdVisible = false">取 消</el-button>
        <el-button size="small" type="primary" @click.native="handleConfirm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
// import url from '@/assets/empty.png'
export default {
  name: 'SelectCrowd',
  data() {
    return {
      url: 0,
      crowdVisible: false,
      searchForm: { keyword: '' },
      innerTags: [],
      inner: [],
      tableCrowdData: [
        {
          name: 'asda'
        }
      ],
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
      layout: 'sizes, prev, pager, next, jumper, ->, total',
      tableData: [],
      tableTotal: 0,
      crowdTableParams: {
        checkSelectKey: 'id',
        checkSelectVal: [],
        hasNum: false,
        listName: 'crowdUnitList',
        // 行数据的key
        mutiSelectUniqueKey: 'crowdId',
        // 多选ref的名称
        mutiSelectName: 'crowdlist',
        tableColumns: [
          {
            label: '人群名称',
            prop: 'crowdName'
          },
          {
            label: '人群描述',
            prop: 'crowdDesc'
          },
          {
            label: '人数',
            prop: 'total'
          }
        ]
      }
    }
  },
  methods: {
    init(val) {
      console.log(val)
      this.inner = this.$common.utils.deepClone(val)
      this.innerTags = this.$common.utils.deepClone(val)
      this.crowdVisible = true
      this.searchForm.keyword = ''
      this.$nextTick(() => {
        this.$refs.crowdTable.$refs.crowdlistMutiTable.clearSelection()
        this.$refs.crowdTable.page.pageNum = 1
        this.getCrowdList()
      })
    },
    getCrowdList() {
      var params = {
        req: {
          keyword: this.searchForm.keyword,
          merchantId: this.$globalState.session.merchantId,
          crowdType: 3,
          filterType: 2,
          pageSize: this.$refs.crowdTable.page.pageSize,
          pageNum: this.$refs.crowdTable.page.pageNum
        }
      }
      this.$apis.customerTransform.queryCrowdtree(params).then(res => {
        this.tableData = res.crowdUnitList
        this.tableTotal = res.total
        console.log(this.inner)
        console.log(this.tableData)
        this.tableData.forEach(item => {
          this.inner.forEach((itm, index) => {
            if (itm.crowdId == item.crowdId) {
              this.rowClick(item)
            }
          })
        })
      })
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        Object.assign(this.searchForm.req, {})
        resolve()
      })
    },
    selectionTable(val) {
      this.innerTags = []
      for (let i = 0; i < val.length; i++) {
        console.log(i)
        const tagArr = this.innerTags.map(item => item.crowdId)
        if (!tagArr.includes(val[i].crowdId)) {
          this.innerTags.push(val[i])
        }
      }
    },
    remove(item) {
      this.$refs.crowdTable.$refs.crowdlistMutiTable.toggleRowSelection(item)
    },
    rowClick(row) {
      console.log(this.$refs.crowdTable)
      this.$refs.crowdTable.$refs.crowdlistMutiTable.toggleRowSelection(row)
    },
    search() {
      this.getCrowdList()
    },
    handleConfirm() {
      this.$emit('crowdData', this.innerTags)
      this.crowdVisible = false
      this.searchForm = { req: {} }
    }
  }
}
</script>

<style lang="scss" scoped>
.member-wrapper {
  display: flex;

  .member-title {
    font-size: 16px;
    color: #333;
    font-weight: 600;
    line-height: 22px;
    margin-bottom: 6px;

    span {
      display: inline-block;
      padding-left: 5px;
      font-size: 12px;
      color: #999;
      font-weight: 500;
    }
  }

  .member-left {
    width: 800px;

    .member-content {
      border: 1px solid #eee;
      padding-bottom: 20px;

      /deep/ {
        .el-table {
          height: 40vh;
          overflow-y: auto;
        }
      }

      .member-form {
        padding: 10px 20px;
      }

      .table-content {
        max-height: 456px;
        overflow: auto;
        border-top: 1px solid #eee;
      }
    }

    .member-checked {
      text-align: right;
      margin-top: 10px;
    }
  }

  .member-right {
    width: 286px;
    margin-left: 14px;

    .member-name {
      font-size: 14px;
      color: #333;
      line-height: 20px;
      padding: 18px;
      border: 1px solid #eee;
    }
  }
}

.tag-box {
  height: 100%;
  width: 100%;
}

.input-tag-wrapper {
  position: relative;
  font-size: 14px;
  border: 1px solid #eee;
  border-top: none;
  box-sizing: border-box;
  color: #606266;
  display: inline-block;
  padding: 8px 10px;
  line-height: 32px;
  transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  width: 100%;
  height: calc(100% - 86px);
  display: flex;
  align-items: center;
  max-height: 500px;
  overflow: auto;

  // margin-bottom: 10px;
  i {
    color: #75acff;
    margin-right: 3px;
    font-size: 14px;
  }

  /deep/ input {
    /* input { */
    /* background-color: red!important;  调试用的样式 */
    outline: none !important;
    border: none !important;
  }

  /deep/ .el-input {
    min-width: 150px;
    width: auto;
    flex: 1;
  }
}

.el-tag {
  margin-right: 10px;
  line-height: 22px;
  margin-bottom: 5px;
  height: 24px;
  background: #fafbfe !important;
}

/deep/.el-dialog__title {
  font-weight: 600;
}
</style>