ludc
2023-09-13 4a2835ddadb796c69f180097b95f971dbab4687d
Source/UBCS-WEB/src/components/refer/vciWebReferTree.vue
@@ -1,5 +1,5 @@
<template>
  <avue-input-tree ref="referTree" :props="props" :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" :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>
</template>
<script>
@@ -8,7 +8,7 @@
export default {
  name: "vciWebReferTree",
  props:["referConfig","value","text","title"],
  props:["referConfig","value","text","title","disabled"],
  data() {
    return {
      options: this.referConfig.options,
@@ -34,8 +34,8 @@
  },
  created() {
    this.getParams();
    console.log('referConfig:')
    console.log(this.referConfig)
    // console.log('referConfig:')
    // console.log(this.referConfig)
  },
  mounted() {
    if(!this.lazy){
@@ -119,13 +119,27 @@
          queryParams['replaceMap["' + key + '"]'] = this.options.replaceParams[key];//新的方式
        }
      }
      queryParams['parentValue']='\\IN(SELECT oid from PL_CODE_CLASSIFY where id =\'hesuanfenlei\')'
      this.params=queryParams;
    },
    getTree(){
      getTree(this.params,this.treeUrl).then(res => {
          this.treeData=res.data
    getTree() {
      getTree(this.params, this.treeUrl).then(res => {
        res.data.map(item => {
          if (!item.attribute) {
            item.attribute = {
              data: {}
            }
          } else {
            item.attribute.data = item.attribute.data || {}
          }
          return {
            ...item,
            leaf: !item.hasChildren
          }
        })
        this.treeData = res.data
      })
    },
    treeLoad: function (treeNode, resolve) {
      const parentOid = (treeNode.level === 0) ? 0 : treeNode.data.oid;
@@ -141,6 +155,13 @@
      }
      getLazyTree(this.params,this.treeUrl).then(res => {
        resolve(res.data.data.map(item => {
          if(!item.attribute){
            item.attribute={
              data:{}
            }
          }else{
            item.attribute.data=item.attribute.data || {}
          }
          return {
            ...item,
            leaf: !item.hasChildren
@@ -150,56 +171,44 @@
    },
    nodeClick(data, node, nodeComp){
      if(!this.isMuti) {
        //不要用watch监听value值,会找不到text
        this.value = data[this.config.valueField];
        this.text = data[this.config.textField];
        this.currentNode = data;
        this.$emit("setValue", {
          field: this.referConfig.field,
          showField: this.referConfig.showField,
          value: this.value,
          text: this.text,
          rawData: [this.currentNode]
        });
        this.setValue({checkedNodes:[data]})
      }
     },
    checked:(checkedNode, checkedData)=> {
      debugger;
      /*
      * this用时始终要报错,只能先注释
    checked(checkedNode, checkedData) {
      this.setValue(checkedData)
    },
    setValue:function (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[this.config.valueField] || item[this.config.valueField])
        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[textFieldArray[i]] || item[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));
      }
      this.value = value.join(',');
      this.text = text.join(',')*/
      this.value=checkedData.checkedKeys;
      this.text = text.join(',')
      this.$emit("setValue", {
        field: this.referConfig.field,
        showField: this.referConfig.showField,
        value: this.value,
        text: this.text,
        isTreeMuti:true,
        rawData: checkedData.checkedNodes
        text: this.text || '',
        isTreeMuti:this.isMuti,
        rawData: checkedData.checkedNodes,
        fieldMap:this.referConfig.fieldMap
      });
    }
  },
  watch:{
  }
  watch:{}
}
</script>