ludc
2023-05-16 5845950aa395da1a1f56a5fff4c80358cf4b5f7f
Source/UBCS-WEB/src/components/Tree/classifyTrees.vue
@@ -6,14 +6,14 @@
        <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">修改</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">启用</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">停用</el-button>
            <el-button plain size="small" type="primary">导出</el-button>
            <el-button plain size="small" type="primary">导入</el-button>
            <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>
@@ -50,12 +50,18 @@
            <el-button type="primary" @click="TreeAddHandler">确 定</el-button>
          </div>
        </el-dialog>
        <avue-tree ref="tree" v-model="TreeAvueform" v-loading="loading" :data="Treedata" :option="Treeoption" :defaultExpandAll="false"
                    style="height: 80.5vh;padding-top: 5px;padding-bottom: 30px"
        <!--        修改对话框-->
        <el-dialog :visible.sync="TreeEditFormVisible" append-to-body title="修改分类">
          <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"
        >
        </avue-tree>
      </basic-container>
    </el-aside>
    <el-main>
@@ -63,25 +69,47 @@
        <!--        右侧表格-->
        <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"
                       style="height: 700px"></avue-crud>
          <basic-container>
               <avue-crud v-model="crudForm" :data="this.Formlist" :option="this.crudTreeOption" v-loading="FormLoing"
               >
            <template slot="menuLeft">
              <el-button plain size="small" type="primary">查询</el-button>
              <el-button plain size="small" type="primary" @click="TemRefresh">刷新</el-button>
              <el-button plain size="small" type="primary">从其它模板克隆</el-button>
              <div style="display: inline-block"> <el-input v-model="FindText" placeholder="请输入关键字按回车查询"
                                                            size="small"
                                                            @keyup.enter.native="EnterFind"></el-input></div>
            </template>
          </avue-crud>
          </basic-container>
    <templatePro :ProData="this.ProData"></templatePro>
        </span>
        <span v-else-if="type.prop==='tab2'">
<!--          如果是表格加表单就再次引入这个classifyTreeform组件,里面是表单的内容,没用就删除掉。把上面tab栏也删除了-->
          <classifyTreeform ref="childForm" :TreeNewForm="TreeList" :nodeList="nodeList"></classifyTreeform>
          <template-pro></template-pro>
           <classifyTreeform ref="childForm" :TreeNewForm="TreeList" :nodeList="nodeList"></classifyTreeform>
        </span>
      </basic-container>
    </el-main>
  </el-container>
</template>
<script>
//这里声明一些菜单组件用法:首先布局分为左侧菜单右侧表格,可能会有右侧Tab栏加表单的情况。所以另外引入了一个右侧表单的组件"classifyTreeform"。
//首先父组件调用子组件菜单,通过provide传递参数。有Treeoption左侧树新增表单项 Treedata左侧树节点配置项 crudTreeOption右侧表格配置项 crudTreeData右侧表格显示内容
//其中表格的配置项直接父传子传递过来就行,直接:option=传递的参数名,里面数据显示的内容因为是和左侧联动的,所以重新一个Formlist,通过点击树节点下标来动态渲染右侧表格,下面方法都有具体注释
//然后再说右侧的表单,专门定义了一个组件,通过父传子再把表单数据TreeList传递过去,传递前在10deCLi1ck方法里面便了处理也是一个联动的效果,表单的配置项在哪个子组件或者父组件写都可以。
import {getAtrrList,TreeSave,TreeDel} from "@/api/template/templateAttr";
import {
  getAtrrList,
  TreeSave,
  TreeDel,
  TreeCheckDel,
  TreeObjcet,
  TreeEnable,
  TreeDeactivate,
  importClassify,
  gridCodeClassifyTemplate,
  getObjectByOid,
  gridCodeClassifyTemplateAttr
} from "@/api/template/templateAttr";
export default {
  name: "classifyTrees.vue",
@@ -91,13 +119,21 @@
  inject: ['crudTreeOption', "crudTreeData"],
  data() {
    return {
      ProData: [],
      FindText: "",
      fileList: [],
      FlagObj: {},
      //修改对话框
      TreeEditFormVisible: false,
      //添加对话框
      TreeAddFormVisible: false,
      //当前点击项
      nodeClickList: "",
      // 分类和主题库状态
      //分类和主题库状态
      TreeFlag: false,
      // 树加载
      //树加载
      loading: false,
      FormLoing:false,
      TreeAddform: {
        id: "",
        name: "",
@@ -115,13 +151,13 @@
      TreeAvueform: {},
      Treedata: [],
      Treeoption: {
        addBtn:false,
        editBtn:false,
        delBtn:false,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        defaultExpandAll: false,
        menu:false,
        //这个是多选
        multiple:true,
        menu: false,
        // //这个是多选
        // multiple: true,
      },
      crudForm: "",
      //动态切换处理过的表格数据
@@ -154,7 +190,8 @@
        }
      ],
      //传递给子组件动态渲染的数据
      TreeList: {}
      TreeList: {},
      //定义一个模板属性id,数据是模板管理表格里面的oid
    }
  },
  //tab栏默认是表格
