el-tree 根据节点属性控制节点显隐

一、整体思路

  • 用render-content方法实现树节点的内容区的渲染,根据节点属性判断是否渲染内容区,若不显示,则删除该节点。

二、代码实现

   <div id="tree">
      <el-tree
        ref="tree"
        :data="treeData"
        show-checkbox
        node-key="id"
        :default-checked-keys="checkedKeys"
        default-expand-all
        :expand-on-click-node="false"
        @check="handleCheckChange"
        :render-content="renderContent"
      ></el-tree>
    </div>
    // 根据number属性值判断是否渲染节点
    renderContent(h, { node, data, store }) {  
      if(data.number!=0){
        return(
          <span class="custom-tree-node">
            <span>{data.label +' ('+ number+')'}</span>
          </span>
        )
      }else{
        this.remove(node, data)
      }
    },
    // 删除节点数据方法
    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)
    },
<u-modal :ref="`senPi`" :size="`huge`" :is-heading-slot-empty="true"> <template #title> <u-text :text="`报价详情`"></u-text> </template> <template #body> <u-linear-layout direction="vertical" wrap> <u-form :layout="`inline`" key="form_13"> <u-form-item :layout="`center`"> <template #label> <u-text :text="`供应商id`"></u-text> </template> <u-select :clearable="true" :placeholder="`请选择供应商id`" :dataSource="__select_20_handleDataSourceLoad()" :pageSize="50" :textField="`supplier.name`" :valueField="`supplier.name`" :pagination="true" :value.sync="filter2.supplierId" :emptyValueIsNull="true" key="select_20" > <template #option="current"></template> <template #renderFooter></template> </u-select> </u-form-item> <u-form-item :layout="`center`"> <template #label> <u-text :text="`最终供应商`"></u-text> </template> <u-select :clearable="true" :value.sync="filter2.finalSupplier" :placeholder="`请选择最终供应商`" :dataSource="$utils['EnumToList']({ concept: 'TypeAnnotation', typeKind: 'reference', typeNamespace: 'app.enums', typeName: 'Is_Final_Supplier', inferred: false, ruleMap: {}, typeArguments: [] })" :emptyValueIsNull="true" key="select_22" > <template #option="current"></template> <template #renderFooter></template> </u-select> </u-form-item> <u-form-item :layout="`center`" :labelSize="`auto`"> <u-button :color="`primary`" :text="`查 询`" @click="onQueryClick($event)"></u-button> </u-form-item> </u-form> <!-- 树形表格,支持折叠子表 --> <el-table :data="treeData" row-key="id" :tree-props="{ children: 'quotedPrices', hasChildren: 'hasChildren' }" border style="--cw-style-font-size: 10px; font-size: 10px; --table-view-th-padding: 1px; --table-view-td-padding: 1px; --table-cell-padding: 0px" > <!-- 展开列 --> <el-table-column type="expand" label="展开" width="50" :expandable="(row) => Array.isArray(row.quotedPrices) && row.quotedPrices.length > 0" :expanded="(row) => row.isExpanded" @expand-change="handleExpandChange" ></el-table-column> <el-table-column prop="materialApplyId" label="物料申请单id" width="150"></el-table-column> <el-table-column prop="supplierId" label="供应商id" width="150"></el-table-column> <el-table-column prop="finalSupplier" label="最终供应商" width="150"></el-table-column> <!-- 子表格:报价详情 --> <el-table-column label="报价详情" width="300"> <template #default="scope"> <el-table v-if="Array.isArray(scope.row.quotedPrices) && scope.row.quotedPrices.length > 0" :data="scope.row.quotedPrices" style="width: 100%; font-size: 10px;" border > <el-table-column prop="times" label="报价次数" width="100"></el-table-column> <el-table-column prop="price" label="报价价格" width="100"></el-table-column> <el-table-column prop="lastPrice" label="是否最终报价" width="100"></el-table-column> </el-table> </template> </el-table-column> </el-table> </u-linear-layout> </template> </u-modal>
03-12
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值