BuyerView.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. //
  2. // BuyerView.m
  3. // yunbaolive
  4. //
  5. // Created by ybRRR on 2020/1/16.
  6. // Copyright © 2020 cat. All rights reserved.
  7. //
  8. #import "BuyerView.h"
  9. #import "LookHistoryVC.h"
  10. #import "AddressVC.h"
  11. #import "AccountBalanceVC.h"
  12. #import "OrderListVC.h"
  13. #import "ApplyShopVC.h"
  14. #import "ShopApplyStatusVC.h"
  15. #import "YBUserAuthVC.h"
  16. @implementation BuyerView
  17. -(instancetype)initWithFrame:(CGRect)frame
  18. {
  19. self = [super initWithFrame:frame];
  20. if (self) {
  21. [self creatUI];
  22. [self creatSectionOne];
  23. [self creatSectionTwo];
  24. [self creatSectionThree];
  25. }
  26. return self;
  27. }
  28. #pragma mark -----数据请求-------------
  29. -(void)requstData{
  30. YBWeakSelf;
  31. NSDictionary *dic = @{
  32. @"uid":[Config getOwnID],
  33. @"token":[Config getOwnToken],
  34. };
  35. [YBNetworking postWithUrl:@"Buyer.getHome" Dic:dic Suc:^(int code, id info, NSString *msg) {
  36. if (code ==0) {
  37. NSDictionary *infos = [info firstObject];
  38. [weakSelf reloadUIWithData:infos];
  39. shopStatus = minstr([infos valueForKey:@"apply_status"]);
  40. if ([shopStatus isEqual:@"1"]) {
  41. backView3.hidden = YES;
  42. }else{
  43. backView3.hidden = NO;
  44. }
  45. }else{
  46. [MBProgressHUD showError:msg];
  47. }
  48. } Fail:^(id fail) {
  49. }];
  50. }
  51. -(void)reloadUIWithData:(NSDictionary *)dic{
  52. //待付款
  53. if ([minstr([dic valueForKey:@"wait_payment"]) isEqual:@"0"]) {
  54. wait_payLb.hidden = YES;
  55. }else{
  56. wait_payLb.hidden = NO;
  57. wait_payLb.text =minstr([dic valueForKey:@"wait_payment"]);
  58. }
  59. //待发货
  60. if ([minstr([dic valueForKey:@"wait_shipment"]) isEqual:@"0"]) {
  61. wait_sendLb.hidden = YES;
  62. }else{
  63. wait_sendLb.hidden = NO;
  64. wait_sendLb.text =minstr([dic valueForKey:@"wait_shipment"]);
  65. }
  66. //待收货
  67. if ([minstr([dic valueForKey:@"wait_receive"]) isEqual:@"0"]) {
  68. wait_receiveLb.hidden = YES;
  69. }else{
  70. wait_receiveLb.hidden = NO;
  71. wait_receiveLb.text =minstr([dic valueForKey:@"wait_receive"]);
  72. }
  73. //待评价
  74. if ([minstr([dic valueForKey:@"wait_evaluate"]) isEqual:@"0"]) {
  75. wait_evaluateLb.hidden = YES;
  76. }else{
  77. wait_evaluateLb.hidden = NO;
  78. wait_evaluateLb.text =minstr([dic valueForKey:@"wait_evaluate"]);
  79. }
  80. //退款
  81. if ([minstr([dic valueForKey:@"refund"]) isEqual:@"0"]) {
  82. wait_refundLb.hidden = YES;
  83. }else{
  84. wait_refundLb.hidden = NO;
  85. wait_refundLb.text =minstr([dic valueForKey:@"refund"]);
  86. }
  87. if([minstr([dic valueForKey:@"apply_status"]) isEqual:@"1"]){
  88. backView3.hidden = YES;
  89. }
  90. }
  91. -(void)creatUI{
  92. headImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, _window_width, 190)];
  93. headImg.userInteractionEnabled = YES;
  94. headImg.image = [UIImage imageNamed:@"顶部背景"];
  95. [self addSubview:headImg];
  96. UIImageView *avatarImg = [[UIImageView alloc]init];
  97. [avatarImg sd_setImageWithURL:[NSURL URLWithString:[Config getUserAvatar]]];
  98. avatarImg.layer.cornerRadius = 25;
  99. avatarImg.layer.masksToBounds = YES;
  100. [self addSubview:avatarImg];
  101. [avatarImg mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.top.equalTo(self).offset(34+statusbarHeight+20+15);
  103. make.width.height.mas_equalTo(50);
  104. make.left.equalTo(self).offset(20);
  105. }];
  106. UILabel *nameLb = [[UILabel alloc]init];
  107. nameLb.font =[UIFont boldSystemFontOfSize:15];
  108. nameLb.textColor = [UIColor whiteColor];
  109. nameLb.text = [Config getOwnNicename];
  110. [self addSubview:nameLb];
  111. [nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
  112. make.left.equalTo(avatarImg.mas_right).offset(5);
  113. make.centerY.equalTo(avatarImg.mas_centerY);
  114. make.height.mas_equalTo(18);
  115. }];
  116. }
  117. -(void)creatSectionOne{
  118. backView1 = [[UIView alloc]init];
  119. backView1.frame = CGRectMake(15, headImg.bottom-35, _window_width-30, 70);
  120. backView1.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
  121. backView1.layer.cornerRadius = 5;
  122. backView1.layer.masksToBounds = YES;
  123. backView1.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.05].CGColor;
  124. backView1.layer.shadowOffset = CGSizeMake(0,0);
  125. backView1.layer.shadowOpacity = 1;
  126. backView1.layer.shadowRadius = 3;
  127. [self addSubview:backView1];
  128. NSArray *titleArr = @[YZMsg(@"我的地址"),YZMsg(@"账户余额")];//YZMsg(@"浏览记录"),
  129. NSArray *imageArr = @[YZMsg(@"shop_地址"),YZMsg(@"shop_账户")];//YZMsg(@"shop_记录"),
  130. for (int i = 0; i < titleArr.count; i ++) {
  131. UIButton *btn = [UIButton buttonWithType:0];
  132. btn.frame = CGRectMake(i *backView1.width/2, 10, backView1.width/2, 50);
  133. [btn setTitle:titleArr[i] forState:0];
  134. [btn setTitleColor:[UIColor blackColor] forState:0];
  135. btn.titleLabel.font = [UIFont boldSystemFontOfSize:12];
  136. btn.imageView.contentMode = UIViewContentModeScaleAspectFit;
  137. [btn setImage:[UIImage imageNamed:imageArr[i]] forState:0];
  138. btn = [PublicObj setUpImgDownText:btn];
  139. btn.tag = 10000+i;
  140. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  141. [backView1 addSubview:btn];
  142. }
  143. }
  144. -(void)creatSectionTwo{
  145. backView2 = [[UIView alloc]initWithFrame:CGRectMake(15, backView1.bottom+10, _window_width-30, 120)];
  146. backView2.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
  147. backView2.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.05].CGColor;
  148. backView2.layer.shadowOffset = CGSizeMake(0,0);
  149. backView2.layer.shadowOpacity = 1;
  150. backView2.layer.shadowRadius = 3;
  151. backView2.layer.cornerRadius = 5;
  152. [self addSubview:backView2];
  153. UILabel *orderTitle = [[UILabel alloc]init];
  154. orderTitle.frame = CGRectMake(15, 15, 80, 18);
  155. orderTitle.text =YZMsg(@"我的订单");
  156. orderTitle.font = SYS_Font(14);
  157. orderTitle.textColor = [UIColor blackColor];
  158. [backView2 addSubview:orderTitle];
  159. UIButton *allOrderBtn = [UIButton buttonWithType:0];
  160. allOrderBtn.frame = CGRectMake(backView2.width-110, 15, 110, 18);
  161. [allOrderBtn setTitleColor:RGB(200, 200, 200) forState:0];
  162. [allOrderBtn setTitle:YZMsg(@"查看全部订单") forState:0];
  163. [allOrderBtn setImage:[UIImage imageNamed:@"shop_right"] forState:0];
  164. allOrderBtn.titleLabel.font = [UIFont systemFontOfSize:13];
  165. [allOrderBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, - allOrderBtn.imageView.image.size.width, 0, allOrderBtn.imageView.image.size.width)];
  166. [allOrderBtn setImageEdgeInsets:UIEdgeInsetsMake(0, allOrderBtn.titleLabel.bounds.size.width, 0, -allOrderBtn.titleLabel.bounds.size.width)];
  167. allOrderBtn.tag = 10009;
  168. [allOrderBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  169. [backView2 addSubview:allOrderBtn];
  170. NSArray *title2Arr = @[@"待付款",@"待发货",@"待收货",@"待评价",@"退款"];
  171. for (int i = 0; i < title2Arr.count; i ++) {
  172. UIButton *btn = [UIButton buttonWithType:0];
  173. btn.frame = CGRectMake(i *backView2.width/5, orderTitle.bottom +18, backView1.width/5, 50);
  174. /*
  175. [btn setTitle:YZMsg(title2Arr[i]) forState:0];
  176. [btn setTitleColor:[UIColor blackColor] forState:0];
  177. btn.titleLabel.font = [UIFont boldSystemFontOfSize:12];
  178. btn.imageView.contentMode = UIViewContentModeScaleAspectFit;
  179. [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"shop_%@",title2Arr[i]]] forState:0];
  180. btn = [PublicObj setUpImgDownText:btn];
  181. */
  182. btn.tag = 20000+i;
  183. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  184. [backView2 addSubview:btn];
  185. UIImageView *icomImg = [[UIImageView alloc]init];
  186. icomImg.frame = CGRectMake(btn.width/2-10, 0, 20, 20);
  187. icomImg.image = [UIImage imageNamed:[NSString stringWithFormat:@"shop_%@",title2Arr[i]]];
  188. [btn addSubview:icomImg];
  189. UILabel *titleLb = [[UILabel alloc]init];
  190. titleLb.frame = CGRectMake(10, icomImg.bottom+3, btn.width-20, 30);
  191. titleLb.font =[UIFont systemFontOfSize:12];
  192. titleLb.text = YZMsg(title2Arr[i]);
  193. titleLb.textColor = UIColor.blackColor;
  194. titleLb.lineBreakMode = NSLineBreakByWordWrapping;
  195. titleLb.numberOfLines = 0;
  196. titleLb.textAlignment = NSTextAlignmentCenter;
  197. [btn addSubview:titleLb];
  198. UILabel *countlb= [[UILabel alloc]init];
  199. countlb.frame = CGRectMake(btn.width-20, 0, 12, 12);
  200. countlb.backgroundColor = Pink_Cor;
  201. countlb.layer.cornerRadius = 6;
  202. countlb.layer.masksToBounds = YES;
  203. countlb.font = [UIFont systemFontOfSize:8];
  204. countlb.textColor = [UIColor whiteColor];
  205. countlb.textAlignment = NSTextAlignmentCenter;
  206. [btn addSubview:countlb];
  207. countlb.hidden = YES;
  208. if (i ==0 ) {
  209. wait_payLb = countlb;
  210. }else if (i == 1){
  211. wait_sendLb = countlb;
  212. }else if (i == 2){
  213. wait_receiveLb = countlb;
  214. }else if (i == 3){
  215. wait_evaluateLb = countlb;
  216. }else if (i == 4){
  217. wait_refundLb = countlb;
  218. }
  219. }
  220. }
  221. -(void)creatSectionThree{
  222. backView3 = [[UIView alloc]initWithFrame:CGRectMake(15, backView2.bottom+10, _window_width-30, 50)];
  223. backView3.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
  224. backView3.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.05].CGColor;
  225. backView3.layer.shadowOffset = CGSizeMake(0,0);
  226. backView3.layer.shadowOpacity = 1;
  227. backView3.layer.shadowRadius = 3;
  228. backView3.layer.cornerRadius = 5;
  229. [self addSubview:backView3];
  230. UILabel *openShopTitle = [[UILabel alloc]init];
  231. openShopTitle.frame = CGRectMake(15, 15, 180, 20);
  232. openShopTitle.text =YZMsg(@"我要开店");
  233. openShopTitle.font = SYS_Font(14);
  234. openShopTitle.textColor = [UIColor blackColor];
  235. [backView3 addSubview:openShopTitle];
  236. UIButton *openShopBtn = [UIButton buttonWithType:0];
  237. if([lagType isEqual:EN]){
  238. openShopBtn.frame = CGRectMake(backView2.width- backView3.width/2, 15, backView3.width/2, 18);
  239. }else{
  240. openShopBtn.frame = CGRectMake(backView2.width-130, 15, 130, 18);
  241. }
  242. [openShopBtn setTitleColor:RGB(200, 200, 200) forState:0];
  243. [openShopBtn setTitle:YZMsg(@"开小店,来赚钱") forState:0];
  244. [openShopBtn setImage:[UIImage imageNamed:@"shop_right"] forState:0];
  245. openShopBtn.titleLabel.font = [UIFont systemFontOfSize:13];
  246. openShopBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
  247. [openShopBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, - openShopBtn.imageView.image.size.width, 0, openShopBtn.imageView.image.size.width)];
  248. [openShopBtn setImageEdgeInsets:UIEdgeInsetsMake(0, openShopBtn.titleLabel.bounds.size.width, 0, -openShopBtn.titleLabel.bounds.size.width)];
  249. openShopBtn.tag = 30000;
  250. [openShopBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  251. [backView3 addSubview:openShopBtn];
  252. UIButton *clickBtn = [UIButton buttonWithType:0];
  253. clickBtn.frame = CGRectMake(0, 0, backView3.width, backView3.height);
  254. clickBtn.tag = 30000;
  255. [clickBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  256. [backView3 addSubview:clickBtn];
  257. }
  258. -(void)btnClick:(UIButton *)sender{
  259. switch (sender.tag) {
  260. // //浏览记录
  261. // case 10000:{
  262. // LookHistoryVC *history = [[LookHistoryVC alloc]init];
  263. // [[YBBaseAppDelegate sharedAppDelegate]pushViewController:history animated:YES];
  264. // }
  265. // break;
  266. //我的地址
  267. case 10000:{
  268. AddressVC *address = [[AddressVC alloc]init];
  269. address.titleStr = YZMsg(@"我的地址");
  270. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:address animated:YES];
  271. }
  272. break;
  273. //账户余额
  274. case 10001:{
  275. AccountBalanceVC *balance = [[AccountBalanceVC alloc]init];
  276. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:balance animated:YES];
  277. }
  278. break;
  279. //全部订单
  280. case 10009:{
  281. OrderListVC *order = [[OrderListVC alloc]init];
  282. order.selectIndex = 0;
  283. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:order animated:YES];
  284. }
  285. break;
  286. //待付款
  287. case 20000:{
  288. OrderListVC *order = [[OrderListVC alloc]init];
  289. order.selectIndex = 1;
  290. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:order animated:YES];
  291. }
  292. break;
  293. //待发货
  294. case 20001:{
  295. OrderListVC *order = [[OrderListVC alloc]init];
  296. order.selectIndex = 2;
  297. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:order animated:YES];
  298. }
  299. break;
  300. //待收货
  301. case 20002:{
  302. OrderListVC *order = [[OrderListVC alloc]init];
  303. order.selectIndex = 3;
  304. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:order animated:YES];
  305. }
  306. break;
  307. //待评价
  308. case 20003:{
  309. OrderListVC *order = [[OrderListVC alloc]init];
  310. order.selectIndex = 4;
  311. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:order animated:YES];
  312. }
  313. break;
  314. //退款
  315. case 20004: {
  316. OrderListVC *order = [[OrderListVC alloc]init];
  317. order.selectIndex = 5;
  318. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:order animated:YES];
  319. }
  320. break;
  321. //我要开店
  322. case 30000:{
  323. if ([shopStatus isEqual:@"-1"]) {
  324. [self getAuthInfo];
  325. }else{
  326. ShopApplyStatusVC *status = [[ShopApplyStatusVC alloc]init];
  327. status.statusStr = shopStatus;
  328. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:status animated:YES];
  329. }
  330. }
  331. break;
  332. default:
  333. break;
  334. }
  335. }
  336. -(void)getAuthInfo{
  337. YBWeakSelf;
  338. NSDictionary *dic = @{
  339. @"uid":[Config getOwnID],
  340. @"token":[Config getOwnToken],
  341. };
  342. [YBNetworking postWithUrl:@"Auth.getAuth" Dic:dic Suc:^(int code, id info, NSString *msg) {
  343. if (code ==0) {
  344. NSDictionary *infos = [info firstObject];
  345. if (![minstr([infos valueForKey:@"status"]) isEqual:@"1"]) {
  346. [weakSelf showAuthView];
  347. }else{
  348. ApplyShopVC *apply = [[ApplyShopVC alloc]init];
  349. apply.presonDic = infos;
  350. apply.subEvent = ^{
  351. [weakSelf requstData];
  352. };
  353. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:apply animated:YES];
  354. }
  355. }else{
  356. [MBProgressHUD showError:msg];
  357. }
  358. } Fail:^(id fail) {
  359. }];
  360. }
  361. -(void)showAuthView{
  362. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:YZMsg(@"提示") message:YZMsg(@"请先进行实名认证") preferredStyle:UIAlertControllerStyleAlert];
  363. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:YZMsg(@"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  364. }];
  365. UIAlertAction *sureAction = [UIAlertAction actionWithTitle:YZMsg(@"去认证") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  366. YBUserAuthVC *authVC = [[YBUserAuthVC alloc]init];
  367. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:authVC animated:YES];
  368. }];
  369. [cancelAction setValue:UIColor.grayColor forKey:@"_titleTextColor"];
  370. [sureAction setValue:Pink_Cor forKey:@"_titleTextColor"];
  371. [alertControl addAction:cancelAction];
  372. [alertControl addAction:sureAction];
  373. [[[YBBaseAppDelegate sharedAppDelegate] topViewController]presentViewController:alertControl animated:YES completion:nil];
  374. }
  375. @end