ludc
2023-11-30 1b8098b7f79b66a80e5ca49d8765606cb5fa0408
Source/UBCS-WEB/src/components/Master/MasterTree.vue
@@ -1,44 +1,52 @@
<template>
  <avue-tree ref="tree" v-model="CloneTreeAvueform" v-loading="loading" :data="Treedata" :defaultExpandAll="false"
             :option="Treeoption"
             style="height: calc(100vh - 150px);"
             @node-click=" nodeClick"
  ></avue-tree>
  <div class="app" style="position: relative;">
    <avue-tree ref="tree" v-model="CloneTreeAvueform" v-loading="loading" :data="Treedata" :defaultExpandAll="false"
               :option="Treeoption" style="width: fit-content;" @node-click="nodeClick">
      <template slot-scope="{ node }">
        <span v-html="node.label"></span>
      </template>
    </avue-tree>
    <div style="position: absolute; right: 0px; top: -1px;">
      <el-link class="refresh-icon" icon="el-icon-refresh" @click="getTreeLists"></el-link>
    </div>
  </div>
</template>
<script>
import {getTreeList} from "@/api/MasterData/master";
import {mapMutations, mapState} from "vuex";
import {TableData,MasterTable} from "@/api/GetItem";
import {TableData, MasterTable} from "@/api/GetItem";
export default {
  name: "MasterTree",
  props:{
    pageSize:{
      type:String,
      default:"10"
  props: {
    pageSize: {
      type: String,
      default: "100"
    },
    currentPage:{
      type:String,
      default:"1"
    currentPage: {
      type: String,
      default: "1"
    },
    templateOid:{
      type:String,
      default:''
    templateOid: {
      type: String,
      default: ''
    },
  },
  data(){
    return{
      masterVrBtnList:[],
      tableHeadFindData:[],
      tableHeadDataFateher:[],
      templateOids:"",
      tableDataArray:[],
      codeClassifyOid:"",
      coderuleoid:"",
      CloneTreeAvueform:{},
      loading:false,
      Treedata:[],
  data() {
    return {
      TreeValue: '',
      idData: '',
      referTreeId: '',
      masterVrBtnList: [],
      tableHeadFindData: [],
      tableHeadDataFateher: [],
      templateOids: "",
      tableDataArray: [],
      codeClassifyOid: "",
      coderuleoid: "",
      CloneTreeAvueform: {},
      loading: false,
      Treedata: [],
      nodeClickList: "",
      Treeoption: {
        addBtn: false,
@@ -51,15 +59,20 @@
        //   console.log(node)
        //   console.log(resolve)
        // }
        treeLoad:function (node, resolve){
          if(node.data != false){
        treeLoad: (node, resolve) => {
          if (node.data != false) {
            const parentId = (node.level === 0) ? 0 : node.data.oid;
            const parentBtmName = node.data.attributes.btmname
            getTreeList({parentOid:parentId,parentBtmName:parentBtmName}).then(res=>{
              resolve(res.data.map(item=>{
            const parentBtmName = node.data.attributes.btmname;
            getTreeList({
              parentOid: parentId,
              parentBtmName: parentBtmName,
              'conditionMap[btmTypeId]': this.referTreeId
            }).then(res => {
              resolve(res.data.map(item => {
                return {
                  ...item,
                  label:item.text
                  label: `<span style="color:#409EFF">${item.count}</span> ${item.text}`,
                  count: item.count
                }
              }))
            })
@@ -70,22 +83,54 @@
  },
  created() {
    this.getTreeLists()
  },
  mounted() {
  },
  computed:{
   },
  methods:{
  computed: {
    formatCount() {
      return (label) => {
        const countIndex = label.indexOf('</span>') + '</span>'.length;
        const count = label.slice(countIndex);
        const coloredCount = `<span class="count">${count}</span>`;
        return `${label.slice(0, countIndex)}${coloredCount}`;
      };
    },
  },
  methods: {
    //获取数据
    getTreeLists(){
      getTreeList({'conditionMap[id]': 'wupin'}).then(res=>{
        this.Treedata=res.data
        this.ModifyProperties(this.Treedata, 'text', 'label');
        this.codeClassifyOid=res.data[0].oid;
        this.coderuleoid=res.data[0].attributes.coderuleoid;
        this.$emit("coderuleoid", this.coderuleoid )
      }).catch(res=>{
        console.log(res)
      })
    getTreeLists() {
      const index = this.$route.query.id.indexOf('@');
      const result = this.$route.query.id.substring(0, index);
      this.idData = result
      // console.log(this.$route)
      getTreeList({'conditionMap[id]': this.idData}).then(res => {
        if (res) {
          if (res.data.length === 0) {
            this.$message.error("主数据分类查询为空!");
          } else {
            this.Treedata = res.data;
            const [firstProperty] = res.data;
            this.ModifyProperties(this.Treedata, 'text', 'label');
            this.referTreeId = firstProperty.attributes.btmTypeId;
            // console.log(this.referTreeId)
            this.codeClassifyOid = firstProperty.oid;
            this.coderuleoid = firstProperty.attributes.coderuleoid;
            this.$emit("coderuleoid", this.coderuleoid)
            this.$emit('Treedata', this.Treedata)
            this.Treedata.forEach((item, index) => {
              item.label = `<span style="color:#409EFF">${item.count}</span> ${item.label}`;
            });
            this.$emit("coderuleoid", this.coderuleoid)
            this.$emit('Treedata', this.Treedata)
            // console.log(this.Treedata)
          }
        }
      }).catch(res => {
        // console.log(res)
        this.$message.error(res)
      });
    },
    //定义一个修改数据属性名的方法
@@ -101,29 +146,29 @@
      }
    },
    //表格刷新
    TableRend(){
    TableRend() {
      TableData({
        templateOid: this.templateOids,
        codeClassifyOid: this.nodeClickList.oid,
        page: this.currentPage,
        limit: this.pageSize,
      }).then(res => {
        this.tableDataArray=res.data.data;
        this.$emit('tableDataArray',this.tableDataArray)
        this.$emit('total',res.data.total)
        console.log('table',this.tableDataArray)
        this.tableDataArray = res.data.data;
        this.$emit('tableDataArray', this.tableDataArray)
        this.$emit('total', res.data.total)
      })
    },
    //表格头部
    TableHeadRend() {
      const index = this.$route.query.id.indexOf('@');
      const result = this.$route.query.id.substring(0, index);
      // console.log(this.$route)
      return new Promise((resolve, reject) => {
        MasterTable({
          codeClassifyOid: this.nodeClickList.oid,
          functionId: 5,
          functionId: result,
        }).then(res => {
          console.log('1-', res.data)
          console.log('123-', res.data.buttons)
          const flagsToDeleteBtn = ["CODEIMPORTHISTORY", "CODEBATCHADD", "CODESTARTPROCESS", "CODEEXPORT", "CODEQUERY"];
          const flagsToDeleteBtn = ["CODEIMPORTHISTORY", "CODEEXPORT", "CODEQUERY", "batchApplyCode"];
          //不同节点显示不同按钮
          if (!res.data.leaf) {
            this.masterVrBtnList = res.data.buttons.filter(obj => flagsToDeleteBtn.includes(obj.uniqueFlag));
@@ -132,17 +177,16 @@
          }
          this.tableHeadDataFateher = res.data;
          this.templateOids = res.data.tableDefineVO.oid;
          let List = res.data.tableDefineVO.cols[0];
          const [List] = res.data.tableDefineVO.cols;
          List.forEach(item => {
            let columnItem = {
              label: item.title,
              prop: item.field,
              prop: item.queryField,
              // type: this.columnType[item.type],
              sortable: item.sort,
              width: item.minWidth
            };
            this.tableHeadFindData.push(Object.assign(item, columnItem))
            // console.log(' this.tableHeadFindData', this.tableHeadFindData)
          })
          this.$emit('tableHeadDataFateher', this.tableHeadDataFateher);
          this.$emit('tableHeadFindData', this.tableHeadFindData);
@@ -156,14 +200,18 @@
    //树点击事件
    async nodeClick(data) {
      try {
        // console.log(data)
        this.TreeValue = data.label.split("</span>")[1].trim();
        // console.log('TreeValue',this.TreeValue)
        this.$emit('TreeValue', this.TreeValue)
        this.nodeClickList = data;
        this.tableHeadDataFateher=[]
        this.tableHeadFindData=[]
        this.tableHeadDataFateher = []
        this.tableHeadFindData = []
        await this.TableHeadRend(); // 先执行 TableHeadRend()
        this.TableRend(); // TableHeadRend() 方法完成后再执行 TableRend()
        this.$emit('nodeClick',this.templateOids)
        this.$emit("codeClassifyOid", this.nodeClickList.oid )
        console.log('树',this.nodeClickList)
        this.$emit('nodeClick', this.templateOids)
        this.$emit("codeClassifyOid", this.nodeClickList.oid)
        this.$emit("nodeClickList", this.nodeClickList)
      } catch (error) {
        // 处理错误
        this.$message.error(error)
@@ -173,6 +221,31 @@
}
</script>
<style scoped>
<style lang="scss" scoped>
.app {
  overflow: auto;
  height: calc(100vh - 150px);
}
.app::-webkit-scrollbar {
  height: 15px; // 纵向滚动条 必写
  background: white;
  border: white;
  width: 10px;
}
// 滚动条的滑块
.app::-webkit-scrollbar-thumb {
  background-color: #ececec;
  border-radius: 20px;
  border: #ececec;
}
.refresh-icon {
  color: #409EFF;
  margin-top: 8px;
  margin-left: 6px;
  font-size: 18px;
}
</style>