田源
2023-12-21 2bd948dd66d69a48f0c34f8d9852e05bc574602c
Source/UBCS-WEB/src/components/refer/vciWebReferTree.vue
@@ -1,34 +1,44 @@
<template>
  <avue-input-tree ref="referTree" :props="props" :disabled="disabled" :lazy="lazy" :tree-load="treeLoad" :node-click="nodeClick" :checked="checked"
                   :leaf-only="referConfig.onlyLeaf" :multiple="isMuti" v-model="value" :placeholder="title" :dic="treeData"></avue-input-tree>
  <avue-input-tree ref="referTree"
                   v-model="value"
                   :checked="checked"
                   :dic="treeData"
                   :disabled="disabled"
                   :lazy="lazy"
                   :leaf-only="referConfig.onlyLeaf"
                   :multiple="isMuti"
                   :node-click="nodeClick"
                   :placeholder="title"
                   :props="props"
                   :tree-load="treeLoad"></avue-input-tree>
</template>
<script>
import {getTree,getLazyTree} from "@/api/refer/tree";
import {getTree, getLazyTree} from "@/api/refer/tree";
import {validatenull} from "@/util/validate";
export default {
  name: "vciWebReferTree",
  props:["referConfig","value","text","title","disabled"],
  props: ["referConfig", "value", "text", "title", "disabled"],
  data() {
    return {
      visible: false,
      options: this.referConfig.options,
      lazy: this.referConfig.options.loadType == 'node',
      isMuti:("true" == this.referConfig.options.isMuti || this.referConfig.options.isMuti == true || this.referConfig.options.muti == true) ? true : false,
      isMuti: ("true" == this.referConfig.options.isMuti || this.referConfig.options.isMuti == true || this.referConfig.options.muti == true) ? true : false,
      props: {
        value: 'oid',
        label: "name"
      },
      config:{
      config: {
        valueField: this.referConfig.valueField || this.referConfig.options.valueField || 'oid',
        textField:this.referConfig.textField || this.referConfig.options.textField || "name",
        textSep:this.referConfig.textSep || ' '
        textField: this.referConfig.textField || this.referConfig.options.textField || "name",
        textSep: this.referConfig.textSep || ' '
      },
      treeUrl: this.referConfig.options.url || '/api/ubcs-code/mdmEngineController/defaultReferTree',
      treeData: [],
      checkedData:[],
      currentNode:{},
      checkedData: [],
      currentNode: {},
      params: {},
      loadType: {'all': 'all', 'node': 'node'},
      copyParam: ['btmType', 'lnType', 'toBtmType', 'textField', 'valueField', 'parentFieldName', 'parentValue', 'sort', 'order', 'isDirection', 'whereSql', 'isMuti', 'queryScheme', 'isQueryAllColumn', 'queryColumn', 'split', 'loadType', 'onlyLeaf', 'onlyLeafText', 'parentUsedField']
@@ -38,44 +48,44 @@
    this.getParams();
  },
  mounted() {
    if(!this.lazy){
      if(this.options.data){//如果是固定数据的情况下
        this.treeData=this.options.data
      }else{
    if (!this.lazy) {
      if (this.options.data) {//如果是固定数据的情况下
        this.treeData = this.options.data
      } else {
        this.getTree()
      }
    }
  },
  computed:{},
  computed: {},
  methods: {
    getParams:function (){
    getParams: function () {
      var queryParams = {};
      if(this.options.extraParams){
      if (this.options.extraParams) {
        queryParams = this.options.extraParams;
      }
      for(var i= 0 ; i < this.copyParam.length ; i ++){
        if(this.copyParam[i] == "btmType") {
      for (var i = 0; i < this.copyParam.length; i++) {
        if (this.copyParam[i] == "btmType") {
          queryParams[this.copyParam[i]] = this.options['referBo'] || this.options['referType'];
        }else if(this.copyParam[i] in this.options){
        } else if (this.copyParam[i] in this.options) {
          queryParams[this.copyParam[i]] = this.options[this.copyParam[i]];
        }
      }
      queryParams['referBo'] = this.options['referBo'] || this.options['referType'];
      queryParams['referType']= queryParams['referBo']
      queryParams['selectAllLevel'] = (this.options.loadType == this.loadType.all?true:false);//true时后台会报错
      queryParams['referType'] = queryParams['referBo']
      queryParams['selectAllLevel'] = (this.options.loadType == this.loadType.all ? true : false);//true时后台会报错
      queryParams.muti =this.isMuti;
      if(queryParams.isQueryAllColumn =="true"){
      queryParams.muti = this.isMuti;
      if (queryParams.isQueryAllColumn == "true") {
        queryParams.isQueryAllColumn = true;
      }
      if(this.options.useFormKey && this.options.formValues){
      if (this.options.useFormKey && this.options.formValues) {
        //使用表单上的字段来过滤
        queryParams['conditionMap["' + (this.options.paramForFormKey?this.options.paramForFormKey:this.options.useFormKey)  + '"]'] = this.options.formValues[this.options.useFormKey];
        queryParams['conditionMap["' + (this.options.paramForFormKey ? this.options.paramForFormKey : this.options.useFormKey) + '"]'] = this.options.formValues[this.options.useFormKey];
      }
      if (!this.options.loadType) {
        this.options.loadType = this.loadType.node;
      }
      queryParams['queryAllLevel'] = this.options.loadType == this.loadType.node? false : true;//默认逐级展开
      queryParams['queryAllLevel'] = this.options.loadType == this.loadType.node ? false : true;//默认逐级展开
      queryParams['loadType'] = this.options.loadType;
      queryParams['multipleSelect'] = this.isMuti;
      queryParams['isMuti'] = queryParams['multipleSelect'];
@@ -83,10 +93,10 @@
        queryParams['order'] = this.options.initSort.type;//方法
        queryParams['sort'] = this.options.initSort.field;//字段
      }
      if(this.options.sortField){
      if (this.options.sortField) {
        queryParams['sort'] = this.options.sortField;//字段
      }
      if(this.options.sortType){
      if (this.options.sortType) {
        queryParams['order'] = this.options.sortType;//方法
      }
      if (this.options.rootParams) {
@@ -100,7 +110,7 @@
          queryParams['conditionMap["' + key + '"]'] = this.options.conditionParams[key];//新的方式
        }
      }
      if(this.options.where ) {
      if (this.options.where) {
        for (var key in this.options.where) {
          queryParams['conditionMap["' + key + '"]'] = this.options.where[key];//新
        }
@@ -125,7 +135,7 @@
          queryParams['replaceMap["' + key + '"]'] = this.options.replaceParams[key];//新的方式
        }
      }
      this.params=queryParams;
      this.params = queryParams;
    },
    getTree() {
@@ -150,24 +160,24 @@
    treeLoad: function (treeNode, resolve) {
      //逐级加载
      const parentOid = (treeNode.level === 0) ? 0 : treeNode.data.oid;
      this.params.parentOid=parentOid.indexOf('@vcitreesep@') > -1 ? parentOid.split('@vcitreesep@')[1] : parentOid;
      this.params.parentValue=this.params.parentOid;
      this.params.parentBtmName=treeNode.data.attributes.btmName || treeNode.data.attributes.btmname;
      this.params.parentBtmType=this.params.parentBtmName;
      this.params.parentOid = parentOid.indexOf('@vcitreesep@') > -1 ? parentOid.split('@vcitreesep@')[1] : parentOid;
      this.params.parentValue = this.params.parentOid;
      this.params.parentBtmName = treeNode.data.attributes.btmName || treeNode.data.attributes.btmname;
      this.params.parentBtmType = this.params.parentBtmName;
      if (this.options.rootParams && treeNode.level !== 0) {
        for (var key in this.options.rootParams) {
          delete this.params[key]
        }
      }
      getLazyTree(this.params,this.treeUrl).then(res => {
      getLazyTree(this.params, this.treeUrl).then(res => {
        resolve(res.data.data.map(item => {
          if(!item.attributes){
            item.attributes={
              data:{}
          if (!item.attributes) {
            item.attributes = {
              data: {}
            }
          }else{
            item.attributes.data=item.attributes.data || {}
          } else {
            item.attributes.data = item.attributes.data || {}
          }
          return {
            ...item,
@@ -176,39 +186,39 @@
        }))
      });
    },
    nodeClick(data, node, nodeComp){
      if(!this.isMuti) {
        this.setValue({checkedNodes:[data]})
    nodeClick(data, node, nodeComp) {
      if (!this.isMuti) {
        this.setValue({checkedNodes: [data]})
      }
    },
    checked(checkedNode, checkedData) {
      this.setValue(checkedData)
    },
    setValue:function (checkedData){
      this.checkedData=checkedData
    setValue: function (checkedData) {
      this.checkedData = checkedData
      var value = [];
      var text = [];
      const textSep =this.config.textSep;
      for(var j =0;j<checkedData.checkedNodes.length;j++){
        const item=checkedData.checkedNodes[j];
        var v=this.config.valueField.indexOf("attribute.")>=0?(item.attributes[this.config.valueField.replace("attribute.","")] || item.attributes.data[this.config.valueField.replace("attribute.","")]):(item.attributes[this.config.valueField] || item[this.config.valueField] || item.attributes.data[this.config.valueField])
      const textSep = this.config.textSep;
      for (var j = 0; j < checkedData.checkedNodes.length; j++) {
        const item = checkedData.checkedNodes[j];
        var v = this.config.valueField.indexOf("attribute.") >= 0 ? (item.attributes[this.config.valueField.replace("attribute.", "")] || item.attributes.data[this.config.valueField.replace("attribute.", "")]) : (item.attributes[this.config.valueField] || item[this.config.valueField] || item.attributes.data[this.config.valueField])
        value.push(v);
        var tempRaw = [];
        var textFieldArray = this.config.textField.split(",");
        for (var i = 0; i < textFieldArray.length; i++) {//显示的字段可能有多个
          if (!validatenull(textFieldArray[i])) {
            var t=textFieldArray[i].indexOf("attribute.")>=0?(item.attributes[textFieldArray[i].replace("attribute.","")] ||item.attributes.data[textFieldArray[i].replace("attribute.","")]):(item.attributes[textFieldArray[i]] || item[textFieldArray[i]] || item.attributes.data[textFieldArray[i]])
            var t = textFieldArray[i].indexOf("attribute.") >= 0 ? (item.attributes[textFieldArray[i].replace("attribute.", "")] || item.attributes.data[textFieldArray[i].replace("attribute.", "")]) : (item.attributes[textFieldArray[i]] || item[textFieldArray[i]] || item.attributes.data[textFieldArray[i]])
            tempRaw.push(t);
          }
        }
        text.push(tempRaw.join(textSep));
      }
      let mapFields =this.referConfig.fieldMap || {};
      let mapFields = this.referConfig.fieldMap || {};
      try {
        if(!validatenull(this.options.mapFields)){
          mapFields =Object.assign(this.referConfig.fieldMap,JSON.parse(this.options.mapFields)) ;
        if (!validatenull(this.options.mapFields)) {
          mapFields = Object.assign(this.referConfig.fieldMap, JSON.parse(this.options.mapFields));
        }
      }catch (e) {
      } catch (e) {
      }
      this.value = value.join(',');
@@ -218,9 +228,9 @@
        showField: this.referConfig.showField,
        value: this.value,
        text: this.text || '',
        isTreeMuti:this.isMuti,
        isTreeMuti: this.isMuti,
        rawData: checkedData.checkedNodes,
        fieldMap:mapFields
        fieldMap: mapFields
      });
    }
  }