@@ -235,10 +235,16 @@ let methods = {
235235 for ( const key in this . _searchFormFields ) {
236236 let value = this . _searchFormFields [ key ] ;
237237 if ( this . emptyValue ( value ) ) continue ;
238+
238239 if ( typeof value == "number" ) {
239240 value = value + "" ;
240241 }
241242 let displayType = this . getSearchItem ( key ) ;
243+ //联级只保留选中节点的最后一个值
244+ if ( displayType == "cascader" ) {
245+ //查询下面所有的子节点,如:选中的是父节点,应该查询下面所有的节点数据--待完
246+ value = value . length ? ( value [ value . length - 1 ] + "" ) : "" ;
247+ }
242248 if (
243249 typeof value == "string" ||
244250 [ "date" , "datetime" ] . indexOf ( displayType ) == - 1
@@ -384,6 +390,7 @@ let methods = {
384390 }
385391 } ,
386392 resetForm ( formName , sourceObj ) {
393+ // return;
387394 //重置表单数据
388395 if ( this . $refs [ formName ] ) {
389396 this . $refs [ formName ] . reset ( ) ;
@@ -404,6 +411,7 @@ let methods = {
404411 this . getKeyValueType ( this . searchFormOptions , false ) ;
405412 this . keyValueType . _dinit = true ;
406413 }
414+ var _cascaderParentTree ;
407415 for ( const key in form ) {
408416 if ( sourceObj . hasOwnProperty ( key ) ) {
409417 let newVal = sourceObj [ key ] ;
@@ -415,7 +423,26 @@ let methods = {
415423 kv_type == "cascader"
416424 ) {
417425 // 2020.05.31增加iview组件Cascader
418- if (
426+ // 2020.11.01增加iview组件Cascader表单重置时查询所有的父节点
427+ if ( kv_type == "cascader" ) {
428+ var treeDic = this . dicKeys . find ( dic => {
429+ return dic . fileds && dic . fileds . indexOf ( key ) != - 1 ;
430+ } )
431+ if ( treeDic && treeDic . orginData && treeDic . orginData . length ) {
432+ if ( typeof treeDic . orginData [ 0 ] . id == 'number' ) {
433+ newVal = ~ ~ newVal ;
434+ } else {
435+ newVal = newVal + '' ;
436+ }
437+ _cascaderParentTree = this . base . getTreeAllParent ( newVal , treeDic . orginData ) ;
438+ if ( _cascaderParentTree ) {
439+ newVal = _cascaderParentTree . map ( x => { return x . id } )
440+ }
441+ } else {
442+ newVal = [ newVal ] ;
443+ }
444+ }
445+ else if (
419446 newVal != "" &&
420447 newVal != undefined &&
421448 typeof newVal == "string"
@@ -437,7 +464,21 @@ let methods = {
437464 newVal += "" ;
438465 }
439466 }
440- form [ key ] = newVal ;
467+ if ( newVal instanceof Array ) {
468+ form [ key ] . splice ( 0 )
469+ // this.$set(form, key, newVal);
470+ form [ key ] . push ( ...newVal ) ;
471+ this . $nextTick ( ( ) => {
472+ //封装后iview原生监听不到model变化,后面再调试看看2020.11.01
473+ _cascaderParentTree = _cascaderParentTree || [ ] ;
474+ _cascaderParentTree . forEach ( c => {
475+ c . label = c . value ;
476+ } )
477+ this . $refs . form . $refs [ key ] [ 0 ] . selected = _cascaderParentTree ;
478+ } ) ;
479+ } else {
480+ form [ key ] = newVal ;
481+ }
441482 } else {
442483 form [ key ] = form [ key ] instanceof Array ? [ ] : "" ;
443484 }
@@ -484,14 +525,18 @@ let methods = {
484525 _editFormFields [ key ] = this . _editFormFields [ key ] ;
485526 }
486527 }
487-
488- // else {
489- // _editFormFields = this._editFormFields;
490- // }
491528 //将数组转换成string
529+ //2020.11.01增加级联处理
492530 for ( const key in _editFormFields ) {
493531 if ( _editFormFields [ key ] instanceof Array ) {
494- _editFormFields [ key ] = _editFormFields [ key ] . join ( "," ) ;
532+
533+ var iscascader = this . dicKeys . some ( x => { return x . type == "cascader" && x . fileds && x . fileds . indexOf ( key ) != - 1 } ) ;
534+ if ( iscascader && _editFormFields [ key ] . length ) {
535+ _editFormFields [ key ] = _editFormFields [ key ] [ _editFormFields [ key ] . length - 1 ] ;
536+ } else {
537+ _editFormFields [ key ] = _editFormFields [ key ] . join ( "," ) ;
538+ }
539+
495540 }
496541 }
497542
@@ -894,11 +939,30 @@ let methods = {
894939 keys . push ( d . dataKey ) ;
895940 //2020.05.03修复查询表单与编辑表单type类型变成强一致性的问题
896941 //this.dicKeys.push({ dicNo: d.dataKey, data: [], type: d.type });
897- let _dic = { dicNo : d . dataKey , data : [ ] } ;
942+ // 2020.11.01增加iview组件Cascader数据源存储
943+ let _dic = { dicNo : d . dataKey , data : [ ] , fileds : [ d . field ] , orginData : [ ] } ;
944+ if ( d . type == "cascader" ) {
945+ _dic . type = "cascader" ;
946+ }
898947 if ( isEdit ) {
899- _dic [ " e_type" ] = d . type ;
948+ _dic [ ' e_type' ] = d . type ;
900949 }
901950 this . dicKeys . push ( _dic ) ;
951+ } else if ( d . type == "cascader" ) {
952+ //强制开启联级可以选择某个节点
953+ if ( ! d . hasOwnProperty ( "changeOnSelect" ) ) {
954+ d . changeOnSelect = true ;
955+ // d.formatter = label => {
956+ // return label.join(' / ')
957+ // };
958+ }
959+
960+ this . dicKeys . forEach ( x => {
961+ if ( x . dicNo == d . dataKey ) {
962+ x . type = "cascader" ;
963+ x . fileds . push ( d . field ) ;
964+ }
965+ } )
902966 }
903967
904968 //2020.01.30移除内部表单formOptions数据源配置格式data.data,所有参数改为与组件api格式相同
@@ -929,11 +993,16 @@ let methods = {
929993 return x . dicNo == key ;
930994 } ) ;
931995 if ( ! dic || dic . length == 0 ) {
932- dicKeys . push ( { dicNo : key , config : "" , data : [ ] } ) ;
996+ dicKeys . push ( { dicNo : key , data : [ ] } ) ;
933997 dic = [ dicKeys [ dicKeys . length - 1 ] ] ;
934998 keys . push ( key ) ;
935999 }
936- item . bind = dic [ 0 ] ;
1000+ //2020.11.01增加级联处理
1001+ if ( dic [ 0 ] . type == "cascader" ) {
1002+ item . bind = { data : dic [ 0 ] . orginData , tyep : "select" }
1003+ } else {
1004+ item . bind = dic [ 0 ] ;
1005+ }
9371006 //2020.05.03优化table数据源checkbox与select类型从编辑列中选取
9381007 item . bind . type = item . bind . e_type || "string" ;
9391008 } ) ;
@@ -944,12 +1013,16 @@ let methods = {
9441013 dic . forEach ( d => {
9451014 this . dicKeys . forEach ( x => {
9461015 if ( x . dicNo != d . dicNo ) return true ;
947- // try {
948- // x.config = eval("(" + d.config + ")");
949- // } catch (error) {
950- // x.config = { valueField: '', textField: '' }
951- // }
952- if ( d . data . length > 0 && ! d . data [ 0 ] . hasOwnProperty ( "key" ) ) {
1016+ //2020.10.26增加级联数据源绑定处理
1017+ if ( x . type == "cascader" ) {
1018+ // x.data=d.data;
1019+ //生成tree结构
1020+ x . data . push ( ... this . base . convertTree ( JSON . parse ( JSON . stringify ( d . data ) ) , ( node , data , isRoot ) => {
1021+ node . label = node . value ;
1022+ node . value = node . key ;
1023+ } ) ) ;
1024+ x . orginData . push ( ...d . data ) ;
1025+ } else if ( d . data . length > 0 && ! d . data [ 0 ] . hasOwnProperty ( "key" ) ) {
9531026 let source = d . data ,
9541027 newSource = new Array ( source . length ) ;
9551028 for ( let index = 0 ; index < source . length ; index ++ ) {
0 commit comments