@@ -167,7 +204,7 @@
    getAttr() {
      getAtrrList().then(res => {
        this.Treedata = res.data;
        this.Treedata.forEach((item, value) => {
        this.Treedata.forEach(() => {
          for (let i = 0; i < this.Treedata.length; i++) {
            this.Treedata[i].value = i;
          }
@@ -175,7 +212,7 @@
        //调用修改属性名方法
        this.ModifyProperties(this.Treedata, 'text', 'label');
      }).catch(res => {
        console.log(res)
        this.$message.error(res)
      })
    },
    //定义一个修改对象属性名的方法
@@ -199,41 +236,62 @@
      }
    },
    //树节点添加事件
    TreeAddHandler(){
      const data=this.TreeAddform
      this.$set(data,"parentCodeClassifyOid",this.nodeClickList.oid)
      console.log(data)
      TreeSave(data).then(res=>{
        console.log(res)
      }).catch(res=>{
        console.log(res)
    TreeAddHandler() {
      const data = this.TreeAddform
      this.$set(data, "parentCodeClassifyOid", this.nodeClickList.oid)
      TreeSave(data).then(() => {
        this.$message({
          type: 'success',
          message: '添加成功!'
        });
        this.getAttr();
        this.TreeAddFormVisible = false
        this.TreeAddform = ""
      }).catch(res => {
        this.$message({
          type: 'warning',
          message: res
        });
      })
    },
    //树节点删除按钮
    TreeDel(){
      const oid=this.nodeClickList.oid
      if(this.nodeClickList !==""){
        this.$confirm('是否删除当前选择的分类,将会把子分类一并删除,如果存在编码数据将不能被删除,是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          customClass: 'my-messagebox',
        }).then(() => {
          if(this.nodeClickList.children.length > 0){
    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(JSON.parse(oid)).then(()=>{
              TreeDel(this.nodeClickList).then(() => {
                this.$message({
                  type: 'success',
                  message: '删除成功!'
                });
              }).catch(res=>{
                this.getAttr();
              }).catch(res => {
                this.$message({
                  type: 'error',
                  type: 'warning',
                  message: res
                });
              })
@@ -243,25 +301,24 @@
                message: '已取消删除'
              });
            });
          }else {
            TreeDel(oid).then(()=>{
              this.$message({
                type: 'success',
                message: '删除成功!'
              });
            }).catch(res=>{
              this.$message({
                type: 'error',
                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
      }
    },
    //树刷新
@@ -273,31 +330,147 @@
        this.nodeClickList = ""
      }, 600);
    },
    nodeClick(data) {
      //点击左侧树右侧动态的方法
      // this.Formlist = this.crudTreeData[data.value].column
      // this.nodeList=data.value
      // this.TreeList = this.Treeform.find(item => {
      //   return item.value == data.value
      // });
    //启用和停用都先判断状态
    //启用
    Enable() {
      if (this.FlagObj.lcStatus == "Enabled") {
        this.$message({
          type: 'warning',
          message: '当前分类不是停用状态'
        });
      } else {
        this.$confirm('是否将子分类一并启用?', '提示', {
          confirmButtonText: '是',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          TreeEnable(this.nodeClickList).then((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) => {
            this.$message({
              type: 'success',
              message: '停用成功!'
            });
            this.nodeClickList['flag'] = true;
            this.getAttr()
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消停用'
          });
        });
      }
    },
    async nodeClick(data) {
      //定义一个模板属性id,数据是模板管理表格里面的oid
      this.nodeClickList = data
      console.log(data)
      console.log(data.oid)
      try {
        await TreeObjcet(data.oid).then(res => {
          this.FlagObj = res.data.data
        }).catch(res => {
          this.$message.error(res)
        })
        //模板管理表格数据
        await gridCodeClassifyTemplate(data.oid).then(res => {
          this.Formlist = res.data.data.filter(item => {
          if(item.codeclassifyoid != ""){
            return  item.codeclassifyoid == this.nodeClickList.oid
          }
          })
          console.log("formlist", this.Formlist)
          gridCodeClassifyTemplateAttr({'conditionMap[classifyTemplateOid]': this.Formlist[0].oid}).then(res => {
            this.ProData = res.data.data
            console.log(this.ProData)
          }).catch(res => {
            this.$message.error(res)
          })
        }).catch(res => {
              console.log(res)
        })
        //  基本信息表单数据
        await getObjectByOid(this.nodeClickList.oid).then(res => {
          this.TreeList = res.data.data
          // eslint-disable-next-line no-const-assig
        }).catch(res => {
          this.$message.error(res)
        })
      } catch (error) {
        console.log(error)
      }
    },
    //tab栏切换
    handleChange(column) {
      this.type = column
    },
    //模板管理表格查询
    EnterFind() {
      console.log(this.Formlist)
      if (this.FindText == "") {
        gridCodeClassifyTemplate().then(res => {
          this.Formlist = res.data.data
        })
      } else {
        gridCodeClassifyTemplate().then(res => {
            this.Formlist = res.data.data.filter(item => {
                  return item.name.includes(this.FindText)
              }
            )
          }
        )
      }
    },
    TemRefresh(){
      this.FormLoing=true
      if(this.nodeClickList.oid != ""){
        gridCodeClassifyTemplate(this.nodeClickList.oid).then(res=>{
          this.Formlist = res.data.data.filter(item => {
            return  item.codeclassifyoid == this.nodeClickList.oid
          })
        })
      }else {
        this.FormLoing=true
      }
      setTimeout(() => {
        this.FormLoing=false
      }, 600);
    },
    // 左树多选
    checkChange(val) {
      console.log(val)
    },
  }
}
</script>
<style lang="scss">
<style lang="scss" scoped>
.el-form {
  display: flex;
  flex-wrap: wrap; /* 设置可换行,以便在小屏幕设备上使用多行布局 */
@@ -307,9 +480,11 @@
  flex: 1; /* 设置元素占据1份空间 */
  margin-right: 1rem; /* 设置元素之间的间距 */
}
.my-messagebox {
  width: 700px;
}
.my-messageboxs {
  width: 500px;
}