InfoEditViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. //
  2. // InfoEditViewController.m
  3. // model
  4. //
  5. // Created by liufei on 2018/7/25.
  6. // Copyright © 2018年 Mine. All rights reserved.
  7. //
  8. #import "InfoEditViewController.h"
  9. @interface InfoEditViewController ()
  10. @property(nonatomic, strong) UITextField *infoTextField;
  11. @property(nonatomic, strong) UIButton *btnAgree;
  12. @end
  13. @implementation InfoEditViewController
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  17. btn.frame = CGRectMake(0, 0, 40, 40);
  18. [btn setImage:[UIImage imageNamed:@"fanhui2"] forState:UIControlStateNormal];
  19. btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
  20. [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
  21. UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
  22. UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  23. self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem];
  24. [self configUI];
  25. }
  26. - (void)viewWillAppear:(BOOL)animated {
  27. [super viewWillAppear:animated];
  28. [self.navigationController setNavigationBarHidden:NO animated:YES];
  29. }
  30. - (void)configUI {
  31. self.view.backgroundColor = [UIColor colorWithHexString:@"#F2F4F5"];
  32. self.navigationController.navigationBar.tintColor = [UIColor colorWithHexString:@"#F2F4F5"];
  33. UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(handleSave)];
  34. rightItem.tintColor = [UIColor blackColor];
  35. self.navigationItem.rightBarButtonItem = rightItem;
  36. UIView *container = [[UIView alloc] initWithFrame:CGRectMake(20, 10, ScreenWidth - 40, 60)];
  37. container.layer.cornerRadius = 8;
  38. container.clipsToBounds = YES;
  39. container.backgroundColor = [UIColor whiteColor];
  40. [self.view addSubview:container];
  41. self.infoTextField = [[UITextField alloc] init];
  42. self.infoTextField.backgroundColor = [UIColor whiteColor];
  43. [container addSubview:self.infoTextField];
  44. [self.infoTextField mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.centerY.equalTo(container);
  46. make.height.equalTo(container);
  47. make.leftMargin.equalTo(container).offset(15);
  48. make.rightMargin.equalTo(container).offset(-15);
  49. }];
  50. switch (_editType) {
  51. case InfoEditTypeName:
  52. self.title = @"用户名";
  53. self.infoTextField.placeholder = @"请输入用户名";
  54. self.infoTextField.text = [ModelUser modelUser].pet;
  55. break;
  56. case InfoEditTypeAge:
  57. self.title = @"年龄";
  58. self.infoTextField.placeholder = @"请输入年龄";
  59. self.infoTextField.text = [ModelUser modelUser].age;
  60. self.infoTextField.keyboardType = UIKeyboardTypeNumberPad;
  61. break;
  62. case InfoEditTypeHeight:
  63. self.title = @"身高";
  64. self.infoTextField.placeholder = @"请输入身高(cm)";
  65. self.infoTextField.text = [ModelUser modelUser].hei;
  66. self.infoTextField.keyboardType = UIKeyboardTypeDecimalPad;
  67. break;
  68. case InfoEditTypeWeight:
  69. self.title = @"体重";
  70. self.infoTextField.placeholder = @"请输入体重(kg)";
  71. self.infoTextField.text = [ModelUser modelUser].wei;
  72. self.infoTextField.keyboardType = UIKeyboardTypeDecimalPad;
  73. break;
  74. case InfoEditTypeSigature:
  75. self.title = @"个性签名";
  76. self.infoTextField.text = [ModelUser modelUser].lname;
  77. self.infoTextField.placeholder = @"请输入个性签名";
  78. break;
  79. case InfoEditTypeVprice: {
  80. self.title = @"视频单价";
  81. self.infoTextField.text = [ModelUser modelUser].vprice;
  82. self.infoTextField.placeholder = @"请输入视频单价(6--49)元";
  83. self.infoTextField.keyboardType = UIKeyboardTypeNumberPad;
  84. UILabel *yuan = [[UILabel alloc] init];
  85. yuan.textAlignment = NSTextAlignmentCenter;
  86. yuan.text = @"元";
  87. yuan.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  88. yuan.textColor = [UIColor blackColor];
  89. [container addSubview:yuan];
  90. [yuan mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.centerY.equalTo(container);
  92. make.rightMargin.equalTo(container);
  93. make.height.equalTo(container);
  94. make.width.mas_equalTo(60);
  95. }];
  96. UIView *border = [[UIView alloc] init];
  97. border.backgroundColor = [UIColor colorWithHexString:@"#F2F4F5"];
  98. [container addSubview:border];
  99. [border mas_makeConstraints:^(MASConstraintMaker *make) {
  100. make.height.equalTo(container);
  101. make.centerY.equalTo(container);
  102. make.width.mas_equalTo(1);
  103. make.rightMargin.equalTo(container).offset(-60);
  104. }];
  105. UILabel *remark1 = [[UILabel alloc] init];
  106. remark1.numberOfLines = 0;
  107. remark1.text = @"1.面试视频定价区间为6元—49元每分钟,可自行定价;\n2.面试视频定价以个人获得荣誉为参考依据,荣誉越多,可适当提高视频定价;\n3.面试视频的收益,模特本人可提现的比例为定价金额的50%;";
  108. remark1.font = [UIFont systemFontOfSize:13];
  109. remark1.textColor = [UIColor blackColor];
  110. [self.view addSubview:remark1];
  111. [remark1 mas_makeConstraints:^(MASConstraintMaker *make) {
  112. make.left.equalTo(self.view).offset(20);
  113. make.right.equalTo(self.view.mas_right).offset(-20);
  114. make.top.equalTo(container.mas_bottom).offset(15);
  115. }];
  116. UILabel *remark2 = [[UILabel alloc] init];
  117. remark2.numberOfLines = 0;
  118. remark2.text = @"说明:\n1.面试视频采用收费模式,为避免或降低用户对模特的打扰;\n2.面试视频是增加模特收益的一种形式。";
  119. remark2.font = [UIFont systemFontOfSize:13];
  120. remark2.textColor = [UIColor colorWithHexString:@"#808080"];
  121. [self.view addSubview:remark2];
  122. [remark2 mas_makeConstraints:^(MASConstraintMaker *make) {
  123. make.left.equalTo(self.view).offset(20);
  124. make.right.equalTo(self.view.mas_right).offset(-20);
  125. make.top.equalTo(remark1.mas_bottom).offset(8);
  126. }];
  127. UIButton *btnAgree = [[UIButton alloc] init];
  128. [btnAgree setImage:[UIImage imageNamed:@"btn_allow"] forState:UIControlStateNormal];
  129. [btnAgree setImage:[UIImage imageNamed:@"btn_allow_check"] forState:UIControlStateSelected];
  130. [btnAgree setTitle:@"我已知晓并同意" forState:UIControlStateNormal];
  131. [btnAgree setTitleColor:[UIColor colorWithHexString:@"#FF4095"] forState:UIControlStateNormal];
  132. btnAgree.titleLabel.font = [UIFont systemFontOfSize:13];
  133. btnAgree.imageEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
  134. btnAgree.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -5);
  135. [btnAgree addTarget:self action:@selector(allow:) forControlEvents:UIControlEventTouchUpInside];
  136. [self.view addSubview:btnAgree];
  137. [btnAgree mas_makeConstraints:^(MASConstraintMaker *make) {
  138. make.width.mas_equalTo(124);
  139. make.height.mas_equalTo(20);
  140. make.top.equalTo(remark2.mas_bottom).offset(15);
  141. make.left.equalTo(self.view).offset(20);
  142. }];
  143. self.btnAgree = btnAgree;
  144. break;
  145. }
  146. case InfoEditTypeHobby:
  147. self.title = @"兴趣爱好";
  148. self.infoTextField.text = [ModelUser modelUser].hobby;
  149. self.infoTextField.placeholder = @"请填写兴趣爱好";
  150. break;
  151. case InfoEditTypeCollege:
  152. self.title = @"毕业院校";
  153. self.infoTextField.text = [ModelUser modelUser].college;
  154. self.infoTextField.placeholder = @"请填写毕业院校";
  155. break;
  156. case InfoEditTypeOccupation:
  157. self.title = @"职业";
  158. self.infoTextField.text = [ModelUser modelUser].occupation;
  159. self.infoTextField.placeholder = @"请填写职业";
  160. break;
  161. case InfoEditTypeConstellation:
  162. self.title = @"星座";
  163. self.infoTextField.text = [ModelUser modelUser].constellation;
  164. self.infoTextField.placeholder = @"请填写星座";
  165. break;
  166. default:
  167. break;
  168. }
  169. }
  170. - (void)allow:(UIButton *)button {
  171. button.selected = !button.selected;
  172. }
  173. - (void)handleSave {
  174. if (self.infoTextField.text.length != 0) {
  175. [self.infoTextField resignFirstResponder];
  176. if (_editType == InfoEditTypeVprice) {
  177. NSInteger price = [self.infoTextField.text integerValue];
  178. if (price < 6 || price > 49) {
  179. [MBProgressHUD showOnlyText:@"视频单价不能小于6元或大于49元" controller:self];
  180. return;
  181. }
  182. }
  183. if (self.editType == InfoEditTypeVprice && !self.btnAgree.isSelected) {
  184. [MBProgressHUD showOnlyText:@"请选择同意" controller:self];
  185. return;
  186. }
  187. [self handleInfo:self.infoTextField.text];
  188. }
  189. }
  190. - (void)handleInfo:(NSString *)info {
  191. NSString *paramterKey;
  192. switch (_editType) {
  193. case InfoEditTypeName:
  194. paramterKey = @"name";
  195. break;
  196. case InfoEditTypeAge:
  197. paramterKey = @"age";
  198. break;
  199. case InfoEditTypeHeight:
  200. paramterKey = @"hei";
  201. break;
  202. case InfoEditTypeWeight:
  203. paramterKey = @"wei";
  204. break;
  205. case InfoEditTypeSigature:
  206. paramterKey = @"lname";
  207. break;
  208. case InfoEditTypeVprice:
  209. paramterKey = @"vprice";
  210. break;
  211. case InfoEditTypeHobby:
  212. paramterKey = @"hobby";
  213. break;
  214. case InfoEditTypeCollege:
  215. paramterKey = @"college";
  216. break;
  217. case InfoEditTypeOccupation:
  218. paramterKey = @"occupation";
  219. break;
  220. case InfoEditTypeConstellation:
  221. paramterKey = @"constellation";
  222. break;
  223. default:
  224. break;
  225. }
  226. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  227. [YanCNetWorkManager requestPostWithURLStr:Url_updateModelCard(PublicUrl)
  228. parameters:@{paramterKey: info, @"modelpk": [ModelUser user].modelpk}
  229. finish:^(id dataDic) {
  230. [MBProgressHUD hideHUDForView:self.view animated:YES];
  231. if (self.complete) {
  232. self.complete(info);
  233. }
  234. [self.navigationController popViewControllerAnimated:YES];
  235. }
  236. enError:^(NSError *error) {
  237. }];
  238. }
  239. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  240. [super touchesBegan:touches withEvent:event];
  241. [self.infoTextField resignFirstResponder];
  242. }
  243. @end