// // CGPurchaseintentionViewController.m // jitao // // Created by 罗云飞 on 2017/12/27. // Copyright © 2017年 罗云飞. All rights reserved. // #import "CGPurchaseintentionViewController.h" #import "AddIntentionModel.h" #import "MyOrderViewController.h" @interface CGPurchaseintentionViewController (){ UITextView *textview; AddIntentionModel *model; NSString *remarks; } @end @implementation CGPurchaseintentionViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = NewGroupTableViewBackgroundColor; remarks = @""; if ([_commodityType isEqualToString:@"1"]) { [self setNavTitle:@"购买意向"]; }else if ([_commodityType isEqualToString:@"2"]){ [self setNavTitle:@"接单"]; }else if ([_commodityType isEqualToString:@"3"]){ [self setNavTitle:@"服务意向"]; }else if ([_commodityType isEqualToString:@"6"]){ [self setNavTitle:@"服务意向"]; }else if ([_commodityType isEqualToString:@"0"]){ [self setNavTitle:@"服务意向"]; } [self Networkrequest]; // Do any additional setup after loading the view. } #pragma mark -----------意向订单网络请求------- - (void)Networkrequest { NSMutableDictionary *dic = NewMutableDictionaryInit; [dic safeSetObject:_ID forKey:@"commodityId"]; [dic safeSetObject:_commodityType forKey:@"commodityType"]; [NetworkRequestManager requestGetWithInterfacePrefix:JT_toAddIntention parameters:dic onSuccess:^(id requestData) { NSLog(@"服务器返回数据 :%@",requestData); if ([requestData[@"error"] count] !=0) { for (NSDictionary *dic in requestData[@"error"]) { [MBProgressHUD showError:dic[@"message"] toView:self.view]; } }else{ model = [[AddIntentionModel alloc] initWithDictionary:requestData[@"data"] error:nil]; [self loadsview]; } } onFailure:^{ }]; } - (void)loadsview { UIView *view = [UIView new]; view.backgroundColor = NewWhiteColor; ViewRadius(view, 3); [self.view addSubview:view]; view.sd_layout .leftSpaceToView(self.view, 15) .topSpaceToView(self.view, NavHeader+10) .rightSpaceToView(self.view, 15) .heightIs(70); UILabel *title = [UILabel new]; title.text = model.commodityName; title.font = NewFont(fitScreenWidth(14)); [title setSingleLineAutoResizeWithMaxWidth:0]; [view addSubview:title]; title.sd_layout .leftSpaceToView(view, 15) .topSpaceToView(view, 15) .heightIs(14); UILabel *ordernumber = [UILabel new]; ordernumber.text = [NSString stringWithFormat:@"订单编号:%@",model.orderNo]; ordernumber.font = NewFont(fitScreenWidth(12)); ordernumber.textColor = NewButtonColor; [ordernumber setSingleLineAutoResizeWithMaxWidth:0]; [view addSubview:ordernumber]; ordernumber.sd_layout .leftEqualToView(title) .heightIs(11) .bottomSpaceToView(view, 15); UILabel *time = [UILabel new]; time.text = model.createTime; time.font = NewFont(fitScreenWidth(11)); time.textColor = [UIColor colorWithString:@"#9A9A9A"]; [time setSingleLineAutoResizeWithMaxWidth:0]; [view addSubview:time]; time.sd_layout .rightSpaceToView(view, 15) .bottomEqualToView(ordernumber) .heightIs(10); UIView *view1 = [UIView new]; view1.backgroundColor = NewWhiteColor; ViewRadius(view1, 3); [self.view addSubview:view1]; view1.sd_layout .leftSpaceToView(self.view, 15) .heightIs(100) .rightSpaceToView(self.view, 15) .topSpaceToView(view, 1); UILabel *content = [UILabel new]; content.text = model.introduction; content.font = NewFont(12); content.textColor = [UIColor colorWithString:@"#9A9A9A"]; content.lineBreakMode = NSLineBreakByTruncatingTail; content.numberOfLines = 2; [view1 addSubview:content]; content.sd_layout .leftSpaceToView(view1, 15) .topSpaceToView(view1, 15) .rightSpaceToView(view1, 15) .heightIs(30); UILabel *jiage = [UILabel new]; jiage.text = [NSString stringWithFormat:@"价格:%@",model.commodityPrice]; jiage.font = NewFont(fitScreenWidth(12)); [jiage setSingleLineAutoResizeWithMaxWidth:0]; [view1 addSubview:jiage]; jiage.sd_layout .leftSpaceToView(view1, 15) .heightIs(13) .topSpaceToView(content, 15); UILabel *dingjin = [UILabel new]; dingjin.text = [NSString stringWithFormat:@"定金:%@",model.firstPayment]; dingjin.font = NewFont(fitScreenWidth(12)); [dingjin setSingleLineAutoResizeWithMaxWidth:0]; dingjin.textColor = [UIColor colorWithString:@"#FF8523"]; [view1 addSubview:dingjin]; dingjin.sd_layout .leftSpaceToView(dingjin, fitScreenWidth(35)) .heightIs(13) .topEqualToView(jiage); textview = [[UITextView alloc] init]; textview.font = NewFont(fitScreenWidth(12)); textview.textColor = NewGrayColor; textview.backgroundColor = NewWhiteColor; textview.delegate = self; textview.text= @"请备注留言,以便服务人员能更好的了解你的意向~"; ViewBorderRadius(textview, 5, 1, NewClearColor); [self.view addSubview:textview]; textview.sd_layout .leftSpaceToView(self.view, 15) .rightSpaceToView(self.view, 15) .heightIs(133) .topSpaceToView(view1, 24); UIButton *submit = [UIButton new]; if ([_commodityType isEqualToString:@"1"]) { [submit setTitle:@"提交购买意向" forState:UIControlStateNormal]; }else if([_commodityType isEqualToString:@"2"]){ [submit setTitle:@"接单" forState:UIControlStateNormal]; }else if ([_commodityType isEqualToString:@"3"]||[_commodityType isEqualToString:@"0"]){ [submit setTitle:@"提交服务意向" forState:UIControlStateNormal]; }else if ([_commodityType isEqualToString:@"6"]){ [submit setTitle:@"提交服务意向" forState:UIControlStateNormal]; } [submit setTitleColor:NewWhiteColor forState:UIControlStateNormal]; submit.titleLabel.font = NewFont(15); submit.backgroundColor = NewButtonColor; ViewRadius(submit, 8); NewTouchUpInside(submit, submitclick:); [self.view addSubview:submit]; submit.sd_layout .leftSpaceToView(self.view, 50) .rightSpaceToView(self.view, 50) .heightIs(50) .topSpaceToView(textview, 30); } #pragma mark -------提交意向订单--------- - (void)submitclick:(UIButton *)sender { [MBProgressHUD showLoadToView:self.view title:@"请稍后..."]; NSMutableDictionary *dic = NewMutableDictionaryInit; [dic safeSetObject:model.orderNo forKey:@"orderNo"];//订单编号 [dic safeSetObject:model.commodityId forKey:@"commodityId"];//商品ID [dic safeSetObject:model.commodityMode forKey:@"commodityMode"];//商品规格 [dic safeSetObject:@"1" forKey:@"commodityQuantity"];//商品数量 [dic safeSetObject:_commodityType forKey:@"commodityType"];//商品类型 [dic safeSetObject:model.createTime forKey:@"createTime"];//创建时间 [dic safeSetObject:remarks forKey:@"remarks"];//备注 [NetworkRequestManager requestPostWithInterfacePrefix:JT_addIntention parameters:dic onSuccess:^(id requestData) { [MBProgressHUD hideHUDForView:self.view]; NSLog(@"服务器返回数据 :%@",requestData); if ([requestData[@"error"] count] !=0) { for (NSDictionary *dic in requestData[@"error"]) { [MBProgressHUD showError:dic[@"message"] toView:self.view]; } }else{ // if ([_commodityType isEqualToString:@"1"]) { // [MBProgressHUD showSuccess:@"提交购买意向成功" toView:self.view]; // }else if ([_commodityType isEqualToString:@"2"]){ // [MBProgressHUD showSuccess:@"提交接单成功" toView:self.view]; // } // NewPopViewController; [self Jumptomyorder]; } } onFailure:^{ [MBProgressHUD hideHUDForView:self.view]; }]; } #pragma mark - UITextView获得焦点之后,并且已经是第一响应者 -(void)textViewDidBeginEditing:(UITextView *)textView { // NSLog(@"UITextView获得焦点之后,并且已经是第一响应者"); if ([textView.text isEqualToString:@"请备注留言,以便服务人员能更好的了解你的意向~"]) { textView.text = @""; textView.textColor = NewGrayColor; } } #pragma mark - UITextView失去焦点之后 -(void)textViewDidEndEditing:(UITextView *)textView { //NSLog(@"UITextView失去焦点"); if ([textView.text isEqualToString:@""] || textView.text.length == 0) { textView.text = @"请备注留言,以便服务人员能更好的了解你的意向~"; textView.textColor = NewRGBColor(199, 199, 205, 1); } } #pragma mark - 详细地址限制字数 -(void)textViewDidChangeSelection:(UITextView *)textView { if(textView.text.length > 100){ textView.text = [textView.text substringWithRange:NSMakeRange(0,100)]; } if (textView.text.length > 0) { NSLog(@"textView.text:%@",textView.text); if ([textView.text isEqualToString:@"请备注留言,以便服务人员能更好的了解你的意向~"]) { remarks = @""; }else{ remarks = nil; remarks = textView.text; } } } #pragma mark ----是否跳转到我的订单界面 - (void)Jumptomyorder { UIAlertController *alertController2 = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"提交成功,后继状态请前往我的订单列表" preferredStyle:(UIAlertControllerStyleAlert)]; UIAlertAction *okAction2 = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) { //退出登录 MyOrderViewController *vc = [[MyOrderViewController alloc] init]; NewPushViewController(vc); }]; UIAlertAction *cancelAction2 = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction *action) { //NSLog(@"取消"); NewPopViewController; }]; [alertController2 addAction:okAction2]; [alertController2 addAction:cancelAction2]; [self presentViewController:alertController2 animated:YES completion:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end