123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- //
- // YXSetCodeViewController.m
- // Temperature
- //
- // Created by TC on 2025/3/29.
- //
- #import "YXSetCodeViewController.h"
- #import "YXSetWifiViewController.h"
- #import "OPQRCodeViewController.h"
- #import <YBPopupMenu/YBPopupMenu.h>
- #import "YXDeviceInfoModel.h"
- #import "RDSBindDeviceVC.h"
- @interface YXSetCodeViewController ()<OPQRCodeViewControllerDelegate,YBPopupMenuDelegate>
- @property (weak, nonatomic) IBOutlet UIView *nameBgView;
- @property (weak, nonatomic) IBOutlet UITextField *nameTextField;
- /**选择主控**/
- @property (weak, nonatomic) IBOutlet UIView *mainBgView;
- @property (weak, nonatomic) IBOutlet UILabel *mainLabel;
- @property (weak, nonatomic) IBOutlet UIView *codeBgView;
- @property (weak, nonatomic) IBOutlet UITextField *codeTextFeild;
- @property (weak, nonatomic) IBOutlet UIButton *codeBtn;
- @property (weak, nonatomic) IBOutlet UIView *locationBgView;
- @property (weak, nonatomic) IBOutlet UITextField *locationTextFeild;
- @property (weak, nonatomic) IBOutlet UIButton *locationBtn;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *mainTopConstraint;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *codeTopConstraint;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *locationTopConstraint;
- @property (weak, nonatomic) IBOutlet UIButton *confirmBtn;
- @property (nonatomic, strong) NSMutableArray *deviceArray;
- @property (nonatomic, strong) NSMutableArray *mainArray;
- @property (nonatomic, strong) NSMutableArray *mainTitleArray;
- @property (nonatomic, strong) RDSRoomModel *model;
- @property (nonatomic, strong)YXDeviceInfoModel *mainModel;
- @end
- @implementation YXSetCodeViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = [UIColor whiteColor];
- [self createUI];
- [self getDeviceLocation];
- [self setDataSource];
- }
- -(void)createUI
- {
- // 15 70 125
- if ([self.itemModel.is_master integerValue] == 1) {
- self.mainBgView.hidden = YES;
- self.mainTopConstraint.constant = 0;
-
- if ([self.itemModel.need_device_code integerValue] == 1) {
- self.codeBgView.hidden = NO;
- self.codeTopConstraint.constant = 15;
- self.locationTopConstraint.constant = 70;
- }else{
- self.codeBgView.hidden = YES;
- self.locationTopConstraint.constant = 15;
- }
- }else{
- self.mainBgView.hidden = NO;
- self.mainTopConstraint.constant = 15;
-
- if ([self.itemModel.need_device_code integerValue] == 1) {
- self.codeBgView.hidden = NO;
- self.codeTopConstraint.constant = 70;
- self.locationTopConstraint.constant = 125;
- }else{
- self.codeBgView.hidden = YES;
- self.codeTopConstraint.constant = 0;
- self.locationTopConstraint.constant = 70;
- }
- }
-
- self.nameBgView.layer.cornerRadius = 20;
- self.nameBgView.layer.borderWidth = 1.0;
- self.nameBgView.layer.borderColor = [UIColor colorWithHexString:@"#C7C7C7"].CGColor;
-
- self.codeBgView.layer.cornerRadius = 20;
- self.codeBgView.layer.borderWidth = 1.0;
- self.codeBgView.layer.borderColor = [UIColor colorWithHexString:@"#C7C7C7"].CGColor;
-
- self.locationBgView.layer.cornerRadius = 20;
- self.locationBgView.layer.borderWidth = 1.0;
- self.locationBgView.layer.borderColor = [UIColor colorWithHexString:@"#C7C7C7"].CGColor;
-
- self.mainBgView.layer.cornerRadius = 20;
- self.mainBgView.layer.borderWidth = 1.0;
- self.mainBgView.layer.borderColor = [UIColor colorWithHexString:@"#C7C7C7"].CGColor;
-
- [self.codeBtn addTarget:self action:@selector(erweimasaomiao) forControlEvents:UIControlEventTouchUpInside];
-
-
- if ([self.itemModel.bluetooth integerValue] == 1) {
- [self.confirmBtn setTitle:@"下一步" forState:UIControlStateNormal];
- }else{
- [self.confirmBtn setTitle:@"确认添加" forState:UIControlStateNormal];
- }
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectMainControl)];
-
- [self.mainBgView addGestureRecognizer:tap];
-
- UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectDeviceLocation)];
- [self.locationTextFeild addGestureRecognizer:tap2];
- }
- - (void)setDataSource {
- self.nameTextField.text = self.itemModel.name;
-
- }
- /**选择主控**/
- - (void)selectMainControl {
-
- [RDSDemoApiHelper rds_getDeviceListWithHomeId:TheDataManager.current_home_id roomId:@"" isMaster:YES Success:^(id responseObject) {
- if ([responseObject[@"code"] integerValue] == 0) {
- NSDictionary *dataDic = responseObject[@"data"];
- NSArray *listArray = dataDic[@"list"];
- self.mainArray = [YXDeviceInfoModel mj_objectArrayWithKeyValuesArray:listArray];
- [self.mainTitleArray removeAllObjects];
- for (YXDeviceInfoModel *model in self.mainArray) {
- [self.mainTitleArray addObject:model.name];
- }
-
- [YBPopupMenu showRelyOnView:self.mainBgView titles:self.mainTitleArray icons:nil menuWidth: SCREEN_WIDTH - 60 otherSettings:^(YBPopupMenu *popupMenu) {
- popupMenu.delegate = self;
- popupMenu.animationManager.duration = 0.25;
- popupMenu.textColor = [UIColor colorWithHexString:@"#1F1F1F"];
- popupMenu.tag = 2;
- }];
-
- }
- } failure:^(NSError *error) {
-
- }];
-
- }
- /**选择设备位置**/
- - (void)selectDeviceLocation {
- [self.view endEditing:YES];
- NSMutableArray *titles = [NSMutableArray array];
- for (RDSRoomModel *model in self.deviceArray) {
- [titles addObject:model.name];
- }
- [YBPopupMenu showRelyOnView:self.locationBgView titles:titles icons:nil menuWidth: SCREEN_WIDTH - 60 otherSettings:^(YBPopupMenu *popupMenu) {
- popupMenu.delegate = self;
- popupMenu.animationManager.duration = 0.25;
- popupMenu.textColor = [UIColor colorWithHexString:@"#1F1F1F"];
- popupMenu.tag = 1;
- }];
- }
- - (void)ybPopupMenu:(YBPopupMenu *)ybPopupMenu didSelectedAtIndex:(NSInteger)index {
- NSInteger tag = ybPopupMenu.tag;
- if (tag == 1) {
- RDSRoomModel *model = self.deviceArray[index];
- self.locationTextFeild.text = model.name;
- self.model = model;
- }
-
- if (tag == 2) {
- self.mainModel = self.mainArray[index];
- self.mainLabel.text = self.mainModel.name;
- self.mainLabel.textColor = [UIColor colorWithHexString:@"#1E1E1E"];
- }
- }
- - (IBAction)confirmBtnClick:(id)sender {
- NSString *type_id = @"";
- if (self.itemModel.steps.count > 0) {
- YXDeviceStepModel *model = self.itemModel.steps[0];
- type_id = model.device_type_id;
- }
-
- NSString *code = @"";
- NSString *subCode = @"";
- if ([self.itemModel.is_master integerValue] == 1) {
- code = self.codeTextFeild.text;
- if (code.length == 0 && [self.itemModel.need_device_code integerValue] == 1) {
- //主控
- [RDSHudShower showBottomToast:@"主控设备编号为空"];
- return;
- }
- }else{
- //分控
- code = self.mainModel.device_code;
- if (code.length == 0) {
- [RDSHudShower showBottomToast:@"主控设备编号为空"];
- return;
- }
-
- subCode = self.codeTextFeild.text;
- if (subCode.length == 0) {
- [RDSHudShower showBottomToast:@"分控设备编号为空"];
- return;
- }
- }
-
- if ([self.itemModel.bluetooth integerValue] == 1) {
- //主控、永续精灵
- YXSetWifiViewController *wifiVc = [[YXSetWifiViewController alloc]init];
- wifiVc.itemModel = self.itemModel;
- wifiVc.type_id = type_id;
- wifiVc.room_id = self.model.record_id;
- wifiVc.home_id = self.model.home_id;
- if ([self.itemModel.need_device_code integerValue] == 1) {
- //主控
- wifiVc.deviceCode = code;
- }else{
- //永续精灵
- wifiVc.deviceCode = @"";
- }
- wifiVc.deviceName = self.nameTextField.text;
- wifiVc.bluetooth = self.itemModel.bluetooth;
- wifiVc.need_device_code = self.itemModel.need_device_code;
- wifiVc.blue_code = self.itemModel.blue_code;
- [self.navigationController pushViewController:wifiVc animated:YES];
- }else{
- //分控
- RDSBindDeviceVC *vc = [[RDSBindDeviceVC alloc] init];
- vc.deviceCode = code;
- vc.is_master = [self.itemModel.is_master boolValue];
- vc.deviceName = self.nameTextField.text;
- vc.subCode = subCode;
-
- YXDeviceStepModel *model = _itemModel.steps.firstObject;
- vc.deviceTypeId = model.device_type_id;
- vc.home_id = self.model.home_id;
- vc.room_id = self.model.record_id;
- vc.type_id = type_id;
- vc.isYXJL = NO;
- vc.bluetooth = self.itemModel.bluetooth;
- vc.need_device_code = self.itemModel.need_device_code;
-
- [self pushViewController:vc animated:YES];
- }
- }
- - (void)erweimasaomiao {
- OPQRCodeViewController *vc = [[OPQRCodeViewController alloc] init];
- vc.delegate = self;
- vc.topOffset = -kNavHeight;
- vc.modalPresentationStyle = UIModalPresentationFullScreen;
- [self presentViewController:vc animated:YES completion:nil];
- }
- #pragma mark - OPQRCodeViewControllerDelegate
- // 扫码返回字符串
- - (void)rdy_didFinishPickingMediaWithInfo:(NSString *)stringValue{
-
- DDLog(@"二维码:%@",stringValue);
- if(!kNULLString(stringValue)){
- self.codeTextFeild.text = stringValue;
- }
- }
- - (void)getDeviceLocation {
- [RDSDemoApiHelper rds_getRoomListWithHomeId:TheDataManager.current_home_id success:^(NSDictionary * responseObject) {
- if ([responseObject[@"code"] integerValue] == 0) {
- self.deviceArray = [YXHomeRoomModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"]];
- for (YXHomeRoomModel *model in self.deviceArray) {
- model.devices = [YXHomeDeviceModel mj_objectArrayWithKeyValuesArray:model.devices];
- }
-
- }
- } failure:^(NSError *error) {
-
- }];
- }
- - (NSMutableArray *)deviceArray {
- if (!_deviceArray) {
- _deviceArray = [NSMutableArray array];
- }
- return _deviceArray;
- }
- - (NSMutableArray *)mainTitleArray {
- if (!_mainTitleArray) {
- _mainTitleArray = [NSMutableArray array];
- }
- return _mainTitleArray;
- }
- /*
- #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
|