CNLiveCommuntyOrderViewController.m
19.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
//
// CNLiveCommuntyOrderViewController.m
// CNLiveCommunitModule
//
// Created by open on 2022/2/8.
//
#import "CNLiveCommuntyOrderViewController.h"
@interface CNLiveCommuntyOrderViewController ()<DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>
@property (nonatomic, strong) CNLiveCommuntyActivityMaintainsCreateModel * createMdoel;
@property (nonatomic, assign) CNLiveCommuntyOrderShowType showType;
@property (nonatomic, assign) BOOL isShowTopAndBottem;
@property (nonatomic, strong) UIView * bottemView;
@property (nonatomic, strong) UIButton * payButton;
@property (nonatomic, copy) NSString *maintenId;
@property (nonatomic, assign) BOOL isChat;
@end
@implementation CNLiveCommuntyOrderViewController
- (instancetype)initWithShowType:(CNLiveCommuntyOrderShowType)showType CreateModel:(nonnull CNLiveCommuntyActivityMaintainsCreateModel *)createModel
{
self = [super initWithStyle:UITableViewStyleGrouped];
if (self) {
_createMdoel = createModel;
_showType = showType;
}
return self;
}
- (instancetype)initWithShowType:(CNLiveCommuntyOrderShowType)showType MaintenId:(NSString *)maintenId
{
self = [super initWithStyle:UITableViewStyleGrouped];
if (self) {
_maintenId = maintenId;
_showType = showType;
}
return self;
}
- (instancetype)initWithMaintenId:(NSString *)maintenId
{
self = [super initWithStyle:UITableViewStyleGrouped];
if (self) {
_isChat = YES;
_maintenId = maintenId;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = UIColorHex(#F9F9F9);
self.title = @"订单详情";
[self reloadDataWithDataSource];
}
-(void)reloadDataWithDataSource
{
if ([self.maintenId isNotBlank]) {
__weak typeof(self) weakSelf = self;
[CNLiveCommuntViewModel requestWithCommuntyMaintenDetailForMaintenId:self.maintenId isChat:self.isChat CompleterBlock:^(CNLiveCommuntyActivityMaintainsCreateModel * _Nonnull createModel) {
if (createModel) {
weakSelf.createMdoel = createModel;
if (weakSelf.isChat) weakSelf.showType = weakSelf.createMdoel.showType;
[weakSelf setupWithBottemView];
[weakSelf setupWithNaviView];
[weakSelf.tableView reloadData];
}
}];
}
}
-(void)setupWithNaviView
{
if (self.showType == CNLiveCommuntyOrderShowTypeListYetOrder
|| self.showType == CNLiveCommuntyOrderShowTypeChatReadyOrder
|| [self.createMdoel.userId isEqualToString:[CNUserInfoManager manager].userInfoModel.uid]) {
NSString * name = @"";
UIColor * titleColor = [UIColor whiteColor];
if (self.showType == CNLiveCommuntyOrderShowTypeListYetOrder && ![self.createMdoel.userId isEqualToString:[CNUserInfoManager manager].userInfoModel.uid]) {
name = @"咨询电话";
titleColor = UIColorHex(#0091FF);
}
if (self.showType == CNLiveCommuntyOrderShowTypeChatReadyOrder || [self.createMdoel.userId isEqualToString:[CNUserInfoManager manager].userInfoModel.uid]) {
name = @"取消订单";
titleColor = UIColorHex(#F5A623FF);
}
UIButton * submiteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
submiteBtn.frame = CGRectMake(0, 0, 50, 14);
[submiteBtn setTitle:name forState:UIControlStateNormal];
[submiteBtn setTitleColor:titleColor forState:UIControlStateNormal];
submiteBtn.backgroundColor = [UIColor whiteColor];
submiteBtn.titleLabel.font = [UIFont systemFontOfSize:14];
[submiteBtn addTarget:self action:@selector(rightBarButtonAction:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:submiteBtn];
if (self.showType == CNLiveCommuntyOrderShowTypeListFailureOrder) {
self.navigationItem.rightBarButtonItem = nil;
}
}else{
self.navigationItem.rightBarButtonItem = nil;
}
}
-(void)setupWithBottemView
{
if (self.showType == CNLiveCommuntyOrderShowTypeChatYetOrder
|| self.showType == CNLiveCommuntyOrderShowTypeChatReadyOrder
|| self.showType == CNLiveCommuntyOrderShowTypeListFailureOrder) {
__weak typeof(self) weakSelf = self;
if (!self.bottemView) {
self.bottemView = [[UIView alloc] init];
self.bottemView.backgroundColor = [UIColor whiteColor];
self.bottemView.hidden = self.showType == CNLiveCommuntyOrderShowTypeListFailureOrder;
[self.view addSubview:self.bottemView];
[self.bottemView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.mas_equalTo(weakSelf.view);
make.height.mas_equalTo(50);
}];
}
NSString * payString = @"";
if (self.showType == CNLiveCommuntyOrderShowTypeChatYetOrder) payString = @"立即接单";
if (self.showType == CNLiveCommuntyOrderShowTypeChatReadyOrder) payString = @"取消接单";
if (!self.payButton) {
self.payButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.payButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.payButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
self.payButton.backgroundColor = UIColorHex(#CD0302);
self.payButton.layer.masksToBounds = YES;
self.payButton.layer.cornerRadius = 18;
self.payButton.titleLabel.font = [UIFont systemFontOfSize:16];
self.payButton.titleLabel.font = [UIFont boldSystemFontOfSize:16];
[self.payButton addTarget:self action:@selector(payResultAction:) forControlEvents:UIControlEventTouchUpInside];
[self.bottemView addSubview:self.payButton];
[self.payButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(weakSelf.bottemView);
make.right.mas_equalTo(weakSelf.bottemView.mas_right).offset(-10);
make.left.mas_equalTo(weakSelf.bottemView.mas_left).offset(10);
make.height.mas_equalTo(36);
}];
}
[self.payButton setTitle:payString forState:UIControlStateNormal];
[self.payButton setTitle:payString forState:UIControlStateHighlighted];
if (self.showType == CNLiveCommuntyOrderShowTypeChatReadyOrder && [self.createMdoel.totalFee isNotBlank] && [self.createMdoel.totalFee integerValue] > 0) {
self.payButton.hidden = self.showType == CNLiveCommuntyOrderShowTypeChatCompletOrder;
self.bottemView.hidden = self.showType == CNLiveCommuntyOrderShowTypeChatCompletOrder;
[self.bottemView removeAllSubviews];
}
}else{
if (self.bottemView && self.showType == CNLiveCommuntyOrderShowTypeChatCompletOrder) {
self.payButton.hidden = self.showType == CNLiveCommuntyOrderShowTypeChatCompletOrder;
self.bottemView.hidden = self.showType == CNLiveCommuntyOrderShowTypeChatCompletOrder;
[self.bottemView removeAllSubviews];
}
}
}
-(void)rightBarButtonAction:(UIButton *)button
{
MJWeakSelf
if ([button.titleLabel.text isEqualToString:@"咨询电话"]) {
}
if ([button.titleLabel.text isEqualToString:@"取消订单"]) {
[CNLiveCommuntSignUpView showAlertViewWithMessage:@"确定取消订单后,此订单将失效" CompleterBlock:^{
[CNLiveCommuntViewModel requestWithCommuntyCancleOrderMentOrderId:weakSelf.createMdoel.idStr CompleterBlock:^{
weakSelf.showType = CNLiveCommuntyOrderShowTypeListFailureOrder;
[weakSelf setupWithBottemView];
[weakSelf setupWithNaviView];
[weakSelf.tableView reloadData];
}];
}];
}
}
-(void)payResultAction:(UIButton *)button
{
MJWeakSelf
if ([button.titleLabel.text isEqualToString:@"立即接单"]) {
[QMUITips showLoadingInView:self.view];
[CNLiveCommuntViewModel requestWithCommuntyGrabOrderMentOrderId:self.createMdoel.idStr type:YES CompleterBlock:^{
[CNLiveCommuntSignUpView showHaveTipSuccessViewCompleterBlock:^{
weakSelf.showType = CNLiveCommuntyOrderShowTypeChatReadyOrder;
[button setTitle:@"取消接单" forState:UIControlStateNormal];
[button setTitle:@"取消接单" forState:UIControlStateHighlighted];
[weakSelf setupWithBottemView];
[weakSelf setupWithNaviView];
[weakSelf.tableView reloadData];
}];
}];
}
if ([button.titleLabel.text isEqualToString:@"取消接单"]) {
[CNLiveCommuntSignUpView showAlertViewWithMessage:@"确定取消接单后,此订单将重新转至群" CompleterBlock:^{
[CNLiveCommuntViewModel requestWithCommuntyGrabOrderMentOrderId:weakSelf.createMdoel.idStr type:NO CompleterBlock:^{
weakSelf.showType = CNLiveCommuntyOrderShowTypeChatYetOrder;
[button setTitle:@"立即接单" forState:UIControlStateNormal];
[button setTitle:@"立即接单" forState:UIControlStateHighlighted];
[weakSelf setupWithBottemView];
[weakSelf setupWithNaviView];
[weakSelf.tableView reloadData];
}];
}];
}
}
- (void)initTableView
{
[super initTableView];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.emptyDataSetSource = self;
self.tableView.emptyDataSetDelegate = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.tableFooterView = [[UIView alloc] init];
self.tableView.backgroundColor = UIColorHex(#f9f9f9);
}
-(void)layoutTableView
{
[super layoutTableView];
self.tableView.frame = CGRectMake(0, kNavigationBarHeight, kScreenWidth, kScreenHeight - kNavigationBarHeight);
if (self.showType == CNLiveCommuntyOrderShowTypeChatYetOrder
|| self.showType == CNLiveCommuntyOrderShowTypeChatReadyOrder) {
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 60, 0);
}
}
-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:kCNLiveHiddenModalViewWithQrNotification object:nil];
}
#pragma mark =
#pragma mark - DZNEmptyDataSetSource Methods
- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
return [[NSAttributedString alloc] initWithString:@"暂无订单详情" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]}];
}
-(UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
return [CNLiveCommuntTools cCommunt_setImageWithName:@"c_community_content_empty"];
}
- (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
{
return [UIColor whiteColor];
}
- (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView
{
return YES;
}
- (BOOL)emptyDataSetShouldAllowTouch:(UIScrollView *)scrollView
{
return YES;
}
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
{
return NO;
}
#pragma mark =
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (self.createMdoel) {
if (self.showType == CNLiveCommuntyOrderShowTypeListYetOrder) return 2;
if (self.showType == CNLiveCommuntyOrderShowTypeListReadyOrder) return 2;
if (self.showType == CNLiveCommuntyOrderShowTypeListCompletOrder) return 3;
if (self.showType == CNLiveCommuntyOrderShowTypeListFailureOrder) return 1;
if (self.showType == CNLiveCommuntyOrderShowTypeChatYetOrder) return 1;
if (self.showType == CNLiveCommuntyOrderShowTypeChatReadyOrder) return 2;
if (self.showType == CNLiveCommuntyOrderShowTypeChatCompletOrder) return 1;
}
return 0;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (self.createMdoel) {
if (self.showType == CNLiveCommuntyOrderShowTypeChatYetOrder
|| self.showType == CNLiveCommuntyOrderShowTypeChatCompletOrder
|| self.showType == CNLiveCommuntyOrderShowTypeListFailureOrder) {
if (section == 0) return self.createMdoel.infoArray.count;
}
if (self.showType == CNLiveCommuntyOrderShowTypeListYetOrder
|| self.showType == CNLiveCommuntyOrderShowTypeListReadyOrder) {
if (section == 0) return self.createMdoel.infoArray.count;
if (section == 1) return self.createMdoel.processArray.count;
}
if (self.showType == CNLiveCommuntyOrderShowTypeChatReadyOrder) {
if (section == 0) return self.createMdoel.infoArray.count;
if (section == 1) return 1;
}
if (self.showType == CNLiveCommuntyOrderShowTypeListCompletOrder) {
if (section == 0) return self.createMdoel.infoArray.count;
if (section == 1) return 1;
if (section == 2) return self.createMdoel.processArray.count;
}
}
return 0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.showType == CNLiveCommuntyOrderShowTypeChatYetOrder
|| self.showType == CNLiveCommuntyOrderShowTypeChatCompletOrder
|| self.showType == CNLiveCommuntyOrderShowTypeListFailureOrder) {
return [CNLiveCommuntSignUpOrderViewCell setTableView:tableView Dict:self.createMdoel.infoArray[indexPath.row]];
}
if (self.showType == CNLiveCommuntyOrderShowTypeListYetOrder
|| self.showType == CNLiveCommuntyOrderShowTypeListReadyOrder) {
if (indexPath.section == 0) return [CNLiveCommuntSignUpOrderViewCell setTableView:tableView Dict:self.createMdoel.infoArray[indexPath.row]];
if (indexPath.section == 1) return [CNLiveCommuntSignUpDetailViewCell setTableView:tableView isTop:indexPath.row == 0 isBottom:indexPath.row == (self.createMdoel.processArray.count - 1) Dict:self.createMdoel.processArray[indexPath.row]];
}
if (self.showType == CNLiveCommuntyOrderShowTypeChatReadyOrder) {
__weak typeof(self) weakSelf = self;
if (indexPath.section == 0) return [CNLiveCommuntSignUpOrderViewCell setTableView:tableView Dict:self.createMdoel.infoArray[indexPath.row]];
if (indexPath.section == 1) return [CNLiveCommuntSignUpAmountViewCell setTableView:tableView CreateModel:self.createMdoel ReloadBlock:^{
[weakSelf reloadDataWithDataSource];
}];
}
if (self.showType == CNLiveCommuntyOrderShowTypeListCompletOrder) {
if (indexPath.section == 0) return [CNLiveCommuntSignUpOrderViewCell setTableView:tableView Dict:self.createMdoel.infoArray[indexPath.row]];
if (indexPath.section == 1) return [CNLiveCommuntSignUpContactViewCell setTableView:tableView CreateModel:self.createMdoel];
if (indexPath.section == 2) return [CNLiveCommuntSignUpDetailViewCell setTableView:tableView isTop:indexPath.row == 0 isBottom:indexPath.row == (self.createMdoel.processArray.count - 1) Dict:self.createMdoel.processArray[indexPath.row]];
}
return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.showType == CNLiveCommuntyOrderShowTypeChatYetOrder
|| self.showType == CNLiveCommuntyOrderShowTypeChatCompletOrder
|| self.showType == CNLiveCommuntyOrderShowTypeListFailureOrder) {
return 30;
}
if (self.showType == CNLiveCommuntyOrderShowTypeListYetOrder
|| self.showType == CNLiveCommuntyOrderShowTypeListReadyOrder) {
if (indexPath.section == 0) return 30;
if (indexPath.section == 1) return 70;
}
if (self.showType == CNLiveCommuntyOrderShowTypeChatReadyOrder) {
if (indexPath.section == 0) return 30;
if (indexPath.section == 1) return 130;
}
if (self.showType == CNLiveCommuntyOrderShowTypeListCompletOrder) {
if (indexPath.section == 0) return 30;
if (indexPath.section == 1) return 60;
if (indexPath.section == 2) return 70;
}
return 0.001f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return section == 0 || ((self.showType == CNLiveCommuntyOrderShowTypeListReadyOrder || self.showType == CNLiveCommuntyOrderShowTypeListYetOrder) && section == 1) || (self.showType == CNLiveCommuntyOrderShowTypeListCompletOrder && section == 2) ? 50 : 0;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (section == 0 || ((self.showType == CNLiveCommuntyOrderShowTypeListReadyOrder || self.showType == CNLiveCommuntyOrderShowTypeListYetOrder) && section == 1) || (self.showType == CNLiveCommuntyOrderShowTypeListCompletOrder && section == 2)) {
UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 50)];
view.backgroundColor = [UIColor clearColor];
UIView * radiusView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, kScreenWidth - 20, 40)];
radiusView.backgroundColor = [UIColor whiteColor];
radiusView.layer.shadowColor = [UIColor blackColor].CGColor;
radiusView.layer.shadowOffset = CGSizeMake(0, 0);
radiusView.layer.shadowOpacity = 0.3;
radiusView.layer.shadowRadius = 8;
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_WIDTH - 20, 40) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(12, 12)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.path = maskPath.CGPath;
radiusView.layer.mask = maskLayer;
[view insertSubview:radiusView belowSubview:view];
UILabel * nameLabel = [[UILabel alloc] init];
nameLabel.textColor = UIColorHex(#333333);
nameLabel.lineBreakMode = NSLineBreakByTruncatingTail;
nameLabel.numberOfLines = 1;
nameLabel.font = [UIFont systemFontOfSize:15];
nameLabel.font = [UIFont boldSystemFontOfSize:15];
nameLabel.text = section == 0 ? [NSString stringWithFormat:@"订单编号:%@",self.createMdoel.idStr]:@"进度详情";
[view addSubview:nameLabel];
[nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(view);
make.left.mas_equalTo(view.mas_left).offset(20);
}];
return view;
}else{
return nil;
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return section == 0 || ((self.showType == CNLiveCommuntyOrderShowTypeListReadyOrder || self.showType == CNLiveCommuntyOrderShowTypeListYetOrder) && section == 1) || (self.showType == CNLiveCommuntyOrderShowTypeListCompletOrder && section == 2) ? 10 : 0;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
if (section == 0 || ((self.showType == CNLiveCommuntyOrderShowTypeListReadyOrder || self.showType == CNLiveCommuntyOrderShowTypeListYetOrder) && section == 1) || (self.showType == CNLiveCommuntyOrderShowTypeListCompletOrder && section == 2)) {
UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
view.backgroundColor = [UIColor clearColor];
UIView * radiusView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, kScreenWidth - 20, 10)];
radiusView.backgroundColor = [UIColor whiteColor];
radiusView.layer.shadowColor = [UIColor blackColor].CGColor;
radiusView.layer.shadowOffset = CGSizeMake(0, 0);
radiusView.layer.shadowOpacity = 0.3;
radiusView.layer.shadowRadius = 10;
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_WIDTH - 20, 10) byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(5, 5)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.path = maskPath.CGPath;
radiusView.layer.mask = maskLayer;
[view insertSubview:radiusView belowSubview:view];
return view;
}else{
return nil;
}
}
@end