selectLable.vue 8.79 KB
<template>
  <div class="tag-main">
    <GLDialog bigTitle="选择标签" mode="big" :visible.sync="dialogVisible" :before-close="handleClose">
      <div class="tag-panel">
        <div class="tag-panel-select">
          <div class="tag-title">预选标签</div>
          <div class="tag-select-box">
            <div class="tag-box-header">
              <el-input size="small" v-model="labelGroupName" placeholder="请输入搜索内容" clearable @keydown.enter.native="handleSearch"></el-input>
              <el-button size="small" type="primary" @click="handleSearch">查询</el-button>
              <el-button size="small" @click="handleReset">重置</el-button>
            </div>
            <div class="checkbox-group-box" :style="{ height: heightBox + 'px' }">
              <div style="margin-bottom: 8px" class="checkbox-box" v-for="(item, index) in labelTreeRets" :key="index" @click="item.checked = !item.checked">
                <span class="el-tree-node__expand-icon el-icon-caret-right" :class="{ expanded: item.checked }" @click="item.checked = !item.checked"></span>
                {{ item.labelGroup.name }}
                <el-tag :size="size">{{ item.labelType }}</el-tag>
                <el-radio-group class="tag-group" v-model="item.tagChecked" v-show="item.checked">
                  <div v-for="(itm, idx) in item.labelList" :key="idx" class="radio-tag">
                    <el-tooltip effect="dark" placement="top" :disabled="itm.name.length < 8">
                      <el-radio class="radio-text" :label="itm">{{ itm.name }}</el-radio>
                      <div slot="content">{{ itm.name }}</div>
                    </el-tooltip>
                  </div>
                </el-radio-group>
              </div>
            </div>
          </div>
        </div>
        <div class="tag-panel-selected">
          <div class="tag-title">已选标签</div>
          <div class="tag-select-box">
            <div class="tag-box-header">标签名称({{ selectNum }}项)</div>
            <div class="tag-selected-box" :style="{ height: heightBox + 'px' }">
              <template v-for="item in labelTreeRets">
                <el-tag :title="item.tagChecked.name" v-if="item.tagChecked" type="info" class="tag-selected-item" :key="item.tagChecked" closable :disable-transitions="false" @close="remove(item, idx)">
                  {{ item.tagChecked.name }}
                </el-tag>
              </template>
            </div>
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="dialogVisible = false">取 消</el-button>
        <el-button size="small" type="primary" @click="handleSelect">确 定</el-button>
      </span>
    </GLDialog>
  </div>
</template>

<script>
import util from '@/utils/util'
export default {
  name: 'activityModel',
  data() {
    return {
      heightBox: 200,
      dialogVisible: false,
      labelGroupName: '',
      selectNum: 0,
      searchStatus: false,
      labelTreeRets: []
    }
  },
  watch: {
    labelTreeRets: {
      handler() {
        this.selectNum = 0
        this.labelTreeRets.forEach(item => {
          if (item.tagChecked) {
            this.selectNum++
          }
        })
      },
      deep: true
    }
  },
  methods: {
    jumpUrl() {
      util.openUrl(location.origin + '/custom/tagsManage/index')
      this.dialogVisible = false
    },
    init(item) {
      console.log(item, '23232')
      this.labelGroupName = ''
      this.dialogVisible = true
      this.querylabeltree(item)
    },
    handleSearch() {
      this.searchStatus = true
      this.querylabeltree()
    },
    querylabeltree(selectItem) {
      this.$apis.customerTransform
        .querylabeltree({
          labelTreeReq: {
            pageNum: 1,
            pageSize: 1000,
            shopId: this.$globalState.session.merchantId,
            labelGroupName: this.labelGroupName,
            edition: this.$globalState.session.merchantModel
          }
        })
        .then(res => {
          if (selectItem && selectItem.length > 0) {
            this.labelTreeRets = res.labelTreeRets.map(item => {
              return {
                labelType: item.labelType,
                labelGroup: item.labelGroup,
                labelList: item.labelList,
                checked: false,
                tagChecked: null,
                isIndeterminate: false,
                checkAll: false
              }
            })
            //回显
            selectItem.forEach(item => {
              this.labelTreeRets.forEach(tag => {
                if (item.labelGroup.id == tag.labelGroup.id) {
                  let labelId = item.labelList[0].id
                  let index = tag.labelList.findIndex(iem => iem.id == labelId)
                  // tag.tagChecked = item.tagChecked
                  tag.tagChecked = tag.labelList[index]
                }
              })
            })
          } else {
            this.labelTreeRets = res.labelTreeRets.map(item => {
              return {
                labelType: item.labelType,
                labelGroup: item.labelGroup,
                labelList: item.labelList,
                checked: false,
                tagChecked: null,
                isIndeterminate: false,
                checkAll: false
              }
            })
          }
        })
    },
    remove(item, idx) {
      item.tagChecked = null
    },
    //选中
    handleSelect() {
      if (this.selectNum > 3) {
        this.$message({
          message: '最多选择三个标签',
          type: 'warning',
          customClass: 'dialog-tips'
        })
        return
      }
      this.dialogVisible = false
      let labelTreeRets = this.labelTreeRets
        .map(item => {
          if (item.tagChecked) {
            return {
              labelGroup: item.labelGroup,
              labelType: item.labelType,
              labelList: [item.tagChecked]
            }
          }
        })
        .filter(item => item)
      this.$emit('tagSelected', labelTreeRets)
    },
    handleReset() {
      this.labelGroupName = ''
      this.querylabeltree()
    }
  },
  mounted() {
    let clientHeight = document.documentElement.clientHeight
    this.heightBox = clientHeight - 0.15 * clientHeight - 350
  }
}
</script>

