田源
2023-09-11 90fce6d89901ce0fb68ae9ea897b636679e8906d
Source/UBCS-WEB/src/components/Master/MasterTree.vue
@@ -1,43 +1,44 @@
<template>
  <avue-tree ref="tree" v-model="CloneTreeAvueform" v-loading="loading" :data="Treedata" :defaultExpandAll="false"
             :option="Treeoption"
             style="height: 80.5vh;padding-top: 5px;padding-bottom: 30px"
             style="height: calc(100vh - 150px);"
             @node-click=" nodeClick"
  ></avue-tree>
</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{
      tableHeadFindData:[],
      tableHeadDataFateher:[],
      templateOids:"",
      tableDataArray:[],
      codeClassifyOid:"",
      coderuleoid:"",
      CloneTreeAvueform:{},
      loading:false,
      Treedata:[],
  data() {
    return {
      idData: '',
      masterVrBtnList: [],
      tableHeadFindData: [],
      tableHeadDataFateher: [],
      templateOids: "",
      tableDataArray: [],
      codeClassifyOid: "",
      coderuleoid: "",
      CloneTreeAvueform: {},
      loading: false,
      Treedata: [],
      nodeClickList: "",
      Treeoption: {
        addBtn: false,
@@ -50,15 +51,15 @@
        //   console.log(node)
        //   console.log(resolve)
        // }
        treeLoad:function (node, resolve){
          if(node.data != false){
        treeLoad: function (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=>{
            getTreeList({parentOid: parentId, parentBtmName: parentBtmName}).then(res => {
              resolve(res.data.map(item => {
                return {
                  ...item,
                  label:item.text
                  label: item.text
                }
              }))
            })
@@ -68,23 +69,34 @@
    }
  },
  created() {
    this.getTreeList()
    this.getTreeLists()
  },
  computed:{
   },
  methods:{
  computed: {},
  methods: {
    //获取数据
    getTreeList(){
      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=>{
    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.codeClassifyOid = firstProperty.oid;
            this.coderuleoid = firstProperty.attributes.coderuleoid;
            this.$emit("coderuleoid", this.coderuleoid)
            this.$emit('Treedata', this.Treedata)
          }
        }
      }).catch(res => {
        console.log(res)
      })
        this.$message.error(res)
      });
    },
    //定义一个修改数据属性名的方法
@@ -100,29 +112,37 @@
      }
    },
    //表格刷新
    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() {
      return new Promise((resolve,reject)=>{
      const index = this.$route.query.id.indexOf('@');
      const result = this.$route.query.id.substring(0, index);
      return new Promise((resolve, reject) => {
        MasterTable({
          codeClassifyOid: this.nodeClickList.oid,
          functionId: 5,
          functionId: result,
        }).then(res => {
          const flagsToDeleteBtn = ["CODEIMPORTHISTORY", "CODEEXPORT", "CODEQUERY", "batchApplyCode"];
          //不同节点显示不同按钮
          if (!res.data.leaf) {
            this.masterVrBtnList = res.data.buttons.filter(obj => flagsToDeleteBtn.includes(obj.uniqueFlag));
          } else {
            this.masterVrBtnList = res.data.buttons
          }
          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,
@@ -131,12 +151,13 @@
              sortable: item.sort,
              width: item.minWidth
            };
         this.tableHeadFindData.push(columnItem)
            this.tableHeadFindData.push(Object.assign(item, columnItem))
          })
          this.$emit('tableHeadDataFateher', this.tableHeadDataFateher);
          this.$emit('tableHeadFindData', this.tableHeadFindData);
          this.$emit('tableHeadBttoms', this.masterVrBtnList);
          resolve();
        }).catch(err=>{
        }).catch(err => {
          reject(err)
        })
      })
@@ -145,13 +166,12 @@
    async nodeClick(data) {
      try {
        this.nodeClickList = data;
        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.templateOids)
        console.log('元数据cod',this.codeClassifyOid)
        console.log('元数据nodeclick', this.nodeClickList.oid)
        this.$emit('nodeClick', this.templateOids)
        this.$emit("codeClassifyOid", this.nodeClickList.oid)
      } catch (error) {
        // 处理错误
        this.$message.error(error)