1
+ import eventBus from "../utils/eventBus" ;
2
+
1
3
Component ( {
2
4
behaviors : [ 'wx://form-field' ] ,
3
5
externalClasses : [ 'l-class' , 'l-error-text' , 'l-error-text-class' ] ,
@@ -40,8 +42,8 @@ Component({
40
42
41
43
init ( target ) {
42
44
if ( this . _keys === undefined ) this . _keys = { } ;
43
- // if(this._selected === undefined) this._selected = {};
44
- // this.checkDefaultItem(target);
45
+ if ( this . _selected === undefined ) this . _selected = { } ;
46
+ this . checkDefaultItem ( target ) ;
45
47
this . checkedKeyRepeat ( target ) ;
46
48
} ,
47
49
@@ -55,9 +57,9 @@ Component({
55
57
} ,
56
58
57
59
checkDefaultItem ( target ) {
58
- const { key, checked } = target . properties ;
60
+ const { key, checked, cell } = target . properties ;
59
61
if ( checked ) {
60
- this . _selected [ key ] = checked ;
62
+ this . _selected [ key ] = { ... cell , checked : true , value : key } ;
61
63
}
62
64
} ,
63
65
@@ -74,12 +76,13 @@ Component({
74
76
} ,
75
77
76
78
onEmitEventHandle ( currentItem ) {
77
- // currentItem.checked ? this.addSelect(currentItem.key ):this.removeSelect(currentItem.key);
79
+ currentItem . checked ? this . addSelect ( currentItem ) :this . removeSelect ( currentItem . key ) ;
78
80
79
81
this . triggerEvent ( 'linchange' , currentItem , {
80
82
bubbles : true ,
81
83
composed : true
82
84
} ) ;
85
+ eventBus . emit ( `lin-form-change-${ this . id } ` , this . id ) ;
83
86
} ,
84
87
onEmitOverflowHandle ( data ) {
85
88
this . triggerEvent ( 'linout' , data , {
@@ -90,16 +93,21 @@ Component({
90
93
removeSelect ( key ) {
91
94
delete this . _selected [ key ] ;
92
95
} ,
93
- addSelect ( key ) {
94
- this . _selected [ key ] = key ;
96
+ addSelect ( currentItem ) {
97
+ let { key, ...obj } = currentItem
98
+ this . _selected [ key ] = { ...obj , value : key } ;
95
99
} ,
96
- _selected ( ) {
97
- const items = this . getRelationNodes ( '../checkbox/index' ) ;
98
- let num = 0 ;
99
- items . map ( item => {
100
- item . properties . checked ? num ++ : '' ;
101
- } ) ;
102
- return num ;
100
+ getValues ( ) {
101
+ return Object . values ( this . _selected )
102
+ } ,
103
+ reset ( ) {
104
+ this . _selected = { }
105
+ const list = this . getRelationNodes ( '../checkbox/index' ) ;
106
+ return list . forEach ( item => {
107
+ return item . setData ( {
108
+ checked : false
109
+ } )
110
+ } )
103
111
}
104
112
105
113
}
0 commit comments