You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
161 lines
5.3 KiB
161 lines
5.3 KiB
// |
|
// TimeframeListViewController.m |
|
// tongxin |
|
// |
|
// Created by ecell on 2023/7/12. |
|
// Copyright © 2023 xTT. All rights reserved. |
|
// |
|
|
|
#import "TimeframeListViewController.h" |
|
#import "CommonTableView.h" |
|
#import "TimeframeTableViewCell.h" |
|
#import "AddTimeframeViewController.h" |
|
|
|
@interface TimeframeListViewController ()<CommonTableViewDelegate> |
|
@property (nonatomic ,strong) CommonTableView *listTable; |
|
|
|
@property (nonatomic ,strong) NSMutableArray *modelArr; |
|
|
|
|
|
@end |
|
|
|
@implementation TimeframeListViewController |
|
|
|
- (void)viewDidLoad { |
|
[super viewDidLoad]; |
|
// Do any additional setup after loading the view. |
|
self.zx_navTitle = @"使用时段"; |
|
self.view.backgroundColor = tabViewBG; |
|
self.modelArr = [NSMutableArray new]; |
|
[self zx_setRightBtnWithText:@"保存" clickedBlock:^(ZXNavItemBtn * _Nonnull btn) { |
|
if (self.modelArr.count <= 0) |
|
{ |
|
[SVProgressHUD showErrorWithStatus:@"请添加使用时段"]; |
|
return; |
|
} |
|
[self save]; |
|
}]; |
|
|
|
[self.view addSubview:self.listTable]; |
|
[self.listTable mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.right.equalTo(self.view); |
|
make.top.equalTo(self.view).offset(iPhoneX_NavHeight); |
|
make.bottom.equalTo(self.view.mas_bottom); |
|
}]; |
|
|
|
WEAKSELF |
|
UIButton *addBtn = [UICommon ui_buttonSimple:CGRectZero font:FontBold_(48) normalColor:KKWhiteColorColor normalText:@"+" click:^(id x) { |
|
[weakSelf pusAddView:nil]; |
|
}]; |
|
addBtn.backgroundColor = mainColor; |
|
addBtn.layer.cornerRadius = 22; |
|
addBtn.layer.masksToBounds = YES; |
|
addBtn.clipsToBounds = YES; |
|
[self.view addSubview:addBtn]; |
|
[addBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.right.equalTo(self.view.mas_right).inset(40); |
|
make.bottom.equalTo(self.view.mas_bottom).inset(TabBarHeight+10); |
|
make.size.mas_equalTo(CGSizeMake(44, 44)); |
|
}]; |
|
|
|
if (self.model.useTime.length > 0) |
|
[self modelzhuanhuan:self.model.useTime]; |
|
} |
|
|
|
- (CommonTableView *)listTable |
|
{ |
|
if (!_listTable) |
|
{ |
|
WeakSelf |
|
_listTable = [[CommonTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain cellHeight:75 cellRow:0 isAdaptive:NO isLine:YES commonCell:TimeframeTableViewCell.class |
|
createCell:^(ZZTableViewCell * _Nonnull cells, NSIndexPath * _Nonnull indexPath) { |
|
TimeframeTableViewCell *cell = (TimeframeTableViewCell *)cells; |
|
cell.modelDic = weakSelf.modelArr[indexPath.row]; |
|
|
|
} selectedCell:^(UITableView * _Nonnull tableView, NSIndexPath * _Nonnull indexPath) { |
|
[weakSelf pusAddView:weakSelf.modelArr[indexPath.row]]; |
|
|
|
} DidscrollView:^(UIScrollView * _Nonnull scrollView) { |
|
|
|
}]; |
|
_listTable.backgroundColor = KKClearColor; |
|
_listTable.delegates = self; |
|
_listTable.isEditing = YES; |
|
|
|
} |
|
return _listTable; |
|
} |
|
|
|
|
|
- (void)save |
|
{ |
|
NSMutableArray *arr = [NSMutableArray new]; |
|
for (NSDictionary *dic in self.modelArr) |
|
{ |
|
NSString *time = F(@"%@-%@-%@", dic[@"s"],dic[@"e"],dic[@"w"]); |
|
[arr addObject:time]; |
|
} |
|
NSLog(@"%@",[arr componentsJoinedByString:@"&"]); |
|
|
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
[parameters setValue:self.model._id forKey:@"id"]; |
|
[parameters setValue:self.model.package forKey:@"package"]; |
|
[parameters setValue:@(1) forKey:@"status"]; |
|
[parameters setValue:[arr componentsJoinedByString:@"&"] forKey:@"useTime"]; |
|
[parameters setValue:cUser.accesstoken forKey:@"accesstoken"]; |
|
[cUser.cDevice postManager:parameters Success:^(id responseObject) { |
|
|
|
} failure:^(id faiObject) { |
|
|
|
}]; |
|
} |
|
|
|
#pragma mark CommTableViewDelegate |
|
- (void)CommTableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath |
|
{ |
|
[self.modelArr removeObject:self.modelArr[indexPath.row]]; |
|
self.listTable.cellRow = self.modelArr.count; |
|
[self.listTable reloadData]; |
|
} |
|
|
|
|
|
- (void)pusAddView:(NSDictionary *)dic |
|
{ |
|
WEAKSELF |
|
AddTimeframeViewController *vc = [[AddTimeframeViewController alloc] init]; |
|
vc.modelDic = dic; |
|
vc.blockAddClick = ^(NSString * _Nonnull times) { |
|
if (dic) |
|
[weakSelf.modelArr removeObject:dic]; |
|
[weakSelf modelzhuanhuan:times]; |
|
}; |
|
[self.navigationController pushViewController:vc animated:YES]; |
|
} |
|
|
|
- (void)modelzhuanhuan:(NSString *)timef |
|
{ |
|
NSArray *periodArr = [timef componentsSeparatedByString:@"&"]; |
|
for (NSString *tt in periodArr) |
|
{ |
|
NSArray *tArr = [tt componentsSeparatedByString:@"-"]; |
|
NSMutableDictionary *dic = [NSMutableDictionary dictionary]; |
|
[dic setValue:tArr[0] forKey:@"s"]; |
|
[dic setValue:tArr[1] forKey:@"e"]; |
|
[dic setValue:tArr[2] forKey:@"w"]; |
|
[self.modelArr addObject:dic]; |
|
} |
|
self.listTable.cellRow = self.modelArr.count; |
|
[self.listTable reloadData]; |
|
} |
|
|
|
/* |
|
#pragma mark - Navigation |
|
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation |
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { |
|
// Get the new view controller using [segue destinationViewController]. |
|
// Pass the selected object to the new view controller. |
|
} |
|
*/ |
|
|
|
@end
|
|
|