CNLiveApplyRefundController.m
13.4 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
//
// CNLiveApplyRefundController.m
// CNLiveMyOrderModule
//
// Created by 殷巧娟 on 2019/11/27.
//
#import "CNLiveApplyRefundController.h"
#import "CNLiveMineOrderView.h"
#import "CNLiveSelectedRefundReasonView.h"
#import "CNLiveUploadVoucher.h"
#import "CNLiveOrderDetailContentView.h"
#import "CNLiveRefundBasicCell.h"
#import "CNLiveBaseKit.h"
#import "CNLiveOrderList.h"
#import "UIColor+CNLiveExtension.h"
#import "Masonry.h"
#import "UIImage+CNLiveAdd.h"
#import "HUDHelper.h"
#import "CNLiveNetworking.h"
#import "CNUserInfoManager.h"
#import "CNLiveEnvironment.h"
#import "AFNetworking.h"
#import "CNLiveOrderHeader.h"
@interface CNLiveApplyRefundController ()<UIGestureRecognizerDelegate,UITableViewDelegate,UITableViewDataSource,CNLiveUploadVoucherHeightDelegate>
@property (nonatomic, strong) NSArray *images;
@property (nonatomic, strong) CNLiveOrderListOrderItem *orderItem;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, assign) CGFloat height; //最后一个分组的高度
@property (nonatomic, strong) UIButton *submitBtn; //提交按钮
@property (nonatomic, strong) UIView *footerView; //tableView的footerView
@property (nonatomic, copy) NSString *reasonStr; //退款原因
@property (nonatomic, copy) NSString *refundAmount; //退款金额
@property (nonatomic, copy) NSString *refundInstruct; //退款说明
@property (nonatomic, assign) CGFloat totalPrice; //总价
@property (nonatomic, strong) NSArray *selectedPhotos; //选择图片
@end
@implementation CNLiveApplyRefundController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"申请退款";
[self.view addSubview:self.tableView];
self.view.userInteractionEnabled = YES;
self.tableView.tableFooterView = self.footerView;
self.tableView.tableFooterView.height = 75;
self.height = (KScreenWidth - 20 - 2*8 - 4)/3 - 8 + 55;
}
- (void)setList:(CNLiveOrderList *)list {
_list = list;
self.totalPrice = list.orderItem.totalPrice;
}
#pragma mark - 更新图片数量代理
- (void)updateSelectedPhotos:(NSArray *)selectedPhotos {
self.selectedPhotos = selectedPhotos;
CGFloat margin = 8;
CGFloat itemH = (KScreenWidth - 20 - 2*margin - 4)/3 - margin;
CGFloat collectionH = 0;
NSInteger column = 3; //列
NSInteger row = 0; //行
NSInteger isSelectPhoto = 0;
if (selectedPhotos.count > 0) {
if (selectedPhotos.count == 9) {
isSelectPhoto = 0;
}else {
isSelectPhoto = 1;
}
}else {
isSelectPhoto = 1;
}
if ((selectedPhotos.count + isSelectPhoto) %column <=0) {
row = (selectedPhotos.count + isSelectPhoto) /column;
}else {
row = (selectedPhotos.count + isSelectPhoto ) /column + 1;
}
collectionH = 2*margin + (row - 1) *8 + row*itemH + 55;
self.height = collectionH;
[self.tableView reloadData];
}
#pragma mark - TargetAction
- (void)submitBtnAction {
if (CNLiveStringIsEmpty(self.reasonStr)) {
[[HUDHelper sharedInstance] tipMessage:@"退款原因不能为空"];
return;
}
if (CNLiveStringIsEmpty(self.refundAmount)) {
[[HUDHelper sharedInstance]tipMessage:@"退款金额不能为空"];
return;
}
if ([self.refundAmount floatValue] <= 0) {
[[HUDHelper sharedInstance]tipMessage:@"退款金额要大于0"];
return;
}
NSNumber *totalPriceNumber = [NSNumber numberWithFloat:self.totalPrice];
NSNumber *refundPriceNumber = [NSNumber numberWithFloat:[self.refundAmount floatValue]];
if ([refundPriceNumber compare:totalPriceNumber] == NSOrderedDescending) {
[[HUDHelper sharedInstance]tipMessage:@"退款金额不能大于总金额"];
return;
}
if (![CNLiveNetworking isNetworking]) {
[[HUDHelper sharedInstance]tipMessage:@"网络已断开"];
return;
}
NSDictionary *param = @{
@"sid":@"10511059",
@"appId":AppId,
@"orderId":self.list.orderItem.orderId,
@"note":CNLiveStringIsEmpty(self.refundInstruct) ? @"":self.refundInstruct,
@"refundSum":CNLiveStringIsEmpty(self.refundAmount)? @"":self.refundAmount,
@"cause":CNLiveStringIsEmpty(self.reasonStr)?@"":self.reasonStr
};
[CNLiveNetworking uploadNetworkWithURLString:CNApplyRefundUrl Param:param FormDataBlock:^(id<AFMultipartFormData> formData) {
[self.selectedPhotos enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
UIImage *image = (UIImage *)obj;
NSData *imageData = UIImageJPEGRepresentation(image, 0.5);
NSString *fileName = [NSString stringWithFormat:@"Image%d",(int)idx+1];
NSString *name = [NSString stringWithFormat:@"Image%d",(int)idx+1];
/*
*该方法的参数
1. appendPartWithFileData:要上传的照片[二进制流]
2. name:对应网站上[upload.php中]处理文件的字段(比如upload)
3. fileName:要保存在服务器上的文件名
4. mimeType:上传的文件的类型
*/
[formData appendPartWithFileData:imageData name:name fileName:fileName mimeType:@"image/jpeg"];
}];
} ProgressBlock:^(NSProgress *progress) {
} CompletionBlock:^(NSURLSessionTask *requestTask, id responseObject, NSError *error) {
[QMUITips hideAllTipsInView:self.view];
if (!error) {
if ([responseObject[@"errorCode"] integerValue] == 0) {
[self.navigationController popViewControllerAnimated:YES];
[[NSNotificationCenter defaultCenter]postNotificationName:CNApplyRefundSuccessNotification object:nil];
}else {
[[HUDHelper sharedInstance]tipMessage:@"申请退款失败"];
}
}else {
[[HUDHelper sharedInstance]tipMessage:error.description];
}
}];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
return 6;
}else if (section == 1){
return 1;
}else if (section == 2){
return 1;
}else if (section == 3){
return 4;
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
__weak typeof(self) weakSelf = self;
static NSString *basicIdentifier = @"CNLiveRefundBasicCell";
static NSString *basicPriceIdentifier = @"CNLiveRefundBasicPriceCell";
static NSString *canOrNORefIdentifier = @"CNLiveCanOrNoRefundCell";
static NSString *goodsPriceeIdentifier = @"CNLiveRefundGoodsPriceCell";
static NSString *reasonIdentifier = @"CNLiveRefundReasonCell";
static NSString *instructionsIdentifier = @"CNLiveRefundInstructionsCell";
static NSString *credentialIdentifier = @"CNLiveRefundCredentialCell";
if (indexPath.section == 0) {
if (indexPath.row == 1) {
CNLiveRefundBasicPriceCell *basicPriceCell = [tableView dequeueReusableCellWithIdentifier:basicPriceIdentifier];
if (!basicPriceCell) {
basicPriceCell = [[CNLiveRefundBasicPriceCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:basicPriceIdentifier];
}
basicPriceCell.list = self.list;
return basicPriceCell;
}else {
NSArray *basicTitles = @[@"基本信息",@"",@"服务内容",@"服务费",@"运费",@"配送方式"];
CNLiveRefundBasicCell *basicCell = [tableView dequeueReusableCellWithIdentifier:basicIdentifier];
if (!basicCell) {
basicCell = [[CNLiveRefundBasicCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:basicIdentifier indexPath:indexPath];
}
NSString *text = basicTitles[indexPath.row];
basicCell.text = text;
basicCell.list = self.list;
return basicCell;
}
}else if (indexPath.section == 1){
CNLiveCanOrNoRefundCell *canOrNoRefCell = [tableView dequeueReusableCellWithIdentifier:canOrNORefIdentifier];
if (!canOrNoRefCell) {
canOrNoRefCell = [[CNLiveCanOrNoRefundCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:canOrNORefIdentifier];
}
canOrNoRefCell.list = self.list;
return canOrNoRefCell;
}else if (indexPath.section == 2){
CNLiveRefundGoodsPriceCell *goodsPriceCell = [tableView dequeueReusableCellWithIdentifier:goodsPriceeIdentifier];
if (!goodsPriceCell) {
goodsPriceCell = [[CNLiveRefundGoodsPriceCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:goodsPriceeIdentifier];
}
goodsPriceCell.list = self.list;
return goodsPriceCell;
}else if (indexPath.section == 3){
if (indexPath.row == 0) {
CNLiveRefundReasonCell *reasonCell = [tableView dequeueReusableCellWithIdentifier:reasonIdentifier];
if (!reasonCell) {
reasonCell = [[CNLiveRefundReasonCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reasonIdentifier];
}
reasonCell.refundReasonBlock = ^(NSString * _Nonnull reasonStr) {
weakSelf.reasonStr = reasonStr;
};
return reasonCell;
}else if ((indexPath.row == 1) || (indexPath.row == 2)) {
CNLiveRefundInstructionsCell *instructionsCell = [tableView dequeueReusableCellWithIdentifier:instructionsIdentifier];
if (!instructionsCell) {
instructionsCell = [[CNLiveRefundInstructionsCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:instructionsIdentifier indexPath:indexPath];
}
instructionsCell.refundDetailsBlock = ^(NSString * _Nonnull refundText) {
if (indexPath.row == 1) {
weakSelf.refundAmount = refundText;
}else if (indexPath.row == 2){
weakSelf.refundInstruct = refundText;
}
};
return instructionsCell;
}else if (indexPath.row == 3){
CNLiveRefundCredentialCell *credentialCell = [tableView dequeueReusableCellWithIdentifier:credentialIdentifier];
if (!credentialCell) {
credentialCell = [[CNLiveRefundCredentialCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:credentialIdentifier];
}
credentialCell.delegate = self;
return credentialCell;
}
}
return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
if (indexPath.row == 1) {
return 85;
}else {
return 45;
}
}else if (indexPath.section == 1){
return 45;
}else if (indexPath.section == 2){
return 125;
}else if (indexPath.section == 3){
if (indexPath.row == 3) {
return self.height;
}else{
return 40;
}
}
return 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 10)];
view.backgroundColor = CNLiveColorWithHexString(@"F5F5F8");
return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (section == 0) {
return 0.01;
}else {
return 10;
}
return 0.01;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
#pragma mark - Lazy
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, kNavigationBarHeight, KScreenWidth, KScreenHeight - kNavigationBarHeight) style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.estimatedRowHeight = (KScreenWidth - 20 - 2*8 - 4)/3 - 8 + 55;
_tableView.userInteractionEnabled = YES;
_tableView.backgroundColor = CNLiveColorWithHexString(@"F5F5F8");
}
return _tableView;
}
- (UIButton *)submitBtn {
if (!_submitBtn) {
_submitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_submitBtn.frame = CGRectMake(15, 10, KScreenWidth - 30, 55);
[_submitBtn setBackgroundImage:CNLiveUIImageWithColor(KYellowColor) forState:UIControlStateNormal];
[_submitBtn setBackgroundImage:CNLiveUIImageWithColor(KYellowHightColor) forState:UIControlStateHighlighted];
[_submitBtn setTitle:@"提交" forState:UIControlStateNormal];
_submitBtn.layer.cornerRadius = 3;
_submitBtn.layer.masksToBounds = YES;
[_submitBtn addTarget:self action:@selector(submitBtnAction) forControlEvents:UIControlEventTouchUpInside];
}
return _submitBtn;
}
- (UIView *)footerView {
if (!_footerView) {
_footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 75)];
[_footerView addSubview:self.submitBtn];
}
return _footerView;
}
@end