// // ModelDataController.m // model // // Created by JuYi on 2018/7/16. // Copyright © 2018年 Mine. All rights reserved. // 模卡资料 #import "ModelDataController.h" #import "MeasurementsViewController.h" #import "ModelPhotoViewController.h" #import "ModelTagViewController.h" #import "ModelHonorViewController.h" #import "InfoEditViewController.h" #import @interface ModelDataController () { 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 *spdjCell;//视频单价 @property (nonatomic, strong) UITableViewCell *fgbqCell;//风格标签 @property (nonatomic, strong) UITableViewCell *lnameCell; //个性签名 @property (nonatomic, strong) UITableViewCell *wdryCell; // 我的荣誉 @property (nonatomic, strong) NSMutableArray *areaArray; @end @implementation ModelDataController - (void)viewDidLoad { [super viewDidLoad]; if ([[ModelUser user].modelpk isEqualToString:@"51"]) { self.titlesArr = @[@"姓名",@"年龄",@"身高",@"体重",@"三围",@"照片",@"地区",@"风格标签",@"个人签名",@"我的荣誉"]; self.conentArr = @[@"干路路",@"19岁",@"165cm",@"50kg",@"82/63/88",@"4张照片",@"南京",@"3个标签",@"我喜欢我的工作",@"3个荣誉"]; }else{ self.titlesArr = @[@"姓名",@"年龄",@"身高",@"体重",@"三围",@"照片",@"地区",@"视频单价",@"风格标签",@"个人签名",@"我的荣誉"]; self.conentArr = @[@"干路路",@"19岁",@"165cm",@"50kg",@"82/63/88",@"4张照片",@"南京",@"10元/分钟",@"3个标签",@"我喜欢我的工作",@"3个荣誉"]; } self.areaArray = [NSMutableArray array]; //设置导航条 [self creatNavBar]; //设置子试图 [self creatSubViews]; [self getAreaData]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [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)creatNavBar { 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]; // nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整 self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem]; } - (void)backClick { [self.navigationController popViewControllerAnimated:YES]; } - (void)creatSubViews { // 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, 45); [bindingBtn setBackgroundImage:[UIImage imageNamed:@"tixian-1"] forState:UIControlStateNormal]; [bindingBtn setTitle:@"保存" forState:UIControlStateNormal]; [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]; } #pragma mark -- UITableViewDelegate, UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.titlesArr.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.row]; if (indexPath.row == 0) { self.nameCell = modelCell; modelCell.detailTextLabel.text = tempUser.pet; } else if (indexPath.row == 1) { self.ageCell = modelCell; modelCell.detailTextLabel.text = tempUser.age; } else if (indexPath.row == 2) { self.heiCell = modelCell; modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@cm",tempUser.hei]; } else if (indexPath.row == 3) { self.weiCell = modelCell; modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@kg",tempUser.wei]; } else if (indexPath.row == 4) { self.waiBustHipCell = modelCell; modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@/%@/%@",tempUser.bust,tempUser.wai,tempUser.hip]; } else if (indexPath.row == 5) { self.photoCell = modelCell; modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@张照片",tempUser.photocount]; } else if (indexPath.row == 6) { self.areaCell = modelCell; for (NSDictionary *dic in self.areaArray) { if ([dic[@"pk"] isEqual:tempUser.area]) { modelCell.detailTextLabel.text = dic[@"name"]; } } } else if (indexPath.row == 7) { if ([[ModelUser user].modelpk isEqualToString:@"51"]) { self.fgbqCell = modelCell; modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@个标签",tempUser.stylecount]; }else{ self.spdjCell = modelCell; modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@元/分钟",tempUser.vprice]; } } else if (indexPath.row == 8) { if ([[ModelUser user].modelpk isEqualToString:@"51"]) { self.lnameCell = modelCell; modelCell.detailTextLabel.text = tempUser.lname; }else{ self.fgbqCell = modelCell; modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@个标签",tempUser.stylecount]; } } else if (indexPath.row == 9) { if ([[ModelUser user].modelpk isEqualToString:@"51"]) { self.wdryCell = modelCell; modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@个荣誉",tempUser.honorcount]; }else{ self.lnameCell = modelCell; modelCell.detailTextLabel.text = tempUser.lname; } } else { if ([[ModelUser user].modelpk isEqualToString:@"51"]) { }else{ 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]; if (indexPath.row == 0) { InfoEditViewController *infoVc = [InfoEditViewController new]; infoVc.editType = InfoEditTypeName; [self.navigationController pushViewController:infoVc animated:YES]; } else if (indexPath.row == 1) { InfoEditViewController *infoVc = [InfoEditViewController new]; infoVc.editType = InfoEditTypeAge; [self.navigationController pushViewController:infoVc animated:YES]; } else if (indexPath.row == 2) { InfoEditViewController *infoVc = [InfoEditViewController new]; infoVc.editType = InfoEditTypeHeight; [self.navigationController pushViewController:infoVc animated:YES]; } else if (indexPath.row == 3) { InfoEditViewController *infoVc = [InfoEditViewController new]; infoVc.editType = InfoEditTypeWeight; [self.navigationController pushViewController:infoVc animated:YES]; } else if (indexPath.row == 4) { MeasurementsViewController *bmhVc = [MeasurementsViewController new]; [self.navigationController pushViewController:bmhVc animated:YES]; } else if (indexPath.row == 5) { ModelPhotoViewController *photovc = [ModelPhotoViewController new]; [self.navigationController pushViewController:photovc animated:YES]; } else if (indexPath.row == 6) { 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 (indexPath.row == 7) { if ([[ModelUser user].modelpk isEqualToString:@"51"]) { ModelTagViewController *tagVC = [ModelTagViewController new]; [self.navigationController pushViewController:tagVC animated:YES]; }else{ InfoEditViewController *infoVc = [InfoEditViewController new]; infoVc.editType = InfoEditTypeVprice; [self.navigationController pushViewController:infoVc animated:YES]; } } else if (indexPath.row == 8) { if ([[ModelUser user].modelpk isEqualToString:@"51"]) { InfoEditViewController *infoVc = [InfoEditViewController new]; infoVc.editType = InfoEditTypeSigature; [self.navigationController pushViewController:infoVc animated:YES]; }else{ ModelTagViewController *tagVC = [ModelTagViewController new]; [self.navigationController pushViewController:tagVC animated:YES]; } } else if (indexPath.row == 9) { if ([[ModelUser user].modelpk isEqualToString:@"51"]) { ModelHonorViewController *honorVc = [ModelHonorViewController new]; [self.navigationController pushViewController:honorVc animated:YES]; }else{ InfoEditViewController *infoVc = [InfoEditViewController new]; infoVc.editType = InfoEditTypeSigature; [self.navigationController pushViewController:infoVc animated:YES]; } } else if (indexPath.row == 10) { if ([[ModelUser user].modelpk isEqualToString:@"51"]) { }else{ ModelHonorViewController *honorVc = [ModelHonorViewController new]; [self.navigationController pushViewController:honorVc animated:YES]; } } } #pragma mark -- 保存按钮 - (void)bindingBtnAction { NSLog(@"name %@", self.nameCell.textLabel.text); if (self.nameCell.textLabel.text.length == 0) { [MBProgressHUD showOnlyText:@"请选择填写姓名" controller:self]; return; } NSLog(@"age %@", self.ageCell.textLabel.text); if (self.ageCell.textLabel.text.length == 0) { [MBProgressHUD showOnlyText:@"请选择填写年龄" controller:self]; return; } NSLog(@"heiCell %@", self.heiCell.textLabel.text); if (self.heiCell.textLabel.text.length == 0) { [MBProgressHUD showOnlyText:@"请选择填写身高" controller:self]; return; } NSLog(@"体重 %@", self.weiCell.textLabel.text); if (self.weiCell.textLabel.text.length == 0) { [MBProgressHUD showOnlyText:@"请选择填写体重" controller:self]; return; } NSLog(@"三围 %@", self.nameCell.textLabel.text); if (self.nameCell.textLabel.text.length == 0) { [MBProgressHUD showOnlyText:@"请选择填写三围" controller:self]; return; } NSLog(@"地区 %@", self.areaCell.textLabel.text); if (self.areaCell.textLabel.text.length == 0) { [MBProgressHUD showOnlyText:@"请选择填写地区" controller:self]; return; } if (![[ModelUser user].modelpk isEqualToString:@"51"]) { NSLog(@"视频单价 %@", self.spdjCell.textLabel.text); if (self.spdjCell.textLabel.text.length == 0) { [MBProgressHUD showOnlyText:@"请选择填写视频单价" controller:self]; return; } } NSLog(@"风格标签 %@", self.fgbqCell.textLabel.text); if (self.fgbqCell.textLabel.text.length == 0) { [MBProgressHUD showOnlyText:@"请选择填写标签" controller:self]; return; } NSLog(@"个人签名 %@", self.lnameCell.textLabel.text); if (self.lnameCell.textLabel.text.length == 0) { [MBProgressHUD showOnlyText:@"请选择填写签名" controller:self]; return; } [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 = [[NSDictionary alloc] initWithObjectsAndKeys:modelUser.modelpk,@"modelpk",self.lnameCell.textLabel.text,@"lname", nil]; [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