OrderListViewController.m 77 KB

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