ModelDataController.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. //
  2. // ModelDataController.m
  3. // model
  4. //
  5. // Created by JuYi on 2018/7/16.
  6. // Copyright © 2018年 Mine. All rights reserved.
  7. // 模卡资料
  8. #import "ModelDataController.h"
  9. #import "MeasurementsViewController.h"
  10. #import "ModelPhotoViewController.h"
  11. #import "ModelTagViewController.h"
  12. #import "ModelHonorViewController.h"
  13. #import "InfoEditViewController.h"
  14. #import <BRPickerView.h>
  15. @interface ModelDataController ()<UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate>
  16. {
  17. ModelUser *tempUser;
  18. }
  19. @property (nonatomic, strong) UITableView *tableView;
  20. @property (nonatomic, strong) NSArray *titlesArr;
  21. @property (nonatomic, strong) NSArray *conentArr;
  22. @property (nonatomic, strong) UITableViewCell *nameCell;
  23. @property (nonatomic, strong) UITableViewCell *ageCell;
  24. @property (nonatomic, strong) UITableViewCell *heiCell;
  25. @property (nonatomic, strong) UITableViewCell *weiCell;
  26. @property (nonatomic, strong) UITableViewCell *waiBustHipCell; // 三围
  27. @property (nonatomic, strong) UITableViewCell *photoCell;
  28. @property (nonatomic, strong) UITableViewCell *areaCell; //地区(int类型,可空)
  29. @property (nonatomic, strong) UITableViewCell *spdjCell;//视频单价
  30. @property (nonatomic, strong) UITableViewCell *fgbqCell;//风格标签
  31. @property (nonatomic, strong) UITableViewCell *lnameCell; //个性签名
  32. @property (nonatomic, strong) UITableViewCell *wdryCell; // 我的荣誉
  33. @property (nonatomic, strong) NSMutableArray *areaArray;
  34. @end
  35. @implementation ModelDataController
  36. - (void)viewDidLoad {
  37. [super viewDidLoad];
  38. if ([[ModelUser user].modelpk isEqualToString:@"51"]) {
  39. self.titlesArr = @[@"姓名",@"年龄",@"身高",@"体重",@"三围",@"照片",@"地区",@"风格标签",@"个人签名",@"我的荣誉"];
  40. self.conentArr = @[@"干路路",@"19岁",@"165cm",@"50kg",@"82/63/88",@"4张照片",@"南京",@"3个标签",@"我喜欢我的工作",@"3个荣誉"];
  41. }else{
  42. self.titlesArr = @[@"姓名",@"年龄",@"身高",@"体重",@"三围",@"照片",@"地区",@"视频单价",@"风格标签",@"个人签名",@"我的荣誉"];
  43. self.conentArr = @[@"干路路",@"19岁",@"165cm",@"50kg",@"82/63/88",@"4张照片",@"南京",@"10元/分钟",@"3个标签",@"我喜欢我的工作",@"3个荣誉"];
  44. }
  45. self.areaArray = [NSMutableArray array];
  46. //设置导航条
  47. [self creatNavBar];
  48. //设置子试图
  49. [self creatSubViews];
  50. [self getAreaData];
  51. }
  52. - (void)viewWillAppear:(BOOL)animated {
  53. [super viewWillAppear:animated];
  54. [self getModelData];
  55. }
  56. - (void)didReceiveMemoryWarning {
  57. [super didReceiveMemoryWarning];
  58. // Dispose of any resources that can be recreated.
  59. }
  60. - (void)getAreaData {
  61. [YanCNetWorkManager requestGETWithURLStr:Url_getArea(PublicUrl) parameters:@{} finish:^(id dataDic) {
  62. [self.areaArray addObjectsFromArray:dataDic[@"data"]];
  63. [self.tableView reloadData];
  64. } enError:^(NSError *error) {
  65. }];
  66. }
  67. - (void)getModelData {
  68. [YanCNetWorkManager requestGETWithURLStr:Url_getModelData(PublicUrl) parameters:@{@"modelpk":[ModelUser user].modelpk} finish:^(id dataDic) {
  69. [[ModelUser modelUser] setValuesForKeysWithDictionary:[dataDic[@"data"] firstObject]];
  70. tempUser = [ModelUser mj_objectWithKeyValues:[dataDic[@"data"] firstObject]];
  71. [self.tableView reloadData];
  72. } enError:^(NSError *error) {
  73. }];
  74. }
  75. - (void)creatNavBar {
  76. self.title = @"模卡资料";
  77. //
  78. UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
  79. btn.frame = CGRectMake(0, 0, 40, 40);
  80. [btn setImage:[UIImage imageNamed:@"fanhui2"] forState:UIControlStateNormal];
  81. btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
  82. [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
  83. UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
  84. UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  85. // nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整
  86. self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem];
  87. }
  88. - (void)backClick {
  89. [self.navigationController popViewControllerAnimated:YES];
  90. }
  91. - (void)creatSubViews {
  92. //
  93. UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)];
  94. headerView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
  95. //
  96. UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - 460)];
  97. footerView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
  98. UIButton *bindingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  99. bindingBtn.frame = CGRectMake(20, 39, ScreenWidth - 40, 45);
  100. [bindingBtn setBackgroundImage:[UIImage imageNamed:@"tixian-1"] forState:UIControlStateNormal];
  101. [bindingBtn setTitle:@"保存" forState:UIControlStateNormal];
  102. [bindingBtn setTitleColor:RGBValueColor(0xffffff, 1.0) forState:UIControlStateNormal];
  103. [bindingBtn addTarget:self action:@selector(bindingBtnAction) forControlEvents:UIControlEventTouchUpInside];
  104. [footerView addSubview:bindingBtn];
  105. //
  106. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) style:UITableViewStylePlain];
  107. // self.tableView.scrollEnabled = NO;
  108. self.tableView.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
  109. self.tableView.delegate = self;
  110. self.tableView.dataSource = self;
  111. self.tableView.showsVerticalScrollIndicator = NO;
  112. // self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  113. self.tableView.tableHeaderView = headerView;
  114. self.tableView.tableFooterView = footerView;
  115. [self.view addSubview:self.tableView];
  116. }
  117. #pragma mark -- UITableViewDelegate, UITableViewDataSource
  118. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  119. return self.titlesArr.count;
  120. }
  121. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  122. static NSString *reuseIdentifier=@"cellID";
  123. UITableViewCell *modelCell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
  124. if (modelCell == nil) {
  125. modelCell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentifier];
  126. }
  127. modelCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  128. modelCell.selectionStyle = UITableViewCellSelectionStyleNone;
  129. modelCell.detailTextLabel.textColor = RGBValueColor(0x999999, 1.0);
  130. modelCell.textLabel.textColor = RGBValueColor(0x333333, 1.0);
  131. modelCell.textLabel.font = [UIFont systemFontOfSize:14.0];
  132. modelCell.detailTextLabel.font = [UIFont systemFontOfSize:14.0];
  133. modelCell.textLabel.text = self.titlesArr[indexPath.row];
  134. if (indexPath.row == 0) {
  135. self.nameCell = modelCell;
  136. modelCell.detailTextLabel.text = tempUser.pet;
  137. } else if (indexPath.row == 1) {
  138. self.ageCell = modelCell;
  139. modelCell.detailTextLabel.text = tempUser.age;
  140. } else if (indexPath.row == 2) {
  141. self.heiCell = modelCell;
  142. modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@cm",tempUser.hei];
  143. } else if (indexPath.row == 3) {
  144. self.weiCell = modelCell;
  145. modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@kg",tempUser.wei];
  146. } else if (indexPath.row == 4) {
  147. self.waiBustHipCell = modelCell;
  148. modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@/%@/%@",tempUser.bust,tempUser.wai,tempUser.hip];
  149. } else if (indexPath.row == 5) {
  150. self.photoCell = modelCell;
  151. modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@张照片",tempUser.photocount];
  152. } else if (indexPath.row == 6) {
  153. self.areaCell = modelCell;
  154. for (NSDictionary *dic in self.areaArray) {
  155. if ([dic[@"pk"] isEqual:tempUser.area]) {
  156. modelCell.detailTextLabel.text = dic[@"name"];
  157. }
  158. }
  159. } else if (indexPath.row == 7) {
  160. if ([[ModelUser user].modelpk isEqualToString:@"51"]) {
  161. self.fgbqCell = modelCell;
  162. modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@个标签",tempUser.stylecount];
  163. }else{
  164. self.spdjCell = modelCell;
  165. modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@元/分钟",tempUser.vprice];
  166. }
  167. } else if (indexPath.row == 8) {
  168. if ([[ModelUser user].modelpk isEqualToString:@"51"]) {
  169. self.lnameCell = modelCell;
  170. modelCell.detailTextLabel.text = tempUser.lname;
  171. }else{
  172. self.fgbqCell = modelCell;
  173. modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@个标签",tempUser.stylecount];
  174. }
  175. } else if (indexPath.row == 9) {
  176. if ([[ModelUser user].modelpk isEqualToString:@"51"]) {
  177. self.wdryCell = modelCell;
  178. modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@个荣誉",tempUser.honorcount];
  179. }else{
  180. self.lnameCell = modelCell;
  181. modelCell.detailTextLabel.text = tempUser.lname;
  182. }
  183. } else {
  184. if ([[ModelUser user].modelpk isEqualToString:@"51"]) {
  185. }else{
  186. self.wdryCell = modelCell;
  187. modelCell.detailTextLabel.text = [NSString stringWithFormat:@"%@个荣誉",tempUser.honorcount];
  188. }
  189. }
  190. return modelCell;
  191. }
  192. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  193. return 50;
  194. }
  195. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  196. UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  197. if (indexPath.row == 0) {
  198. InfoEditViewController *infoVc = [InfoEditViewController new];
  199. infoVc.editType = InfoEditTypeName;
  200. [self.navigationController pushViewController:infoVc animated:YES];
  201. } else if (indexPath.row == 1) {
  202. InfoEditViewController *infoVc = [InfoEditViewController new];
  203. infoVc.editType = InfoEditTypeAge;
  204. [self.navigationController pushViewController:infoVc animated:YES];
  205. } else if (indexPath.row == 2) {
  206. InfoEditViewController *infoVc = [InfoEditViewController new];
  207. infoVc.editType = InfoEditTypeHeight;
  208. [self.navigationController pushViewController:infoVc animated:YES];
  209. } else if (indexPath.row == 3) {
  210. InfoEditViewController *infoVc = [InfoEditViewController new];
  211. infoVc.editType = InfoEditTypeWeight;
  212. [self.navigationController pushViewController:infoVc animated:YES];
  213. } else if (indexPath.row == 4) {
  214. MeasurementsViewController *bmhVc = [MeasurementsViewController new];
  215. [self.navigationController pushViewController:bmhVc animated:YES];
  216. } else if (indexPath.row == 5) {
  217. ModelPhotoViewController *photovc = [ModelPhotoViewController new];
  218. [self.navigationController pushViewController:photovc animated:YES];
  219. } else if (indexPath.row == 6) {
  220. NSMutableArray *tempArray = [NSMutableArray array];
  221. for (NSDictionary *dic in self.areaArray) {
  222. [tempArray addObject:dic[@"name"]];
  223. }
  224. [BRStringPickerView showStringPickerWithTitle:@"请选择地区" dataSource:tempArray defaultSelValue:nil resultBlock:^(id selectValue) {
  225. for (NSDictionary *dic in self.areaArray) {
  226. if ([dic[@"name"] isEqualToString:selectValue]) {
  227. [YanCNetWorkManager requestPostWithURLStr:Url_updateModelCard(PublicUrl) parameters:@{@"area":dic[@"pk"],@"modelpk":[ModelUser user].modelpk} finish:^(id dataDic) {
  228. if ([dataDic[@"msg"] isEqualToString:@"success"]) {
  229. [MBProgressHUD showSuccess:@"修改成功"];
  230. cell.detailTextLabel.text = selectValue;
  231. } else {
  232. [MBProgressHUD showError:@"修改失败"];
  233. }
  234. } enError:^(NSError *error) {
  235. }];
  236. }
  237. }
  238. }];
  239. } else if (indexPath.row == 7) {
  240. if ([[ModelUser user].modelpk isEqualToString:@"51"]) {
  241. ModelTagViewController *tagVC = [ModelTagViewController new];
  242. [self.navigationController pushViewController:tagVC animated:YES];
  243. }else{
  244. InfoEditViewController *infoVc = [InfoEditViewController new];
  245. infoVc.editType = InfoEditTypeVprice;
  246. [self.navigationController pushViewController:infoVc animated:YES];
  247. }
  248. } else if (indexPath.row == 8) {
  249. if ([[ModelUser user].modelpk isEqualToString:@"51"]) {
  250. InfoEditViewController *infoVc = [InfoEditViewController new];
  251. infoVc.editType = InfoEditTypeSigature;
  252. [self.navigationController pushViewController:infoVc animated:YES];
  253. }else{
  254. ModelTagViewController *tagVC = [ModelTagViewController new];
  255. [self.navigationController pushViewController:tagVC animated:YES];
  256. }
  257. } else if (indexPath.row == 9) {
  258. if ([[ModelUser user].modelpk isEqualToString:@"51"]) {
  259. ModelHonorViewController *honorVc = [ModelHonorViewController new];
  260. [self.navigationController pushViewController:honorVc animated:YES];
  261. }else{
  262. InfoEditViewController *infoVc = [InfoEditViewController new];
  263. infoVc.editType = InfoEditTypeSigature;
  264. [self.navigationController pushViewController:infoVc animated:YES];
  265. }
  266. } else if (indexPath.row == 10) {
  267. if ([[ModelUser user].modelpk isEqualToString:@"51"]) {
  268. }else{
  269. ModelHonorViewController *honorVc = [ModelHonorViewController new];
  270. [self.navigationController pushViewController:honorVc animated:YES];
  271. }
  272. }
  273. }
  274. #pragma mark -- 保存按钮
  275. - (void)bindingBtnAction {
  276. NSLog(@"name %@", self.nameCell.textLabel.text);
  277. if (self.nameCell.textLabel.text.length == 0) {
  278. [MBProgressHUD showOnlyText:@"请选择填写姓名" controller:self];
  279. return;
  280. }
  281. NSLog(@"age %@", self.ageCell.textLabel.text);
  282. if (self.ageCell.textLabel.text.length == 0) {
  283. [MBProgressHUD showOnlyText:@"请选择填写年龄" controller:self];
  284. return;
  285. }
  286. NSLog(@"heiCell %@", self.heiCell.textLabel.text);
  287. if (self.heiCell.textLabel.text.length == 0) {
  288. [MBProgressHUD showOnlyText:@"请选择填写身高" controller:self];
  289. return;
  290. }
  291. NSLog(@"体重 %@", self.weiCell.textLabel.text);
  292. if (self.weiCell.textLabel.text.length == 0) {
  293. [MBProgressHUD showOnlyText:@"请选择填写体重" controller:self];
  294. return;
  295. }
  296. NSLog(@"三围 %@", self.nameCell.textLabel.text);
  297. if (self.nameCell.textLabel.text.length == 0) {
  298. [MBProgressHUD showOnlyText:@"请选择填写三围" controller:self];
  299. return;
  300. }
  301. NSLog(@"地区 %@", self.areaCell.textLabel.text);
  302. if (self.areaCell.textLabel.text.length == 0) {
  303. [MBProgressHUD showOnlyText:@"请选择填写地区" controller:self];
  304. return;
  305. }
  306. if (![[ModelUser user].modelpk isEqualToString:@"51"]) {
  307. NSLog(@"视频单价 %@", self.spdjCell.textLabel.text);
  308. if (self.spdjCell.textLabel.text.length == 0) {
  309. [MBProgressHUD showOnlyText:@"请选择填写视频单价" controller:self];
  310. return;
  311. }
  312. }
  313. NSLog(@"风格标签 %@", self.fgbqCell.textLabel.text);
  314. if (self.fgbqCell.textLabel.text.length == 0) {
  315. [MBProgressHUD showOnlyText:@"请选择填写标签" controller:self];
  316. return;
  317. }
  318. NSLog(@"个人签名 %@", self.lnameCell.textLabel.text);
  319. if (self.lnameCell.textLabel.text.length == 0) {
  320. [MBProgressHUD showOnlyText:@"请选择填写签名" controller:self];
  321. return;
  322. }
  323. [MBProgressHUD showSuccess:@"保存成功"];
  324. [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(backClick) userInfo:nil repeats:NO];
  325. }
  326. #pragma mark -- 网络请求
  327. - (void)postDataFromNetworking {
  328. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  329. ModelUser *modelUser = [ModelUser user];
  330. NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:modelUser.modelpk,@"modelpk",self.lnameCell.textLabel.text,@"lname", nil];
  331. [YanCNetWorkManager requestPostWithURLStr:Url_updateModelCard(PublicUrl) parameters:dic finish:^(id dataDic) {
  332. [MBProgressHUD hideHUDForView:self.view animated:YES];
  333. NSString *issuccess = dataDic[@"msg"];
  334. if ([issuccess isEqualToString:@"success"]) {
  335. [MBProgressHUD showSuccess:@"保存成功"];
  336. } else {
  337. }
  338. } enError:^(NSError *error) {
  339. [MBProgressHUD hideHUDForView:self.view animated:YES];
  340. }];
  341. }
  342. @end