| | |
| | | <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> |
| | | <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> |
| | | </template> |
| | | |
| | | <script> |
| | | import {getTree,getLazyTree} from "@/api/refer/tree"; |
| | | import {validatenull} from "@/util/validate"; |
| | | |
| | | export default { |
| | | name: "vciWebReferTree", |
| | | props:["referConfig","value","text"], |
| | | props:["referConfig","value","text","title"], |
| | | data() { |
| | | return { |
| | | options: this.referConfig.options, |
| | | lazy: this.referConfig.options.loadType == 'node', |
| | | isMuti: this.referConfig.isMuti, |
| | | placeholder: this.referConfig.placeholder || '请选择内容', |
| | | isMuti:("true" == this.referConfig.options.isMuti || this.referConfig.options.isMuti == true || this.referConfig.options.muti == true) ? true : false, |
| | | props: { |
| | | value: this.referConfig.valueField || this.referConfig.options.valueField || 'oid', |
| | | label: this.referConfig.textField || this.referConfig.options.textField || "name" |
| | | //value:"value", |
| | | //label:"title" |
| | | value: 'oid', |
| | | label: "name" |
| | | }, |
| | | treeUrl: this.referConfig.options.url || '/api/ubcs-code/codeClassify/treeCodeClassify', |
| | | config:{ |
| | | valueField: this.referConfig.valueField || this.referConfig.options.valueField || 'oid', |
| | | textField:this.referConfig.textField || this.referConfig.options.textField || "name", |
| | | textSep:this.referConfig.textSep || ' ' |
| | | }, |
| | | treeUrl: this.referConfig.options.url || '/api/ubcs-code/mdmEngineController/defaultReferTree', |
| | | treeData: [], |
| | | selectionList: [], |
| | | currentNode:{}, |
| | | params: {}, |
| | | loadType: {'all': 'all', 'node': 'node'}, |
| | |
| | | } |
| | | } |
| | | }, |
| | | computed:{}, |
| | | methods: { |
| | | getParams:function (){ |
| | | var queryParams = {}; |
| | |
| | | } |
| | | } |
| | | queryParams['referBo'] = this.options['referBo'] || this.options['referType']; |
| | | queryParams['referType']= queryParams['referBo'] |
| | | queryParams['selectAllLevel'] = (this.options.loadType == this.loadType.all?true:false);//true时后台会报错 |
| | | if(queryParams.isMuti =="true"){ |
| | | queryParams.muti =true; |
| | | } |
| | | |
| | | queryParams.muti =this.isMuti; |
| | | if(queryParams.isQueryAllColumn =="true"){ |
| | | queryParams.isQueryAllColumn = true; |
| | | } |
| | |
| | | })) |
| | | }); |
| | | }, |
| | | 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}); |
| | | nodeClick(data, node, nodeComp){ |
| | | if(!this.isMuti) { |
| | | this.setValue({checkedNodes:[data]}) |
| | | } |
| | | }, |
| | | 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]) |
| | | 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]]) |
| | | tempRaw.push(t); |
| | | } |
| | | } |
| | | text.push(tempRaw.join(textSep)); |
| | | } |
| | | this.value = value.join(','); |
| | | this.text = text.join(',') |
| | | this.$emit("setValue", { |
| | | field: this.referConfig.field, |
| | | showField: this.referConfig.showField, |
| | | value: this.value, |
| | | text: this.text || '', |
| | | isTreeMuti:this.isMuti, |
| | | rawData: checkedData.checkedNodes |
| | | }); |
| | | } |
| | | }, |
| | | watch:{ |
| | | } |
| | | watch:{} |
| | | } |
| | | </script> |
| | | |