ScanOrderListViewController.m 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215
  1. //
  2. // ScanOrderListViewController.m
  3. // iSales-USAI
  4. //
  5. // Created by Rui Zhang on 2/8/22.
  6. // Copyright © 2022 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "ScanOrderListViewController.h"
  9. #import "OrderListTableViewCell.h"
  10. #import "RANetwork.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 "RASingleton.h"
  19. #import "ERPUtils.h"
  20. #import "UploadCell.h"
  21. #import "CustomerEditViewController.h"
  22. #import "CreateOrderViewController.h"
  23. #import "MainViewController.h"
  24. @interface ScanOrderListViewController ()
  25. @property (nonatomic,strong) NSOperationQueue *dataOperationQueue;
  26. @property (nonatomic,strong) NSMutableArray *mergeList;
  27. @property (nonatomic,assign) NSInteger orderType;///<sales order/shop order
  28. @property (nonatomic,strong) NSMutableDictionary *sales_order_filter;
  29. @property (nonatomic,strong) NSMutableDictionary *shop_order_filter;
  30. @property (strong, nonatomic) IBOutlet UIBarButtonItem *mergeListButton;
  31. @property (strong, nonatomic) IBOutlet UIBarButtonItem *editOrderListButton;
  32. @property (strong, nonatomic) IBOutlet UISegmentedControl *orderTypeSegmentControl;
  33. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableTopConstraint;
  34. @end
  35. @implementation ScanOrderListViewController
  36. - (NSOperationQueue *)dataOperationQueue {
  37. if (!_dataOperationQueue) {
  38. _dataOperationQueue = [[NSOperationQueue alloc] init];
  39. _dataOperationQueue.maxConcurrentOperationCount = 1;
  40. }
  41. return _dataOperationQueue;
  42. }
  43. - (void)dealloc {
  44. [[NSNotificationCenter defaultCenter] removeObserver:self];
  45. AppDelegate* appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  46. [appdelegate.uploadManager removeObserver:self forKeyPath:@"arr_queue"];
  47. }
  48. - (NSMutableArray *)mergeList {
  49. if (!_mergeList) {
  50. _mergeList = [NSMutableArray array];
  51. }
  52. return _mergeList;
  53. }
  54. -(void) logout
  55. {
  56. [self.mergeList removeAllObjects];
  57. self.offset = 0;
  58. [self.content_data removeAllObjects];
  59. [self.submit_content_data removeAllObjects];
  60. [self.table_order reloadData];
  61. [self.table_submit reloadData];
  62. self.status_cadedate = nil;
  63. }
  64. #ifndef RA_NOTIFICATION
  65. -(void) reload_container_getdata:(bool) update_data
  66. {
  67. [super reload_container_getdata:update_data];
  68. if(update_data)
  69. {
  70. // self.offset = 0;
  71. // [self.content_data removeAllObjects];
  72. self.reset_result=true;
  73. self.norefresh=true;
  74. [self reload_data];
  75. }
  76. else
  77. {
  78. [self.table_order reloadData];
  79. }
  80. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  81. if(appDelegate.can_create_order)
  82. {
  83. [self.btn_newOrder setImage:[UIImage imageNamed:@"neworder"]];
  84. self.btn_newOrder.enabled = true;
  85. }
  86. else
  87. {
  88. [self.btn_newOrder setImage:nil];
  89. self.btn_newOrder.enabled = false;
  90. }
  91. }
  92. #endif
  93. -(void) showHidePrice
  94. {
  95. #ifndef RA_NOTIFICATION
  96. [self reload_container_getdata:false];
  97. #endif
  98. }
  99. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
  100. {
  101. if([keyPath isEqualToString:@"arr_queue"])
  102. {
  103. // NSArray* arr1 = [change objectForKey:NSKeyValueChangeOldKey];
  104. // NSArray* arr2 = [change objectForKey:NSKeyValueChangeNewKey];
  105. // if(arr1.count!=arr2.count)
  106. __weak typeof(self) weakself = self;
  107. dispatch_async(dispatch_get_main_queue(), ^{
  108. blockDebugLog(@"arr_queue changed reload tableview");
  109. [self.table_upload reloadData];
  110. });
  111. }
  112. // if(context)
  113. // NSLog(@"old: %@", [change objectForKey:NSKeyValueChangeOldKey]);
  114. // NSLog(@"old: %@", [change objectForKey:NSKeyValueChangeNewKey]);
  115. // NSLog(@"context: %@", context);
  116. }
  117. - (void)onNewOrder: (NSNotification *)notification
  118. {
  119. [self onNewOrderClicked:nil];
  120. }
  121. - (void)onShowList: (NSNotification *)notification
  122. {
  123. if([notification.name isEqualToString:@"ShowUnSubmit"])
  124. {
  125. [self.orderTypeSegmentControl setSelectedSegmentIndex:0];
  126. self.table_order.hidden=false;
  127. self.table_submit.hidden = true;
  128. // [self.table_upload reloadData];
  129. [self.table_order reloadData];
  130. [self.table_submit reloadData];
  131. // onSegmentChanged
  132. }
  133. else
  134. {
  135. [self.orderTypeSegmentControl setSelectedSegmentIndex:1];
  136. self.table_order.hidden=true;
  137. self.table_submit.hidden = false;
  138. // [self.table_order reloadData];
  139. [self.table_order reloadData];
  140. [self.table_submit reloadData];
  141. }
  142. }
  143. - (void)viewDidLoad {
  144. [super viewDidLoad];
  145. // self.edgesForExtendedLayout = UIRectEdgeNone;
  146. self.loading_queue = dispatch_queue_create("orderlist_loading", NULL);
  147. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  148. self.label_net_err.layer.borderWidth = 2.0;
  149. self.label_net_err.layer.cornerRadius=15;
  150. self.label_net_err.layer.masksToBounds=true;
  151. #ifndef RA_NOTIFICATION
  152. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changePriceType:) name:Change_Price_Type_Notification object:nil];
  153. #endif
  154. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(lockOrderListNotification:) name:Lock_Permission_Notification object:nil];
  155. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(lockOrderListNotification:) name:unLock_Permission_Notification object:nil];
  156. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleUserLogin:) name:User_LoginOK_Notification object:nil];
  157. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onNewOrder:) name:@"NewOrder" object:nil];
  158. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onShowList:) name:@"ShowSubmit" object:nil];
  159. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onShowList:) name:@"ShowUnSubmit" object:nil];
  160. AppDelegate* appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  161. [appdelegate.uploadManager addObserver:self
  162. forKeyPath:@"arr_queue"
  163. options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
  164. context:@"arr_queue changed"];
  165. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  166. // tap.minimumPressDuration = 0.8; //定义按的时间
  167. [self.label_net_err addGestureRecognizer:tap];
  168. // Do any additional setup after loading the view.
  169. self.offset = 0;
  170. self.limit = 25;
  171. self.content_data = [[NSMutableArray alloc]init];
  172. self.submit_content_data = [[NSMutableArray alloc]init];
  173. // Customer Order Type 0 Shop Order/ 1 Sales Order
  174. // self.orderType = self.orderTypeSegmentControl.selectedSegmentIndex;
  175. [RASingleton sharedInstance].customer_order_type = self.orderType;
  176. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  177. ref.tag = 201 ;
  178. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  179. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  180. // ref.hidden = true;
  181. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  182. [self.table_order addSubview:ref];
  183. self.table_order.allowsMultipleSelectionDuringEditing = YES;
  184. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  185. // NSString *documents = [paths objectAtIndex:0];
  186. // NSString *dist_path = [documents stringByAppendingPathComponent:@"status_filter_cadedate.json"];
  187. // if ([[NSFileManager defaultManager] fileExistsAtPath:dist_path]) {
  188. //
  189. // DebugLog(@"文件已经存在了");
  190. //
  191. // }
  192. // else
  193. // {
  194. //
  195. //
  196. //
  197. // // DebugLog(@"resourceSampleImagesFolderPath=%@",resourceFolderPath);
  198. //
  199. // NSData *mainBundleFile = [NSData dataWithContentsOfFile:order_filter_source_path];
  200. //
  201. // // DebugLog(@"mainBundleFile==%@",mainBundleFile);
  202. //
  203. // [[NSFileManager defaultManager] createFileAtPath:dist_path
  204. //
  205. // contents:mainBundleFile
  206. //
  207. // attributes:nil];
  208. //
  209. // }
  210. [self loadfilter];
  211. }
  212. -(void) loadfilter
  213. {
  214. //
  215. // if(self.status_cadedate!=nil)
  216. // return;
  217. //
  218. // UIApplication * app = [UIApplication sharedApplication];
  219. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  220. //
  221. // if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  222. // self.shop_order_filter = [RASingleton sharedInstance].shop_order_status_filter;
  223. // self.sales_order_filter = [RASingleton sharedInstance].sales_order_status_filter;
  224. // if(self.init_style==OL_OPEN)
  225. // {
  226. // NSData *data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"status_filter_cadedate_open" ofType:@"json" ]];
  227. // NSError *error=nil;
  228. // self.status_cadedate = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  229. //
  230. // }
  231. //// else if (self.orderTypeSegmentControl.selectedSegmentIndex == 0) {
  232. //// self.status_cadedate = self.shop_order_filter;
  233. //// } else {
  234. //// self.status_cadedate = self.sales_order_filter;
  235. //// }
  236. // return;
  237. // }
  238. //
  239. // NSData* json =nil;
  240. // if(self.init_style==OL_OPEN)
  241. // {
  242. // json=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"status_filter_cadedate_open" ofType:@"json" ]];
  243. // NSError *error=nil;
  244. // self.status_cadedate = [[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  245. //
  246. // }
  247. // else
  248. // {
  249. // // json=//[NSData dataWithContentsOfFile:dist_path];
  250. // // NSError *error=nil;
  251. // self.status_cadedate = appDelegate.OrderFilter;//[[NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  252. // }
  253. }
  254. - (IBAction)onCancel:(id)sender {
  255. if(self.onCancel)
  256. self.onCancel();
  257. [self.navigationController popViewControllerAnimated:false];
  258. }
  259. - (IBAction)onStatusFilterClick:(id)sender {
  260. // if (self.table_order.isEditing || self.init_style == OL_OPEN) {
  261. // return;
  262. // }
  263. // EnumSelectViewController* enumvc =[[UIStoryboard storyboardWithName:@"CommonEditor" bundle:nil] instantiateViewControllerWithIdentifier:@"EnumSelectorViewController"];
  264. // enumvc.delegate = self;
  265. // enumvc.max_select = 0;
  266. // //enumvc.updatePosition = indexPath;
  267. // // if([[required lowercaseString] isEqualToString:@"true"])
  268. // // enumvc.canbeEmpty = false;
  269. // // else
  270. // // enumvc.canbeEmpty =true;
  271. // enumvc.cadedate = self.status_cadedate ;
  272. // enumvc.title = @"Order Status Selection";
  273. // // enumvc.value = [value_json mutableCopy];
  274. // enumvc.single_select =false;
  275. //
  276. // [self.navigationController pushViewController:enumvc animated:true];
  277. }
  278. - (void)viewWillAppear:(BOOL)animated
  279. {
  280. [super viewWillAppear:animated];
  281. [self loadfilter];
  282. [[self navigationController] setNavigationBarHidden:!self.showNavibar animated:NO];
  283. // 检查权限
  284. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  285. NSMutableArray *items = [self.toolbarView.items mutableCopy];
  286. if(appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  287. // Check for Saved Order中Type和History Type不一致导致Status不正确
  288. [RASingleton sharedInstance].customer_order_type = self.orderType;
  289. // if (!self.table_order.isEditing) { // 在编辑状态下不能change Type否则显示混乱
  290. // [self changeOrderType:self.orderType];
  291. // }
  292. // 合并订单的权限
  293. if ([RASingleton sharedInstance].permissions_merge_order) { // 能够合并
  294. // 4 6 顺序不能换
  295. if (![items containsObject:self.editOrderListButton]) { // 没显示button
  296. [items insertObject:self.editOrderListButton atIndex:4];
  297. }
  298. self.toolbarView.items = items;
  299. } else { // 不能合并
  300. if ([items containsObject:self.editOrderListButton]) { // 显示button
  301. [items removeObject:self.editOrderListButton];
  302. }
  303. self.toolbarView.items = items;
  304. }
  305. // // Check For Saved Order 不能合并
  306. // if(self.init_style==OL_OPEN || self.orderType == 1) {
  307. //
  308. // if ([items containsObject:self.editOrderListButton]) { // 显示button
  309. // [items removeObject:self.editOrderListButton];
  310. // }
  311. //
  312. // self.toolbarView.items = items;
  313. //
  314. // }
  315. } else {
  316. if ([items containsObject:self.editOrderListButton]) { // 显示button
  317. [items removeObject:self.editOrderListButton];
  318. }
  319. self.toolbarView.items = items;
  320. }
  321. // 非Customer用户不用区分Sales Order 和 Shop Order
  322. {
  323. self.orderTypeSegmentControl.hidden = NO;
  324. // [self.view removeConstraint:self.tableTopConstraint];
  325. //
  326. //
  327. // NSLayoutConstraint *myConstraint =[NSLayoutConstraint
  328. // constraintWithItem:self.table_order //item1
  329. // attribute:NSLayoutAttributeTop //约束属性
  330. // relatedBy:NSLayoutRelationEqual //属性间的关系
  331. // toItem:self.orderTypeSegmentControl//item2
  332. // attribute:NSLayoutAttributeBottom//约束属性
  333. // multiplier:1
  334. // constant:0.0];// 固定距离
  335. // self.tableTopConstraint = myConstraint;
  336. // [self.view addConstraint: myConstraint];//为button重新添加一个约束
  337. //
  338. //
  339. //
  340. // CGFloat y = CGRectGetMinY(self.orderTypeSegmentControl.frame);
  341. // CGFloat height = CGRectGetHeight(self.orderTypeSegmentControl.frame);
  342. // CGRect frame = self.table_order.frame;
  343. // if (frame.origin.y == y) {
  344. // frame.origin.y = y + height;
  345. // frame.size.height -= height;
  346. // }
  347. // self.table_order.frame = frame;
  348. }
  349. // 修复Homer显示NPD
  350. // if (self.orderTypeSegmentControl.numberOfSegments > 1) {
  351. // [self.orderTypeSegmentControl setTitle:[NSString stringWithFormat:@"Purchase Order to %@",COMPANY_SHORT_NAME] forSegmentAtIndex:1];
  352. // }
  353. //
  354. // // 显示Sales Order与否
  355. // if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  356. // if ([RASingleton sharedInstance].global_lock || ![RASingleton sharedInstance].customer_can_see_sales_Order) { // 是否解锁,是否有查看Sales Order权限
  357. // if (self.orderTypeSegmentControl.numberOfSegments > 1) {
  358. // [self.orderTypeSegmentControl removeSegmentAtIndex:1 animated:YES];
  359. // [self changeOrderType:0];
  360. // }
  361. // } else {
  362. //
  363. // if (self.orderTypeSegmentControl.numberOfSegments == 1 && !self.table_order.isEditing) {
  364. // [self.orderTypeSegmentControl insertSegmentWithTitle:[NSString stringWithFormat:@"Purchase Order to %@",COMPANY_SHORT_NAME] atIndex:1 animated:YES];
  365. // }
  366. //
  367. // }
  368. // }
  369. }
  370. -(void) newoloorder
  371. {
  372. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  373. appDelegate.can_set_cart_price = true;
  374. appDelegate.can_see_price = true;
  375. RASingleton.sharedInstance.scan_cart = nil;
  376. RASingleton.sharedInstance.price_type = 1;
  377. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  378. // NSString *documents = [paths objectAtIndex:0];
  379. {
  380. NSString *orderdir = [OLDataProvider getScanPath];
  381. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  382. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  383. }
  384. #ifdef RA_NOTIFICATION
  385. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  386. #else
  387. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  388. [main_vc reloadCart:true immediately:false];
  389. #endif
  390. // MainViewController * mainvc=(MainViewController * )appDelegate.main_vc;
  391. // mainvc.btnScan.enabled = true;
  392. // [appDelegate updateScanButton:true];
  393. // AppDelegate* appDelegate = (AppDelegate*)UIApplication.sharedApplication.delegate;
  394. MainViewController * mainvc = (MainViewController*)appDelegate.main_vc;
  395. // [ActiveViewController Notify:@"ScanOrderListViewController" Message:@"NewOrder"];
  396. [mainvc switchToCart];
  397. }
  398. - (IBAction)onNewOrderClicked:(id)sender {
  399. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  400. if(appDelegate.order_code.length>0)
  401. {
  402. // // 当前订单先关闭
  403. [OLDataProvider scanCloseOrder];
  404. }
  405. {
  406. [self newoloorder];
  407. }
  408. }
  409. - (void)didReceiveMemoryWarning {
  410. [super didReceiveMemoryWarning];
  411. // Dispose of any resources that can be recreated.
  412. }
  413. -(void)manually_refresh
  414. {
  415. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
  416. if(self.isrefreshing)
  417. {
  418. [reF endRefreshing];
  419. return;
  420. }
  421. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  422. if ([self respondsToSelector:@selector(ReloadData)])
  423. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  424. }
  425. -(void)ReloadData
  426. {
  427. // [self.content_data removeAllObjects];
  428. // [self.table_order reloadData];
  429. // self.table_order.hidden = true;
  430. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
  431. [reF endRefreshing];
  432. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  433. self.keywords=nil;
  434. // self.offset = 0;
  435. self.reset_result=true;
  436. // [self.content_data removeAllObjects];
  437. // [self.table_order reloadData];
  438. [self loadpage];
  439. // [self loadpage];
  440. }
  441. - (void)operation_loadPage {
  442. if (self.dataOperationQueue.operationCount > 1) { // 队列后面还有操作
  443. return;
  444. }
  445. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  446. // NSString *documents = [paths objectAtIndex:0];
  447. NSString *userdir = [OLDataProvider getUserPath];
  448. NSMutableDictionary* orderlist = [OLDataProvider getScanOrderList];
  449. // NSString *orderlistPath = [userdir stringByAppendingPathComponent:@"orderlist.json"];
  450. // orderlist=[[RAUtils dictfromfile:orderlistPath] mutableCopy];
  451. [self.content_data removeAllObjects];
  452. int count = [orderlist[@"count"] intValue];
  453. for(int i=0;i<count;i++)
  454. {
  455. NSDictionary* objmsg = [orderlist objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  456. [self.content_data addObject:[NSMutableDictionary dictionaryWithDictionary:objmsg]];
  457. }
  458. NSMutableDictionary* submitlist = [OLDataProvider getScanSubmitList];
  459. // NSString *submitlistPath = [userdir stringByAppendingPathComponent:@"submitlist.json"];
  460. // submitlist=[[RAUtils dictfromfile:submitlistPath] mutableCopy];
  461. [self.submit_content_data removeAllObjects];
  462. int scount = [submitlist[@"count"] intValue];
  463. for(int i=0;i<scount;i++)
  464. {
  465. NSDictionary* objmsg = [submitlist objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  466. [self.submit_content_data addObject:[NSMutableDictionary dictionaryWithDictionary:objmsg]];
  467. }
  468. // int i =self.btnrefresh.state;
  469. self.load_more_hint=@"All loaded";
  470. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"no_more", nil);
  471. // [self.btnrefresh setTitle:@"No more" forState:UIControlStateNormal];
  472. dispatch_sync(dispatch_get_main_queue(), ^{
  473. // self.table_order.hidden = false;
  474. // self.table_submit.hidden = false;
  475. self.reset_result=false;
  476. [self.table_order reloadData ];
  477. [self.table_submit reloadData ];
  478. });
  479. return;
  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. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
  510. PopWaitAlert* pop = [RAUtils waiting_pop:@"Create Order" completion:nil];
  511. [RANetwork request_create_order:^(NSMutableDictionary *result) {
  512. NSMutableDictionary* return_json =result;
  513. // [waitalert dismissViewControllerAnimated:YES completion:^{
  514. [pop hide];
  515. if([[return_json valueForKey:@"result"] intValue]==2)
  516. {
  517. int result=[[return_json valueForKey:@"result"] intValue];
  518. if(result==2)
  519. {
  520. //successed.
  521. NSString* order_code = [return_json valueForKey:@"orderCode"];
  522. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  523. appDelegate.order_code = order_code;
  524. appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  525. #ifdef RA_NOTIFICATION
  526. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  527. #else
  528. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  529. [main_vc reloadCart:true immediately:false];
  530. #endif
  531. [self ReloadData];
  532. }
  533. }
  534. else
  535. {
  536. [RAUtils message_box:@"Create Order" message:[return_json valueForKey:@"err_msg"] completion:nil];
  537. }
  538. // }];
  539. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  540. }];
  541. }
  542. #pragma mark - Table view data source
  543. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  544. {
  545. if(tableView==self.table_order||tableView==self.table_submit)
  546. return 66;
  547. else
  548. return 100;
  549. }
  550. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  551. //{
  552. // return 0;
  553. //}
  554. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  555. //{
  556. // return 0;
  557. //}
  558. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  559. //{
  560. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  561. // return myView;
  562. //
  563. //}
  564. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  565. {
  566. if(tableView==self.table_order)
  567. {
  568. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  569. if(value==nil)
  570. value=@"";
  571. unsigned long color = strtoul([value UTF8String],0,16);
  572. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  573. // myView.backgroundColor = UIColorFromRGB(0x996633);
  574. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  575. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  576. myView.layer.shadowOffset = CGSizeMake(0, 0);
  577. myView.layer.shadowOpacity = 0.5;
  578. myView.layer.shadowRadius = 2.0;
  579. UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 11, 130, 22)];
  580. statuslabel.textColor=UIColorFromRGB(color);
  581. statuslabel.backgroundColor = [UIColor clearColor];
  582. statuslabel.text=NSLocalizedString(@"Status", nil);
  583. [statuslabel sizeToFit];
  584. [myView addSubview:statuslabel];
  585. // UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 21, 130, 22)];
  586. // solabel.textColor=UIColorFromRGB(color);
  587. // solabel.backgroundColor = [UIColor clearColor];
  588. // solabel.text=NSLocalizedString(@"SO#", nil);
  589. // [solabel sizeToFit];
  590. // [myView addSubview:solabel];
  591. // UILabel *userlabel = [[UILabel alloc] initWithFrame:CGRectMake(165, 21, 125, 22)];
  592. // userlabel.textColor=UIColorFromRGB(color);
  593. // userlabel.backgroundColor = [UIColor clearColor];
  594. // userlabel.text=NSLocalizedString(@"Sales rep", nil);
  595. // [userlabel sizeToFit];
  596. // [myView addSubview:userlabel];
  597. UILabel *creatorlabel = [[UILabel alloc] initWithFrame:CGRectMake(165, 11, 125, 22)];
  598. creatorlabel.textColor=UIColorFromRGB(color);
  599. creatorlabel.backgroundColor = [UIColor clearColor];
  600. creatorlabel.text=NSLocalizedString(@"Create by", nil);
  601. [creatorlabel sizeToFit];
  602. [myView addSubview:creatorlabel];
  603. UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(296, 11, 150, 22)];
  604. contactlabel.textColor=UIColorFromRGB(color);
  605. contactlabel.backgroundColor = [UIColor clearColor];
  606. contactlabel.text=NSLocalizedString(@"Company / Contact ID", nil);
  607. [contactlabel sizeToFit];
  608. [myView addSubview:contactlabel];
  609. //
  610. // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(424, 11, 52, 22)];
  611. // modellabel.textColor=[UIColor whiteColor];
  612. // modellabel.backgroundColor = [UIColor clearColor];
  613. // modellabel.text=NSLocalizedString(@"Model", nil);
  614. // [modellabel sizeToFit];
  615. // [myView addSubview:modellabel];
  616. // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-276, 2, 100, 22)];
  617. // modellabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  618. // modellabel.textColor=[UIColor whiteColor];
  619. // modellabel.backgroundColor = [UIColor clearColor];
  620. // modellabel.text=NSLocalizedString(@"Items/QTY", nil);
  621. // [modellabel sizeToFit];
  622. // [myView addSubview:modellabel];
  623. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  624. UILabel *pricelabel = nil;
  625. if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType==1)
  626. pricelabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 2, 100, 22)];
  627. else
  628. pricelabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 11, 100, 22)];
  629. pricelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  630. pricelabel.textColor=UIColorFromRGB(color);
  631. pricelabel.backgroundColor = [UIColor clearColor];
  632. pricelabel.text=NSLocalizedString(@"Order Total", nil);
  633. [pricelabel sizeToFit];
  634. [myView addSubview:pricelabel];
  635. if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType==1)
  636. {
  637. UILabel *polabel = nil;
  638. polabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 21, 100, 22)];
  639. polabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  640. polabel.textColor=UIColorFromRGB(color);
  641. polabel.backgroundColor = [UIColor clearColor];
  642. polabel.text=NSLocalizedString(@"PO#", nil);
  643. [polabel sizeToFit];
  644. [myView addSubview:polabel];
  645. }
  646. UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-163/*605*/,11, 148, 22)];
  647. timelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  648. timelabel.textColor=UIColorFromRGB(color);
  649. timelabel.backgroundColor = [UIColor clearColor];
  650. if(self.time_zone==nil)
  651. timelabel.text=@"Create time";
  652. else
  653. timelabel.text=[NSString stringWithFormat:@"Create time (%@)",self.time_zone];
  654. [timelabel sizeToFit];
  655. [myView addSubview:timelabel];
  656. myView.autoresizesSubviews=true;
  657. // [myView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];
  658. // modellabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  659. // pricelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  660. // timelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  661. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  662. //
  663. return myView;
  664. }
  665. else
  666. if(tableView==self.table_submit)
  667. {
  668. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  669. if(value==nil)
  670. value=@"";
  671. unsigned long color = strtoul([value UTF8String],0,16);
  672. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  673. // myView.backgroundColor = UIColorFromRGB(0x996633);
  674. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  675. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  676. myView.layer.shadowOffset = CGSizeMake(0, 0);
  677. myView.layer.shadowOpacity = 0.5;
  678. myView.layer.shadowRadius = 2.0;
  679. UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 11, 130, 22)];
  680. statuslabel.textColor=UIColorFromRGB(color);
  681. statuslabel.backgroundColor = [UIColor clearColor];
  682. statuslabel.text=NSLocalizedString(@"SO#", nil);
  683. [statuslabel sizeToFit];
  684. [myView addSubview:statuslabel];
  685. // UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 21, 130, 22)];
  686. // solabel.textColor=UIColorFromRGB(color);
  687. // solabel.backgroundColor = [UIColor clearColor];
  688. // solabel.text=NSLocalizedString(@"SO#", nil);
  689. // [solabel sizeToFit];
  690. // [myView addSubview:solabel];
  691. // UILabel *userlabel = [[UILabel alloc] initWithFrame:CGRectMake(165, 21, 125, 22)];
  692. // userlabel.textColor=UIColorFromRGB(color);
  693. // userlabel.backgroundColor = [UIColor clearColor];
  694. // userlabel.text=NSLocalizedString(@"Sales rep", nil);
  695. // [userlabel sizeToFit];
  696. // [myView addSubview:userlabel];
  697. UILabel *creatorlabel = [[UILabel alloc] initWithFrame:CGRectMake(165, 11, 125, 22)];
  698. creatorlabel.textColor=UIColorFromRGB(color);
  699. creatorlabel.backgroundColor = [UIColor clearColor];
  700. creatorlabel.text=NSLocalizedString(@"Create by", nil);
  701. [creatorlabel sizeToFit];
  702. [myView addSubview:creatorlabel];
  703. UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(296, 11, 150, 22)];
  704. contactlabel.textColor=UIColorFromRGB(color);
  705. contactlabel.backgroundColor = [UIColor clearColor];
  706. contactlabel.text=NSLocalizedString(@"Company / Customer ID", nil);
  707. [contactlabel sizeToFit];
  708. [myView addSubview:contactlabel];
  709. //
  710. // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(424, 11, 52, 22)];
  711. // modellabel.textColor=[UIColor whiteColor];
  712. // modellabel.backgroundColor = [UIColor clearColor];
  713. // modellabel.text=NSLocalizedString(@"Model", nil);
  714. // [modellabel sizeToFit];
  715. // [myView addSubview:modellabel];
  716. // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-276, 2, 100, 22)];
  717. // modellabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  718. // modellabel.textColor=[UIColor whiteColor];
  719. // modellabel.backgroundColor = [UIColor clearColor];
  720. // modellabel.text=NSLocalizedString(@"Items/QTY", nil);
  721. // [modellabel sizeToFit];
  722. // [myView addSubview:modellabel];
  723. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  724. UILabel *pricelabel = nil;
  725. if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType==1)
  726. pricelabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 2, 100, 22)];
  727. else
  728. pricelabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 11, 100, 22)];
  729. pricelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  730. pricelabel.textColor=UIColorFromRGB(color);
  731. pricelabel.backgroundColor = [UIColor clearColor];
  732. pricelabel.text=NSLocalizedString(@"Order Total", nil);
  733. [pricelabel sizeToFit];
  734. [myView addSubview:pricelabel];
  735. if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType==1)
  736. {
  737. UILabel *polabel = nil;
  738. polabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 21, 100, 22)];
  739. polabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  740. polabel.textColor=UIColorFromRGB(color);
  741. polabel.backgroundColor = [UIColor clearColor];
  742. polabel.text=NSLocalizedString(@"PO#", nil);
  743. [polabel sizeToFit];
  744. [myView addSubview:polabel];
  745. }
  746. UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-163/*605*/,11, 148, 22)];
  747. timelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  748. timelabel.textColor=UIColorFromRGB(color);
  749. timelabel.backgroundColor = [UIColor clearColor];
  750. if(self.time_zone==nil)
  751. timelabel.text=@"Create time";
  752. else
  753. timelabel.text=[NSString stringWithFormat:@"Create time (%@)",self.time_zone];
  754. [timelabel sizeToFit];
  755. [myView addSubview:timelabel];
  756. myView.autoresizesSubviews=true;
  757. // [myView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];
  758. // modellabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  759. // pricelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  760. // timelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  761. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  762. //
  763. return myView;
  764. }
  765. else return nil;
  766. }
  767. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  768. {
  769. return 44;
  770. }
  771. //
  772. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  773. // if(section==0)
  774. // return nil;
  775. // else
  776. // return @"detail section";
  777. //}
  778. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  779. {
  780. return 1;
  781. }
  782. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  783. {
  784. if(tableView==self.table_order)
  785. {
  786. return self.content_data.count;
  787. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  788. // if( self.content_data.count==0)
  789. // return 0;
  790. // return self.content_data.count+1;
  791. }
  792. if(tableView==self.table_submit)
  793. {
  794. return self.submit_content_data.count;
  795. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  796. // if( self.content_data.count==0)
  797. // return 0;
  798. // return self.content_data.count+1;
  799. }
  800. else
  801. {
  802. AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  803. return Appdelegate.uploadManager.arr_queue.count;
  804. }
  805. }
  806. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  807. {
  808. if(tableView==self.table_order)
  809. {
  810. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  811. // if(tableView==self.itemListTable)
  812. // {
  813. // if(indexPath.row>self.content_data.count)
  814. // {
  815. // int debug=true;
  816. // }
  817. // DebugLog(@"row %ld",(long)indexPath.row);
  818. // if(indexPath.row==self.content_data.count)
  819. // {
  820. // UITableViewCell *moreCell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"mores"];
  821. // UILabel *moreDataLabel=[[UILabel alloc] init];
  822. //
  823. // moreDataLabel.tag=200;
  824. // moreDataLabel.text=self.load_more_hint;
  825. // [moreDataLabel setFont:[UIFont systemFontOfSize:14.0f]];
  826. // [moreDataLabel setTextAlignment:NSTextAlignmentCenter];
  827. // moreDataLabel.frame=CGRectMake(0, 10, self.table_order.bounds.size.width, 20);
  828. // [moreDataLabel setBackgroundColor:[UIColor clearColor]];
  829. // moreDataLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
  830. // // [moreDataLabel addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
  831. //
  832. // [moreCell.contentView addSubview:moreDataLabel];
  833. // if([self.load_more_hint isEqualToString:@"Load more..."])
  834. // [self performSelector:@selector(loadmore) withObject:nil afterDelay:1];
  835. // // DebugLog(@"更多...");
  836. // moreCell.backgroundColor = [UIColor whiteColor];
  837. // return moreCell;
  838. // }
  839. // else
  840. {
  841. NSString *CellIdentifier = @"OrderListTableViewCell";
  842. OrderListTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  843. NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"];
  844. NSString* price= [self.content_data[indexPath.row] valueForKey:@"price"];
  845. // if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  846. // {
  847. //
  848. // }
  849. // else
  850. // {
  851. // price=nil;
  852. // }
  853. //
  854. // NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  855. NSString* purchase_time= [self.content_data[indexPath.row] valueForKey:@"purchase_time"];
  856. NSString* status = [self.content_data[indexPath.row] valueForKey:@"order_status"] ;
  857. // if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  858. // status = [ERPUtils orderStatus:statusCode];
  859. // }
  860. NSString* customer_name = [self.content_data[indexPath.row] valueForKey:@"customer_name"];
  861. NSString* model_count = [self.content_data[indexPath.row] valueForKey:@"model_count"];
  862. NSString* sales = [self.content_data[indexPath.row] valueForKey:@"sales_rep"];
  863. NSString* creator = [self.content_data[indexPath.row] valueForKey:@"create_by"];
  864. NSString *po = [self.content_data[indexPath.row] valueForKey:@"po_id"];
  865. CGRect price_frame = cell.labelprice.frame;
  866. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType == 1) {
  867. cell.label_po.hidden = NO;
  868. price_frame.origin.y = 5;
  869. cell.label_po.text = po;
  870. } else {
  871. cell.label_po.hidden = YES;
  872. price_frame.origin.y = 21;
  873. }
  874. cell.labelprice.frame = price_frame;
  875. cell.label_so.text=so;
  876. cell.labelprice.text=price;//price;
  877. cell.label_date.text=purchase_time;
  878. cell.label_contact.text=customer_name;
  879. cell.label_model.hidden = false;
  880. cell.label_model.text = model_count;
  881. cell.label_sales.text = sales;
  882. cell.label_creator.text = creator;
  883. cell.label_status.text=status;
  884. cell.backgroundColor = [UIColor whiteColor];
  885. return cell;
  886. }
  887. }
  888. else if(tableView==self.table_submit)
  889. {
  890. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  891. {
  892. NSString *CellIdentifier = @"OrderListTableViewCell";
  893. OrderListTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  894. NSString* so= [self.submit_content_data[indexPath.row] valueForKey:@"so#"];
  895. NSString* price= [self.submit_content_data[indexPath.row] valueForKey:@"price"];
  896. // if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  897. // {
  898. //
  899. // }
  900. // else
  901. // {
  902. // price=nil;
  903. // }
  904. //
  905. // NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  906. NSString* purchase_time= [self.submit_content_data[indexPath.row] valueForKey:@"purchase_time"];
  907. NSString* status = [self.submit_content_data[indexPath.row] valueForKey:@"order_status"] ;
  908. // if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  909. // status = [ERPUtils orderStatus:statusCode];
  910. // }
  911. NSString* customer_name = [self.submit_content_data[indexPath.row] valueForKey:@"customer_name"];
  912. NSString* model_count = [self.submit_content_data[indexPath.row] valueForKey:@"model_count"];
  913. NSString* sales = [self.submit_content_data[indexPath.row] valueForKey:@"sales_rep"];
  914. NSString* creator = [self.submit_content_data[indexPath.row] valueForKey:@"create_by"];
  915. NSString *po = [self.submit_content_data[indexPath.row] valueForKey:@"po_id"];
  916. CGRect price_frame = cell.labelprice.frame;
  917. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType == 1) {
  918. cell.label_po.hidden = NO;
  919. price_frame.origin.y = 5;
  920. cell.label_po.text = po;
  921. } else {
  922. cell.label_po.hidden = YES;
  923. price_frame.origin.y = 21;
  924. }
  925. cell.labelprice.frame = price_frame;
  926. cell.label_so.text=so;
  927. cell.labelprice.text=price;//[RAConvertor currencyNumber:(price.floatValue)];//price;
  928. cell.label_date.text=purchase_time;
  929. cell.label_contact.text=customer_name;
  930. cell.label_model.hidden = false;
  931. cell.label_model.text = model_count;
  932. cell.label_sales.text = sales;
  933. cell.label_creator.text = creator;
  934. cell.label_status.text=status;
  935. cell.backgroundColor = [UIColor whiteColor];
  936. return cell;
  937. }
  938. }
  939. else
  940. {
  941. AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  942. {
  943. NSString *CellIdentifier = @"UploadCell";
  944. UploadCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  945. NSDictionary * item_json = Appdelegate.uploadManager.arr_queue[indexPath.row];
  946. //
  947. // if (cell.operation) {
  948. // cell.operation.updateUI = nil;
  949. // }
  950. RAUploadOperation* op = item_json[@"operation"];
  951. NSString* status =nil;
  952. switch ([item_json[@"status"] intValue]) {
  953. case TaskStatusStart:
  954. status=@"uploading";
  955. break;
  956. case TaskStatusStop:
  957. status=@"stop";
  958. break;
  959. case TaskStatusError:
  960. status=@"warning";
  961. break;
  962. case TaskStatusWait:
  963. status=@"waiting";
  964. break;
  965. case TaskStatusFinish:
  966. status=@"finish";
  967. break;
  968. default:
  969. status=@"warning";
  970. break;
  971. }
  972. double progress =[item_json[@"progress"] doubleValue];
  973. cell.progress=progress;
  974. cell.name=item_json[@"file"];
  975. cell.state= status;
  976. cell.errorMsg = item_json[@"msg"];
  977. // __block RAUploadOperation* block_op = op;
  978. // __block UploadCell* block_cell = cell;
  979. // __block NSIndexPath* block_index = indexPath;
  980. // long idx = indexPath.row;
  981. // __weak typeof(self) weakself = self;
  982. op.updateUI=^(){
  983. // blockDebugLog(@"updateUI @ row%ld %p \n operation %p",idx,block_cell,block_op);
  984. NSString* status =nil;
  985. switch ([item_json[@"status"] intValue]) {
  986. case TaskStatusStart:
  987. status=@"uploading";
  988. break;
  989. case TaskStatusStop:
  990. status=@"stop";
  991. break;
  992. case TaskStatusError:
  993. status=@"warning";
  994. break;
  995. case TaskStatusWait:
  996. status=@"waiting";
  997. break;
  998. case TaskStatusFinish:
  999. status=@"finish";
  1000. break;
  1001. default:
  1002. status=@"warning";
  1003. break;
  1004. }
  1005. double progress =[item_json[@"progress"] doubleValue];
  1006. cell.progress=progress;
  1007. cell.name=item_json[@"file"];
  1008. cell.state= status;
  1009. cell.errorMsg = item_json[@"msg"];
  1010. };
  1011. DebugLog(@"%@ set update ui",item_json[@"file"]);
  1012. // cell.operation = op;
  1013. //
  1014. return cell;
  1015. }
  1016. }
  1017. }
  1018. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  1019. {
  1020. if(tableView==self.table_order)
  1021. {
  1022. // RASingleton.sharedInstance.enable_OfflineOrder = true;
  1023. if (tableView.isEditing) { // 编辑模式下不响应
  1024. return;
  1025. }
  1026. //
  1027. if(indexPath.row==self.content_data.count)
  1028. return;
  1029. {
  1030. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1031. // NSString *orderdir = [OLDataProvider getScanPath];
  1032. NSString *userdir = [OLDataProvider getUserPath];
  1033. NSMutableDictionary* orderitem =self.content_data[indexPath.row];
  1034. NSString* ordercode =orderitem[@"order_code"];
  1035. NSString *orderdir = [userdir stringByAppendingPathComponent:ordercode];
  1036. // NSMutableDictionary* order= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"order.json"]] mutableCopy];
  1037. NSMutableDictionary* cart= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"cart.json"]] mutableCopy];
  1038. if([appDelegate.available_price_group containsObject:cart[@"price_group"]] && [RADataProvider all_price_group][cart[@"price_group"]]!=nil)
  1039. {
  1040. appDelegate.order_code = ordercode;
  1041. [appDelegate setUser:orderitem[@"create_by"]];
  1042. // appDelegate.user =;
  1043. // appDelegate.custo orderitem[@"customer_name"]
  1044. // appDelegate.user_type = USER_ROLE_EMPLOYEE;
  1045. appDelegate.can_set_cart_price = true;
  1046. appDelegate.can_see_price = true;
  1047. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1048. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1049. // NSString *documents = [paths objectAtIndex:0];
  1050. NSMutableDictionary* contact= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"contact.json"]] mutableCopy];
  1051. // NSMutableDictionary* app= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"app.json"]] mutableCopy];
  1052. [appDelegate setCustomerInfo: contact];
  1053. appDelegate.contact_id = contact[@"customer_cid"];
  1054. RASingleton.sharedInstance.scan_cart = cart;
  1055. appDelegate.price_group = cart[@"price_group"];
  1056. RASingleton.sharedInstance.price_type = [cart[@"price_type"] intValue];
  1057. [appDelegate update_count_mark];
  1058. // [appDelegate updateScanButton:true];
  1059. [appDelegate SetMode:@""];
  1060. #ifdef RA_NOTIFICATION
  1061. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1062. #else
  1063. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1064. #endif
  1065. // [self.navigationController pushViewController:orderinfoVC animated:true];
  1066. [((MainViewController*)appDelegate.main_vc) switchToCart];
  1067. return;
  1068. }
  1069. else
  1070. {
  1071. //价格组不存在 询问刷新
  1072. NSString * title =@"Price Has Changed";
  1073. NSString* message = @"Shopping cart items will show updated prices. ";
  1074. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
  1075. //block代码块取代了delegate
  1076. // [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  1077. // textField.text = self.save_name;
  1078. //
  1079. //
  1080. // }];
  1081. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Continue" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1082. NSMutableDictionary* orderitem =self.content_data[indexPath.row];
  1083. NSString* ordercode =orderitem[@"order_code"];
  1084. appDelegate.order_code = ordercode;
  1085. [appDelegate setUser:orderitem[@"create_by"]];
  1086. // appDelegate.user =;
  1087. // appDelegate.custo orderitem[@"customer_name"]
  1088. // appDelegate.user_type = USER_ROLE_EMPLOYEE;
  1089. appDelegate.can_set_cart_price = true;
  1090. appDelegate.can_see_price = true;
  1091. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1092. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1093. // NSString *documents = [paths objectAtIndex:0];
  1094. NSMutableDictionary* contact= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"contact.json"]] mutableCopy];
  1095. // NSMutableDictionary* app= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"app.json"]] mutableCopy];
  1096. [appDelegate setCustomerInfo: contact];
  1097. appDelegate.contact_id = contact[@"customer_cid"];
  1098. //用默认价格组替换订单之前保存的价格组
  1099. [RADataProvider default_price_group];
  1100. cart[@"price_group"]=appDelegate.price_group;
  1101. RASingleton.sharedInstance.scan_cart = cart;
  1102. // appDelegate.price_group = cart[@"price_group"];
  1103. RASingleton.sharedInstance.price_type = [cart[@"price_type"] intValue];
  1104. [appDelegate update_count_mark];
  1105. // [appDelegate updateScanButton:true];
  1106. [appDelegate SetMode:@""];
  1107. #ifdef RA_NOTIFICATION
  1108. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_CART_REFRESH];
  1109. #else
  1110. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1111. #endif
  1112. // [self.navigationController pushViewController:orderinfoVC animated:true];
  1113. [((MainViewController*)appDelegate.main_vc) switchToCart];
  1114. return;
  1115. }];
  1116. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Close" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1117. DebugLog(@"Cancel");
  1118. return;
  1119. }];
  1120. [alertControl addAction:actionOne];
  1121. [alertControl addAction:alertthree];
  1122. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1123. [self presentViewController:alertControl animated:YES completion:nil];
  1124. }
  1125. }
  1126. }
  1127. else if(tableView==self.table_submit)
  1128. {
  1129. // RASingleton.sharedInstance.enable_OfflineOrder = true;
  1130. if (tableView.isEditing) { // 编辑模式下不响应
  1131. return;
  1132. }
  1133. //
  1134. // if(indexPath.row==self.content_data.count)
  1135. // return;
  1136. {
  1137. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1138. NSMutableDictionary* orderitem =self.submit_content_data[indexPath.row];
  1139. NSString* ordercode =orderitem[@"order_code"];
  1140. NSString *orderdir = [OLDataProvider getScanOrderPathByCode:ordercode];
  1141. // orderdir = [orderdir stringByAppendingPathComponent:ordercode];
  1142. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1143. CreateOrderViewController * orderinfoVC = [[CreateOrderViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1144. orderinfoVC.disable_dropdown_refresh=true;
  1145. orderinfoVC.url_type = URL_FILE;
  1146. orderinfoVC.request_url=[orderdir stringByAppendingPathComponent:@"order.json"];
  1147. orderinfoVC.params = params;
  1148. orderinfoVC.title=@"";
  1149. orderinfoVC.delegate=nil;
  1150. [self.navigationController pushViewController:orderinfoVC animated:true];
  1151. // if(checked.count==count)
  1152. // {
  1153. // orderinfoVC.have_tail = true
  1154. // }
  1155. // appDelegate.order_code = ordercode;
  1156. //
  1157. // [appDelegate setUser:orderitem[@"create_by"]];
  1158. //
  1159. // appDelegate.can_set_cart_price = true;
  1160. // appDelegate.can_see_price = true;
  1161. //
  1162. //
  1163. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1164. //
  1165. //
  1166. //
  1167. //
  1168. // NSString *orderdir = [OLDataProvider getScanPath];
  1169. // NSMutableDictionary* cart= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"cart.json"]] mutableCopy];
  1170. // NSMutableDictionary* contact= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"contact.json"]] mutableCopy];
  1171. //
  1172. // [appDelegate setCustomerInfo: contact];
  1173. // appDelegate.contact_id = contact[@"customer_cid"];
  1174. // RASingleton.sharedInstance.scan_cart = cart;
  1175. // RASingleton.sharedInstance.price_type = [cart[@"price_type"] intValue];
  1176. //
  1177. //
  1178. // [appDelegate update_count_mark];
  1179. // [appDelegate SetMode:@""];
  1180. //
  1181. //
  1182. //
  1183. //#ifdef RA_NOTIFICATION
  1184. // [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1185. //#else
  1186. //
  1187. //
  1188. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1189. //#endif
  1190. //
  1191. //// [self.navigationController pushViewController:orderinfoVC animated:true];
  1192. //
  1193. // [((MainViewController*)appDelegate.main_vc) switchToCart];
  1194. //
  1195. return;
  1196. }
  1197. }
  1198. }
  1199. #pragma mark - searchBar delegate;
  1200. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  1201. {
  1202. self.keywords=searchBar.text;
  1203. // self.offset = 0;
  1204. // [self.content_data removeAllObjects];
  1205. self.reset_result=true;
  1206. [self loadpage];
  1207. }
  1208. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  1209. {
  1210. if([searchText isEqualToString:@""] && !self.reset)
  1211. {
  1212. DebugLog(@"clear");
  1213. self.reset=true;
  1214. self.keywords=nil;
  1215. // self.offset = 0;
  1216. // [self.content_data removeAllObjects];
  1217. self.reset_result=true;
  1218. [self loadpage];
  1219. }
  1220. else
  1221. self.reset = false;
  1222. }
  1223. #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
  1224. //- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
  1225. - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath
  1226. {
  1227. // 添加一个删除按钮
  1228. // self.indexPath=indexPath;
  1229. if(tableView==self.table_order)
  1230. {
  1231. if(indexPath.row==self.content_data.count)
  1232. // return @[];
  1233. return [UISwipeActionsConfiguration configurationWithActions:@[]];
  1234. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1235. // NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"];
  1236. NSString* order_code= [self.content_data[indexPath.row] valueForKey:@"order_code"];
  1237. // NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  1238. // NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  1239. if(true/*appDelegate.user_type==USER_ROLE_EMPLOYEE || (appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeCustomer)*/) {
  1240. // UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1241. UIContextualAction* deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Delete" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  1242. DebugLog(@"delete click");
  1243. NSString * title =@"Are you sure to delete order?";
  1244. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
  1245. //block代码块取代了delegate
  1246. // [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  1247. // textField.text = self.save_name;
  1248. //
  1249. //
  1250. // }];
  1251. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1252. [OLDataProvider deleteScanOrder:order_code];
  1253. if([appDelegate.order_code isEqualToString:order_code])
  1254. [appDelegate closeOrder];
  1255. //
  1256. // [self prepareReturn:nil];
  1257. // [self.navigationController popViewControllerAnimated:true];
  1258. // [((MainViewController*)appDelegate.main_vc) switchToOrder];
  1259. return;
  1260. }];
  1261. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1262. DebugLog(@"Cancel");
  1263. }];
  1264. [alertControl addAction:actionOne];
  1265. [alertControl addAction:alertthree];
  1266. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1267. [self presentViewController:alertControl animated:YES completion:nil];
  1268. }];
  1269. deleteRowAction.backgroundColor = UIColor.redColor;//UIColorFromRGB(0x336699);
  1270. // 添加一个编辑按钮
  1271. //
  1272. // if(/*[order_status isEqualToString:@"Saved Order"]*/statusCode == 1&&appDelegate.can_cancel_order)
  1273. // return @[cancelAction];
  1274. //
  1275. // else
  1276. // {
  1277. {
  1278. NSMutableArray* arr=[@[] mutableCopy];
  1279. if(appDelegate.can_delete_order)
  1280. [arr addObject:deleteRowAction];
  1281. // if(appDelegate.can_cancel_order)
  1282. // [arr addObject:cancelAction];
  1283. // return arr;
  1284. return [UISwipeActionsConfiguration configurationWithActions:arr];
  1285. }
  1286. // }
  1287. }
  1288. // return @[];
  1289. return [UISwipeActionsConfiguration configurationWithActions:@[]];
  1290. }
  1291. else if(tableView==self.table_submit)
  1292. {
  1293. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1294. // NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"];
  1295. NSString* order_code= [self.submit_content_data[indexPath.row] valueForKey:@"order_code"];
  1296. // NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  1297. // NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  1298. {
  1299. // UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1300. UIContextualAction* deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Delete" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  1301. DebugLog(@"delete click");
  1302. NSString * title =@"Are you sure to delete the submitted record?";
  1303. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
  1304. //block代码块取代了delegate
  1305. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1306. [OLDataProvider deleteSubmittedOrder:order_code];
  1307. return;
  1308. }];
  1309. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1310. DebugLog(@"Cancel");
  1311. }];
  1312. [alertControl addAction:actionOne];
  1313. [alertControl addAction:alertthree];
  1314. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1315. [self presentViewController:alertControl animated:YES completion:nil];
  1316. }];
  1317. deleteRowAction.backgroundColor = UIColorFromRGB(0x336699);
  1318. // 添加一个编辑按钮
  1319. {
  1320. NSMutableArray* arr=[@[] mutableCopy];
  1321. if(appDelegate.can_delete_order)
  1322. [arr addObject:deleteRowAction];
  1323. // if(appDelegate.can_cancel_order)
  1324. // [arr addObject:cancelAction];
  1325. // return arr;
  1326. return [UISwipeActionsConfiguration configurationWithActions:arr];
  1327. }
  1328. // }
  1329. }
  1330. }
  1331. else
  1332. {
  1333. AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  1334. NSMutableDictionary * task = Appdelegate.uploadManager.arr_queue[indexPath.row];
  1335. __weak typeof(self) weakself = self;
  1336. // UITableViewRowAction *startAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Restart"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1337. UIContextualAction* startAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"Restart" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  1338. if (Appdelegate.uploadManager.onlyWiFi && Appdelegate.uploadManager.reach.currentReachabilityStatus != ReachableViaWiFi) {
  1339. [weakself.view makeToast:@"Current Network is not WiFi" duration:3.0 position:CSToastPositionCenter];
  1340. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1341. return ;
  1342. }
  1343. DebugLog(@"Start click");
  1344. task[@"retry"]=[NSNumber numberWithInt:0];
  1345. [Appdelegate.uploadManager startTask:task];
  1346. [tableView reloadData];
  1347. }];
  1348. startAction.backgroundColor = UIColorFromRGB(0xff9933);
  1349. // UITableViewRowAction *removeAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Remove" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1350. UIContextualAction* removeAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Remove" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
  1351. [Appdelegate.uploadManager removeTask:task];
  1352. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1353. }];
  1354. removeAction.backgroundColor = UIColorFromRGB(0x9BBF5A);
  1355. // UIColorFromRGB(0x336699);
  1356. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1357. switch ([task[@"status"] intValue]) {
  1358. case TaskStatusFinish:
  1359. // return @[removeAction];
  1360. return [UISwipeActionsConfiguration configurationWithActions:@[removeAction]];
  1361. case TaskStatusError:
  1362. // return @[startAction,removeAction];
  1363. return [UISwipeActionsConfiguration configurationWithActions:@[startAction,removeAction]];
  1364. case TaskStatusStop:
  1365. // return @[startAction];
  1366. return [UISwipeActionsConfiguration configurationWithActions:@[startAction]];
  1367. default:
  1368. return nil;
  1369. break;
  1370. }
  1371. }
  1372. }
  1373. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  1374. if(tableView==self.table_order)
  1375. {
  1376. if(indexPath.row==self.content_data.count)
  1377. return NO;
  1378. // // if(self.init_style==OL_OPEN)
  1379. // // return NO;
  1380. //
  1381. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1382. // // NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  1383. // NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  1384. //
  1385. // if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1386. // // saved && ((type==0 && merge_permission) || type == 1 || can_cancel)
  1387. //
  1388. // BOOL isSavedOrder = /*[order_status isEqualToString:@"Saved Order"]*/statusCode == 1;
  1389. // switch (self.orderType) {
  1390. // case 0:{ // Shop Order
  1391. //
  1392. // if (!isSavedOrder) {
  1393. // return NO;
  1394. // } else {
  1395. // if ([RASingleton sharedInstance].permissions_merge_order || appDelegate.can_cancel_order) {
  1396. // return YES;
  1397. // } else {
  1398. // return NO;
  1399. // }
  1400. // }
  1401. //
  1402. // }
  1403. // break;
  1404. // case 1:{ // Sales Order
  1405. // if (isSavedOrder && appDelegate.can_cancel_order) {
  1406. // return YES;
  1407. // }
  1408. // return NO;
  1409. // }
  1410. // break;
  1411. //
  1412. // default:
  1413. // break;
  1414. // }
  1415. //
  1416. // } else {
  1417. // return YES;
  1418. // }
  1419. return YES;
  1420. }
  1421. else if(tableView==self.table_submit)
  1422. {
  1423. return YES;
  1424. }
  1425. else
  1426. {
  1427. AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  1428. if(Appdelegate.uploadManager.arr_queue.count==0)
  1429. return false;
  1430. NSDictionary * item_json = Appdelegate.uploadManager.arr_queue[indexPath.row];
  1431. bool ret=false;
  1432. switch ([item_json[@"status"] intValue]) {
  1433. case TaskStatusStart:
  1434. case TaskStatusWait:
  1435. ret=false;
  1436. break;
  1437. case TaskStatusFinish:
  1438. case TaskStatusStop:
  1439. case TaskStatusError:
  1440. ret = true;
  1441. break;
  1442. default:
  1443. ret=false;
  1444. break;
  1445. }
  1446. return ret;
  1447. }
  1448. }
  1449. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  1450. if(tv==self.table_order)
  1451. {
  1452. if(indexPath.row==self.content_data.count)
  1453. return UITableViewCellEditingStyleNone;
  1454. bool offline_edit =[[self.content_data[indexPath.row] valueForKey:@"offline_edit"] boolValue];
  1455. // NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  1456. NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  1457. if(/*![order_status isEqualToString:@"Saved Order"]&&! [order_status isEqualToString:@"Quote Saved"]*/statusCode != 1 && statusCode != 0)
  1458. return UITableViewCellEditingStyleNone;
  1459. else
  1460. {
  1461. BOOL condition = offline_edit;
  1462. #ifdef OFFLINE_MODE
  1463. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1464. condition = condition || appDelegate.offline_mode==false;
  1465. #else
  1466. condition = YES;
  1467. #endif
  1468. if (condition)
  1469. return UITableViewCellEditingStyleDelete;
  1470. else
  1471. return UITableViewCellEditingStyleNone;
  1472. }
  1473. }
  1474. else
  1475. return UITableViewCellEditingStyleDelete;
  1476. }
  1477. /*
  1478. #pragma mark - Navigation
  1479. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1480. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1481. // Get the new view controller using [segue destinationViewController].
  1482. // Pass the selected object to the new view controller.
  1483. }
  1484. */
  1485. #pragma mark EnumSelectViewControllerDelegate
  1486. -(void) EnumValueChanged:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  1487. {
  1488. self.status_cadedate = value;
  1489. UIApplication * app = [UIApplication sharedApplication];
  1490. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  1491. appDelegate.OrderFilter = value;
  1492. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  1493. // NSString *documents = [paths objectAtIndex:0];
  1494. // NSString *dist_path = [documents stringByAppendingPathComponent:@"status_filter_cadedate.json"];
  1495. //
  1496. //
  1497. // // if ([[NSFileManager defaultManager] fileExistsAtPath:dist_path]) {
  1498. // //
  1499. // // DebugLog(@"文件已经存在了");
  1500. // //
  1501. // // }
  1502. // // else
  1503. // // {
  1504. // //
  1505. // //
  1506. // //
  1507. // // DebugLog(@"resourceSampleImagesFolderPath=%@",resourceFolderPath);
  1508. //
  1509. //NSData *data = [NSJSONSerialization dataWithJSONObject:self.status_cadedate options:kNilOptions error:nil];
  1510. //
  1511. // // DebugLog(@"mainBundleFile==%@",mainBundleFile);
  1512. //
  1513. // [[NSFileManager defaultManager] createFileAtPath:dist_path
  1514. //
  1515. // contents:data
  1516. //
  1517. // attributes:nil];
  1518. //
  1519. // }
  1520. // self.keywords=searchBar.text;
  1521. // self.offset = 0;
  1522. // [self.content_data removeAllObjects];
  1523. self.reset_result=true;
  1524. [self loadpage];
  1525. //[self.btnStatusFilter setTitle:setTitle:alert ];
  1526. }
  1527. #pragma mark - button action
  1528. - (NSIndexPath *)indexPathOfDeleteOrder:(NSString *)orderID {
  1529. for (NSIndexPath *indexPath in self.table_order.indexPathsForSelectedRows) {
  1530. NSString* orderid= [NSString stringWithFormat:@"%@",[self.content_data[indexPath.row] valueForKey:@"order_id"]];
  1531. if ([orderid isEqualToString:orderID]) {
  1532. return indexPath;
  1533. }
  1534. }
  1535. return nil;
  1536. }
  1537. - (void)handleSelectedOrders {
  1538. [self.mergeList removeAllObjects];
  1539. if (!self.table_order.isEditing) {
  1540. return;
  1541. }
  1542. for (NSIndexPath *indexPath in self.table_order.indexPathsForSelectedRows) {
  1543. if(indexPath.row==self.content_data.count)
  1544. continue;
  1545. NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"];
  1546. NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"];
  1547. NSString *create_by = [self.content_data[indexPath.row] valueForKey:@"create_by"];
  1548. NSString *create_time = [self.content_data[indexPath.row] valueForKey:@"purchase_time"];
  1549. NSString *orderCode = [NSString stringWithFormat:@"%@",[self.content_data[indexPath.row] valueForKey:@"order_code"]];
  1550. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  1551. [dic setValue:orderid forKey:@"order_id"];
  1552. [dic setValue:orderCode forKey:@"order_code"];
  1553. [dic setValue:so forKey:@"so_id"];
  1554. [dic setValue:create_by forKey:@"create_by"];
  1555. [dic setValue:create_time forKey:@"create_time"];
  1556. [dic setValue:[NSNumber numberWithInteger:0] forKey:@"check"]; // 合并到
  1557. [self.mergeList addObject:dic];
  1558. }
  1559. }
  1560. - (IBAction)editOrderListButtonClick:(UIBarButtonItem *)sender {
  1561. }
  1562. - (IBAction)onSegmentChanged:(UISegmentedControl *)sender {
  1563. if(sender.selectedSegmentIndex==0)
  1564. {
  1565. self.table_order.hidden=false;
  1566. self.table_upload.hidden = true;
  1567. [self.table_order reloadData];
  1568. }
  1569. else if(sender.selectedSegmentIndex==1)
  1570. {
  1571. // self.table_order.hidden=true;
  1572. // self.table_upload.hidden = false;
  1573. // [self.table_upload reloadData];
  1574. self.table_order.hidden=true;
  1575. self.table_submit.hidden = false;
  1576. [self.table_submit reloadData];
  1577. }
  1578. // else
  1579. // {
  1580. // [self onNewOrderClicked:nil];
  1581. // }
  1582. //
  1583. }
  1584. #pragma mark - notification action
  1585. - (void)changePriceType:(id)notification {
  1586. [self ReloadData];
  1587. }
  1588. - (void)lockOrderListNotification:(NSNotification *)notification {
  1589. if ([notification.name isEqual:Lock_Permission_Notification]) {
  1590. if (self.orderType == 1) {
  1591. self.orderTypeSegmentControl.selectedSegmentIndex = 0;
  1592. // [self changeOrderType:0];
  1593. [self.orderTypeSegmentControl sendActionsForControlEvents:UIControlEventValueChanged];
  1594. }
  1595. if(self.orderTypeSegmentControl.numberOfSegments > 1) {
  1596. [self.orderTypeSegmentControl removeSegmentAtIndex:1 animated:YES];
  1597. // [self changeOrderType:0];
  1598. }
  1599. } else { // 解锁
  1600. if ([RASingleton sharedInstance].customer_can_see_sales_Order) { // 有查看Sales order 权限
  1601. if (self.orderTypeSegmentControl.numberOfSegments == 1 && !self.table_order.isEditing) {
  1602. [self.orderTypeSegmentControl insertSegmentWithTitle:[NSString stringWithFormat:@"Purchase Order to %@",COMPANY_SHORT_NAME] atIndex:1 animated:YES];
  1603. }
  1604. }
  1605. }
  1606. }
  1607. - (void)handleUserLogin:(NSNotification *)notification {
  1608. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1609. self.orderType = 0;
  1610. if (self.table_order.isEditing) {
  1611. [self.table_order setEditing:NO animated:YES];
  1612. self.editOrderListButton.image = [UIImage imageNamed:@"Combinegray"];
  1613. }
  1614. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1615. self.orderTypeSegmentControl.selectedSegmentIndex = 0;
  1616. [RASingleton sharedInstance].customer_order_type = 0;
  1617. }
  1618. }
  1619. - (void)reRefreshView {
  1620. [self.table_order reloadData];
  1621. }
  1622. #pragma mark - RA_NOTIFICAITON
  1623. -(void) refresh_ui
  1624. {
  1625. [self.table_order reloadData];
  1626. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1627. if(appDelegate.can_create_order)
  1628. {
  1629. [self.btn_newOrder setImage:[UIImage imageNamed:@"neworder"]];
  1630. self.btn_newOrder.enabled = true;
  1631. }
  1632. else
  1633. {
  1634. [self.btn_newOrder setImage:nil];
  1635. self.btn_newOrder.enabled = false;
  1636. }
  1637. }
  1638. -(void) reload_data
  1639. {
  1640. self.reset_result=true;
  1641. self.norefresh=true;
  1642. [self loadpage];
  1643. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1644. if(appDelegate.can_create_order)
  1645. {
  1646. [self.btn_newOrder setImage:[UIImage imageNamed:@"neworder"]];
  1647. self.btn_newOrder.enabled = true;
  1648. }
  1649. else
  1650. {
  1651. [self.btn_newOrder setImage:nil];
  1652. self.btn_newOrder.enabled = false;
  1653. }
  1654. }
  1655. -(void) refresh_price
  1656. {
  1657. [self refresh_ui];
  1658. }
  1659. @end