wangting
2023-06-07 a5cb45db6a24630df3b8bab8df51cc153dd4c751
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<template>
  <avue-input-tree ref="referTree" :props="props" :lazy="lazy" :tree-load="treeLoad" :node-click="nodeClick" :leaf-only="!referConfig.onlyLeaf" :multiple="isMuti" v-model="value" :placeholder="placeholder" :dic="treeData"></avue-input-tree>
</template>
 
<script>
import {getTree,getLazyTree} from "@/api/refer/tree";
 
export default {
  name: "vciWebReferTree",
  props:["referConfig","value","text"],
  data() {
    return {
      options: this.referConfig.options,
      lazy: this.referConfig.options.loadType == 'node',
      isMuti: this.referConfig.isMuti,
      placeholder: this.referConfig.placeholder || '请选择内容',
      props: {
        value: this.referConfig.valueField || this.referConfig.options.valueField || 'oid',
        label: this.referConfig.textField || this.referConfig.options.textField || "name"
        //value:"value",
        //label:"title"
      },
      treeUrl: this.referConfig.options.url || '/api/ubcs-code/codeClassify/treeCodeClassify',
      treeData: [],
      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']
    }
  },
  created() {
    this.getParams();
    console.log('referConfig:')
    console.log(this.referConfig)
  },
  mounted() {
    if(!this.lazy){
      if(this.options.data){//如果是固定数据的情况下
        this.treeData=this.options.data
      }else{
        this.getTree()
      }
    }
  },
  methods: {
    getParams:function (){
      var queryParams = {};
      if(this.options.extraParams){
        queryParams = this.options.extraParams;
      }
      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){
          queryParams[this.copyParam[i]] = this.options[this.copyParam[i]];
        }
      }
      queryParams['referBo'] = this.options['referBo'] || this.options['referType'];
      queryParams['selectAllLevel'] = (this.options.loadType == this.loadType.all?true:false);//true时后台会报错
      if(queryParams.isMuti =="true"){
        queryParams.muti =true;
      }
      if(queryParams.isQueryAllColumn =="true"){
        queryParams.isQueryAllColumn = true;
      }
      if(this.options.useFormKey && this.options.formValues){
        //使用表单上的字段来过滤
        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['loadType'] = this.options.loadType;
      queryParams['multipleSelect'] = this.isMuti;
      queryParams['isMuti'] = queryParams['multipleSelect'];
      if (this.options.remoteSort && this.options.initSort) {
        queryParams['order'] = this.options.initSort.type;//方法
        queryParams['sort'] = this.options.initSort.field;//字段
      }
      if (this.options.rootParams) {
        for (var key in this.options.rootParams) {
          queryParams[key] = this.options.rootParams[key];
        }
      }
      if (this.options.conditionParams) {
        //说明是扩展属性
        for (var key in this.options.conditionParams) {
          queryParams['conditionMap["' + key + '"]'] = this.options.conditionParams[key];//新的方式
        }
      }
      if(this.options.where ) {
        for (var key in this.options.where) {
          queryParams['conditionMap["' + key + '"]'] = this.options.where[key];//新
        }
      }
      if (this.options.treeExtandParams) {
        //说明是扩展属性
        for (var key in this.options.treeExtandParams) {
          queryParams['extandParamsMap["' + key + '"]'] = this.options.treeExtandParams[key];//新的方式
        }
      }
      if (this.options.sourceDataParams) {
        //说明是扩展属性
        for (var key in this.options.sourceDataParams) {
          if (key && key.constructor === Object) return;
          queryParams['sourceData["' + key + '"]'] = this.options.sourceDataParams[key];//新的方式
        }
      }
      if (this.options.replaceParams) {
        //说明是扩展属性
        for (var key in this.options.replaceParams) {
          if (key && key.constructor === Object) return;
          queryParams['replaceMap["' + key + '"]'] = this.options.replaceParams[key];//新的方式
        }
      }
      this.params=queryParams;
 
    },
    getTree(){
      getTree(this.params,this.treeUrl).then(res => {
          this.treeData=res.data
        })
    },
    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;
 
      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 => {
        resolve(res.data.data.map(item => {
          return {
            ...item,
            leaf: !item.hasChildren
          }
        }))
      });
    },
    nodeClick(data){
      //不要用watch监听value值,会找不到text
      this.value=data[this.props.value];
      this.text=data[this.props.label];
      this.currentNode=data;
      this.$emit("setValue", {field:this.referConfig.field,showField:this.referConfig.showField,value:this.value,text:this.text,rawData:this.currentNode});
    }
  },
  watch:{
  }
}
</script>
 
<style scoped>
 
</style>