ludc
2023-05-09 1b8120cacac0037fcb1f8ae747c2f54eb735368b
Source/UBCS-WEB/src/components/Tree/classifyTrees.vue
@@ -1,149 +1,45 @@
<template>
  <el-container>
    <!--    左侧菜单-->
    <el-aside>
      <basic-container style="height: 85vh; max-height: 155vh; overflow-y: scroll;">
        <div>
          <div style="display: flex;justify-content: space-around">
            <el-button plain size="small" type="primary" @click="TreeAdd">添加</el-button>
            <el-button plain size="small" type="primary" @click="TreeEdit">修改</el-button>
            <el-button plain size="small" type="primary" @click="TreeDel">删除</el-button>
            <el-button plain size="small" type="primary" @click="Enable">启用</el-button>
          </div>
          <div style="display: flex;justify-content: space-around;margin-top: 5px;margin-bottom: 5px">
            <el-button plain size="small" type="primary" @click="Deactivate">停用</el-button>
            <el-button plain size="small" type="primary" @click="ExportExcel">导出</el-button>
            <el-button plain size="small" type="primary" @click="ImportExcel">导入</el-button>
            <el-button plain size="small" type="primary" @click="flushed">刷新</el-button>
          </div>
        </div>
        <el-upload
          multiple
          :limit="3"
          :on-preview="handlePreview"
          action="https://jsonplaceholder.typicode.com/posts/"
          :file-list="fileList">
          <el-button size="small" type="primary" @click="importExcel">点击上传</el-button>
        </el-upload>
        <!--        树节点添加对话框-->
        <el-dialog :title="this.TreeFlag ? '添加分类' :'添加主题库'" :visible.sync="TreeAddFormVisible" append-to-body
                   style="width: 1700px;margin: auto">
          <el-form :model="TreeAddform">
            <el-form-item :label="this.TreeFlag ? '分类编号:' :'主题库编号:'" label-width="150px" style="display: inline-block">
              <el-input v-model="TreeAddform.id" autocomplete="off" style="width: 170px"></el-input>
            </el-form-item>
            <el-form-item :label="this.TreeFlag ? '分类名称:' :'主题库名称:'" label-width="100px" style="display: inline-block">
              <el-input v-model="TreeAddform.name" autocomplete="off" style="width: 170px"></el-input>
            </el-form-item>
            <el-form-item label="描述:" label-width="150px">
              <el-input v-model="TreeAddform.description" autocomplete="off" style="width: 585px"></el-input>
            </el-form-item>
            <el-form-item v-show="this.TreeFlag==false" label="存储的业务类型:" label-width="150px">
              <el-input v-model="TreeAddform.btmtypename" autocomplete="off" style="width: 585px"></el-input>
            </el-form-item>
            <el-form-item label="编码规则:" label-width="150px">
              <el-input v-model="TreeAddform.coderuleoidName" autocomplete="off" style="width: 585px"></el-input>
            </el-form-item>
            <el-form-item label="关键属性查询规则:" label-width="150px">
              <el-input v-model="TreeAddform.codekeyattrrepeatoidName" autocomplete="off"
                        style="width: 585px"></el-input>
            </el-form-item>
            <el-form-item label="相似查询规则:" label-width="150px">
              <el-input v-model="TreeAddform.codeResembleRuleOidName" autocomplete="off"
                        style="width: 585px"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="TreeAddFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="TreeAddHandler">确 定</el-button>
          </div>
        </el-dialog>
<!--        修改对话框-->
        <el-dialog  title="修改分类" :visible.sync="TreeEditFormVisible" append-to-body>
          <classifyTreeform ref="childForm" :TreeNewForm="TreeList" :nodeList="nodeList"></classifyTreeform>
        </el-dialog>
        <avue-tree ref="tree" v-model="TreeAvueform" v-loading="loading" :data="Treedata" :defaultExpandAll="false"
                   :option="Treeoption"
                   style="height: 80.5vh;padding-top: 5px;padding-bottom: 30px"
                   @node-click=" nodeClick"
                   @check-change="checkChange"
        >
<!--    左侧菜单-->
    <el-aside >
      <basic-container>
        <avue-tree ref="tree" v-model="form" :data="Treedata" :option="Treeoption" @node-click=" nodeClick"
                   @del="rowDel" @save="rowSave" @check-change="checkChange"  style="height: 754px"  >
        </avue-tree>
      </basic-container>
    </el-aside>
    <el-main>
      <basic-container style="height: 85vh; max-height: 155vh; ">
        <!--        右侧表格-->
      <basic-container>
<!--        右侧表格-->
        <avue-tabs :option="tabOption" @change="handleChange"></avue-tabs>
        <span v-if="type.prop==='tab1'">
          <avue-crud v-model="crudForm" :data="this.Formlist" :option="this.crudTreeOption"
          ></avue-crud>
          <templatePro></templatePro>
            <avue-crud v-model="crudForm" :data="this.Formlist" :option="this.crudTreeOption" style="height: 700px"></avue-crud>
        </span>
        <span v-else-if="type.prop==='tab2'">
