InfoEditViewController.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. @end
  12. @implementation InfoEditViewController
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. [self configUI];
  16. // Do any additional setup after loading the view.
  17. }
  18. - (void)configUI {
  19. self.view.backgroundColor = RGBValueColor(0xf7f7f7, 1.0);
  20. self.navigationController.navigationBar.tintColor = RGBValueColor(0x333333, 1);
  21. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(handleSave)];
  22. self.infoTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 10, ScreenWidth, 40)];
  23. self.infoTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 40)];
  24. self.infoTextField.leftViewMode = UITextFieldViewModeAlways;
  25. self.infoTextField.backgroundColor = [UIColor whiteColor];
  26. [self.view addSubview:self.infoTextField];
  27. switch (_editType) {
  28. case InfoEditTypeName:
  29. self.title = @"用户名";
  30. self.infoTextField.placeholder = @"请输入用户名";
  31. self.infoTextField.text = [ModelUser modelUser].pet;
  32. break;
  33. case InfoEditTypeAge:
  34. self.title = @"年龄";
  35. self.infoTextField.placeholder = @"请输入年龄";
  36. self.infoTextField.text = [ModelUser modelUser].age;
  37. self.infoTextField.keyboardType = UIKeyboardTypeNumberPad;
  38. break;
  39. case InfoEditTypeHeight:
  40. self.title = @"身高";
  41. self.infoTextField.placeholder = @"请输入身高(cm)";
  42. self.infoTextField.text = [ModelUser modelUser].hei;
  43. self.infoTextField.keyboardType = UIKeyboardTypeDecimalPad;
  44. break;
  45. case InfoEditTypeWeight:
  46. self.title = @"体重";
  47. self.infoTextField.placeholder = @"请输入体重(kg)";
  48. self.infoTextField.text = [ModelUser modelUser].wei;
  49. self.infoTextField.keyboardType = UIKeyboardTypeDecimalPad;
  50. break;
  51. case InfoEditTypeSigature:
  52. self.title = @"个性签名";
  53. self.infoTextField.text = [ModelUser modelUser].lname;
  54. self.infoTextField.placeholder = @"请输入个性签名";
  55. break;
  56. case InfoEditTypeVprice:
  57. self.title = @"视频单价";
  58. self.infoTextField.text = [ModelUser modelUser].vprice;
  59. self.infoTextField.placeholder = @"请输入视频单价(6--49)元";
  60. self.infoTextField.keyboardType = UIKeyboardTypeNumberPad;
  61. break;
  62. default:
  63. break;
  64. }
  65. }
  66. - (void)handleSave{
  67. if (self.infoTextField.text.length != 0) {
  68. [self.infoTextField resignFirstResponder];
  69. if (_editType == InfoEditTypeVprice) {
  70. NSInteger price = [self.infoTextField.text integerValue];
  71. if (price < 6 || price > 49) {
  72. [MBProgressHUD showOnlyText:@"视频单价不能小于6元或大于49元" controller:self];
  73. return;
  74. }
  75. }
  76. [self handleInfo:self.infoTextField.text];
  77. }
  78. }
  79. - (void)handleInfo:(NSString *)info {
  80. NSString *paramterKey;
  81. switch (_editType) {
  82. case InfoEditTypeName:
  83. paramterKey = @"name";
  84. break;
  85. case InfoEditTypeAge:
  86. paramterKey = @"age";
  87. break;
  88. case InfoEditTypeHeight:
  89. paramterKey = @"hei";
  90. break;
  91. case InfoEditTypeWeight:
  92. paramterKey = @"wei";
  93. break;
  94. case InfoEditTypeSigature:
  95. paramterKey = @"lname";
  96. break;
  97. case InfoEditTypeVprice:
  98. paramterKey = @"vprice";
  99. break;
  100. default:
  101. break;
  102. }
  103. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  104. [YanCNetWorkManager requestPostWithURLStr:Url_updateModelCard(PublicUrl) parameters:@{paramterKey:info,@"modelpk":[ModelUser user].modelpk} finish:^(id dataDic) {
  105. [MBProgressHUD hideHUDForView:self.view animated:YES];
  106. if (self.complete) {
  107. self.complete(info);
  108. }
  109. [self.navigationController popViewControllerAnimated:YES];
  110. } enError:^(NSError *error) {
  111. }];
  112. }
  113. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  114. [super touchesBegan:touches withEvent:event];
  115. [self.infoTextField resignFirstResponder];
  116. }
  117. - (void)didReceiveMemoryWarning {
  118. [super didReceiveMemoryWarning];
  119. // Dispose of any resources that can be recreated.
  120. }
  121. /*
  122. #pragma mark - Navigation
  123. // In a storyboard-based application, you will often want to do a little preparation before navigation
  124. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  125. // Get the new view controller using [segue destinationViewController].
  126. // Pass the selected object to the new view controller.
  127. }
  128. */
  129. @end