// // ModelDataController.m // model // // Created by JuYi on 2018/7/16. // Copyright © 2018年 Mine. All rights reserved. // 模卡资料 #import "ModelCardController.h" #import "MeasurementsViewController.h" #import "ModelPhotoViewController.h" #import "ModelTagViewController.h" #import "ModelHonorViewController.h" #import "InfoEditViewController.h" #import #import "MySkillsController.h" #import "ShareCardController.h" #import "HobbyViewController.h" @interface ModelCardController () { ModelUser *tempUser; } @property(nonatomic, strong) UITableView *tableView; @property(nonatomic, strong) NSArray *titlesArr; @property(nonatomic, strong) NSArray *conentArr; @property(nonatomic, strong) UITableViewCell *nameCell; @property(nonatomic, strong) UITableViewCell *ageCell; @property(nonatomic, strong) UITableViewCell *heiCell; @property(nonatomic, strong) UITableViewCell *weiCell; @property(nonatomic, strong) UITableViewCell *waiBustHipCell; // 三围 @property(nonatomic, strong) UITableViewCell *photoCell; @property(nonatomic, strong) UITableViewCell *areaCell; //地区(int类型,可空) @property(nonatomic, strong) UITableViewCell *occupationCell; //职业 @property(nonatomic, strong) UITableViewCell *spdjCell;//视频单价 @property(nonatomic, strong) UITableViewCell *fgbqCell;//风格标签 @property(nonatomic, strong) UITableViewCell *lnameCell; //个性签名 @property(nonatomic, strong) UITableViewCell *wdryCell; // 我的荣誉 @property(nonatomic, strong) UITableViewCell *constellationCell; // 星座 @property(nonatomic, strong) UITableViewCell *collegeCell; // 学校 @property(nonatomic, strong) UITableViewCell *hobbyCell; // 爱好 @property(nonatomic, strong) NSMutableArray *areaArray; @property(nonatomic, strong) NSArray *jobArray; @property(nonatomic, strong) NSArray *constellationArray; @end @implementation ModelCardController - (void)viewDidLoad { [super viewDidLoad]; self.title = @"模卡资料"; UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake(0, 0, 40, 40); [btn setImage:[UIImage imageNamed:@"fanhui2"] forState:UIControlStateNormal]; btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0); [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn]; UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem]; self.titlesArr = @[@[@"照片"], @[@"姓名"], @[@"个性签名"], @[@"视频单价"], @[@"身高", @"体重", @"三围", @"地区", @"年龄", @"职业", @"星座", @"毕业院校", @"兴趣爱好"], @[@"我的标签"], @[@"我的荣誉"]]; self.conentArr = @[@[@""], @[@""], @[@""], @[@""], @[@"", @"", @"", @"", @"", @"", @"", @"", @""], @[@""], @[@""]]; self.areaArray = [NSMutableArray array]; self.jobArray = @[@"空姐", @"职业模特", @"白领", @"演员", @"护士", @"学生", @"老师", @"品酒师", @"其他"]; self.constellationArray = @[@"水瓶座", @"双鱼座", @"白羊座", @"金牛座", @"双子座", @"巨蟹座", @"狮子座", @"处女座", @"天秤座", @"天蝎座", @"射手座", @"魔蝎座"]; UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)]; headerView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0); // UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - 460)]; footerView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0); UIButton *bindingBtn = [UIButton buttonWithType:UIButtonTypeCustom]; bindingBtn.frame = CGRectMake(20, 39, ScreenWidth - 40, 44); bindingBtn.layer.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:64 / 255.0 blue:149 / 255.0 alpha:1].CGColor; bindingBtn.layer.cornerRadius = 22; bindingBtn.layer.shadowColor = [UIColor colorWithRed:255 / 255.0 green:64 / 255.0 blue:149 / 255.0 alpha:0.36].CGColor; bindingBtn.layer.shadowOffset = CGSizeMake(0, 8); bindingBtn.layer.shadowOpacity = 1; bindingBtn.layer.shadowRadius = 10; if ([@"init" isEqualToString:self.type]) { [bindingBtn setTitle:@"下一步" forState:UIControlStateNormal]; } else { [bindingBtn setTitle:@"查看我的模卡" forState:UIControlStateNormal]; } bindingBtn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium]; [bindingBtn setTitleColor:RGBValueColor(0xffffff, 1.0) forState:UIControlStateNormal]; [bindingBtn addTarget:self action:@selector(bindingBtnAction) forControlEvents:UIControlEventTouchUpInside]; [footerView addSubview:bindingBtn]; self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) style:UITableViewStylePlain]; // self.tableView.scrollEnabled = NO; self.tableView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0); self.tableView.delegate = self; self.tableView.dataSource = self; self.tableView.showsVerticalScrollIndicator = NO; // self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.tableHeaderView = headerView; self.tableView.tableFooterView = footerView; [self.view addSubview:self.tableView]; self.view.backgroundColor = [UIColor colorWithRed:242 / 255.0 green:244 / 255.0 blue:245 / 255.0 alpha:1]; [self getAreaData]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:NO animated:YES]; [self getModelData]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)getAreaData { [YanCNetWorkManager requestGETWithURLStr:Url_getArea(PublicUrl) parameters:@{} finish:^(id dataDic) { [self.areaArray addObjectsFromArray:dataDic[@"data"]]; [self.tableView reloadData]; } enError:^(NSError *error) { }]; } - (void)getModelData { [YanCNetWorkManager requestGETWithURLStr:Url_getModelData(PublicUrl) parameters:@{@"modelpk": [ModelUser user].modelpk} finish:^(id dataDic) { [[ModelUser modelUser] setValuesForKeysWithDictionary:[dataDic[@"data"] firstObject]]; tempUser = [ModelUser mj_objectWithKeyValues:[dataDic[@"data"] firstObject]]; [self.tableView reloadData]; } enError:^(NSError *error) { }]; } - (void)backClick { if ([@"init" isEqualToString:self.type]) { if ([self checkInfo]) { [self.navigationController popViewControllerAnimated:YES]; } } else { [self.navigationController popViewControllerAnimated:YES]; } } #pragma mark -- UITableViewDelegate, UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return self.titlesArr.count; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return ((NSDictionary *) self.titlesArr[section]).count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *reuseIdentifier = @"cellID"; UITableViewCell *modelCell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier]; if (modelCell == nil) { modelCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentifier]; } modelCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; modelCell.selectionStyle = UITableViewCellSelectionStyleNone; modelCell.detailTextLabel.textColor = RGBValueColor(0x999999, 1.0); modelCell.textLabel.textColor = RGBValueColor(0x333333, 1.0); modelCell.textLabel.font = [UIFont systemFontOfSize:14.0]; modelCell.detailTextLabel.font = [UIFont systemFontOfSize:14.0]; modelCell.textLabel.text = self.titlesArr[indexPath.section][indexPath.row]; NSString *rowTitle = self.titlesArr[indexPath.section][indexPath.row]; if ([@"照片" isEqualToString:rowTitle]) { self.photoCell = modelCell; modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@张照片", tempUser.photocount]; } else if ([@"姓名" isEqualToString:rowTitle]) { self.nameCell = modelCell; modelCell.detailTextLabel.text = tempUser.pet; } else if ([@"个性签名" isEqualToString:rowTitle]) { self.lnameCell = modelCell; modelCell.detailTextLabel.text = tempUser.lname; } else if ([@"视频单价" isEqualToString:rowTitle]) { self.spdjCell = modelCell; modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@元/分钟", tempUser.vprice]; } else if ([@"身高" isEqualToString:rowTitle]) { self.heiCell = modelCell; modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@cm", tempUser.hei]; } else if ([@"体重" isEqualToString:rowTitle]) { self.weiCell = modelCell; modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@kg", tempUser.wei]; } else if ([@"三围" isEqualToString:rowTitle]) { self.waiBustHipCell = modelCell; modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@/%@/%@", tempUser.bust, tempUser.wai, tempUser.hip]; } else if ([@"地区" isEqualToString:rowTitle]) { self.areaCell = modelCell; modelCell.detailTextLabel.text = @""; for (NSDictionary *dic in self.areaArray) { if ([dic[@"pk"] isEqual:tempUser.area]) { modelCell.detailTextLabel.text = dic[@"name"]; } } } else if ([@"年龄" isEqualToString:rowTitle]) { self.ageCell = modelCell; modelCell.detailTextLabel.text = tempUser.age; } else if ([@"职业" isEqualToString:rowTitle]) { self.occupationCell = modelCell; modelCell.detailTextLabel.text = tempUser.occupation; } else if ([@"星座" isEqualToString:rowTitle]) { self.constellationCell = modelCell; modelCell.detailTextLabel.text = tempUser.constellation; } else if ([@"毕业院校" isEqualToString:rowTitle]) { self.collegeCell = modelCell; modelCell.detailTextLabel.text = tempUser.college; } else if ([@"兴趣爱好" isEqualToString:rowTitle]) { self.hobbyCell = modelCell; modelCell.detailTextLabel.text = tempUser.hobby; } else if ([@"我的标签" isEqualToString:rowTitle]) { self.fgbqCell = modelCell; modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@个标签", tempUser.stylecount]; } else if ([@"我的荣誉" isEqualToString:rowTitle]) { self.wdryCell = modelCell; modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@个荣誉", tempUser.honorcount]; } return modelCell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 50; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; NSString *rowTitle = self.titlesArr[indexPath.section][indexPath.row]; if ([@"照片" isEqualToString:rowTitle]) { ModelPhotoViewController *photovc = [ModelPhotoViewController new]; [self.navigationController pushViewController:photovc animated:YES]; } else if ([@"姓名" isEqualToString:rowTitle]) { InfoEditViewController *infoVc = [InfoEditViewController new]; infoVc.editType = InfoEditTypeName; [self.navigationController pushViewController:infoVc animated:YES]; } else if ([@"个性签名" isEqualToString:rowTitle]) { InfoEditViewController *infoVc = [InfoEditViewController new]; infoVc.editType = InfoEditTypeSigature; [self.navigationController pushViewController:infoVc animated:YES]; } else if ([@"视频单价" isEqualToString:rowTitle]) { InfoEditViewController *infoVc = [InfoEditViewController new]; infoVc.editType = InfoEditTypeVprice; [self.navigationController pushViewController:infoVc animated:YES]; } else if ([@"身高" isEqualToString:rowTitle]) { InfoEditViewController *infoVc = [InfoEditViewController new]; infoVc.editType = InfoEditTypeHeight; [self.navigationController pushViewController:infoVc animated:YES]; } else if ([@"体重" isEqualToString:rowTitle]) { InfoEditViewController *infoVc = [InfoEditViewController new]; infoVc.editType = InfoEditTypeWeight; [self.navigationController pushViewController:infoVc animated:YES]; } else if ([@"三围" isEqualToString:rowTitle]) { MeasurementsViewController *bmhVc = [MeasurementsViewController new]; [self.navigationController pushViewController:bmhVc animated:YES]; } else if ([@"地区" isEqualToString:rowTitle]) { NSMutableArray *tempArray = [NSMutableArray array]; for (NSDictionary *dic in self.areaArray) { [tempArray addObject:dic[@"name"]]; } [BRStringPickerView showStringPickerWithTitle:@"请选择地区" dataSource:tempArray defaultSelValue:nil resultBlock:^(id selectValue) { for (NSDictionary *dic in self.areaArray) { if ([dic[@"name"] isEqualToString:selectValue]) { [YanCNetWorkManager requestPostWithURLStr:Url_updateModelCard(PublicUrl) parameters:@{@"area": dic[@"pk"], @"modelpk": [ModelUser user].modelpk} finish:^(id dataDic) { if ([dataDic[@"msg"] isEqualToString:@"success"]) { [MBProgressHUD showSuccess:@"修改成功"]; cell.detailTextLabel.text = selectValue; } else { [MBProgressHUD showError:@"修改失败"]; } } enError:^(NSError *error) { }]; } } }]; } else if ([@"年龄" isEqualToString:rowTitle]) { InfoEditViewController *infoVc = [InfoEditViewController new]; infoVc.editType = InfoEditTypeAge; [self.navigationController pushViewController:infoVc animated:YES]; } else if ([@"职业" isEqualToString:rowTitle]) { // InfoEditViewController *infoVc = [InfoEditViewController new]; // infoVc.editType = InfoEditTypeOccupation; // [self.navigationController pushViewController:infoVc animated:YES]; [BRStringPickerView showStringPickerWithTitle:@"请选择职业" dataSource:self.jobArray defaultSelValue:nil resultBlock:^(id selectValue) { [YanCNetWorkManager requestPostWithURLStr:Url_updateModelCard(PublicUrl) parameters:@{@"occupation": selectValue, @"modelpk": [ModelUser user].modelpk} finish:^(id dataDic) { if ([dataDic[@"msg"] isEqualToString:@"success"]) { [MBProgressHUD showSuccess:@"修改成功"]; cell.detailTextLabel.text = selectValue; } else { [MBProgressHUD showError:@"修改失败"]; } } enError:^(NSError *error) { }]; }]; } else if ([@"星座" isEqualToString:rowTitle]) { // InfoEditViewController *infoVc = [InfoEditViewController new]; // infoVc.editType = InfoEditTypeConstellation; // [self.navigationController pushViewController:infoVc animated:YES]; [BRStringPickerView showStringPickerWithTitle:@"请选择星座" dataSource:self.constellationArray defaultSelValue:nil resultBlock:^(id selectValue) { [YanCNetWorkManager requestPostWithURLStr:Url_updateModelCard(PublicUrl) parameters:@{@"constellation": selectValue, @"modelpk": [ModelUser user].modelpk} finish:^(id dataDic) { if ([dataDic[@"msg"] isEqualToString:@"success"]) { [MBProgressHUD showSuccess:@"修改成功"]; cell.detailTextLabel.text = selectValue; } else { [MBProgressHUD showError:@"修改失败"]; } } enError:^(NSError *error) { }]; }]; } else if ([@"毕业院校" isEqualToString:rowTitle]) { InfoEditViewController *infoVc = [InfoEditViewController new]; infoVc.editType = InfoEditTypeCollege; [self.navigationController pushViewController:infoVc animated:YES]; } else if ([@"兴趣爱好" isEqualToString:rowTitle]) { HobbyViewController *hobbyVC = [[HobbyViewController alloc] init]; [self.navigationController pushViewController:hobbyVC animated:YES]; } else if ([@"我的标签" isEqualToString:rowTitle]) { ModelTagViewController *tagVC = [ModelTagViewController new]; [self.navigationController pushViewController:tagVC animated:YES]; } else if ([@"我的荣誉" isEqualToString:rowTitle]) { ModelHonorViewController *honorVc = [ModelHonorViewController new]; [self.navigationController pushViewController:honorVc animated:YES]; } } #pragma mark -- 保存按钮 - (BOOL)checkInfo { if ([tempUser.photocount intValue] < 5) { [self.view makeToast:@"请至少上传5张照片" duration:2.0 position:CSToastPositionCenter]; return NO; } if (tempUser.pet.length == 0) { [self.view makeToast:@"请填写姓名" duration:2.0 position:CSToastPositionCenter]; return NO; } if (tempUser.lname.length == 0) { [self.view makeToast:@"请填写个性签名" duration:2.0 position:CSToastPositionCenter]; return NO; } if (tempUser.vprice.length == 0) { [self.view makeToast:@"请填写视频单价" duration:2.0 position:CSToastPositionCenter]; return NO; } if (tempUser.hei.length == 0 || [@"0" isEqualToString:tempUser.hei]) { [self.view makeToast:@"请填写身高" duration:2.0 position:CSToastPositionCenter]; return NO; } if (tempUser.wei.length == 0 || [@"0" isEqualToString:tempUser.wei]) { [self.view makeToast:@"请填写体重" duration:2.0 position:CSToastPositionCenter]; return NO; } if (tempUser.bust.length == 0) { [self.view makeToast:@"请填写三围" duration:2.0 position:CSToastPositionCenter]; return NO; } if (tempUser.area.length == 0) { [self.view makeToast:@"请填写地区" duration:2.0 position:CSToastPositionCenter]; return NO; } if (tempUser.age.length == 0) { [self.view makeToast:@"请填写年龄" duration:2.0 position:CSToastPositionCenter]; return NO; } if (tempUser.occupation.length == 0) { [self.view makeToast:@"请填写职业" duration:2.0 position:CSToastPositionCenter]; return NO; } if (tempUser.constellation.length == 0) { [self.view makeToast:@"请填写星座" duration:2.0 position:CSToastPositionCenter]; return NO; } if (tempUser.college.length == 0) { [self.view makeToast:@"请填写毕业院校" duration:2.0 position:CSToastPositionCenter]; return NO; } return YES; } - (void)bindingBtnAction { if ([self checkInfo]) { if ([@"init" isEqualToString:self.type]) { MySkillsController *mySkillsVC = [[MySkillsController alloc] init]; [self.navigationController pushViewController:mySkillsVC animated:YES]; } else { ShareCardController *shareCardVC = [[ShareCardController alloc] init]; [self.navigationController pushViewController:shareCardVC animated:YES]; } } // [MBProgressHUD showSuccess:@"保存成功"]; // [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(backClick) userInfo:nil repeats:NO]; } #pragma mark -- 网络请求 - (void)postDataFromNetworking { [MBProgressHUD showHUDAddedTo:self.view animated:YES]; ModelUser *modelUser = [ModelUser user]; NSDictionary *dic = @{@"modelpk": modelUser.modelpk, @"lname": self.lnameCell.textLabel.text}; [YanCNetWorkManager requestPostWithURLStr:Url_updateModelCard(PublicUrl) parameters:dic finish:^(id dataDic) { [MBProgressHUD hideHUDForView:self.view animated:YES]; NSString *issuccess = dataDic[@"msg"]; if ([issuccess isEqualToString:@"success"]) { [MBProgressHUD showSuccess:@"保存成功"]; } else { } } enError:^(NSError *error) { [MBProgressHUD hideHUDForView:self.view animated:YES]; }]; } @end