• element-ui 树形控件实现 三级联动穿梭框


    在这里插入图片描述
    使用树形控件实现,详情看文档 https://element.eleme.cn/#/zh-CN/component/tree

    <template>
      <div class="container">
        <div class="trees">
          <div class="treeP">
    
            <p class="titles">
              <label class="la">
                <span>
                </span>
              </label>
            </p>
    
            <div class="tree1">
              <el-tree
                ref="tree"
                v-loading="listLoading"
                :data="data"
                show-checkbox
                expand-on-click-node
                :check-on-click-node="true"
                node-key="id"
                @check="handleCheckChange"
              />
            </div>
          </div>
    
          <div class="btn">
            <el-button type="primary" icon="el-icon-arrow-right" circle />
          </div>
    
          <div class="treeP">
            <p class="titles">
              <label>
                <span @click="quit">
                  清空
                </span>
              </label>
            </p>
            <div class="tree1">
              <el-tree
                :data="data1"
                node-key="id"
                draggable
                :expand-on-click-node="true"
              >
                <span slot-scope="{ node, data }" class="custom-tree-node">
                  <span>{{ data.brand }} {{ node.label }}</span>
                  <span>
                    <el-button
                      type="text"
                      size="mini"
                      @click="() => remove(node, data)"
                    >
                      删除
                    </el-button>
                  </span>
                </span>
              </el-tree>
            </div>
          </div>
    
        </div>
    
        <!-- 按钮 -->
        <div slot="footer" class="dialog-footer">
          <p style="margin: 20px;" />
          <el-button style="margin-left: 80.5%;" @click="cancel">取 消</el-button>
          <el-button type="primary" @click="updata">确 定</el-button>
        </div>
    
      </div>
    </template>
    
    <script>
    import api from '@/api/product'
    export default {
      name: 'Shuttle',
      props: ['type', 'film_id'],
      data() {
        return {
          listLoading: false,
          checked: false,
          data1: [],
          data: [],
          echo: {
            strId: '',
            name: []
          }
        }
      },
      created() {
        this.listLoading = true
        const data = this.film_id !== undefined ? this.film_id : ''
        api.getTreeList({ film_id: data }).then(res => {
          this.data = res.data
          this.listLoading = false
        })
      },
      methods: {
        // 删除
        remove(node, data) {
          // 清除选中
          const parent = node.parent
          const children = parent.data.children || parent.data
          const index = children.findIndex(d => d.id === data.id)
          children.splice(index, 1)
    
          // 取消勾中
          this.$refs.tree.setChecked(data.id, false)
        },
    
        // 全删
        quit() {
          this.data1 = []
          this.$refs.tree.setCheckedKeys([])
        },
    
        // 添加
        handleCheckChange(data, checked) {
          this.data1 = []
          checked.checkedNodes.forEach((item, index) => {
            if (item.children === undefined || item.children.length === 0) {
              item.brand = this.clean(this.data, item.id)
              this.data1.push(item)
            }
          })
          // console.log(this.data1)
        },
    	
    	// 添加系列
        clean(data, id) {
          let name = ''
          data.forEach((item, index) => {
            if (item.children.length > 0) {
              item.children.forEach((i, ind) => {
                if (i.children.length > 0) {
                  i.children.forEach((j, indexs) => {
                    if (j.id === id) {
                      name = i.label
                    }
                  })
                }
              })
            }
          })
          return name
        },
    
        // 确定
        updata() {
          let str = ''
          this.data1.forEach((item, index) => {
            str += item.id + ','
            this.echo.name.push(item.brand + item.label)
          })
          this.echo.strId = str.substr(0, str.length - 1)
    
          if (this.type === 1) {
            // 新增
            this.$emit('code', this.echo)
            this.quit()
          } else {
            // 编辑
            api.addFilmModelRelation({ film_id: this.film_id, model_ids: this.echo.strId }).then(res => {
              this.$emit('code', '编辑')
              this.quit()
            })
          }
        },
        // 取消
        cancel() {
          this.$emit('code', '取消')
        }
      }
    }
    </script>
    
    <style>
    .container{
        /* width: 1200px; */
        /* height: 700px; */
        /* margin:50px auto; */
        padding: 0;
    }
      .trees{
        width: 100%;
        /* margin: 0 auto; */
        display: flex;
        justify-content: space-around;
      }
       .custom-tree-node {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: space-between;
        font-size: 14px;
        padding-right: 8px;
      }
      .tree1{
        height: 500px;
        padding: 5px;
        overflow: scroll;
        overflow-x:hidden ;
      }
      .treeP{
        width:40%;border: 1px solid #ebeef5;border-radius:5px;
      }
      .titles{
        height: 40px;
        border-bottom: 1px solid #f5f7fa;
        margin: 0;
        box-sizing: border-box;
        padding: 0 5%;
        display: flex;
        align-items: center;
        flex-direction: row-reverse;
      }
     .btn{
         margin: auto;
      }
    </style>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
  • 相关阅读:
    BSV 中的零开销私人时间戳
    机器学习之支持向量机
    docker导致root空间满进入不了系统解决方案
    基于微服务(eureka)的优雅发布设计说明
    FPGA如此火热,ASIC和FPGA到底选哪个好?
    【选型】FPGA选型技巧
    spring
    推荐计算机领域的几本入门书籍
    【半导体行业革新】一键体验智能门户,在线客服+试用申请,效率翻倍!
    c语言编程实例
  • 原文地址:https://blog.csdn.net/weixin_45936690/article/details/125517539