//
|
// PBSitePerViewController.m
|
// IphoneBIMe
|
//
|
// Created by ZhangJF on 2022/8/24.
|
// Copyright © 2022 ProBIM. All rights reserved.
|
//
|
|
#import "PBSiteMechanicalViewController.h"
|
#import "PBProjectModel.h"
|
#import "PBSchedulePlanModel.h"
|
#import "PBScheduleHeaderView.h"
|
#import "PBSitePerTableViewCell.h"
|
#import "PBMaterialPlanModel.h"
|
#import "PBSiteMaterialModel.h"
|
#import "PBEditTimeView.h"
|
#import "PBChooseType.h"
|
#import "PBScheduleListModel.h"
|
|
static NSString *const CellID = @"CellID";
|
@interface PBSiteMechanicalViewController ()<UITableViewDataSource, UITableViewDelegate>
|
@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 *siteMaterialArrM;
|
@property (nonatomic, copy) NSString *fillDate;
|
@property (nonatomic, copy) NSString *creatName;
|
@property (nonatomic, copy) NSString *creatId;
|
@property (nonatomic, assign) BOOL isAdd;
|
@end
|
|
@implementation PBSiteMechanicalViewController
|
|
- (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 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 (PBSiteMaterialModel *obj in self.siteMaterialArrM) {
|
// if (obj.MobileSafe_Name == nil || obj.MobileSafe_Measure == nil) {
|
// [YJProgressHUD showMessage:@"请填写完整" inView:self.view];
|
// return;
|
// }
|
NSDictionary *dict = @{
|
@"MaterialsDetial_Name": obj.MaterialsDetial_Name == nil? @"" : obj.MaterialsDetial_Name, //机械名称
|
@"MaterialsDetial_PlanNum": obj.MaterialsDetial_PlanNum == nil? @"" : obj.MaterialsDetial_PlanNum,//机械计划数量
|
// @"MaterialsDetial_AddNum": obj.MaterialsDetial_AddNum, //机械累计数量
|
@"MaterialsDetial_AdddelNum": obj.MaterialsDetial_AdddelNum == nil? @"" : obj.MaterialsDetial_AdddelNum,//机械增减数量
|
@"MaterialsDetial_NewNum": obj.MaterialsDetial_NewNum == nil? @"" : obj.MaterialsDetial_NewNum,//机械现场数量
|
@"MaterialsDetial_type": obj.MaterialsDetial_type==nil? @"": obj.MaterialsDetial_type,//机械类别
|
@"MaterialsDetial_ProjectID": self.schedulePlanModel.UID == nil? @"" : self.schedulePlanModel.UID,//进度计划编码
|
@"MaterialsDetial_Unittime": self.fillDate == nil? @"" : self.fillDate,//填报日期
|
@"MaterialsDetial_createuser": self.creatName == nil? @"" : self.creatName,//填报人
|
@"organizeId": self.projectModel.organizeid == nil? @"" : self.projectModel.organizeid //项目编码
|
|
};
|
[arrM addObject:dict];
|
}
|
|
[[PBNetworkTools sharedTools] AddMaterialsJSONWithOrganizeId: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:(PBSiteMaterialModel *)materialModel {
|
[[PBNetworkTools sharedTools] GetMaterialsWithOrganizeId: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) {
|
PBMaterialPlanModel *model = [PBMaterialPlanModel yy_modelWithDictionary:obj];
|
[typeArrM addObject:model];
|
}
|
if (indexPath == nil){
|
self.typeDataList = typeArrM.copy;
|
}else {
|
PBMaterialPlanModel *typeModel = typeArrM[0];
|
materialModel.MaterialsDetial_Name = typeModel.Materials_Name;
|
materialModel.MaterialsDetial_PlanNum = typeModel.Materials_PlanNum;
|
materialModel.MaterialsDetial_AddNum = typeModel.Materials_AddNum;
|
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
|
}
|
}else {
|
[YJProgressHUD showMessage:networkModel.Msg inView:self.view];
|
}
|
}];
|
}
|
|
- (void)loadData {
|
self.dataList = @[@{@"name": @"现场机械情况", @"child": self.siteMaterialArrM}];
|
if(self.isAdd) {
|
[self.tableView reloadData];
|
}else {
|
[[PBNetworkTools sharedTools] GetMaterialsJSONWithUnittime: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) {
|
PBSiteMaterialModel *model = [PBSiteMaterialModel yy_modelWithDictionary:obj];
|
[self.siteMaterialArrM 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];
|
|
// UITableViewController *tvc = [[UITableViewController alloc] initWithStyle:UITableViewStyleGrouped];
|
// [self addChildViewController:tvc];
|
// self.tableView = tvc.tableView;
|
|
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:[PBSitePerTableViewCell 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 *addTaskBtn = [[UIButton alloc] init];
|
[addTaskBtn setImage:[UIImage imageNamed:@"add_mechinal"] forState:UIControlStateNormal];
|
[addTaskBtn addTarget:self action:@selector(addPersonAction) forControlEvents:UIControlEventTouchUpInside];
|
[self.view addSubview:addTaskBtn];
|
[addTaskBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(self.tableView.mas_bottom).offset(7);
|
make.left.equalTo(self.view).offset(10);
|
make.right.equalTo(self.view).offset(-10);
|
make.height.equalTo(@48);
|
}];
|
PBScheduleHeaderView *headerV = [[PBScheduleHeaderView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 132)];
|
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];
|
}
|
};
|
self.tableView.tableHeaderView = headerV;
|
|
}
|
- (void)addPersonAction {
|
PBSiteMaterialModel *sitePerModel = [[PBSiteMaterialModel alloc] init];
|
[self.siteMaterialArrM addObject:sitePerModel];
|
[self.tableView reloadData];
|
}
|
|
|
#pragma mark - Table view data source
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
return self.dataList.count;
|
}
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
NSDictionary *item = self.dataList[section];
|
NSArray *arr = [item valueForKey:@"child"];
|
return arr.count;
|
}
|
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
|
return 52;
|
}
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
|
//最后一个
|
return 0.01;
|
}
|
|
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
|
return nil;
|
}
|
|
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
|
UIView *bgView = [[UIView alloc]init];
|
bgView.backgroundColor = [UIColor whiteColor];
|
UIView *iconV = [[UIView alloc] init];
|
iconV.backgroundColor = PBColor(95, 158, 249);
|
[bgView addSubview:iconV];
|
[iconV mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(bgView).offset(20);
|
make.size.mas_equalTo(CGSizeMake(6, 20));
|
make.left.equalTo(bgView);
|
}];
|
NSDictionary *dict = self.dataList[section];
|
UILabel *nameL = [UILabel z_labelWithText:[dict valueForKey:@"name"] Color:[UIColor z_colorWithR:95 G:158 B:249] isBold:YES Font:18];
|
[bgView addSubview:nameL];
|
[nameL mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.centerY.equalTo(iconV);
|
make.left.equalTo(iconV.mas_right).offset(5);
|
}];
|
return bgView;
|
}
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
NSDictionary *item = self.dataList[indexPath.section];
|
NSArray *arr = [item valueForKey:@"child"];
|
PBSiteMaterialModel *model = arr[indexPath.row];
|
PBSitePerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID forIndexPath:indexPath];
|
cell.siteMaterialModel = model;
|
cell.materialIndex = indexPath.row + 1;
|
cell.ChooseTypeBlock = ^{
|
[self.view endEditing:YES];
|
[PBKeyWindow addSubview:self.chooseTypeView];
|
self.chooseTypeView.siteMaterialModel = model;
|
self.chooseTypeView.dateList = self.typeDataList;
|
self.chooseTypeView.ChooseCompleteBlock = ^(BOOL isSelsected, NSInteger index){
|
if (isSelsected) {
|
PBMaterialPlanModel *typeModel = self.typeDataList[index];
|
// [self loadUserTypeWithPlanID:self.schedulePlanModel.UID andUserType:typeModel.Materials_Name andIndexPath:indexPath andModel:model];
|
model.MaterialsDetial_Name = typeModel.Materials_Name;
|
model.MaterialsDetial_PlanNum = typeModel.Materials_PlanNum;
|
//清空
|
model.MaterialsDetial_AdddelNum = @"";
|
model.MaterialsDetial_NewNum = @"";
|
model.MaterialsDetial_type = @"";
|
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
|
}
|
};
|
[self.chooseTypeView show];
|
};
|
cell.DeleteBlock = ^{
|
[self.siteMaterialArrM removeObjectAtIndex:indexPath.row];
|
[self.tableView reloadData];
|
};
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
return cell;
|
}
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
}
|
|
- (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 *)siteMaterialArrM {
|
if (_siteMaterialArrM == nil) {
|
_siteMaterialArrM = [[NSMutableArray alloc] init];
|
}
|
return _siteMaterialArrM;
|
}
|
|
/*
|
#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
|