el-cascader 使用

注意:此处不在form表单中使用

<template>
  <div class="block">
    <!--    <el-cascader ref="cascader" :props="{ expandTrigger: 'hover',multiple: true,checkStrictly:true }"
                     placeholder="试试搜索:XX"
                     :options="pdfTree" clearable>
          <template slot-scope="{ node, data }">
            <span style="display:block" @click="handleNodeClick(node)">{{ data.label }}</span>
          </template>
        </el-cascader>-->
    <el-cascader
        style="width: 100%"
        placeholder="试试搜索:文件"
        ref="cascader"
        :props="{ value:'id' }"
        :options="pdfTree" clearable filterable>
      <template slot-scope="{ node, data }">
        <span @click="handleNodeClick(node,data)">{{ data.label }}</span>
        <span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
      </template>
    </el-cascader>
  </div>
</template>
<script>
export default {
  name: "fileCascader",
  props: {
    //业务外键Id
    refId: {type: String},
    refType: {default: 'default'},
    groupCode: {default: 'default'},
    keyword: {type: String},
    //预览是否带水印
    watermark: {default: true}
  },
  data() {
    return {
      pdfTree: [],
      current: {},
      fileId: '',
      //
    }
  },
  watch: {
    refId() {
      this.loadData()
    }
  },
  methods: {
    $init() {
      this.loadData();
    },
    deletePdf(row) {
      this.$confirm('此操作将进行删除信息, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http.post('files/delete/' + row.id)
            .then(({data}) => {
              if (data.success) {
                this.loadData()
                this.$message.success("删除成功")
              }
            })
      })
    },
    fileToPdf(row) {
      this.loading = true
      this.$http.post('ofd/fileToOfd/', {fileId: row.id})
          .then(({data}) => {
            if (data && data.success) {
              this.$message.success(data.data)
              this.loadData()
            }
            this.loading = false
          })
    },
    async getNullChildren(v) {
      if (v.children == null) {
        await this.handleNodeClick(v)
      } else {
        await this.getNullChildren(v.children[0])
      }
    },
    async loadData() {
      this.loading = true
      const {data} = await this.$http.post('fileView/fileTree', {
        refId: this.refId,
        refType: this.refType,
        groupCode: this.groupCode
      })
      this.loading = false
      if (data.success) {
        this.loading = false
        if (data && data.success) {
          this.pdfTree = data.data
          if (this.pdfTree.length > 0) {
            this.fileId = this.pdfTree[0].id
            // this.setCurrentKey(this.pdfTree[0])
            this.current = this.pdfTree[0]
            await this.getNullChildren(this.pdfTree[0])
          }
          this.$forceUpdate()
        }
      }
      this.loading = false
    },
    async handleNodeClick(node, data) {
      if(data){
        console.log('node=', node, ';data=', data)
        this.current = data
        this.fileId = this.current.id
        // this.setCurrentKey(v)
        //子节点 点击获取文件
        if (this.current.children == null) {
          this.$emit("showFile", this.current)
        } else {
          //文件夹
        }
      }
    },
    // setCurrentKey(v) {
    //   this.$nextTick(() => {
    //     this.$refs.tree.setCurrentKey(v.id)
    //   })
    // }
  }
}
</script>
<style lang="scss">
.file_tree {
  .el-tree-node__content {
    padding: 4px;
  }

  .el-tree-node__content:hover {
    background-color: #eee;
  }

  .is-current {
    .el-tree-node__content {
      color: $--color-white;
      background-color: $--color-primary-dark-1;
      font-weight: bold;
    }
  }
}
</style>

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

【这个世界会好的】

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值