// // SOSViewController.m // LekangGuard // // Created by ecell on 2022/12/6. // #import "SOSViewController.h" #import "SOSTableViewCell.h" @interface SOSViewController () @property (nonatomic ,strong) UITableView *sosTable; @property (nonatomic ,strong) SOSModel *sosModel; @end @implementation SOSViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.zx_navTitle = GJText(@"SOS号码"); self.modelListArr = [NSMutableArray arrayWithArray:@[@"",@"",@""]]; self.view.backgroundColor = KKBackgroundGrey; [self zx_setRightBtnWithText:GJText(@"保存") clickedBlock:^(ZXNavItemBtn * _Nonnull btn) { [self AddSosPhone]; }]; [self.view addSubview:self.sosTable]; [self.sosTable 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); }]; [self GetQueryPhone]; } - (UITableView *)sosTable { if (!_sosTable) { _sosTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; _sosTable.backgroundColor = KKClearColor; _sosTable.delegate = self; _sosTable.dataSource = self; _sosTable.rowHeight = Adapted(60); //_sosTable.separatorStyle = UITableViewCellSeparatorStyleNone; [_sosTable registerClass:SOSTableViewCell.class forCellReuseIdentifier:NSStringFromClass(SOSTableViewCell.class)]; } return _sosTable; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { SOSTableViewCell *cell = [SOSTableViewCell cellWithTableView:tableView indexPath:indexPath]; cell.rows = indexPath.row; cell.titleStr = F(@"%@%ld", GJText(@"SOS号码"), indexPath.row+1); cell.sosText = self.modelListArr[indexPath.row]; cell.isInputMsg = ^(NSInteger row, NSString * _Nonnull text) { [self.modelListArr replaceObjectAtIndex:row withObject:text]; }; return cell; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.modelListArr.count; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 90; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; UILabel *lable = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:FontADA_(14) textColor:UIColor.systemGrayColor text:@"" Radius:0]; lable.text = GJText(@"1.请为设备设置紧急号码,设备按下SOS按键,即可拨打上方设置的号码\n2.如果您想删除SOS号码,请将号码删除,然后点击保存\n3.设备使用SOS功能时,会依次拨打下方号码,轮打3遍结束"); [view addSubview:lable]; [lable mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(view).offset(Adapted(20)); make.left.right.equalTo(view).inset(Adapted(15)); }]; return view; } #pragma mark SOS号码查询 /// SOS号码查询 - (void)GetQueryPhone { [UICommon MessageUpload:@"加载中"]; NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; [[[APIManager sharedManager] APGET:F(@"%@/%@", QueryPhone_URL,APIManager.sharedManager.deviceModel.imei) parameters:parameters resultClass:SOSModel.class] subscribeNext:^(SOSModel *model) { [UICommon HidenLoading]; if (model != nil) { self.sosModel = model; [self.modelListArr replaceObjectAtIndex:0 withObject:model.sosPhoneOne]; [self.modelListArr replaceObjectAtIndex:1 withObject:model.sosPhoneTwo]; [self.modelListArr replaceObjectAtIndex:2 withObject:model.sosPhoneThree]; } [self.sosTable reloadData]; } error:^(NSError * _Nullable error) { NSDictionary *dic = error.userInfo; [UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; }]; } #pragma mark 添加或编辑SOS号码 /// 添加或编辑SOS号码 - (void)AddSosPhone { [UICommon MessageUpload:@"加载中"]; NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; [parameters setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"]; [parameters setValue:self.modelListArr[0] forKey:@"sosPhoneOne"]; [parameters setValue:self.modelListArr[1] forKey:@"sosPhoneTwo"]; [parameters setValue:self.modelListArr[2] forKey:@"sosPhoneThree"]; [parameters setValue:@"2" forKey:@"source"]; /// (来源,1.PC 2.APP) if (self.sosModel != nil) [parameters setValue:self.sosModel.imeiSosId forKey:@"imeiSosId"]; [[[APIManager sharedManager] APPOST:AddSosPhone_URL parameters:parameters isJson:YES resultClass:nil] subscribeNext:^(id _Nullable x) { [UICommon HidenLoading]; [UICommon MessageSuccessText:@"保存成功"]; AfterDispatch(1, ^{ [self.navigationController popViewControllerAnimated:YES]; }); } error:^(NSError * _Nullable error) { NSDictionary *dic = error.userInfo; [UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; }]; } /* #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