<style lang="scss" scoped>
.dialog-jump {
  color: #5850ff;
  float: left;
  line-height: 24px;
  text-decoration: underline;
  cursor: pointer;
}
.tag-panel {
  display: flex;
  .tag-panel-select {
    width: 60%;
    /deep/ {
      .el-checkbox__label {
        width: 100%;
        vertical-align: middle;
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
        word-wrap: break-word;
      }
    }
  }
  .tag-panel-selected {
    width: 40%;
    margin-left: 10px;
    .tag-box-header {
      font-size: 14px;
      font-weight: 400;
      color: #333333;
      line-height: 20px;
      padding-left: 20px !important;
    }
  }
  .tag-title {
    font-size: 16px;
    font-weight: 400;
    color: #333333;
    line-height: 22px;
  }
  .tag-select-box {
    margin-top: 10px;
    border-radius: 2px;
    border: 1px solid #eeeeee;
    padding: 6px;
    .tag-box-header {
      box-sizing: border-box;
      display: flex;
      height: 56px;
      align-items: center;
      border-bottom: 1px solid #eeeeee;
      margin: -6px;
      margin-bottom: 10px;
      padding: 0px 6px;
      /deep/ {
        .el-input {
          width: 60%;
          margin-right: 10px;
        }
      }
    }
    .tag-selected-item {
      margin: 0px 6px 6px 0px;
      height: 26px;
      line-height: 24px;
      font-size: 14px;
      color: #666;
      max-width: 200px;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }
    .el-tree-node__expand-icon {
      color: #5850ff;
      font-size: 16px;
    }
    .tag-group {
      margin-left: 26px;
      display: flex;
      flex-wrap: wrap;
      .radio-tag {
        display: inline-block;
        width: 50%;
        .el-radio {
          margin: 8px 0;
          display: inline-flex;
          align-items: center;
          /deep/.el-radio__inner {
            box-shadow: none !important;
          }
          /deep/.el-radio__label {
            display: inline-block;
            max-width: 120px;
            text-overflow: ellipsis;
            white-space: nowrap;
            overflow: hidden;
            word-wrap: break-word;
          }
        }
      }
    }
  }
}
.checkbox-group-box {
  overflow: auto;
  .checkbox-box {
    cursor: pointer;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #333333;
    line-height: 20px;
    /deep/ {
      .el-tag {
        color: #aaa5fa !important;
        font-size: 12px;
        border: none;
        background: rgba($color: #5850ff, $alpha: 0.1);
      }
    }
  }
}
.tag-selected-box {
  min-height: 200px;
}
</style>