<!--          如果是表格加表单就再次引入这个classifyTreeform组件,里面是表单的内容,没用就删掉。把上面的tab栏也删除了-->
<!--          如果是表格加表单就再次引入这个classifyTreeform组件,里面是表单的内容,没用就删除掉。把上面tab栏也删除了-->
           <classifyTreeform ref="childForm" :TreeNewForm="TreeList" :nodeList="nodeList"></classifyTreeform>
          <classifyTreeform  ref="childForm" :nodeList="nodeList" :TreeNewForm="TreeList"></classifyTreeform>
          <template-pro></template-pro>
        </span>
      </basic-container>
    </el-main>
  </el-container>
</template>
<script>
//这里声明一些菜单组件用法:首先布局分为左侧菜单右侧表格,可能会有右侧Tab栏加表单的情况。所以另外引入了一个右侧表单的组件"classifyTreeform"。
//首先父组件调用子组件菜单,通过provide传递参数。有Treeoption左侧树新增表单项 Treedata左侧树节点配置项 crudTreeOption右侧表格配置项 crudTreeData右侧表格显示内容
//其中表格的配置项直接父传子传递过来就行,直接:option=传递的参数名,里面数据显示的内容因为是和左侧联动的,所以重新一个Formlist,通过点击树节点下标来动态渲染右侧表格,下面方法都有具体注释
//然后再说右侧的表单,专门定义了一个组件,通过父传子再把表单数据TreeList传递过去,传递前在10deCLi1ck方法里面便了处理也是一个联动的效果,表单的配置项在哪个子组件或者父组件写都可以。
import {getAtrrList, TreeSave, TreeDel, TreeCheckDel,TreeObjcet,TreeEnable,TreeDeactivate,importClassify,gridCodeClassifyTemplateAttr} from "@/api/template/templateAttr";
export default {
  name: "classifyTrees.vue",
  //使用inject接收参数
  //Treeoption左侧树新增表单项 Treedata左侧树节点 配置项 crudTreeOption右侧表格配置项 crudTreeData右侧表格显示内容
  //Treeoption左侧树新增表单项 Treedata左侧树节点配置项 crudTreeOption右侧表格配置项 crudTreeData右侧表格显示内容
  //Treeform右侧表单配置项
  inject: ['crudTreeOption', "crudTreeData"],
  inject: ['crudTreeOption',"crudTreeData", "Treedata", "Treeoption"],
  data() {
    return {
      fileList:[],
      FlagObj:{},
      //修改对话框
      TreeEditFormVisible:false,
      //添加对话框
      TreeAddFormVisible: false,
      //当前点击项
      nodeClickList: "",
      //分类和主题库状态
      TreeFlag: false,
      //树加载
      loading: false,
      TreeAddform: {
        id: "",
        name: "",
        description: "",
        //相似查询规则
        codeResembleRuleOidName: "",
        //关键属性查询规则
        codekeyattrrepeatoidName: "",
        //编码规则
        coderuleoidName: "",
        //存储的业务类型
        btmtypename: ""
      },
      //avue-tree数据,暂时没有作用,里面功能用element写了,只用avue的一个树组件不用内置表单了。
      TreeAvueform: {},
      Treedata: [],
      Treeoption: {
        addBtn: false,
        editBtn: false,
        delBtn: false,
        defaultExpandAll: false,
        menu: false,
        // //这个是多选
        // multiple: true,
      },
      crudForm: "",
      form: {},
      //动态切换处理过的表格数据
      Formlist: [],
      //tab状态
@@ -165,247 +61,31 @@
        {
          name: "测试1",
          sex: "男",
          value: 0
          value:0
        },
        {
          name: "测试2",
          sex: "女",
          value: 1
          value:1
        }
      ],
      //传递给子组件动态渲染的数据
      TreeList: {}
      TreeList:{}
    }
  },
  //tab栏默认是表格
  mounted() {
    this.type = this.tabOption.column[0];
    this.getAttr();
    console.log(this.fileList)
  },
  methods: {
    ExportExcel(){
      console.log(this.fileList)
    },
    importExcel(){
    },
    handlePreview(file) {
      debugger
      console.log(file);
      importClassify(file.raw).then(res=>{
        console.log(res)
      })
    },
    //分类树数据处理
    getAttr() {
      getAtrrList().then(res => {
        this.Treedata = res.data;
        this.Treedata.forEach(() => {
          for (let i = 0; i < this.Treedata.length; i++) {
            this.Treedata[i].value = i;
          }
        })
        //调用修改属性名方法
        this.ModifyProperties(this.Treedata, 'text', 'label');
      }).catch(res => {
        console.log(res)
      })
    },
    //定义一个修改对象属性名的方法
    ModifyProperties(obj, oldName, newName) {
      for (let key in obj) {
        if (key === oldName) {
          obj[newName] = obj[key];
          delete obj[key];
        }
        if (typeof obj[key] === 'object') {
          this.ModifyProperties(obj[key], oldName, newName);
        }
      }
    },
    //树节点添加按钮
    TreeAdd() {
      this.TreeAddFormVisible = true;
      // 判断当前是否有点击子项
      if (this.nodeClickList !== "") {
        this.TreeFlag = true
      }
    },
    //树节点添加事件
    TreeAddHandler() {
      const data = this.TreeAddform
      this.$set(data, "parentCodeClassifyOid", this.nodeClickList.oid)
      console.log(data)
      TreeSave(data).then(() => {
        this.$message({
          type: 'success',
          message: '添加成功!'
        });
        this.getAttr();
        this.TreeAddFormVisible = false
        this.TreeAddform=""
      }).catch(res => {
        this.$message({
          type: 'warning',
          message: res
        });
      })
    },
    //树节点删除按钮
    TreeDel() {
      this.$confirm('是否删除当前选择的分类,将会把子分类一并删除,如果存在编码数据将不能被删除,是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        customClass: 'my-messagebox',
      }).then(() => {
        TreeCheckDel(this.nodeClickList).then(res => {
          if (res.data.data) {
            TreeDel(this.nodeClickList).then(() => {
              this.$message({
                type: 'success',
                message: '删除成功!'
              });
              this.getAttr();
            }).catch(res => {
              this.$message({
                type: 'warning',
                message: res
              });
            })
          } else {
            this.$confirm('当前数据包含有下级数据,要删除的话会和下级数据一起删除,你确认继续?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning',
              customClass: 'my-messageboxs',
            }).then(() => {
              TreeDel(this.nodeClickList).then(() => {
                this.$message({
                  type: 'success',
                  message: '删除成功!'
                });
                this.getAttr();
              }).catch(res => {
                this.$message({
                  type: 'warning',
                  message: res
                });
              })
            }).catch(() => {
              this.$message({
                type: 'info',
                message: '已取消删除'
              });
            });
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    //修改回填
    TreeEdit(){
      if(this.nodeClickList == ""){
        this.$message({
          type: 'warning',
          message:'请先从树上选择一条数据!'
        });
      }else {
        this.TreeEditFormVisible=true
      }
    },
    //树刷新
    flushed() {
      console.log(this.fileList)
      // this.loading = true
      // this.getAttr()
      // setTimeout(() => {
      //   this.loading = false;
      //   this.nodeClickList = ""
      // }, 600);
    },
    //启用和停用都先判断状态
    //启用
    Enable(){
      if(this.FlagObj.lcStatus == "Enabled"){
        this.$message({
          type: 'warning',
          message: '当前分类不是停用状态'
        });
      }else {
        this.$confirm('是否将子分类一并启用?', '提示', {
          confirmButtonText: '是',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          TreeEnable(this.nodeClickList).then((res)=>{
            console.log(res)
            this.$message({
              type: 'success',
              message: '启用成功!'
            });
            this.getAttr()
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消启用'
          });
        });
      }
    },
    //停用
    Deactivate(){
      if(this.FlagObj.lcStatus ==="Disabled"){
        this.$message({
          type: 'warning',
          message: '当前分类不是启用状态!'
        });
      }else {
        this.$confirm('是否停用当前分类,停用后,子分类也将不能被使用,是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          TreeDeactivate(this.nodeClickList).then((res)=>{
            console.log(res)
            this.$message({
              type: 'success',
              message: '停用成功!'
            });
            this.nodeClickList['flag']=true;
            this.getAttr()
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消停用'
          });
        });
      }
    },
    nodeClick(data) {
      //点击左侧树右侧动态的方法
      // this.Formlist = this.crudTreeData[data.value].column
      // this.nodeList=data.value
      // this.TreeList = this.Treeform.find(item => {
      //   return item.value == data.value
      // });
      this.nodeClickList = data
      TreeObjcet(data.oid).then(res=>{
        console.log("object",res)
        this.FlagObj=res.data.data
      })
      gridCodeClassifyTemplateAttr(data.oid).then(res=>{
        console.log(res)
      }).catch(res=>{
        console.log(res)
      })
      this.Formlist = this.crudTreeData[data.value].column
      this.nodeList=data.value
      this.TreeList = this.Treeform.find(item => {
        return item.value == data.value
      });
      console.log(data)
    },
    //tab栏切换
    handleChange(column) {
@@ -415,23 +95,42 @@
    checkChange(val) {
      console.log(val)
    },
    //删除
    rowDel(row, index, done) {
      console.log(row)
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message.success('删除成功')
        done();
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    //添加
    rowSave(node,data,done,loading) {
      this.$message.success('新增回调')
      // this.form.id = new Date().getTime();
      // this.form.value=new Date().getTime();
      // this.form.children=[];
      console.log(this.form)
      // console.log("Type",node,data,done,loading)
      // console.log(node,"node")
      // console.log("data",data)
      // console.log("done",done)
      // console.log("loading",loading)
      done();
    },
  }
}
</script>
<style lang="scss">
.el-form {
  display: flex;
  flex-wrap: wrap; /* 设置可换行,以便在小屏幕设备上使用多行布局 */
}
.el-form-item {
  flex: 1; /* 设置元素占据1份空间 */
  margin-right: 1rem; /* 设置元素之间的间距 */
}
.my-messagebox {
  width: 700px;
}
.my-messageboxs {
  width: 500px;
}
</style>