OrderListViewController.m 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850
  1. //
  2. // OrderListViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 8/18/15.
  6. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "OrderListViewController.h"
  9. #import "OrderListTableViewCell.h"
  10. #import "iSalesNetwork.h"
  11. #import "OrderDetailViewController.h"
  12. #import "MainViewController.h"
  13. #import "ContactListViewController.h"
  14. #import "DefaultAppearance.h"
  15. #import "DefaultTableHeaderView.h"
  16. #import "SelectUploadOrderViewController.h"
  17. #import "NotificationNameCenter.h"
  18. #import "Singleton.h"
  19. @interface OrderListViewController ()
  20. @property (nonatomic,strong) NSOperationQueue *dataOperationQueue;
  21. @property (nonatomic,strong) NSMutableArray *mergeList;
  22. @property (nonatomic,assign) NSInteger orderType;///<sales order/shop order
  23. @property (nonatomic,strong) NSMutableDictionary *sales_order_filter;
  24. @property (nonatomic,strong) NSMutableDictionary *shop_order_filter;
  25. @property (strong, nonatomic) IBOutlet UIBarButtonItem *mergeListButton;
  26. @property (strong, nonatomic) IBOutlet UISegmentedControl *orderTypeSegmentControl;
  27. @end
  28. @implementation OrderListViewController
  29. - (NSOperationQueue *)dataOperationQueue {
  30. if (!_dataOperationQueue) {
  31. _dataOperationQueue = [[NSOperationQueue alloc] init];
  32. _dataOperationQueue.maxConcurrentOperationCount = 1;
  33. }
  34. return _dataOperationQueue;
  35. }
  36. - (void)dealloc {
  37. [[NSNotificationCenter defaultCenter] removeObserver:self];
  38. }
  39. - (NSMutableArray *)mergeList {
  40. if (!_mergeList) {
  41. _mergeList = [NSMutableArray array];
  42. }
  43. return _mergeList;
  44. }
  45. -(void) logout
  46. {
  47. [self.mergeList removeAllObjects];
  48. self.offset = 0;
  49. [self.content_data removeAllObjects];
  50. [self.table_order reloadData];
  51. self.status_cadedate = nil;
  52. }
  53. -(void) reload_container_getdata:(bool) update_data
  54. {
  55. [super reload_container_getdata:update_data];
  56. if(update_data)
  57. {
  58. // self.offset = 0;
  59. // [self.content_data removeAllObjects];
  60. self.reset_result=true;
  61. self.norefresh=true;
  62. [self loadpage];
  63. }
  64. else
  65. {
  66. [self.table_order reloadData];
  67. }
  68. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  69. if(appDelegate.can_create_order)
  70. {
  71. [self.btn_newOrder setImage:[UIImage imageNamed:@"neworder"]];
  72. self.btn_newOrder.enabled = true;
  73. }
  74. else
  75. {
  76. [self.btn_newOrder setImage:nil];
  77. self.btn_newOrder.enabled = false;
  78. }
  79. }
  80. -(void) showHidePrice
  81. {
  82. [self reload_container_getdata:false];
  83. }
  84. - (void)viewDidLoad {
  85. [super viewDidLoad];
  86. self.edgesForExtendedLayout = UIRectEdgeNone;
  87. self.loading_queue = dispatch_queue_create("orderlist_loading", NULL);
  88. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  89. self.label_net_err.layer.borderWidth = 2.0;
  90. self.label_net_err.layer.cornerRadius=15;
  91. self.label_net_err.layer.masksToBounds=true;
  92. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changePriceType:) name:Change_Price_Type_Notification object:nil];
  93. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(lockOrderListNotification:) name:Lock_Permission_Notification object:nil];
  94. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(lockOrderListNotification:) name:unLock_Permission_Notification object:nil];
  95. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleUserLogin:) name:User_LoginOK_Notification object:nil];
  96. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  97. // tap.minimumPressDuration = 0.8; //定义按的时间
  98. [self.label_net_err addGestureRecognizer:tap];
  99. // Do any additional setup after loading the view.
  100. self.offset = 0;
  101. self.limit = 25;
  102. self.content_data = [[NSMutableArray alloc]init];
  103. // Customer Order Type 0 Shop Order/ 1 Sales Order
  104. self.orderType = self.orderTypeSegmentControl.selectedSegmentIndex;
  105. [Singleton sharedInstance].customer_order_type = self.orderType;
  106. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  107. ref.tag = 201 ;
  108. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  109. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  110. // ref.hidden = true;
  111. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  112. [self.table_order addSubview:ref];
  113. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  114. // NSString *documents = [paths objectAtIndex:0];
  115. // NSString *dist_path = [documents stringByAppendingPathComponent:@"status_filter_cadedate.json"];
  116. // if ([[NSFileManager defaultManager] fileExistsAtPath:dist_path]) {
  117. //
  118. // DebugLog(@"文件已经存在了");
  119. //
  120. // }
  121. // else
  122. // {
  123. //
  124. //
  125. //
  126. // // DebugLog(@"resourceSampleImagesFolderPath=%@",resourceFolderPath);
  127. //
  128. // NSData *mainBundleFile = [NSData dataWithContentsOfFile:order_filter_source_path];
  129. //
  130. // // DebugLog(@"mainBundleFile==%@",mainBundleFile);
  131. //
  132. // [[NSFileManager defaultManager] createFileAtPath:dist_path
  133. //
  134. // contents:mainBundleFile
  135. //
  136. // attributes:nil];
  137. //
  138. // }
  139. [self loadfilter];
  140. }
  141. -(void) loadfilter
  142. {
  143. if(self.status_cadedate!=nil)
  144. return;
  145. UIApplication * app = [UIApplication sharedApplication];
  146. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  147. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER) {
  148. self.shop_order_filter = [Singleton sharedInstance].shop_order_status_filter;
  149. self.sales_order_filter = appDelegate.OrderFilter;
  150. if (self.orderTypeSegmentControl.selectedSegmentIndex == 0) {
  151. self.status_cadedate = self.shop_order_filter;
  152. } else {
  153. self.status_cadedate = self.sales_order_filter;
  154. }
  155. return;
  156. }
  157. NSData* json =nil;
  158. if(self.init_style==OL_OPEN)
  159. {
  160. json=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"status_filter_cadedate_open" ofType:@"json" ]];
  161. NSError *error=nil;
  162. self.status_cadedate = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  163. }
  164. else
  165. {
  166. // json=//[NSData dataWithContentsOfFile:dist_path];
  167. // NSError *error=nil;
  168. self.status_cadedate = appDelegate.OrderFilter;//[[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  169. }
  170. }
  171. - (IBAction)onCancel:(id)sender {
  172. if(self.onCancel)
  173. self.onCancel();
  174. [self.navigationController popViewControllerAnimated:false];
  175. }
  176. - (IBAction)onStatusFilterClick:(id)sender {
  177. EnumSelectViewController* enumvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"EnumSelectorViewController"];
  178. enumvc.delegate = self;
  179. enumvc.max_select = 0;
  180. //enumvc.updatePosition = indexPath;
  181. // if([[required lowercaseString] isEqualToString:@"true"])
  182. // enumvc.canbeEmpty = false;
  183. // else
  184. // enumvc.canbeEmpty =true;
  185. enumvc.cadedate = self.status_cadedate ;
  186. enumvc.title = @"Order Status Selection";
  187. // enumvc.value = [value_json mutableCopy];
  188. enumvc.single_select =false;
  189. [self.navigationController pushViewController:enumvc animated:true];
  190. }
  191. - (void)viewWillAppear:(BOOL)animated
  192. {
  193. [super viewWillAppear:animated];
  194. [self loadfilter];
  195. // [self ReloadData]; // 保存新订单后返回没刷新
  196. // UIApplication * app = [UIApplication sharedApplication];
  197. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  198. // if(appDelegate.bLogin==false)
  199. // {
  200. // LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  201. //// loginvc.delegate = self;
  202. // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  203. //
  204. // loginvc.returnValue = ^(bool blogin){
  205. //
  206. //
  207. // UIApplication * app = [UIApplication sharedApplication];
  208. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  209. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  210. //
  211. // [main_vc checklogin:true];
  212. //
  213. //// self.offset = 0;
  214. //// [self.content_data removeAllObjects];
  215. //// [self loadpage];
  216. //
  217. // [[self navigationController] setNavigationBarHidden:!self.showNavibar animated:NO];
  218. //
  219. // };
  220. //
  221. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  222. //
  223. //
  224. //
  225. //
  226. //
  227. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  228. //
  229. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  230. // [self presentViewController:navi animated:YES completion:^{
  231. //
  232. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  233. //
  234. // DebugLog(@"LoginViewController present.........");
  235. //
  236. // // self.btop = false;
  237. // // <#code#>
  238. // }];
  239. // }
  240. // else
  241. // {
  242. //
  243. // if(!self.norefresh)//避免 多次刷新
  244. // {
  245. // self.norefresh = true;
  246. // self.offset = 0;
  247. // [self.content_data removeAllObjects];
  248. // [self loadpage];
  249. //
  250. // }
  251. //
  252. // }
  253. [[self navigationController] setNavigationBarHidden:!self.showNavibar animated:NO];
  254. // 检查权限
  255. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  256. NSMutableArray *items = [self.toolbarView.items mutableCopy];
  257. if(appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER) {
  258. // 合并订单的权限
  259. if ([Singleton sharedInstance].permissions_merge_order) { // 能够合并
  260. if (![items containsObject:self.mergeListButton]) { // 没显示button
  261. [items insertObject:self.mergeListButton atIndex:4];
  262. self.toolbarView.items = items;
  263. }
  264. } else { // 不能合并
  265. if ([items containsObject:self.mergeListButton]) { // 显示button
  266. [items removeObject:self.mergeListButton];
  267. self.toolbarView.items = items;
  268. }
  269. }
  270. } else {
  271. // self.mergeListButton.hidden = YES;
  272. if ([items containsObject:self.mergeListButton]) { // 显示button
  273. [items removeObject:self.mergeListButton];
  274. self.toolbarView.items = items;
  275. }
  276. }
  277. // 非Customer用户不用区分Sales Order 和 Shop Order
  278. if (appDelegate.user_type != USER_ROLE_CUSTOMER) {
  279. self.orderTypeSegmentControl.hidden = YES;
  280. CGFloat y = CGRectGetMinY(self.orderTypeSegmentControl.frame);
  281. CGFloat height = CGRectGetHeight(self.orderTypeSegmentControl.frame);
  282. CGRect frame = self.table_order.frame;
  283. if (frame.origin.y != y) {
  284. frame.origin.y = y;
  285. frame.size.height += height;
  286. }
  287. self.table_order.frame = frame;
  288. } else {
  289. self.orderTypeSegmentControl.hidden = NO;
  290. CGFloat y = CGRectGetMinY(self.orderTypeSegmentControl.frame);
  291. CGFloat height = CGRectGetHeight(self.orderTypeSegmentControl.frame);
  292. CGRect frame = self.table_order.frame;
  293. if (frame.origin.y == y) {
  294. frame.origin.y = y + height;
  295. frame.size.height -= height;
  296. }
  297. self.table_order.frame = frame;
  298. }
  299. // 显示Sales Order与否
  300. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER) {
  301. if ([Singleton sharedInstance].global_lock || ![Singleton sharedInstance].customer_can_see_sales_Order) { // 是否解锁,是否有查看Sales Order权限
  302. if (self.orderTypeSegmentControl.numberOfSegments > 1) {
  303. [self.orderTypeSegmentControl removeSegmentAtIndex:1 animated:YES];
  304. }
  305. }
  306. }
  307. }
  308. - (IBAction)onNewOrderClicked:(id)sender {
  309. NSString* msg=@"Do you want to create a new order?";
  310. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  311. if(appDelegate.order_code.length==0)
  312. {
  313. if(appDelegate.contact_id.length>0)
  314. {
  315. msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  316. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  317. }
  318. }
  319. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Warning", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  320. [alert show];
  321. }
  322. - (void)didReceiveMemoryWarning {
  323. [super didReceiveMemoryWarning];
  324. // Dispose of any resources that can be recreated.
  325. }
  326. -(void)manually_refresh
  327. {
  328. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
  329. if(self.isrefreshing)
  330. {
  331. [reF endRefreshing];
  332. return;
  333. }
  334. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  335. if ([self respondsToSelector:@selector(ReloadData)])
  336. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  337. }
  338. -(void)ReloadData
  339. {
  340. // [self.content_data removeAllObjects];
  341. // [self.table_order reloadData];
  342. // self.table_order.hidden = true;
  343. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
  344. [reF endRefreshing];
  345. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  346. self.keywords=self.searchbar.text;
  347. // self.offset = 0;
  348. self.reset_result=true;
  349. // [self.content_data removeAllObjects];
  350. // [self.table_order reloadData];
  351. [self loadpage];
  352. // [self loadpage];
  353. }
  354. - (void)operation_loadPage {
  355. if (self.dataOperationQueue.operationCount > 1) { // 队列后面还有操作
  356. return;
  357. }
  358. // dispatch_async(self.loading_queue, ^{
  359. dispatch_sync(dispatch_get_main_queue(), ^{
  360. if(self.reset_result)
  361. {
  362. self.offset = 0;
  363. [self.content_data removeAllObjects];
  364. [self.table_order reloadData];
  365. }
  366. // NSMutableArray* arr_status = [[NSMutableArray alloc] init];
  367. NSMutableArray* arr_statusname = [[NSMutableArray alloc] init];
  368. int count = [[self.status_cadedate valueForKey:@"count"] intValue];
  369. for(int i=0;i<count;i++)
  370. {
  371. NSDictionary* val_json =[self.status_cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i]];
  372. int check = [[val_json valueForKey:@"check"] intValue];
  373. if(check==1)
  374. {
  375. // [arr_status addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value_id"]]];
  376. [arr_statusname addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value"]]];
  377. // break;
  378. }
  379. }
  380. // NSString * str_status = [arr_status componentsJoinedByString:@","];
  381. NSString * str_statusname = [arr_statusname componentsJoinedByString:@","];
  382. if(str_statusname.length==0)
  383. str_statusname = @"All";
  384. self.label_filter.text = str_statusname;
  385. if(self.offset==0)
  386. {
  387. self.table_order.hidden = true;
  388. self.mum.center = self.view.center;
  389. self.mum.hidden = false;
  390. [self.mum startAnimating];
  391. }
  392. self.label_net_err.hidden=true;
  393. });
  394. // });
  395. // dispatch_async(self.loading_queue, ^{
  396. if(self.isrefreshing)
  397. return;
  398. self.isrefreshing=true;
  399. NSMutableArray* arr_status = [[NSMutableArray alloc] init];
  400. // NSMutableArray* arr_statusname = [[NSMutableArray alloc] init];
  401. int count = [[self.status_cadedate valueForKey:@"count"] intValue];
  402. for(int i=0;i<count;i++)
  403. {
  404. NSDictionary* val_json =[self.status_cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i]];
  405. int check = [[val_json valueForKey:@"check"] intValue];
  406. if(check==1)
  407. {
  408. [arr_status addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value_id"]]];
  409. // [arr_statusname addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value"]]];
  410. // break;
  411. }
  412. }
  413. NSString * str_status = [arr_status componentsJoinedByString:@","];
  414. BOOL isMerged = NO;
  415. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  416. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  417. if (self.orderType == 0) {
  418. isMerged = NO;
  419. } else {
  420. isMerged = YES;
  421. }
  422. }
  423. NSMutableDictionary* content=nil;
  424. content=[[iSalesNetwork request_OrderList:self.offset limit : self.limit keywords:self.keywords status:str_status customer:self.customer_id is_merged:isMerged] mutableCopy];
  425. dispatch_sync(dispatch_get_main_queue(), ^{
  426. [self.mum stopAnimating];
  427. self.isrefreshing=false;
  428. if (self.dataOperationQueue.operationCount > 1) { // 队列后面还有操作
  429. return ;
  430. }
  431. int result=[[content valueForKey:@"result"] intValue];
  432. if(result==2||result==0)
  433. {
  434. int count = [[content valueForKey:@"count" ] intValue] ;
  435. self.time_zone = [content valueForKey:@"time_zone" ];
  436. self.offset += count;
  437. for(int i=0;i<count;i++)
  438. {
  439. NSDictionary* objmsg = [content objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  440. [self.content_data addObject:[NSMutableDictionary dictionaryWithDictionary:objmsg]];
  441. }
  442. if(count<self.limit)
  443. {
  444. // int i =self.btnrefresh.state;
  445. self.load_more_hint=@"All loaded";
  446. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"no_more", nil);
  447. // [self.btnrefresh setTitle:@"No more" forState:UIControlStateNormal];
  448. }
  449. else
  450. {
  451. self.load_more_hint=@"Load more...";
  452. // self.btnrefresh.enabled = true;
  453. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"load_more",nil);
  454. // [self.btnrefresh setTitle:@"Load more" forState:UIControlStateNormal];
  455. }
  456. self.table_order.hidden = false;
  457. self.reset_result=false;
  458. [self.table_order reloadData ];
  459. }
  460. else if(result==RESULT_NET_ERROR &&self.offset==0)
  461. {
  462. self.label_net_err.hidden=false;
  463. self.table_order.hidden = true;
  464. }
  465. else
  466. {
  467. [RAUtils message_alert:[content valueForKey:@"err_msg"] title:@"Loading Order List" controller:self] ;
  468. }
  469. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  470. // bool autologin =[defaults boolForKey:@"autologin"];
  471. // if(!autologin)
  472. // {
  473. // TabBarController * viewController =[self.storyboard instantiateViewControllerWithIdentifier:@"LoginTabBar"];
  474. // [self presentViewController:viewController animated:YES completion:^{
  475. //
  476. // }];
  477. // }
  478. });
  479. // });
  480. }
  481. -(void) loadpage
  482. {
  483. __weak typeof(self) weakself = self;
  484. NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
  485. if (weakself) {
  486. __strong typeof(weakself) strongself = weakself;
  487. [strongself operation_loadPage];
  488. }
  489. }];
  490. [self.dataOperationQueue addOperation:operation];
  491. }
  492. - (void)loadmore
  493. {
  494. // self.btnrefresh.enabled = NO;
  495. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"loading",nil);
  496. // [self.btnrefresh setTitle:@"Loading..." forState:UIControlStateNormal];
  497. [self loadpage];
  498. }
  499. //-(void)changeCell
  500. //{
  501. //// UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  502. //// reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"refreshing"];
  503. // [self performSelector:@selector(loadmore) withObject:nil afterDelay:1];
  504. // DebugLog(@"refresh!!!!!!!!");
  505. //
  506. //}
  507. -(void) neworder
  508. {
  509. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  510. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  511. NSDictionary* return_json = [iSalesNetwork new_Order];
  512. dispatch_async(dispatch_get_main_queue(), ^{
  513. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  514. if([[return_json valueForKey:@"result"] intValue]==2)
  515. {
  516. int result=[[return_json valueForKey:@"result"] intValue];
  517. if(result==2)
  518. {
  519. //successed.
  520. NSString* order_code = [return_json valueForKey:@"orderCode"];
  521. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  522. appDelegate.order_code = order_code;
  523. appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  524. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  525. [main_vc reloadCart:true immediately:false];
  526. [self ReloadData];
  527. // [self performSelector:@selector(loadpage) withObject:nil afterDelay:1];
  528. // [self loadpage];
  529. // if(self.shopCartBlock!=nil)
  530. // {
  531. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  532. //
  533. //
  534. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  535. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  536. // iv.image = img;
  537. // // [self.contentView addSubview:iv];
  538. // self.shopCartBlock(iv);
  539. //
  540. // }
  541. }
  542. }
  543. else
  544. {
  545. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:self] ;
  546. }
  547. });
  548. });
  549. }
  550. #pragma mark - UIAlertViewDelegate
  551. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  552. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  553. {
  554. if(buttonIndex!=alertView.cancelButtonIndex)
  555. {
  556. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  557. if(appDelegate.order_code && appDelegate.order_code.length>0)
  558. {
  559. appDelegate.order_code= nil;
  560. [appDelegate SetSo:nil];
  561. if (appDelegate.user_type == USER_ROLE_EMPLOYEE) {
  562. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  563. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  564. cvc.showNavibar = true;
  565. cvc.contact_type = @"Sales_Order_Customer";
  566. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  567. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  568. appDelegate.customerInfo = value;
  569. self.norefresh = true;
  570. [self neworder];
  571. // [main_vc checklogin:true];
  572. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  573. //
  574. // if(self.returnValue)
  575. // self.returnValue(value);
  576. };
  577. cvc.onCancel = ^(){
  578. self.norefresh = true;
  579. if(appDelegate.customerInfo==nil)
  580. {
  581. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  582. }
  583. else
  584. {
  585. [self neworder];
  586. }
  587. // [main_vc checklogin:true];
  588. };
  589. cvc.onReset = ^(){
  590. // [main_vc checklogin:true];
  591. };
  592. [self.navigationController pushViewController:cvc animated:true];
  593. }
  594. else if (appDelegate.user_type == USER_ROLE_CUSTOMER){
  595. [self neworder];
  596. }
  597. }
  598. else
  599. {
  600. //create new;
  601. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  602. {
  603. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  604. ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  605. cvc.showNavibar = true;
  606. cvc.contact_type = @"Sales_Order_Customer";
  607. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  608. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  609. appDelegate.customerInfo = value;
  610. if(appDelegate.order_code==nil)
  611. [self neworder];
  612. // [main_vc checklogin:true];
  613. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  614. //
  615. // if(self.returnValue)
  616. // self.returnValue(value);
  617. };
  618. cvc.onCancel = ^(){
  619. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  620. };
  621. cvc.onReset = ^(){
  622. [main_vc checklogin:true];
  623. };
  624. [self.navigationController pushViewController:cvc animated:true];
  625. }
  626. else
  627. {
  628. [self neworder];
  629. }
  630. }
  631. }
  632. }
  633. #pragma mark - Table view data source
  634. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  635. {
  636. return 66;
  637. }
  638. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  639. //{
  640. // return 0;
  641. //}
  642. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  643. //{
  644. // return 0;
  645. //}
  646. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  647. //{
  648. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  649. // return myView;
  650. //
  651. //}
  652. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  653. {
  654. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  655. if(value==nil)
  656. value=@"";
  657. unsigned long color = strtoul([value UTF8String],0,16);
  658. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  659. // myView.backgroundColor = UIColorFromRGB(0x996633);
  660. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  661. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  662. myView.layer.shadowOffset = CGSizeMake(0, 0);
  663. myView.layer.shadowOpacity = 0.5;
  664. myView.layer.shadowRadius = 2.0;
  665. UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 2, 130, 22)];
  666. statuslabel.textColor=UIColorFromRGB(color);
  667. statuslabel.backgroundColor = [UIColor clearColor];
  668. statuslabel.text=NSLocalizedString(@"Status", nil);
  669. [statuslabel sizeToFit];
  670. [myView addSubview:statuslabel];
  671. UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 21, 130, 22)];
  672. solabel.textColor=UIColorFromRGB(color);
  673. solabel.backgroundColor = [UIColor clearColor];
  674. solabel.text=NSLocalizedString(@"SO#", nil);
  675. [solabel sizeToFit];
  676. [myView addSubview:solabel];
  677. UILabel *userlabel = [[UILabel alloc] initWithFrame:CGRectMake(155, 2, 135, 22)];
  678. userlabel.textColor=UIColorFromRGB(color);
  679. userlabel.backgroundColor = [UIColor clearColor];
  680. userlabel.text=NSLocalizedString(@"Sales rep", nil);
  681. [userlabel sizeToFit];
  682. [myView addSubview:userlabel];
  683. UILabel *creatorlabel = [[UILabel alloc] initWithFrame:CGRectMake(155, 21, 135, 22)];
  684. creatorlabel.textColor=UIColorFromRGB(color);
  685. creatorlabel.backgroundColor = [UIColor clearColor];
  686. creatorlabel.text=NSLocalizedString(@"Create by", nil);
  687. [creatorlabel sizeToFit];
  688. [myView addSubview:creatorlabel];
  689. UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(300, 11, 150, 22)];
  690. contactlabel.textColor=UIColorFromRGB(color);
  691. contactlabel.backgroundColor = [UIColor clearColor];
  692. contactlabel.text=NSLocalizedString(@"Contact", nil);
  693. [contactlabel sizeToFit];
  694. [myView addSubview:contactlabel];
  695. //
  696. // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(424, 11, 52, 22)];
  697. // modellabel.textColor=[UIColor whiteColor];
  698. // modellabel.backgroundColor = [UIColor clearColor];
  699. // modellabel.text=NSLocalizedString(@"Model", nil);
  700. // [modellabel sizeToFit];
  701. // [myView addSubview:modellabel];
  702. // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-276, 2, 100, 22)];
  703. // modellabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  704. // modellabel.textColor=[UIColor whiteColor];
  705. // modellabel.backgroundColor = [UIColor clearColor];
  706. // modellabel.text=NSLocalizedString(@"Items/QTY", nil);
  707. // [modellabel sizeToFit];
  708. // [myView addSubview:modellabel];
  709. UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 11, 100, 22)];
  710. pricelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  711. pricelabel.textColor=UIColorFromRGB(color);
  712. pricelabel.backgroundColor = [UIColor clearColor];
  713. pricelabel.text=NSLocalizedString(@"Order Total", nil);
  714. [pricelabel sizeToFit];
  715. [myView addSubview:pricelabel];
  716. UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-163/*605*/,11, 148, 22)];
  717. timelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  718. timelabel.textColor=UIColorFromRGB(color);
  719. timelabel.backgroundColor = [UIColor clearColor];
  720. if(self.time_zone==nil)
  721. timelabel.text=@"Create time";
  722. else
  723. timelabel.text=[NSString stringWithFormat:@"Create time (%@)",self.time_zone];
  724. [timelabel sizeToFit];
  725. [myView addSubview:timelabel];
  726. myView.autoresizesSubviews=true;
  727. // [myView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];
  728. // modellabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  729. // pricelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  730. // timelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  731. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  732. //
  733. return myView;
  734. }
  735. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  736. {
  737. return 44;
  738. }
  739. //
  740. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  741. // if(section==0)
  742. // return nil;
  743. // else
  744. // return @"detail section";
  745. //}
  746. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  747. {
  748. return 1;
  749. }
  750. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  751. {
  752. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  753. if( self.content_data.count==0)
  754. return 0;
  755. return self.content_data.count+1;
  756. }
  757. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  758. {
  759. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  760. // if(tableView==self.itemListTable)
  761. // {
  762. // if(indexPath.row>self.content_data.count)
  763. // {
  764. // int debug=true;
  765. // }
  766. // DebugLog(@"row %ld",(long)indexPath.row);
  767. if(indexPath.row==self.content_data.count)
  768. {
  769. UITableViewCell *moreCell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"mores"];
  770. UILabel *moreDataLabel=[[UILabel alloc] init];
  771. moreDataLabel.tag=200;
  772. moreDataLabel.text=self.load_more_hint;
  773. [moreDataLabel setFont:[UIFont systemFontOfSize:14.0f]];
  774. [moreDataLabel setTextAlignment:NSTextAlignmentCenter];
  775. moreDataLabel.frame=CGRectMake(0, 10, self.table_order.bounds.size.width, 20);
  776. [moreDataLabel setBackgroundColor:[UIColor clearColor]];
  777. // [moreDataLabel addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
  778. [moreCell.contentView addSubview:moreDataLabel];
  779. if([self.load_more_hint isEqualToString:@"Load more..."])
  780. [self performSelector:@selector(loadmore) withObject:nil afterDelay:1];
  781. // DebugLog(@"更多...");
  782. moreCell.backgroundColor = [UIColor whiteColor];
  783. return moreCell;
  784. }
  785. else
  786. {
  787. NSString *CellIdentifier = @"OrderListTableViewCell";
  788. OrderListTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  789. NSString* po= [self.content_data[indexPath.row] valueForKey:@"so#"];
  790. NSString* price= [self.content_data[indexPath.row] valueForKey:@"price"];
  791. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  792. {
  793. }
  794. else
  795. {
  796. price=nil;
  797. }
  798. NSString* purchase_time= [self.content_data[indexPath.row] valueForKey:@"purchase_time"];
  799. NSString* status = [self.content_data[indexPath.row] valueForKey:@"order_status"] ;
  800. NSString* customer_name = [self.content_data[indexPath.row] valueForKey:@"customer_name"];
  801. NSString* model_count = [self.content_data[indexPath.row] valueForKey:@"model_count"];
  802. NSString* sales = [self.content_data[indexPath.row] valueForKey:@"sales_rep"];
  803. NSString* creator = [self.content_data[indexPath.row] valueForKey:@"create_by"];
  804. cell.label_so.text=po;
  805. cell.labelprice.text=price;
  806. cell.label_date.text=purchase_time;
  807. cell.label_contact.text=customer_name;
  808. cell.label_model.text = model_count;
  809. cell.label_sales.text = sales;
  810. cell.label_creator.text = creator;
  811. cell.label_status.text=status;
  812. cell.backgroundColor = [UIColor whiteColor];
  813. return cell;
  814. }
  815. // NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  816. // NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  817. // cell.bundle_item=combine_json;
  818. // NSString* img_url = [item_json valueForKey:@"img_url"];
  819. // NSString* description = [item_json valueForKey:@"description"];
  820. // // NSString* identifier = [item_json valueForKey:@"identifier"];
  821. // // NSString* attribute = [item_json valueForKey:@"attribute"];
  822. // NSString* currency = [item_json valueForKey:@"currency"];
  823. // int count =[[item_json valueForKey:@"count"] intValue];
  824. // double price =[[item_json valueForKey:@"price"] doubleValue];
  825. // // cell.labelAttribute.text = attribute;
  826. // cell.labelCurrency.text = currency;
  827. // cell.labelDescription.text = description;
  828. // // cell.labelIdentifier.text = identifier;
  829. // cell.labelPrice.text = [NSString stringWithFormat:@"%.2f",price];
  830. //
  831. //
  832. //
  833. // [cell set_Count:count];
  834. // NSString* file_name=[img_url lastPathComponent];
  835. // NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  836. // if(img_data!=nil)
  837. // {
  838. //
  839. // UIImage * img =[UIImage imageWithData:img_data];
  840. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  841. // }
  842. // else
  843. // {
  844. //
  845. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  846. //
  847. // NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  848. //
  849. // dispatch_async(dispatch_get_main_queue(), ^{
  850. //
  851. //
  852. //
  853. // if(downloadimg_data!=nil)
  854. // {
  855. // [iSalesDB cache_img:downloadimg_data :file_name ];
  856. //
  857. // UIImage * img =[UIImage imageWithData:downloadimg_data];
  858. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  859. // }
  860. //
  861. // });
  862. // });
  863. //
  864. //
  865. // }
  866. // }
  867. // else
  868. // {
  869. // NSString *CellIdentifier = @"OrderInfoListItem";
  870. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  871. // return cell;
  872. // }
  873. }
  874. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  875. {
  876. //
  877. if(indexPath.row==self.content_data.count)
  878. return;
  879. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  880. if(appDelegate.user_type==USER_ROLE_CUSTOMER) { // Customer
  881. if ([Singleton sharedInstance].global_lock) { // Order list 被锁
  882. [RAUtils message_alert:@"App is locked,You can't view the order Detail" title:@"Warning" controller:self];
  883. return;
  884. }
  885. }
  886. NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"];
  887. OrderDetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"OrderDetailViewController" ];
  888. // int i =[[self.content_data[indexPath.row] valueForKey:@"order_code"];
  889. dvc.selectOrder=^(NSMutableDictionary* order_detail){
  890. [self.navigationController popViewControllerAnimated:false];
  891. if(self.selectOrder)
  892. self.selectOrder(order_detail);
  893. };
  894. NSString* order_code =[self.content_data[indexPath.row] valueForKey:@"order_code"];
  895. dvc.is_shoporder=(self.orderType == 0);
  896. dvc.order_code = order_code;
  897. dvc.order_status =[[self.content_data[indexPath.row] valueForKey:@"orderStatus"] intValue];
  898. // bool temp_order = false ;
  899. // NSString* order_status=[self.content_data[indexPath.row] valueForKey:@"order_status"];
  900. // if([order_status isEqualToString:@"Saved"]||[order_status isEqualToString:@"Quoted"])
  901. // temp_order=true;
  902. //
  903. // dvc.isTempOrder = temp_order;
  904. // dvc
  905. dvc.orderid=orderid;
  906. // dvc.category_id=nil;
  907. // dvc.ispush=true;
  908. // [dvc reload];
  909. [self.navigationController pushViewController:dvc animated:true];
  910. }
  911. #pragma mark - searchBar delegate;
  912. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  913. {
  914. self.keywords=searchBar.text;
  915. // self.offset = 0;
  916. // [self.content_data removeAllObjects];
  917. self.reset_result=true;
  918. [self loadpage];
  919. }
  920. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  921. {
  922. if([searchText isEqualToString:@""] && !self.reset)
  923. {
  924. DebugLog(@"clear");
  925. self.reset=true;
  926. self.keywords=nil;
  927. // self.offset = 0;
  928. // [self.content_data removeAllObjects];
  929. self.reset_result=true;
  930. [self loadpage];
  931. }
  932. else
  933. self.reset = false;
  934. }
  935. #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
  936. - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
  937. {
  938. // 添加一个删除按钮
  939. // self.indexPath=indexPath;
  940. if(indexPath.row==self.content_data.count)
  941. return @[];
  942. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  943. NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"];
  944. NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"];
  945. NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  946. if(appDelegate.user_type==USER_ROLE_EMPLOYEE) {
  947. UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  948. DebugLog(@"delete click");
  949. NSString * title =[NSString stringWithFormat:@"Are you sure to delete order SO#: %@",so];
  950. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
  951. //block代码块取代了delegate
  952. // [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  953. // textField.text = self.save_name;
  954. //
  955. //
  956. // }];
  957. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  958. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Delete Order"];
  959. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  960. NSDictionary* return_json = [iSalesNetwork delete_Order:orderid];
  961. dispatch_async(dispatch_get_main_queue(), ^{
  962. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  963. if([[return_json valueForKey:@"result"] intValue]==2)
  964. {
  965. if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
  966. {
  967. appDelegate.order_code= nil;
  968. [appDelegate SetSo:nil];
  969. }
  970. [RAUtils message_alert:nil title:@"Order Delete" controller:self] ;
  971. [self ReloadData];
  972. }
  973. else
  974. {
  975. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Delete Order" controller:self] ;
  976. }
  977. });
  978. });
  979. }];
  980. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  981. DebugLog(@"Cancel");
  982. }];
  983. [alertControl addAction:actionOne];
  984. [alertControl addAction:alertthree];
  985. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  986. [self presentViewController:alertControl animated:YES completion:nil];
  987. }];
  988. deleteRowAction.backgroundColor = UIColorFromRGB(0x336699);
  989. // 添加一个编辑按钮
  990. UITableViewRowAction *cancelAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Cancel Order"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  991. DebugLog(@"edit click");
  992. NSString * title =[NSString stringWithFormat:@"Are you sure to cancel order SO#: %@",so];
  993. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
  994. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  995. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Cancel Order"];
  996. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  997. NSDictionary* return_json = [iSalesNetwork cancel_Order:orderid order_code:nil];
  998. dispatch_async(dispatch_get_main_queue(), ^{
  999. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1000. if([[return_json valueForKey:@"result"] intValue]==2)
  1001. {
  1002. if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
  1003. {
  1004. appDelegate.order_code= nil;
  1005. //appDelegate.user_type = 0;
  1006. appDelegate.customerInfo = nil;
  1007. appDelegate.contact_id = nil;
  1008. appDelegate.order_customer_id = nil;
  1009. [appDelegate SetSo:nil];
  1010. appDelegate.cart_count=0;
  1011. [appDelegate update_count_mark];
  1012. }
  1013. [RAUtils message_alert:nil title:@"Order Canceled" controller:self] ;
  1014. [self ReloadData];
  1015. }
  1016. else
  1017. {
  1018. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Cancel Order" controller:self] ;
  1019. }
  1020. });
  1021. });
  1022. }];
  1023. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1024. DebugLog(@"Cancel");
  1025. }];
  1026. [alertControl addAction:actionOne];
  1027. [alertControl addAction:alertthree];
  1028. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1029. [self presentViewController:alertControl animated:YES completion:nil];
  1030. //
  1031. }];
  1032. cancelAction.backgroundColor = UIColorFromRGB(0xff9933);
  1033. if([order_status isEqualToString:@"Saved Order"]&&appDelegate.can_cancel_order)
  1034. return @[cancelAction];
  1035. else
  1036. {
  1037. if([order_status isEqualToString:@"Quote Saved"])
  1038. {
  1039. NSMutableArray* arr=[@[] mutableCopy];
  1040. if(appDelegate.can_delete_order)
  1041. [arr addObject:deleteRowAction];
  1042. if(appDelegate.can_cancel_order)
  1043. [arr addObject:cancelAction];
  1044. return arr;
  1045. }
  1046. }
  1047. } else if (appDelegate.user_type==USER_ROLE_CUSTOMER) {
  1048. UITableViewRowAction *add2MergeListAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Add To Convert List" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  1049. NSString *orderCode = [NSString stringWithFormat:@"%@",[self.content_data[indexPath.row] valueForKey:@"order_code"]];
  1050. NSString *create_by = [self.content_data[indexPath.row] valueForKey:@"create_by"];
  1051. NSString *create_time = [self.content_data[indexPath.row] valueForKey:@"purchase_time"];
  1052. __block BOOL contain = NO;
  1053. [self.mergeList enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  1054. NSString *so_id = [(NSDictionary *)obj objectForKey:@"so_id"];
  1055. if ([so_id isEqualToString:so]) {
  1056. contain = YES;
  1057. *stop = YES;
  1058. }
  1059. }]; // 避免重复添加
  1060. if (!contain) {
  1061. __block BOOL closeOrder = NO;
  1062. // 检查是否被自己打开
  1063. if ([orderCode isEqualToString:appDelegate.order_code]) {
  1064. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:@"can not add to convert list because current order is opened. Do you want to close order and add to convert list?" preferredStyle:UIAlertControllerStyleAlert];
  1065. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1066. closeOrder = NO;
  1067. [alertVC dismissViewControllerAnimated:YES completion:nil];
  1068. }];
  1069. UIAlertAction *closeOrderAction = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1070. [alertVC dismissViewControllerAnimated:YES completion:nil];
  1071. // 关闭订单
  1072. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Release Order"];
  1073. NSDictionary* order_json = [iSalesNetwork release_Order:orderCode];
  1074. dispatch_async(dispatch_get_main_queue(), ^{
  1075. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1076. if([[order_json valueForKey:@"result"] intValue]==2)
  1077. {
  1078. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1079. [appDelegate closeOrder];
  1080. closeOrder = YES;
  1081. // 锁订单/检查是否被别人锁定
  1082. NSDictionary *lock_dic = [iSalesNetwork lock_order:orderCode]; // 和open一样,只不过不用更新car count
  1083. if ([[lock_dic objectForKey:@"result"] integerValue] == RESULT_TRUE) {
  1084. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  1085. [dic setValue:orderid forKey:@"order_id"];
  1086. [dic setValue:so forKey:@"so_id"];
  1087. [dic setValue:create_by forKey:@"create_by"];
  1088. [dic setValue:create_time forKey:@"create_time"];
  1089. [dic setValue:[NSNumber numberWithInteger:0] forKey:@"check"]; // 合并到
  1090. [self.mergeList addObject:dic];
  1091. } else {
  1092. [RAUtils message_alert:[lock_dic objectForKey:@"err_msg"] title:@"Warning" controller:self];
  1093. }
  1094. }
  1095. else
  1096. {
  1097. closeOrder = NO;
  1098. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Release Order" controller:self] ;
  1099. }
  1100. });
  1101. }];
  1102. [alertVC addAction:cancelAction];
  1103. [alertVC addAction:closeOrderAction];
  1104. [self presentViewController:alertVC animated:YES completion:nil];
  1105. } else {
  1106. closeOrder = YES;
  1107. // 锁订单/检查是否被别人锁定
  1108. NSDictionary *lock_dic = [iSalesNetwork lock_order:orderCode]; // 和open一样,只不过不用更新car count
  1109. if ([[lock_dic objectForKey:@"result"] integerValue] == RESULT_TRUE) {
  1110. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  1111. [dic setValue:orderid forKey:@"order_id"];
  1112. [dic setValue:so forKey:@"so_id"];
  1113. [dic setValue:create_by forKey:@"create_by"];
  1114. [dic setValue:create_time forKey:@"create_time"];
  1115. [dic setValue:[NSNumber numberWithInteger:0] forKey:@"check"]; // 合并到
  1116. [self.mergeList addObject:dic];
  1117. } else {
  1118. [RAUtils message_alert:[lock_dic objectForKey:@"err_msg"] title:@"Warning" controller:self];
  1119. }
  1120. }
  1121. }
  1122. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationFade];
  1123. DebugLog(@"%@",self.mergeList);
  1124. }];
  1125. add2MergeListAction.backgroundColor = UIColorFromRGB(0x336699);
  1126. // Cancel Order Action
  1127. UITableViewRowAction *cancelAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Cancel Order"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1128. DebugLog(@"edit click");
  1129. NSString * title =[NSString stringWithFormat:@"Are you sure to cancel order SO#: %@",so];
  1130. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
  1131. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1132. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Cancel Order"];
  1133. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1134. NSDictionary* return_json = [iSalesNetwork cancel_Order:orderid order_code:nil];
  1135. dispatch_async(dispatch_get_main_queue(), ^{
  1136. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  1137. if([[return_json valueForKey:@"result"] intValue]==2)
  1138. {
  1139. if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
  1140. {
  1141. appDelegate.order_code= nil;
  1142. //appDelegate.user_type = 0;
  1143. appDelegate.customerInfo = nil;
  1144. appDelegate.contact_id = nil;
  1145. appDelegate.order_customer_id = nil;
  1146. [appDelegate SetSo:nil];
  1147. appDelegate.cart_count=0;
  1148. [appDelegate update_count_mark];
  1149. }
  1150. [RAUtils message_alert:nil title:@"Order Canceled" controller:self] ;
  1151. [self ReloadData];
  1152. }
  1153. else
  1154. {
  1155. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Cancel Order" controller:self] ;
  1156. }
  1157. });
  1158. });
  1159. }];
  1160. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1161. DebugLog(@"Cancel");
  1162. }];
  1163. [alertControl addAction:actionOne];
  1164. [alertControl addAction:alertthree];
  1165. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1166. [self presentViewController:alertControl animated:YES completion:nil];
  1167. //
  1168. }];
  1169. cancelAction.backgroundColor = UIColorFromRGB(0xff9933);
  1170. NSMutableArray *actionArr = [NSMutableArray array];
  1171. // 取消订单
  1172. if([order_status isEqualToString:@"Saved Order"]&&appDelegate.can_cancel_order)
  1173. [actionArr addObject:cancelAction];
  1174. if ([Singleton sharedInstance].permissions_merge_order) {// 有合并订单的权限
  1175. if (self.orderType == 0) {// Sales Order不能合并
  1176. [actionArr addObject:add2MergeListAction];
  1177. }
  1178. }
  1179. return actionArr;
  1180. }
  1181. return @[];
  1182. }
  1183. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  1184. if(indexPath.row==self.content_data.count)
  1185. return NO;
  1186. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1187. NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  1188. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  1189. // saved && ((type==0 && merge_permission) || type == 1 || can_cancel)
  1190. // if ([order_status isEqualToString:@"Saved Order"] && (([Singleton sharedInstance].permissions_merge_order && self.orderType == 0) || self.orderType == 1 || appDelegate.can_cancel_order)) {
  1191. // DebugLog(@"%d Yes",indexPath.row);
  1192. // return YES;
  1193. // } else {
  1194. // return NO;
  1195. // }
  1196. BOOL isSavedOrder = [order_status isEqualToString:@"Saved Order"];
  1197. switch (self.orderType) {
  1198. case 0:{ // Shop Order
  1199. if (!isSavedOrder) {
  1200. return NO;
  1201. } else {
  1202. if ([Singleton sharedInstance].permissions_merge_order || appDelegate.can_cancel_order) {
  1203. return YES;
  1204. } else {
  1205. return NO;
  1206. }
  1207. }
  1208. }
  1209. break;
  1210. case 1:{ // Sales Order
  1211. if (isSavedOrder && appDelegate.can_cancel_order) {
  1212. return YES;
  1213. }
  1214. return NO;
  1215. }
  1216. break;
  1217. default:
  1218. break;
  1219. }
  1220. } else {
  1221. return YES;
  1222. }
  1223. return YES;
  1224. }
  1225. - (void)tableView:(UITableView *)tableView
  1226. commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  1227. }
  1228. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  1229. if(indexPath.row==self.content_data.count)
  1230. return UITableViewCellEditingStyleNone;
  1231. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1232. bool offline_edit =[[self.content_data[indexPath.row] valueForKey:@"offline_edit"] boolValue];
  1233. NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  1234. if(![order_status isEqualToString:@"Saved Order"]&&! [order_status isEqualToString:@"Quote Saved"])
  1235. return UITableViewCellEditingStyleNone;
  1236. else
  1237. {
  1238. if(appDelegate.offline_mode==false||offline_edit)
  1239. return UITableViewCellEditingStyleDelete;
  1240. else
  1241. return UITableViewCellEditingStyleNone;
  1242. }
  1243. }
  1244. /*
  1245. #pragma mark - Navigation
  1246. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1247. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1248. // Get the new view controller using [segue destinationViewController].
  1249. // Pass the selected object to the new view controller.
  1250. }
  1251. */
  1252. #pragma mark EnumSelectViewControllerDelegate
  1253. -(void) EnumValueChanged:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  1254. {
  1255. self.status_cadedate = value;
  1256. UIApplication * app = [UIApplication sharedApplication];
  1257. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1258. appDelegate.OrderFilter = value;
  1259. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  1260. // NSString *documents = [paths objectAtIndex:0];
  1261. // NSString *dist_path = [documents stringByAppendingPathComponent:@"status_filter_cadedate.json"];
  1262. //
  1263. //
  1264. // // if ([[NSFileManager defaultManager] fileExistsAtPath:dist_path]) {
  1265. // //
  1266. // // DebugLog(@"文件已经存在了");
  1267. // //
  1268. // // }
  1269. // // else
  1270. // // {
  1271. // //
  1272. // //
  1273. // //
  1274. // // DebugLog(@"resourceSampleImagesFolderPath=%@",resourceFolderPath);
  1275. //
  1276. //NSData *data = [NSJSONSerialization dataWithJSONObject:self.status_cadedate options:kNilOptions error:nil];
  1277. //
  1278. // // DebugLog(@"mainBundleFile==%@",mainBundleFile);
  1279. //
  1280. // [[NSFileManager defaultManager] createFileAtPath:dist_path
  1281. //
  1282. // contents:data
  1283. //
  1284. // attributes:nil];
  1285. //
  1286. // }
  1287. // self.keywords=searchBar.text;
  1288. // self.offset = 0;
  1289. // [self.content_data removeAllObjects];
  1290. self.reset_result=true;
  1291. [self loadpage];
  1292. //[self.btnStatusFilter setTitle:setTitle:alert ];
  1293. }
  1294. #pragma mark - button action
  1295. - (IBAction)mergeListButtonClick:(UIBarButtonItem *)sender {
  1296. if (!self.mergeList.count) {
  1297. [RAUtils message_alert:@"Convert List is Empty" title:nil controller:self];
  1298. return;
  1299. }
  1300. SelectUploadOrderViewController *mergeVC = [[UIStoryboard storyboardWithName:@"OLM" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SelectUploadOrderViewController"];
  1301. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:mergeVC];
  1302. mergeVC.mergeList = self.mergeList;
  1303. mergeVC.title = @"Convert List";
  1304. __weak typeof(self) weakself = self;
  1305. mergeVC.mergeBlock = ^(NSDictionary *ret) {
  1306. if (weakself) {
  1307. __strong typeof(weakself) strongself = weakself;
  1308. if([[ret objectForKey:@"result"]integerValue] == RESULT_TRUE) {
  1309. [weakself.mergeList removeAllObjects];
  1310. [strongself ReloadData];
  1311. } else {
  1312. NSString *msg = [ret objectForKey:@"err_msg"];
  1313. [RAUtils message_alert:msg title:nil controller:strongself];
  1314. }
  1315. }
  1316. };
  1317. nav.modalPresentationStyle = UIModalPresentationFormSheet;
  1318. [self presentViewController:nav animated:YES completion:nil];
  1319. }
  1320. - (void)changeOrderType:(NSInteger)ordertype {
  1321. self.orderType = ordertype;
  1322. [Singleton sharedInstance].customer_order_type = ordertype;
  1323. switch (ordertype) {
  1324. case 0:{
  1325. self.status_cadedate = self.shop_order_filter;
  1326. }
  1327. break;
  1328. case 1:{
  1329. self.status_cadedate = self.sales_order_filter;
  1330. }
  1331. break;
  1332. default:
  1333. break;
  1334. }
  1335. [self ReloadData];
  1336. }
  1337. - (IBAction)orderTypeChanged:(UISegmentedControl *)sender {
  1338. [self changeOrderType:sender.selectedSegmentIndex];
  1339. }
  1340. #pragma mark - notification action
  1341. - (void)changePriceType:(id)notification {
  1342. [self ReloadData];
  1343. }
  1344. - (void)lockOrderListNotification:(NSNotification *)notification {
  1345. if ([notification.name isEqual:Lock_Permission_Notification]) {
  1346. if (self.orderType == 1) {
  1347. self.orderTypeSegmentControl.selectedSegmentIndex = 0;
  1348. // [self changeOrderType:0];
  1349. [self.orderTypeSegmentControl sendActionsForControlEvents:UIControlEventValueChanged];
  1350. }
  1351. if(self.orderTypeSegmentControl.numberOfSegments > 1) {
  1352. [self.orderTypeSegmentControl removeSegmentAtIndex:1 animated:YES];
  1353. }
  1354. } else { // 解锁
  1355. if ([Singleton sharedInstance].customer_can_see_sales_Order) { // 有查看Sales order 权限
  1356. if (self.orderTypeSegmentControl.numberOfSegments == 1) {
  1357. [self.orderTypeSegmentControl insertSegmentWithTitle:@"Sales Order" atIndex:1 animated:YES];
  1358. }
  1359. }
  1360. }
  1361. }
  1362. - (void)handleUserLogin:(NSNotification *)notification {
  1363. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1364. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1365. self.orderTypeSegmentControl.selectedSegmentIndex = 0;
  1366. }
  1367. }
  1368. @end