当前位置: 首页 > news >正文

element树形控件编辑节点组装节点

需求功能:
编辑树节点,组装节点

在这里插入图片描述

<el-scrollbar class="scrollbar-wrapper">
          <el-tree :data="nodeList" ref="tree" :props="defaultProps" :expand-on-click-node="false">
            <template slot-scope="{ node, data }">
              <div class="custom-tree-node">
                <template v-if="node.label">
                  <span>{{node.label}} <span v-if="node.level==4 && false" style="padding-left:30px">
                      <el-checkbox v-model="data.isCommon" true-label="Y" false-label="N">是否常用分类</el-checkbox>
                    </span>
                  </span>
                  <span style="margin-left:20px">
                    <el-button size="small" type="text" @click.stop="appendNode(node,data)"
                      :disabled='node.level==4'>新增</el-button>
                    <el-button size="small" type="text" @click.stop="editNode(node,data)">编辑</el-button>
                    <el-button size="small" type="text" @click.stop="removeNode(node,data)">删除</el-button>
                  </span>
                </template>
                <template v-else="!node.investFormCodeText">
                  <el-row :gutter="20" style="width:80%">
                    <el-col :span="3">
                      <div class="">编号:</div>
                    </el-col>
                    <el-col :span="6">
                      <el-input v-model="data.investFormCode" size="small" placeholder="请输入编号"></el-input>
                    </el-col>
                    <el-col :span="3">
                      <div class="">描述:</div>
                    </el-col>
                    <el-col :span="12">
                      <el-input v-model="data.investFormCodeDesc" size="small" placeholder="请输入描述"></el-input>
                    </el-col>
                  </el-row>
                  <span style="margin-left:20px">
                    <el-button size="small" @click="handleCancel(node,data)">取消</el-button>
                    <el-button size="small" type="primary" @click.stop="addChild(node,data)"
                      :disabled='node.level==4'>保存</el-button>
                  </span>
                </template>
              </div>
            </template>
          </el-tree>
        </el-scrollbar>
data () {
    return {
      nodeList: [],
      defaultProps: {
        children: 'childList',
        label: 'investFormCodeText'
      },
      deleteList: [],
    }
  }
appendNode (node, data) {
      //为 Tree 中的一个节点追加一个子节点
      this.$refs.tree.append({
        dictKey: "marketQuotationInvestForm",
        investFormCodeText: '',
        childList: []
      }, node)
    },
    editNode (node, data) {
      this.$set(data, "tempInvestFormCodeText", data.investFormCodeText);
      this.$set(data, "investFormCodeText", "");
    },
    removeNode (node, data) {
      const parent = node.parent;
      const childList = parent.data.childList || parent.data;
      const index = childList.findIndex(d => d === data);
      if (data.id) {
        this.$confirm('删除配置项将影响历史数据,请确认是否删除?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          childList.splice(index, 1);
          this.deleteList.push({
            id: data.id
          });
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      }
      else {
        childList.splice(index, 1);
      }
    },
// 数据结构
"nodeList": [{
		"investFormCodeText": "TF01 -- 搜索广告",
		"investFormCode": "TF01",
		"childList": null,
		"id": 14,
		"investFormCodeDesc": "搜索广告",
		"parentId": 0
	},
	{
		"investFormCodeText": "TF02 -- 开屏",
		"investFormCode": "TF02",
		"childList": [{
				"investFormCodeText": "A001 -- 抖音-开屏",
				"investFormCode": "A001",
				"childList": [{
						"investFormCodeText": "B001 -- 优选互动",
						"investFormCode": "B001",
						"childList": null,
						"id": 17,
						"investFormCodeDesc": "优选互动",
						"parentId": 16
					},
					{
						"investFormCodeText": "B002 -- 优选点击",
						"investFormCode": "B002",
						"childList": null,
						"id": 18,
						"investFormCodeDesc": "优选点击",
						"parentId": 16
					},
					{
						"investFormCodeText": "B003 -- 超级优选",
						"investFormCode": "B003",
						"childList": null,
						"id": 19,
						"investFormCodeDesc": "超级优选",
						"parentId": 16
					}
				],
				"id": 16,
				"investFormCodeDesc": "抖音-开屏",
				"parentId": 15
			},
			{
				"investFormCodeText": "A002 -- 头条-开屏",
				"investFormCode": "A002",
				"childList": [{
						"investFormCodeText": "B001 -- 优选互动",
						"investFormCode": "B001",
						"childList": null,
						"id": 21,
						"investFormCodeDesc": "优选互动",
						"parentId": 20
					},
					{
						"investFormCodeText": "B002 -- 优选点击",
						"childList": null,
						"id": 22,
						"investFormCodeDesc": "优选点击",
						"parentId": 20
					}
				],
				"id": 20,
				"investFormCodeDesc": "头条-开屏",
				"parentId": 15
			}
		],

相关文章:

  • 上海-华为全联接大会|竹云受邀参加华为云ROMAConnect行业生态联盟成立联合发布会
  • django: You may need to add ‘localhost‘ to ALLOWED_HOSTS
  • k8s使用
  • pycharm远程调试运行程序出现No such file or directory:解决办法
  • c语言练习86:移除元素
  • Java版分布式微服务云开发架构 Spring Cloud+Spring Boot+Mybatis 电子招标采购系统功能清单
  • VueRouter与expres/koa中间件的关联
  • [Mono Depth/3DOD]单目3D检测基础
  • 【科学文献计量】利用pybibx分析Scopus文献数据集(EDA,N-Grams,Cluster,Network analysis,NLP)
  • MySQL系列---Online DDL
  • 【C++】list基本接口+手撕 list(详解迭代器)
  • 2023年中国水电行业研究报告
  • scrapy针对302请求的处理与重试配置
  • 殡葬用品商城小程序的作用是什么
  • tortoise创建本地仓库
  • 【JavaEE初阶】 volatile关键字 与 wait()方法和notify()方法详解
  • Android Studio 配置Git SVN忽略文件
  • android之TextView自由选择复制
  • 如何建立企业数字化营销体系?使用数字化营销系统助企业升级?
  • 汽车烟雾测漏仪(EP120)
  • 中国科协发声:屡禁不止的奇葩论文再次敲响学风建设警钟
  • 国常会:研究深化国家级经济技术开发区改革创新有关举措等
  • 烈士沈绍藩遗孤、革命家帅孟奇养女舒炜逝世,享年96岁
  • 四川资阳市原市长王善平被双开,“笃信风水,大搞迷信活动”
  • 《中国人民银行业务领域数据安全管理办法》发布,6月30日起施行
  • A股三大股指低收:银行股再度走强,两市成交11920亿元