2020@interface EditLabelViewController () <UITableViewDataSource, UITableViewDelegate, SWTableViewCellDelegate, UITextFieldDelegate>
2121{
2222 NSString *_tempLabel;
23+ NSMutableArray *_tempArray;
2324}
2425@property (strong , nonatomic ) NSMutableArray *labels;
2526
@@ -86,6 +87,12 @@ - (void)dealloc
8687 _myTableView.dataSource = nil ;
8788}
8889
90+ - (void )setCurProTopic : (ProjectTopic *)curProTopic
91+ {
92+ _curProTopic = curProTopic;
93+ _tempArray = [NSMutableArray arrayWithArray: _curProTopic.mdLabels];
94+ }
95+
8996- (void )sendRequest
9097{
9198 [self .view beginLoading ];
@@ -95,7 +102,20 @@ - (void)sendRequest
95102 [weakSelf.view endLoading ];
96103 if (data) {
97104 [_labels addObjectsFromArray: data];
98-
105+ for (ProjectTopicLabel *lbl in _labels) {
106+ for (ProjectTopicLabel *tLbl in _curProTopic.mdLabels ) {
107+ if ([lbl.id integerValue ] == [tLbl.id integerValue ]) {
108+ tLbl.name = lbl.name ;
109+ break ;
110+ }
111+ }
112+ for (ProjectTopicLabel *tLbl in _tempArray) {
113+ if ([lbl.id integerValue ] == [tLbl.id integerValue ]) {
114+ tLbl.name = lbl.name ;
115+ break ;
116+ }
117+ }
118+ }
99119 [weakSelf.myTableView reloadData ];
100120 }
101121 }];
@@ -115,22 +135,39 @@ - (NSString *)toDelPath:(NSInteger)index
115135#pragma mark - click
116136- (void )okBtnClick
117137{
138+ _curProTopic.mdLabels = _tempArray;
118139
119- [self .navigationController popViewControllerAnimated: YES ];
140+ self.navigationItem .rightBarButtonItem .enabled = NO ;
141+ if (_isSaveChange) {
142+ @weakify (self);
143+ [[Coding_NetAPIManager sharedManager ] request_ModifyProjectTpoic: self .curProTopic andBlock: ^(id data, NSError *error) {
144+ @strongify (self);
145+ self.navigationItem .rightBarButtonItem .enabled = YES ;
146+ if (data) {
147+ _curProTopic.labels = [NSMutableArray arrayWithArray: _curProTopic.mdLabels];
148+ if (self.topicChangedBlock ) {
149+ self.topicChangedBlock ();
150+ }
151+ [self .navigationController popViewControllerAnimated: YES ];
152+ }
153+ }];
154+ } else {
155+ [self .navigationController popViewControllerAnimated: YES ];
156+ }
120157}
121158
122159- (void )addBtnClick : (UIButton *)sender
123160{
124161 [_mCurrentTextField resignFirstResponder ];
125162 if (_tempLabel.length > 0 ) {
126163 __weak typeof (self) weakSelf = self;
127- [[Coding_NetAPIManager sharedManager ] request_ProjectTopicLabel_Add_WithPath: [self toLabelPath ] withParams: @{@" name" : [_tempLabel aliasedString ], @" color" : @" #d8f3e4 " } andBlock: ^(id data, NSError *error) {
164+ [[Coding_NetAPIManager sharedManager ] request_ProjectTopicLabel_Add_WithPath: [self toLabelPath ] withParams: @{@" name" : [_tempLabel aliasedString ], @" color" : kColorLabelBg } andBlock: ^(id data, NSError *error) {
128165 if (!error) {
129166 ProjectTopicLabel *ptLabel = [[ProjectTopicLabel alloc ] init ];
130167 ptLabel.name = _tempLabel;
131168 ptLabel.id = data;
132169 ptLabel.owner_id = _curProTopic.project_id ;
133- ptLabel.color = @" #d8f3e4 " ;
170+ ptLabel.color = kColorLabelBg ;
134171 [_labels addObject: ptLabel];
135172 [weakSelf.myTableView reloadData ];
136173 _tempLabel = @" " ;
@@ -172,6 +209,15 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
172209 EditLabelCell *cell = [tableView dequeueReusableCellWithIdentifier: kCellIdentifier_EditLabelCell forIndexPath: indexPath];
173210 cell.nameLbl .text = ptLabel.name ;
174211
212+ BOOL selected = FALSE ;
213+ for (ProjectTopicLabel *lbl in _curProTopic.mdLabels ) {
214+ if ([lbl.id integerValue ] == [ptLabel.id integerValue ]) {
215+ selected = TRUE ;
216+ break ;
217+ }
218+ }
219+ cell.selectBtn .selected = selected;
220+
175221 [cell setRightUtilityButtons: [self rightButtons ] WithButtonWidth: [EditLabelCell cellHeight ]];
176222 cell.delegate = self;
177223
@@ -202,6 +248,31 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
202248 if (indexPath.section > 0 ) {
203249 EditLabelCell *cell = (EditLabelCell *)[tableView cellForRowAtIndexPath: indexPath];
204250 cell.selectBtn .selected = !cell.selectBtn .selected ;
251+
252+ ProjectTopicLabel *lbl = _labels[indexPath.row];
253+
254+ if (cell.selectBtn .selected ) {
255+ BOOL add = TRUE ;
256+ for (ProjectTopicLabel *tempLbl in _tempArray) {
257+ if ([tempLbl.id integerValue ] == [lbl.id integerValue ]) {
258+ add = FALSE ;
259+ break ;
260+ }
261+ }
262+ if (add) {
263+ [_tempArray addObject: lbl];
264+ self.navigationItem .rightBarButtonItem .enabled = YES ;
265+ }
266+ } else {
267+ for (ProjectTopicLabel *tempLbl in _tempArray) {
268+ if ([tempLbl.id integerValue ] == [lbl.id integerValue ]) {
269+ [_tempArray removeObject: tempLbl];
270+ self.navigationItem .rightBarButtonItem .enabled = YES ;
271+
272+ break ;
273+ }
274+ }
275+ }
205276 }
206277}
207278
@@ -255,38 +326,55 @@ - (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityBut
255326 NSIndexPath *indexPath = [self .myTableView indexPathForCell: cell];
256327
257328 if (index == 0 ) {
258- [self renameLabel : indexPath.row];
329+ [self renameBtnClick : indexPath.row];
259330 } else {
260331 __weak typeof (self) weakSelf = self;
261332 ProjectTopicLabel *ptLabel = [_labels objectAtIndex: indexPath.row];
262333 NSString *tip = [NSString stringWithFormat: @" 确定要删除标签:%@ ?" , ptLabel.name];
263334 UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle: tip buttonTitles: nil destructiveTitle: @" 确认删除" cancelTitle: @" 取消" andDidDismissBlock: ^(UIActionSheet *sheet, NSInteger index) {
264335 if (index == 0 ) {
265- [weakSelf deleteLabel : indexPath.row];
336+ [weakSelf deleteBtnClick : indexPath.row];
266337 }
267338 }];
268339 [actionSheet showInView: self .view];
269340 }
270341}
271342
272- - (void )renameLabel : (NSInteger )index
343+ - (void )renameBtnClick : (NSInteger )index
273344{
274345 ResetLabelViewController *vc = [[ResetLabelViewController alloc ] init ];
275346 vc.ptLabel = [_labels objectAtIndex: index];
347+ vc.curProTopic = _curProTopic;
276348 [self .navigationController pushViewController: vc animated: YES ];
277349}
278350
279- - (void )deleteLabel : (NSInteger )index
351+ - (void )deleteBtnClick : (NSInteger )index
280352{
281353 __weak typeof (self) weakSelf = self;
282354 [[Coding_NetAPIManager sharedManager ] request_ProjectTopicLabel_Del_WithPath: [self toDelPath: index] andBlock: ^(id data, NSError *error) {
283355 if (!error) {
284- [weakSelf.labels removeObjectAtIndex: index];
285- [weakSelf.myTableView reloadData ];
356+ [weakSelf deleteLabel: index];
286357 }
287358 }];
288359}
289360
361+ - (void )deleteLabel : (NSInteger )index
362+ {
363+ ProjectTopicLabel *lbl = _labels[index];
364+ for (ProjectTopicLabel *tempLbl in _tempArray) {
365+ if ([tempLbl.id integerValue ] == [lbl.id integerValue ]) {
366+ [_tempArray removeObject: tempLbl];
367+ self.navigationItem .rightBarButtonItem .enabled = YES ;
368+ break ;
369+ }
370+ }
371+ [self .labels removeObjectAtIndex: index];
372+ [self .myTableView reloadData ];
373+ }
374+
375+ - (void )renameLabel : (NSInteger )index
376+ {
377+ }
290378#pragma mark - UITextFieldDelegate
291379- (BOOL )textFieldShouldBeginEditing : (UITextField *)textField
292380{
0 commit comments