//
|
// PBSitePerViewController.m
|
// IphoneBIMe
|
//
|
// Created by ZhangJF on 2022/8/24.
|
// Copyright © 2022 ProBIM. All rights reserved.
|
//
|
|
#import "PBSitePerViewController.h"
|
#import "PBProjectModel.h"
|
#import "PBSchedulePlanModel.h"
|
#import "PBScheduleHeaderView.h"
|
#import "PBNewPersonTableViewCell.h"
|
#import "PBPerPlanModel.h"
|
#import "PBSitePerModel.h"
|
#import "PBEditTimeView.h"
|
#import "PBChooseType.h"
|
#import "PBScheduleListModel.h"
|
#import "SGQRCode.h"
|
#import "QQQRCodeVC.h"
|
#import <AMapLocationKit/AMapLocationKit.h>
|
|
static NSString *const CellID = @"CellID";
|
@interface PBSitePerViewController ()<UITableViewDataSource, UITableViewDelegate, AMapLocationManagerDelegate>
|
@property (nonatomic, strong) NSArray *dataList;
|
@property (nonatomic, strong) NSArray *typeDataList;
|
@property (nonatomic, strong) UITableView *tableView;
|
@property (nonatomic, strong) PBEditTimeView *editTimeView;
|
@property (nonatomic, strong) PBChooseType *chooseTypeView;
|
@property (nonatomic, strong) PBScheduleHeaderView *headerView;
|
@property (nonatomic, strong) NSMutableArray *sitePersonArrM;
|
@property (nonatomic, copy) NSString *fillDate;
|
@property (nonatomic, copy) NSString *creatName;
|
@property (nonatomic, copy) NSString *creatId;
|
@property (nonatomic, assign) BOOL isAdd;
|
@property (nonatomic, strong) AMapLocationManager *locationManager;
|
@property (nonatomic, copy) NSString *place;
|
@end
|
|
@implementation PBSitePerViewController
|
|
- (void)viewDidAppear:(BOOL)animated {
|
[super viewDidAppear:animated];
|
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.f) {
|
self.edgesForExtendedLayout = UIRectEdgeNone;
|
self.navigationController.interactivePopGestureRecognizer.enabled = NO; //让rootView禁止滑动
|
}
|
}
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
[self getPositioning];
|
|
[self setupUI];
|
// [self loadUserTypeWithPlanID:@"" andUserType:@"" andIndexPath:nil andModel:nil];
|
// [self loadData];
|
[self setupNav];
|
}
|
|
- (void)setupNav {
|
self.title = @"现场人员";
|
PBBackNavItem *backNav = [PBBackNavItem backNacItem];
|
backNav.title = @"返回";
|
[backNav addTarget:self action:@selector(backItemAction) forControlEvents:UIControlEventTouchUpInside];
|
UIBarButtonItem *backNavItem = [[UIBarButtonItem alloc] initWithCustomView:backNav];
|
self.navigationItem.leftBarButtonItem = backNavItem;
|
|
// UIBarButtonItem *saveNavItem = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(saveAction)];
|
// self.navigationItem.rightBarButtonItem = saveNavItem;
|
}
|
- (void)backItemAction {
|
[self.navigationController popViewControllerAnimated:YES];
|
}
|
//- (void)saveAction{
|
// [YJProgressHUD showProgress:@"正在保存..." inView:self.view];
|
// NSMutableArray *arrM = [[NSMutableArray alloc] init];
|
// for (PBSitePerModel *obj in self.sitePersonArrM) {
|
//// if (obj.MobileSafe_Name == nil || obj.MobileSafe_Measure == nil) {
|
//// [YJProgressHUD showMessage:@"请填写完整" inView:self.view];
|
//// return;
|
//// }
|
// NSDictionary *dict = @{
|
// @"MobileUserDetial_Name": obj.MobileUserDetial_Name == nil? @"" : obj.MobileUserDetial_Name, // 人员名称
|
// @"MobileUserDetial_PlanNum": obj.MobileUserDetial_PlanNum == nil? @"" : obj.MobileUserDetial_PlanNum, //人员计划数量
|
// @"MobileUserDetial_AdddelNum": obj.MobileUserDetial_AdddelNum == nil? @"" : obj.MobileUserDetial_AdddelNum, //人员增减数量
|
//// @"MobileUserDetial_AddNum": obj.MobileUserDetial_AddNum, //人员累计数量
|
// @"MobileUserDetial_NewNum": obj.MobileUserDetial_NewNum == nil? @"" : obj.MobileUserDetial_NewNum, //人员现场数量
|
// @"MobileUserDetial_type": obj.MobileUserDetial_type==nil? @"": obj.MobileUserDetial_type, //人员类别
|
// @"MobileUserDetial_ProjectID": self.schedulePlanModel.UID == nil? @"" : self.schedulePlanModel.UID, //进度计划编码
|
// @"MobileUserDetial_Unittime": self.fillDate == nil? @"" : self.fillDate, //填报日期
|
// @"MobileUserDetial_createuser": self.creatName == nil? @"" : self.creatName, //填报人
|
// @"organizeId": self.projectModel.organizeid == nil? @"": self.projectModel.organizeid //项目编码
|
// };
|
// [arrM addObject:dict];
|
// }
|
//
|
// [[PBNetworkTools sharedTools] AddMobileUserJSONWithOrganizeId:self.projectModel.organizeid andMobile:arrM.copy andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
|
// if (error) {
|
// NSLog(@"%@",error);
|
// [YJProgressHUD showMessage:@"加载失败" inView:self.view];
|
// return;
|
// }
|
// NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
|
// PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str];
|
// if (networkModel.Ret == 1) {
|
// [YJProgressHUD hide];
|
// PBScheduleListModel *listModel = [[PBScheduleListModel alloc] init];
|
// listModel.MobilePA_ProjectID = self.schedulePlanModel.UID;
|
// listModel.MobilePA_ProjectName = self.schedulePlanModel.Name;
|
// listModel.MobilePA_Unittime = self.fillDate;
|
// listModel.MobilePA_CreateUser = self.creatName;
|
// listModel.MobilePA_Createuserid = self.creatId;
|
// listModel.MobilePA_state = @"待提交";
|
// if (self.AddSuccessBlock) {
|
// self.AddSuccessBlock(listModel);
|
// }
|
// [self.navigationController popViewControllerAnimated:YES];
|
// }else {
|
// [YJProgressHUD showMessage:networkModel.Msg inView:self.view];
|
// }
|
// }];
|
//}
|
|
//- (void)loadUserTypeWithPlanID:(NSString *)planId andUserType:(NSString *)type andIndexPath:(NSIndexPath *) indexPath andModel:(PBSitePerModel *)preModel {
|
// [[PBNetworkTools sharedTools] GetMobileUserWithOrganizeId:self.projectModel.organizeid andMobileUserDetial_ProjectID:planId andMobile_UserType:type andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
|
// if (error) {
|
// NSLog(@"%@",error);
|
// [YJProgressHUD showMessage:@"加载失败" inView:self.view];
|
// return;
|
// }
|
// NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
|
// PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str];
|
// if (networkModel.Ret == 1) {
|
// NSMutableArray *typeArrM = [[NSMutableArray alloc] init];
|
// for (NSDictionary *obj in networkModel.Data) {
|
// PBPerPlanModel *model = [PBPerPlanModel yy_modelWithDictionary:obj];
|
// [typeArrM addObject:model];
|
// }
|
// if (indexPath == nil){
|
// self.typeDataList = typeArrM.copy;
|
// }else {
|
// PBPerPlanModel *typeModel = typeArrM[0];
|
// preModel.MobileUserDetial_Name = typeModel.Mobile_UserType;
|
// preModel.MobileUserDetial_PlanNum = typeModel.Mobile_PlanNum;
|
// preModel.MobileUserDetial_AddNum = typeModel.Mobile_AddNum;
|
// [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
|
// }
|
// }else {
|
// [YJProgressHUD showMessage:networkModel.Msg inView:self.view];
|
// }
|
// }];
|
//}
|
|
//- (void)loadData {
|
// self.dataList = @[];
|
// if(self.isAdd) {
|
// [self.tableView reloadData];
|
// }else {
|
// [[PBNetworkTools sharedTools] GetMobileUserJSONWithUnittime:self.fillDate andCreateuserId:self.creatId andPlanID:self.schedulePlanModel.UID andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
|
// if (error) {
|
// NSLog(@"%@",error);
|
// [YJProgressHUD showMessage:@"加载失败" inView:self.view];
|
// return;
|
// }
|
// NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
|
// PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str];
|
// if (networkModel.Ret == 1) {
|
// // [YJProgressHUD hide];
|
// for (NSDictionary *obj in networkModel.Data) {
|
// PBSitePerModel *model = [PBSitePerModel yy_modelWithDictionary:obj];
|
// [self.sitePersonArrM addObject:model];
|
// }
|
// [self.tableView reloadData];
|
// }else {
|
// [YJProgressHUD showMessage:networkModel.Msg inView:self.view];
|
// }
|
// }];
|
// }
|
//}
|
- (void)setupUI {
|
self.view.backgroundColor = [UIColor whiteColor];
|
self.tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
|
self.tableView.dataSource = self;
|
self.tableView.delegate = self;
|
self.tableView.backgroundColor = [UIColor whiteColor];
|
self.tableView.tableFooterView = [UIView new];
|
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
self.tableView.showsVerticalScrollIndicator = NO;
|
self.tableView.rowHeight = UITableViewAutomaticDimension;
|
self.tableView.estimatedRowHeight = 100.f;
|
[self.tableView registerClass:[PBNewPersonTableViewCell class] forCellReuseIdentifier:CellID];
|
[self.view addSubview:self.tableView];
|
|
if (@available(iOS 15.0, *)) {
|
self.tableView.sectionHeaderTopPadding = 0;
|
}
|
CGFloat bottomH = 64.f;
|
if (IS_IPHONE_X) {
|
bottomH = 64.f + IPHONE_X_BOTTOM;
|
}
|
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.bottom.left.right.equalTo(self.view);
|
make.bottom.equalTo(self.view).offset(-bottomH);
|
}];
|
UIButton *approachBtn = [UIButton z_textButton:@"进场" boldFontSize:16 normalColor:[UIColor whiteColor]];
|
approachBtn.tag = 90;
|
approachBtn.backgroundColor = PBColor(0, 122, 254);
|
[approachBtn addTarget:self action:@selector(personnelReporting:) forControlEvents:UIControlEventTouchUpInside];
|
[self.view addSubview:approachBtn];
|
[approachBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(self.tableView.mas_bottom).offset(7);
|
make.left.equalTo(self.view).offset(10);
|
make.height.equalTo(@48);
|
}];
|
UIButton *appearBtn = [UIButton z_textButton:@"出场" boldFontSize:16 normalColor:[UIColor whiteColor]];
|
appearBtn.tag = 91;
|
appearBtn.backgroundColor = WarningColor;
|
[appearBtn addTarget:self action:@selector(personnelReporting:) forControlEvents:UIControlEventTouchUpInside];
|
[self.view addSubview:appearBtn];
|
[appearBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(self.tableView.mas_bottom).offset(7);
|
make.left.equalTo(approachBtn.mas_right);
|
make.right.equalTo(self.view).offset(-10);
|
make.width.equalTo(approachBtn);
|
make.height.equalTo(@48);
|
}];
|
|
PBScheduleHeaderView *headerV = [[PBScheduleHeaderView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 112)];
|
self.headerView = headerV;
|
// headerV.schedulePlanModel = self.schedulePlanModel;
|
// headerV.fillDate = self.fillDate;
|
// headerV.ChooseDate = ^{
|
// if (self.isAdd) {
|
// [self.view endEditing:YES];
|
// [PBKeyWindow addSubview:self.editTimeView];
|
// self.editTimeView.fillData = self.fillDate;
|
// self.editTimeView.ChooseCompleteBlock = ^(BOOL isSelsected, NSString *date){
|
// if (isSelsected) {
|
// date = [date stringByReplacingOccurrencesOfString:@"年" withString:@"-"];
|
// date = [date stringByReplacingOccurrencesOfString:@"月" withString:@"-"];
|
// date = [date stringByReplacingOccurrencesOfString:@"日" withString:@""];
|
// NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
|
// [formatter setDateFormat:@"yyyy-MM-dd"];
|
// NSDate *newDate = [formatter dateFromString:date];
|
// NSString * dateStr = [formatter stringFromDate:newDate];
|
// self.fillDate = dateStr;
|
// self.headerView.fillDate = self.fillDate;
|
// }
|
// };
|
// [self.editTimeView show];
|
// }else {
|
// [YJProgressHUD showMessage:@"无法修改日期" inView:self.view];
|
// }
|
// };
|
headerV.Scanning = ^{
|
[self authorityJudgment];
|
};
|
self.tableView.tableHeaderView = headerV;
|
|
}
|
- (void)authorityJudgment {
|
[SGPermission permissionWithType:SGPermissionTypeCamera completion:^(SGPermission * _Nonnull permission, SGPermissionStatus status) {
|
if (status == SGPermissionStatusNotDetermined) {
|
[permission request:^(BOOL granted) {
|
if (granted) {
|
NSLog(@"第一次授权成功");
|
QQQRCodeVC *VC = [[QQQRCodeVC alloc] init];
|
VC.getPersonBlock = ^(NSString * _Nonnull personId) {
|
[self getFillUserInfoWithID:personId];
|
};
|
[self.navigationController pushViewController:VC animated:YES];
|
|
} else {
|
NSLog(@"第一次授权失败");
|
}
|
}];
|
} else if (status == SGPermissionStatusAuthorized) {
|
NSLog(@"SGPermissionStatusAuthorized");
|
QQQRCodeVC *VC = [[QQQRCodeVC alloc] init];
|
VC.getPersonBlock = ^(NSString * _Nonnull personId) {
|
[self getFillUserInfoWithID:personId];
|
};
|
[self.navigationController pushViewController:VC animated:YES];
|
|
} else if (status == SGPermissionStatusDenied) {
|
NSLog(@"SGPermissionStatusDenied");
|
[self failed];
|
} else if (status == SGPermissionStatusRestricted) {
|
NSLog(@"SGPermissionStatusRestricted");
|
[self unknown];
|
}
|
|
}];
|
}
|
- (void)failed {
|
UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"[前往:设置 - 隐私 - 相机 - SGQRCode] 打开访问开关" preferredStyle:(UIAlertControllerStyleAlert)];
|
UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
|
}];
|
|
[alertC addAction:alertA];
|
dispatch_async(dispatch_get_main_queue(), ^{
|
[self presentViewController:alertC animated:YES completion:nil];
|
});
|
}
|
|
- (void)unknown {
|
UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"未检测到您的摄像头" preferredStyle:(UIAlertControllerStyleAlert)];
|
UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
|
|
}];
|
|
[alertC addAction:alertA];
|
dispatch_async(dispatch_get_main_queue(), ^{
|
[self presentViewController:alertC animated:YES completion:nil];
|
});
|
}
|
- (void)getFillUserInfoWithID:(NSString *)guid {
|
[[PBNetworkTools sharedTools] GetFillUserInfoWithID:guid andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
|
if (error) {
|
NSLog(@"%@",error);
|
[YJProgressHUD showMessage:@"加载失败" inView:self.view];
|
return;
|
}
|
NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
|
PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str];
|
if (networkModel.Ret == 1) {
|
self.dataList = @[networkModel.Data];
|
[self.tableView reloadData];
|
}else {
|
[YJProgressHUD showMessage:networkModel.Msg inView:self.view];
|
}
|
}];
|
}
|
- (void)getPositioning {
|
[YJProgressHUD showProgress:@"" inView:self.view];
|
[AMapLocationManager updatePrivacyShow:(AMapPrivacyShowStatusDidShow) privacyInfo:AMapPrivacyInfoStatusDidContain];
|
[AMapLocationManager updatePrivacyAgree:AMapPrivacyAgreeStatusDidAgree];
|
self.locationManager = [[AMapLocationManager alloc] init];
|
self.locationManager.delegate = self;
|
// 带逆地理信息的一次定位(返回坐标和地址信息)
|
[self.locationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
|
// 定位超时时间,最低2s,此处设置为2s
|
self.locationManager.locationTimeout = 2;
|
// 逆地理请求超时时间,最低2s,此处设置为2s
|
self.locationManager.reGeocodeTimeout = 2;
|
[self.locationManager requestLocationWithReGeocode:YES completionBlock:^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error) {
|
[YJProgressHUD hide];
|
if (error){
|
NSLog(@"locError:{%ld - %@};", (long)error.code, error.localizedDescription);
|
if (error.code == AMapLocationErrorLocateFailed){
|
return;
|
}
|
}
|
NSLog(@"location:%@", location);
|
if (regeocode){
|
NSLog(@"reGeocode:%@", regeocode);
|
self.place = regeocode.formattedAddress;
|
self.headerView.place = regeocode.formattedAddress;
|
}
|
}];
|
}
|
- (void)personnelReporting:(UIButton *)btn {
|
if (self.dataList.count <= 0) {
|
[YJProgressHUD showFailed:@"请先进行扫码,获取人员信息!" inview:self.view];
|
return;
|
}
|
NSInteger type = btn.tag - 90;
|
NSDictionary *dict = self.dataList[0];
|
[YJProgressHUD showProgress:@"" inView:self.view];
|
[[PBNetworkTools sharedTools] aEntryOrExitWithOrganizeId:self.projectModel.organizeid andFillingUserId:[dict valueForKey:@"Id"] andProgressParentId:@"" andProgressTreeId:@"" andProgressProjectId:@"" andAddress:self.place andType:type andCallBack:^(NSURLResponse *response, id responseObject, NSError *error) {
|
if (error) {
|
NSLog(@"%@",error);
|
[YJProgressHUD showMessage:@"操作失败" inView:self.view];
|
return;
|
}
|
NSString *str = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
|
PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str];
|
if (networkModel.Ret == 1) {
|
[YJProgressHUD showSuccess:@"操作成功" inview:self.view];
|
}else {
|
[YJProgressHUD showMessage:networkModel.Msg inView:self.view];
|
}
|
}];
|
|
}
|
|
|
#pragma mark - Table view data source
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
return self.dataList.count;
|
}
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
NSDictionary *item = self.dataList[indexPath.row];
|
PBNewPersonTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID forIndexPath:indexPath];
|
cell.dict = item;
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
return cell;
|
}
|
|
- (void)setSchedulePlanModel:(PBSchedulePlanModel *)schedulePlanModel{
|
_schedulePlanModel = schedulePlanModel;
|
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
|
[formatter setDateFormat:@"yyyy-MM-dd"];
|
self.fillDate = [formatter stringFromDate:[NSDate date]];
|
self.creatName = Realname;
|
self.creatId = UserID;
|
self.isAdd = true;
|
}
|
- (void)setScheduleListModel:(PBScheduleListModel *)scheduleListModel {
|
_scheduleListModel = scheduleListModel;
|
PBSchedulePlanModel *planModel = [[PBSchedulePlanModel alloc] init];
|
planModel.UID = scheduleListModel.MobilePA_ProjectID;
|
planModel.Name = scheduleListModel.MobilePA_ProjectName;
|
self.schedulePlanModel = planModel;
|
self.fillDate = scheduleListModel.MobilePA_Unittime;
|
self.creatName = scheduleListModel.MobilePA_CreateUser;
|
self.creatId = scheduleListModel.MobilePA_Createuserid;
|
self.isAdd = false;
|
}
|
- (void)setProjectModel:(PBProjectModel *)projectModel {
|
_projectModel = projectModel;
|
}
|
- (PBEditTimeView *)editTimeView {
|
if (_editTimeView == nil) {
|
_editTimeView = [[PBEditTimeView alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
_editTimeView.visualViewHeight = 300;
|
}
|
return _editTimeView;
|
}
|
- (PBChooseType *)chooseTypeView {
|
if (_chooseTypeView == nil) {
|
_chooseTypeView = [[PBChooseType alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
_chooseTypeView.visualViewHeight = 300;
|
}
|
return _chooseTypeView;;
|
}
|
- (NSMutableArray *)sitePersonArrM {
|
if (_sitePersonArrM == nil) {
|
_sitePersonArrM = [[NSMutableArray alloc] init];
|
}
|
return _sitePersonArrM;
|
}
|
|
/*
|
#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
|