ScanOrderListViewController.m 115 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983
  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. // NSString* order_code = RASingleton.sharedInstance.scan_temp_code;
  373. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  374. // appDelegate.order_code = order_code;
  375. // if(appDelegate.user.length==0)
  376. // {
  377. // [RAUtils message_alert:@"Please login first." title:@"Warring" controller:self];
  378. // return;
  379. // }
  380. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  381. // NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  382. // RASingleton.sharedInstance.scan_cart=cartTemplate;//[[RAConvertor data2dict:json] mutableCopy];
  383. // appDelegate.user_type = USER_ROLE_EMPLOYEE;
  384. appDelegate.can_set_cart_price = true;
  385. appDelegate.can_see_price = true;
  386. RASingleton.sharedInstance.scan_cart = nil;
  387. RASingleton.sharedInstance.price_type = 1;
  388. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  389. // NSString *documents = [paths objectAtIndex:0];
  390. {
  391. NSString *orderdir = [OLDataProvider getScanPath];
  392. // NSError *error = nil;
  393. // [ [NSFileManager defaultManager] moveItemAtPath:[OLDataProvider getScanTempPath] toPath:orderdir error:&error];
  394. //
  395. //
  396. // [OLDataProvider moveScanTemp2Order];
  397. // bool bsuccess=[[NSFileManager defaultManager] createDirectoryAtPath:orderdir withIntermediateDirectories:YES attributes:nil error:&error];
  398. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  399. // NSString * string = [checked componentsJoinedByString:@","];
  400. // [params setValue:string forKey:@"cart2Checkbox"];
  401. // NSData* data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_ORDER ofType:@"json" ]];
  402. // NSMutableDictionary* dict=[[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  403. //
  404. // NSMutableDictionary* dict=[OLDataProvider loadScanTemplate:@"scan_order.json"];
  405. //
  406. //
  407. //
  408. //
  409. // NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  410. //
  411. //
  412. //
  413. // [RAUtils dicttofile:orderPath dict:dict];
  414. //
  415. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  416. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  417. }
  418. #ifdef RA_NOTIFICATION
  419. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  420. #else
  421. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  422. [main_vc reloadCart:true immediately:false];
  423. #endif
  424. // MainViewController * mainvc=(MainViewController * )appDelegate.main_vc;
  425. // mainvc.btnScan.enabled = true;
  426. // [appDelegate updateScanButton:true];
  427. // AppDelegate* appDelegate = (AppDelegate*)UIApplication.sharedApplication.delegate;
  428. MainViewController * mainvc = (MainViewController*)appDelegate.main_vc;
  429. // [ActiveViewController Notify:@"ScanOrderListViewController" Message:@"NewOrder"];
  430. [mainvc switchToCart];
  431. }
  432. - (IBAction)onNewOrderClicked:(id)sender {
  433. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  434. // if(appDelegate.user.length<=0)
  435. // {
  436. // [RAUtils message_alert:@"Please login first." title:@"Warring" controller:self];
  437. // return;
  438. // }
  439. if(appDelegate.order_code.length>0)
  440. {
  441. // // 当前订单先关闭
  442. [OLDataProvider scanCloseOrder];
  443. }
  444. // RASingleton.sharedInstance.enable_OfflineOrder = true;
  445. // __block MainViewController *brself= self;
  446. // if(appDelegate.contact_id.length<=0&&false)
  447. // {
  448. //
  449. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"New Offline Order" message:nil preferredStyle:UIAlertControllerStyleAlert];
  450. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"With Offline Contact" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  451. //
  452. // // if(appDelegate.order_code && appDelegate.order_code.length>0)
  453. // // {
  454. // // [RAUtils message_alert:@"Please close current order and try again." title:@"" controller:self];
  455. // // }
  456. // // NSLog(@"new click");
  457. //
  458. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  459. //
  460. // // NSString *path = [[NSBundle mainBundle] pathForResource:@"editContact.json" ofType:nil];
  461. //
  462. // CustomerEditViewController * cuseditVC = [[CustomerEditViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  463. // cuseditVC.bnewcustomer=true;
  464. // cuseditVC.bolocustomer = true;
  465. // cuseditVC.url_type = URL_FILE;
  466. // cuseditVC.request_url=[OLDataProvider scanTemplatePath:@"scan_contact.json"];
  467. //
  468. // cuseditVC.params = params;
  469. //
  470. // cuseditVC.returnValue=^(NSMutableDictionary* value)
  471. // {
  472. // if(value==nil)
  473. // {
  474. // [RAUtils message_alert:@"Cannot create order without customer infomation." title:@"" controller:self];
  475. // }
  476. // else
  477. // {
  478. // NSString* contact_id=[[NSUUID new] UUIDString];
  479. //
  480. //
  481. // //---------------- construct customer_contact----------------------
  482. // NSString* customer_first_name = [value valueForKey:@"customer_first_name"];
  483. // if(customer_first_name==nil)
  484. // customer_first_name=@"";
  485. //
  486. // NSString* customer_last_name= [value valueForKey:@"customer_last_name"];
  487. // if(customer_last_name==nil)
  488. // customer_last_name=@"";
  489. // NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
  490. // customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  491. // [value setValue:customer_contact forKey:@"customer_contact"];
  492. //
  493. //
  494. //
  495. // value [@"customer_cid"] = contact_id;
  496. // appDelegate.contact_id=contact_id;
  497. // appDelegate.customerInfo = value;
  498. //
  499. //
  500. //
  501. //
  502. //
  503. //
  504. // // [brself refreshContactDisplay];
  505. // [self newoloorder];
  506. //
  507. // // [brself switchToCart:nil];
  508. //
  509. // }
  510. // };
  511. //
  512. //
  513. // // cuseditVC.delegate=self;
  514. // //
  515. // // if(checked.count==count)
  516. // // {
  517. // // orderinfoVC.have_tail = true
  518. // // }
  519. //
  520. // [[self navigationController] setNavigationBarHidden:NO animated:NO];
  521. // [self.navigationController pushViewController:cuseditVC animated:false];
  522. //
  523. // // [self dismissViewControllerAnimated:NO completion:^{
  524. // //// [(UINavigationController*)[self parentViewController] pushViewController:cuseditVC animated:false];;
  525. // //// [[self navigationController] setNavigationBarHidden:NO animated:NO];
  526. // //
  527. // //// [self pushViewController:cuseditVC animated:false];
  528. // // }];
  529. //
  530. // // [[self navigationController] setNavigationBarHidden:NO animated:NO];
  531. // // [self.navigationController pushViewController:cuseditVC animated:false];
  532. //
  533. //
  534. // }];
  535. //
  536. //
  537. //
  538. // UIAlertAction *alertCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  539. //
  540. // }];
  541. //
  542. // [alertControl addAction:actionOne];
  543. //
  544. // // [alertControl addAction:alertthree];
  545. // [alertControl addAction:alertCancel];
  546. //
  547. // [self presentViewController:alertControl animated:YES completion:nil];
  548. // }
  549. // else
  550. {
  551. [self newoloorder];
  552. }
  553. }
  554. - (void)didReceiveMemoryWarning {
  555. [super didReceiveMemoryWarning];
  556. // Dispose of any resources that can be recreated.
  557. }
  558. -(void)manually_refresh
  559. {
  560. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
  561. if(self.isrefreshing)
  562. {
  563. [reF endRefreshing];
  564. return;
  565. }
  566. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  567. if ([self respondsToSelector:@selector(ReloadData)])
  568. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  569. }
  570. -(void)ReloadData
  571. {
  572. // [self.content_data removeAllObjects];
  573. // [self.table_order reloadData];
  574. // self.table_order.hidden = true;
  575. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
  576. [reF endRefreshing];
  577. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  578. self.keywords=nil;
  579. // self.offset = 0;
  580. self.reset_result=true;
  581. // [self.content_data removeAllObjects];
  582. // [self.table_order reloadData];
  583. [self loadpage];
  584. // [self loadpage];
  585. }
  586. - (void)operation_loadPage {
  587. if (self.dataOperationQueue.operationCount > 1) { // 队列后面还有操作
  588. return;
  589. }
  590. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  591. // NSString *documents = [paths objectAtIndex:0];
  592. NSString *userdir = [OLDataProvider getUserPath];
  593. NSMutableDictionary* orderlist = [OLDataProvider getScanOrderList];
  594. // NSString *orderlistPath = [userdir stringByAppendingPathComponent:@"orderlist.json"];
  595. // orderlist=[[RAUtils dictfromfile:orderlistPath] mutableCopy];
  596. [self.content_data removeAllObjects];
  597. int count = [orderlist[@"count"] intValue];
  598. for(int i=0;i<count;i++)
  599. {
  600. NSDictionary* objmsg = [orderlist objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  601. [self.content_data addObject:[NSMutableDictionary dictionaryWithDictionary:objmsg]];
  602. }
  603. NSMutableDictionary* submitlist = [OLDataProvider getScanSubmitList];
  604. // NSString *submitlistPath = [userdir stringByAppendingPathComponent:@"submitlist.json"];
  605. // submitlist=[[RAUtils dictfromfile:submitlistPath] mutableCopy];
  606. [self.submit_content_data removeAllObjects];
  607. int scount = [submitlist[@"count"] intValue];
  608. for(int i=0;i<scount;i++)
  609. {
  610. NSDictionary* objmsg = [submitlist objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  611. [self.submit_content_data addObject:[NSMutableDictionary dictionaryWithDictionary:objmsg]];
  612. }
  613. // int i =self.btnrefresh.state;
  614. self.load_more_hint=@"All loaded";
  615. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"no_more", nil);
  616. // [self.btnrefresh setTitle:@"No more" forState:UIControlStateNormal];
  617. dispatch_sync(dispatch_get_main_queue(), ^{
  618. // self.table_order.hidden = false;
  619. // self.table_submit.hidden = false;
  620. self.reset_result=false;
  621. [self.table_order reloadData ];
  622. [self.table_submit reloadData ];
  623. });
  624. return;
  625. //
  626. //
  627. //
  628. //// dispatch_async(self.loading_queue, ^{
  629. //
  630. // dispatch_sync(dispatch_get_main_queue(), ^{
  631. // if(self.reset_result)
  632. // {
  633. // self.offset = 0;
  634. // [self.content_data removeAllObjects];
  635. // [self.table_order reloadData];
  636. // }
  637. //
  638. // // NSMutableArray* arr_status = [[NSMutableArray alloc] init];
  639. //
  640. // NSMutableArray* arr_statusname = [[NSMutableArray alloc] init];
  641. // int count = [[self.status_cadedate valueForKey:@"count"] intValue];
  642. // for(int i=0;i<count;i++)
  643. // {
  644. // NSDictionary* val_json =[self.status_cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i]];
  645. // int check = [[val_json valueForKey:@"check"] intValue];
  646. // if(check==1)
  647. // {
  648. // // [arr_status addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value_id"]]];
  649. // [arr_statusname addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value"]]];
  650. //
  651. // // break;
  652. // }
  653. // }
  654. //
  655. // // NSString * str_status = [arr_status componentsJoinedByString:@","];
  656. // NSString * str_statusname = [arr_statusname componentsJoinedByString:@","];
  657. // if(str_statusname.length==0)
  658. // str_statusname = @"All";
  659. // self.label_filter.text = str_statusname;
  660. // if(self.offset==0)
  661. // {
  662. // self.table_order.hidden = true;
  663. //
  664. // self.mum.center = self.view.center;
  665. //
  666. // self.mum.hidden = false;
  667. // [self.mum startAnimating];
  668. // }
  669. // self.label_net_err.hidden=true;
  670. //
  671. // });
  672. //// });
  673. //// dispatch_async(self.loading_queue, ^{
  674. // if(self.isrefreshing)
  675. // return;
  676. // self.isrefreshing=true;
  677. //
  678. //
  679. //
  680. //
  681. //
  682. //
  683. //
  684. //
  685. //
  686. // NSMutableArray* arr_status = [[NSMutableArray alloc] init];
  687. //
  688. // // NSMutableArray* arr_statusname = [[NSMutableArray alloc] init];
  689. // int count = [[self.status_cadedate valueForKey:@"count"] intValue];
  690. // for(int i=0;i<count;i++)
  691. // {
  692. // NSDictionary* val_json =[self.status_cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i]];
  693. // int check = [[val_json valueForKey:@"check"] intValue];
  694. // if(check==1)
  695. // {
  696. // [arr_status addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value_id"]]];
  697. // // [arr_statusname addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value"]]];
  698. //
  699. // // break;
  700. // }
  701. // }
  702. //
  703. // NSString * str_status = [arr_status componentsJoinedByString:@","];
  704. //
  705. //
  706. //
  707. //
  708. //
  709. // dispatch_sync(dispatch_get_main_queue(), ^{
  710. // BOOL isMerged = NO;
  711. // AppDelegate *appDelegate = nil;
  712. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  713. // if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  714. // if (self.orderType == 0) {
  715. // isMerged = NO;
  716. // } else {
  717. // isMerged = YES;
  718. // }
  719. // }
  720. //
  721. // [RANetwork request_orderlist:self.offset limit:self.limit keywords:self.keywords status:str_status customer:self.customer_id is_merged:isMerged completionHandler:^(NSMutableDictionary *result) {
  722. // NSMutableDictionary* content=result;
  723. //
  724. //
  725. //
  726. //
  727. //
  728. //
  729. // [self.mum stopAnimating];
  730. // self.isrefreshing=false;
  731. // if (self.dataOperationQueue.operationCount > 1) { // 队列后面还有操作
  732. // return ;
  733. // }
  734. // int result_code=[[content valueForKey:@"result"] intValue];
  735. //
  736. // if(result_code==2||result_code==0)
  737. // {
  738. //
  739. //
  740. // int count = [[content valueForKey:@"count" ] intValue] ;
  741. //
  742. //
  743. // self.time_zone = [content valueForKey:@"time_zone" ];
  744. // self.offset += count;
  745. // for(int i=0;i<count;i++)
  746. // {
  747. //
  748. // NSDictionary* objmsg = [content objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  749. // [self.content_data addObject:[NSMutableDictionary dictionaryWithDictionary:objmsg]];
  750. //
  751. // }
  752. // if(count<self.limit)
  753. // {
  754. //
  755. // // int i =self.btnrefresh.state;
  756. // self.load_more_hint=@"All loaded";
  757. // // self.btnrefresh.titleLabel.text =NSLocalizedString(@"no_more", nil);
  758. // // [self.btnrefresh setTitle:@"No more" forState:UIControlStateNormal];
  759. // }
  760. // else
  761. // {
  762. // self.load_more_hint=@"Load more...";
  763. // // self.btnrefresh.enabled = true;
  764. // // self.btnrefresh.titleLabel.text =NSLocalizedString(@"load_more",nil);
  765. // // [self.btnrefresh setTitle:@"Load more" forState:UIControlStateNormal];
  766. // }
  767. //
  768. //
  769. // self.table_order.hidden = false;
  770. // self.reset_result=false;
  771. // [self.table_order reloadData ];
  772. // }
  773. // else if(result_code==RESULT_NET_ERROR &&self.offset==0)
  774. // {
  775. // self.label_net_err.hidden=false;
  776. // self.table_order.hidden = true;
  777. // }
  778. // else
  779. // {
  780. // [RAUtils message_alert:[content valueForKey:@"err_msg"] title:@"Loading Order List" controller:self] ;
  781. // }
  782. //
  783. //
  784. //
  785. //
  786. //
  787. //
  788. // }];
  789. //
  790. // });
  791. //
  792. ////
  793. //// NSMutableDictionary* content=nil;
  794. //// content=[[RANetwork request_OrderList:self.offset limit : self.limit keywords:self.keywords status:str_status customer:self.customer_id is_merged:isMerged] mutableCopy];
  795. ////
  796. ////
  797. //// dispatch_sync(dispatch_get_main_queue(), ^{
  798. ////
  799. ////
  800. ////
  801. ////
  802. ////
  803. //// [self.mum stopAnimating];
  804. //// self.isrefreshing=false;
  805. //// if (self.dataOperationQueue.operationCount > 1) { // 队列后面还有操作
  806. //// return ;
  807. //// }
  808. //// int result=[[content valueForKey:@"result"] intValue];
  809. ////
  810. //// if(result==2||result==0)
  811. //// {
  812. ////
  813. ////
  814. //// int count = [[content valueForKey:@"count" ] intValue] ;
  815. ////
  816. ////
  817. //// self.time_zone = [content valueForKey:@"time_zone" ];
  818. //// self.offset += count;
  819. //// for(int i=0;i<count;i++)
  820. //// {
  821. ////
  822. //// NSDictionary* objmsg = [content objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  823. //// [self.content_data addObject:[NSMutableDictionary dictionaryWithDictionary:objmsg]];
  824. ////
  825. //// }
  826. //// if(count<self.limit)
  827. //// {
  828. ////
  829. //// // int i =self.btnrefresh.state;
  830. //// self.load_more_hint=@"All loaded";
  831. //// // self.btnrefresh.titleLabel.text =NSLocalizedString(@"no_more", nil);
  832. //// // [self.btnrefresh setTitle:@"No more" forState:UIControlStateNormal];
  833. //// }
  834. //// else
  835. //// {
  836. //// self.load_more_hint=@"Load more...";
  837. //// // self.btnrefresh.enabled = true;
  838. //// // self.btnrefresh.titleLabel.text =NSLocalizedString(@"load_more",nil);
  839. //// // [self.btnrefresh setTitle:@"Load more" forState:UIControlStateNormal];
  840. //// }
  841. ////
  842. ////
  843. //// self.table_order.hidden = false;
  844. //// self.reset_result=false;
  845. //// [self.table_order reloadData ];
  846. //// }
  847. //// else if(result==RESULT_NET_ERROR &&self.offset==0)
  848. //// {
  849. //// self.label_net_err.hidden=false;
  850. //// self.table_order.hidden = true;
  851. //// }
  852. //// else
  853. //// {
  854. //// [RAUtils message_alert:[content valueForKey:@"err_msg"] title:@"Loading Order List" controller:self] ;
  855. //// }
  856. ////
  857. ////
  858. ////
  859. ////
  860. //// });
  861. ////
  862. //
  863. //// });
  864. }
  865. -(void) loadpage
  866. {
  867. __weak typeof(self) weakself = self;
  868. NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
  869. if (weakself) {
  870. __strong typeof(weakself) strongself = weakself;
  871. [strongself operation_loadPage];
  872. }
  873. }];
  874. [self.dataOperationQueue addOperation:operation];
  875. }
  876. - (void)loadmore
  877. {
  878. // self.btnrefresh.enabled = NO;
  879. // self.btnrefresh.titleLabel.text =NSLocalizedString(@"loading",nil);
  880. // [self.btnrefresh setTitle:@"Loading..." forState:UIControlStateNormal];
  881. [self loadpage];
  882. }
  883. //-(void)changeCell
  884. //{
  885. //// UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  886. //// reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"refreshing"];
  887. // [self performSelector:@selector(loadmore) withObject:nil afterDelay:1];
  888. // DebugLog(@"refresh!!!!!!!!");
  889. //
  890. //}
  891. -(void) neworder
  892. {
  893. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
  894. [RANetwork request_create_order:^(NSMutableDictionary *result) {
  895. NSMutableDictionary* return_json =result;
  896. [waitalert dismissViewControllerAnimated:YES completion:^{
  897. if([[return_json valueForKey:@"result"] intValue]==2)
  898. {
  899. int result=[[return_json valueForKey:@"result"] intValue];
  900. if(result==2)
  901. {
  902. //successed.
  903. NSString* order_code = [return_json valueForKey:@"orderCode"];
  904. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  905. appDelegate.order_code = order_code;
  906. appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  907. #ifdef RA_NOTIFICATION
  908. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  909. #else
  910. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  911. [main_vc reloadCart:true immediately:false];
  912. #endif
  913. [self ReloadData];
  914. // [self performSelector:@selector(loadpage) withObject:nil afterDelay:1];
  915. // [self loadpage];
  916. // if(self.shopCartBlock!=nil)
  917. // {
  918. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  919. //
  920. //
  921. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  922. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  923. // iv.image = img;
  924. // // [self.contentView addSubview:iv];
  925. // self.shopCartBlock(iv);
  926. //
  927. // }
  928. }
  929. }
  930. else
  931. {
  932. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:self] ;
  933. }
  934. }];
  935. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  936. }];
  937. }];
  938. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  939. //
  940. // NSDictionary* return_json = [RANetwork new_Order];
  941. //
  942. // dispatch_async(dispatch_get_main_queue(), ^{
  943. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  944. //
  945. //
  946. // if([[return_json valueForKey:@"result"] intValue]==2)
  947. // {
  948. // int result=[[return_json valueForKey:@"result"] intValue];
  949. // if(result==2)
  950. // {
  951. // //successed.
  952. //
  953. // NSString* order_code = [return_json valueForKey:@"orderCode"];
  954. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  955. // appDelegate.order_code = order_code;
  956. // appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  957. //
  958. //
  959. //#ifdef RA_NOTIFICATION
  960. // [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  961. //#else
  962. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  963. // [main_vc reloadCart:true immediately:false];
  964. //#endif
  965. //
  966. // [self ReloadData];
  967. //
  968. //
  969. // // [self performSelector:@selector(loadpage) withObject:nil afterDelay:1];
  970. // // [self loadpage];
  971. //
  972. //
  973. // // if(self.shopCartBlock!=nil)
  974. // // {
  975. // // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  976. // //
  977. // //
  978. // // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  979. // // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  980. // // iv.image = img;
  981. // // // [self.contentView addSubview:iv];
  982. // // self.shopCartBlock(iv);
  983. // //
  984. // // }
  985. //
  986. // }
  987. // }
  988. // else
  989. // {
  990. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:self] ;
  991. // }
  992. //
  993. //
  994. //
  995. //
  996. // });
  997. // });
  998. }
  999. //#pragma mark - UIAlertViewDelegate
  1000. //// Called when a button is clicked. The view will be automatically dismissed after this call returns
  1001. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  1002. //{
  1003. // if(buttonIndex!=alertView.cancelButtonIndex)
  1004. // {
  1005. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1006. //
  1007. // if(appDelegate.order_code && appDelegate.order_code.length>0)
  1008. // {
  1009. //// appDelegate.order_code= nil;
  1010. //// [appDelegate SetSo:nil];
  1011. //
  1012. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE) {
  1013. // // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1014. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1015. // cvc.showNavibar = true;
  1016. // cvc.contact_type = @"Sales_Order_Customer";
  1017. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1018. //
  1019. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  1020. // appDelegate.customerInfo = value;
  1021. //
  1022. // self.norefresh = true;
  1023. // [self neworder];
  1024. //
  1025. //
  1026. //
  1027. // // [main_vc checklogin:true];
  1028. // // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1029. //
  1030. // //
  1031. // // if(self.returnValue)
  1032. // // self.returnValue(value);
  1033. // };
  1034. //
  1035. // cvc.onCancel = ^(){
  1036. // self.norefresh = true;
  1037. // if(appDelegate.customerInfo==nil)
  1038. // {
  1039. // [RAUtils message_alert:@"Cannot create order without customer infomation." title:@"" controller:self];
  1040. // }
  1041. // else
  1042. // {
  1043. // [self neworder];
  1044. // }
  1045. // // [main_vc checklogin:true];
  1046. // };
  1047. // cvc.onReset = ^(){
  1048. // // [main_vc checklogin:true];
  1049. // };
  1050. //
  1051. // [self.navigationController pushViewController:cvc animated:true];
  1052. // }
  1053. // else if (appDelegate.user_type == USER_ROLE_CUSTOMER){
  1054. // [self neworder];
  1055. // }
  1056. //
  1057. // }
  1058. // else
  1059. // {
  1060. // //create new;
  1061. //
  1062. // if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  1063. // {
  1064. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  1065. // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  1066. // cvc.showNavibar = true;
  1067. // cvc.contact_type = @"Sales_Order_Customer";
  1068. // cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  1069. //
  1070. // appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  1071. // appDelegate.customerInfo = value;
  1072. //
  1073. //
  1074. // if(appDelegate.order_code==nil)
  1075. // [self neworder];
  1076. //
  1077. // // [main_vc checklogin:true];
  1078. // // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  1079. //
  1080. // //
  1081. // // if(self.returnValue)
  1082. // // self.returnValue(value);
  1083. // };
  1084. //
  1085. // cvc.onCancel = ^(){
  1086. //
  1087. // [RAUtils message_alert:@"Cannot create order without customer infomation." title:@"" controller:self];
  1088. //
  1089. //
  1090. //
  1091. // };
  1092. // cvc.onReset = ^(){
  1093. // [main_vc checklogin:true];
  1094. // };
  1095. //
  1096. // [self.navigationController pushViewController:cvc animated:true];
  1097. // }
  1098. // else
  1099. // {
  1100. // [self neworder];
  1101. // }
  1102. // }
  1103. //
  1104. // }
  1105. //}
  1106. #pragma mark - Table view data source
  1107. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  1108. {
  1109. if(tableView==self.table_order||tableView==self.table_submit)
  1110. return 66;
  1111. else
  1112. return 100;
  1113. }
  1114. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  1115. //{
  1116. // return 0;
  1117. //}
  1118. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  1119. //{
  1120. // return 0;
  1121. //}
  1122. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  1123. //{
  1124. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1125. // return myView;
  1126. //
  1127. //}
  1128. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  1129. {
  1130. if(tableView==self.table_order)
  1131. {
  1132. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  1133. if(value==nil)
  1134. value=@"";
  1135. unsigned long color = strtoul([value UTF8String],0,16);
  1136. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1137. // myView.backgroundColor = UIColorFromRGB(0x996633);
  1138. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  1139. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  1140. myView.layer.shadowOffset = CGSizeMake(0, 0);
  1141. myView.layer.shadowOpacity = 0.5;
  1142. myView.layer.shadowRadius = 2.0;
  1143. UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 11, 130, 22)];
  1144. statuslabel.textColor=UIColorFromRGB(color);
  1145. statuslabel.backgroundColor = [UIColor clearColor];
  1146. statuslabel.text=NSLocalizedString(@"Status", nil);
  1147. [statuslabel sizeToFit];
  1148. [myView addSubview:statuslabel];
  1149. // UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 21, 130, 22)];
  1150. // solabel.textColor=UIColorFromRGB(color);
  1151. // solabel.backgroundColor = [UIColor clearColor];
  1152. // solabel.text=NSLocalizedString(@"SO#", nil);
  1153. // [solabel sizeToFit];
  1154. // [myView addSubview:solabel];
  1155. // UILabel *userlabel = [[UILabel alloc] initWithFrame:CGRectMake(165, 21, 125, 22)];
  1156. // userlabel.textColor=UIColorFromRGB(color);
  1157. // userlabel.backgroundColor = [UIColor clearColor];
  1158. // userlabel.text=NSLocalizedString(@"Sales rep", nil);
  1159. // [userlabel sizeToFit];
  1160. // [myView addSubview:userlabel];
  1161. UILabel *creatorlabel = [[UILabel alloc] initWithFrame:CGRectMake(165, 11, 125, 22)];
  1162. creatorlabel.textColor=UIColorFromRGB(color);
  1163. creatorlabel.backgroundColor = [UIColor clearColor];
  1164. creatorlabel.text=NSLocalizedString(@"Create by", nil);
  1165. [creatorlabel sizeToFit];
  1166. [myView addSubview:creatorlabel];
  1167. UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(296, 11, 150, 22)];
  1168. contactlabel.textColor=UIColorFromRGB(color);
  1169. contactlabel.backgroundColor = [UIColor clearColor];
  1170. contactlabel.text=NSLocalizedString(@"Company / Contact ID", nil);
  1171. [contactlabel sizeToFit];
  1172. [myView addSubview:contactlabel];
  1173. //
  1174. // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(424, 11, 52, 22)];
  1175. // modellabel.textColor=[UIColor whiteColor];
  1176. // modellabel.backgroundColor = [UIColor clearColor];
  1177. // modellabel.text=NSLocalizedString(@"Model", nil);
  1178. // [modellabel sizeToFit];
  1179. // [myView addSubview:modellabel];
  1180. // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-276, 2, 100, 22)];
  1181. // modellabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  1182. // modellabel.textColor=[UIColor whiteColor];
  1183. // modellabel.backgroundColor = [UIColor clearColor];
  1184. // modellabel.text=NSLocalizedString(@"Items/QTY", nil);
  1185. // [modellabel sizeToFit];
  1186. // [myView addSubview:modellabel];
  1187. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1188. UILabel *pricelabel = nil;
  1189. if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType==1)
  1190. pricelabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 2, 100, 22)];
  1191. else
  1192. pricelabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 11, 100, 22)];
  1193. pricelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  1194. pricelabel.textColor=UIColorFromRGB(color);
  1195. pricelabel.backgroundColor = [UIColor clearColor];
  1196. pricelabel.text=NSLocalizedString(@"Order Total", nil);
  1197. [pricelabel sizeToFit];
  1198. [myView addSubview:pricelabel];
  1199. if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType==1)
  1200. {
  1201. UILabel *polabel = nil;
  1202. polabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 21, 100, 22)];
  1203. polabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  1204. polabel.textColor=UIColorFromRGB(color);
  1205. polabel.backgroundColor = [UIColor clearColor];
  1206. polabel.text=NSLocalizedString(@"PO#", nil);
  1207. [polabel sizeToFit];
  1208. [myView addSubview:polabel];
  1209. }
  1210. UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-163/*605*/,11, 148, 22)];
  1211. timelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  1212. timelabel.textColor=UIColorFromRGB(color);
  1213. timelabel.backgroundColor = [UIColor clearColor];
  1214. if(self.time_zone==nil)
  1215. timelabel.text=@"Create time";
  1216. else
  1217. timelabel.text=[NSString stringWithFormat:@"Create time (%@)",self.time_zone];
  1218. [timelabel sizeToFit];
  1219. [myView addSubview:timelabel];
  1220. myView.autoresizesSubviews=true;
  1221. // [myView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];
  1222. // modellabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1223. // pricelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1224. // timelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1225. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  1226. //
  1227. return myView;
  1228. }
  1229. else
  1230. if(tableView==self.table_submit)
  1231. {
  1232. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  1233. if(value==nil)
  1234. value=@"";
  1235. unsigned long color = strtoul([value UTF8String],0,16);
  1236. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  1237. // myView.backgroundColor = UIColorFromRGB(0x996633);
  1238. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  1239. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  1240. myView.layer.shadowOffset = CGSizeMake(0, 0);
  1241. myView.layer.shadowOpacity = 0.5;
  1242. myView.layer.shadowRadius = 2.0;
  1243. UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 11, 130, 22)];
  1244. statuslabel.textColor=UIColorFromRGB(color);
  1245. statuslabel.backgroundColor = [UIColor clearColor];
  1246. statuslabel.text=NSLocalizedString(@"SO#", nil);
  1247. [statuslabel sizeToFit];
  1248. [myView addSubview:statuslabel];
  1249. // UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 21, 130, 22)];
  1250. // solabel.textColor=UIColorFromRGB(color);
  1251. // solabel.backgroundColor = [UIColor clearColor];
  1252. // solabel.text=NSLocalizedString(@"SO#", nil);
  1253. // [solabel sizeToFit];
  1254. // [myView addSubview:solabel];
  1255. // UILabel *userlabel = [[UILabel alloc] initWithFrame:CGRectMake(165, 21, 125, 22)];
  1256. // userlabel.textColor=UIColorFromRGB(color);
  1257. // userlabel.backgroundColor = [UIColor clearColor];
  1258. // userlabel.text=NSLocalizedString(@"Sales rep", nil);
  1259. // [userlabel sizeToFit];
  1260. // [myView addSubview:userlabel];
  1261. UILabel *creatorlabel = [[UILabel alloc] initWithFrame:CGRectMake(165, 11, 125, 22)];
  1262. creatorlabel.textColor=UIColorFromRGB(color);
  1263. creatorlabel.backgroundColor = [UIColor clearColor];
  1264. creatorlabel.text=NSLocalizedString(@"Create by", nil);
  1265. [creatorlabel sizeToFit];
  1266. [myView addSubview:creatorlabel];
  1267. UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(296, 11, 150, 22)];
  1268. contactlabel.textColor=UIColorFromRGB(color);
  1269. contactlabel.backgroundColor = [UIColor clearColor];
  1270. contactlabel.text=NSLocalizedString(@"Company / Customer ID", nil);
  1271. [contactlabel sizeToFit];
  1272. [myView addSubview:contactlabel];
  1273. //
  1274. // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(424, 11, 52, 22)];
  1275. // modellabel.textColor=[UIColor whiteColor];
  1276. // modellabel.backgroundColor = [UIColor clearColor];
  1277. // modellabel.text=NSLocalizedString(@"Model", nil);
  1278. // [modellabel sizeToFit];
  1279. // [myView addSubview:modellabel];
  1280. // UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-276, 2, 100, 22)];
  1281. // modellabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  1282. // modellabel.textColor=[UIColor whiteColor];
  1283. // modellabel.backgroundColor = [UIColor clearColor];
  1284. // modellabel.text=NSLocalizedString(@"Items/QTY", nil);
  1285. // [modellabel sizeToFit];
  1286. // [myView addSubview:modellabel];
  1287. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1288. UILabel *pricelabel = nil;
  1289. if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType==1)
  1290. pricelabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 2, 100, 22)];
  1291. else
  1292. pricelabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 11, 100, 22)];
  1293. pricelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  1294. pricelabel.textColor=UIColorFromRGB(color);
  1295. pricelabel.backgroundColor = [UIColor clearColor];
  1296. pricelabel.text=NSLocalizedString(@"Order Total", nil);
  1297. [pricelabel sizeToFit];
  1298. [myView addSubview:pricelabel];
  1299. if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType==1)
  1300. {
  1301. UILabel *polabel = nil;
  1302. polabel=[[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.table_order.frame.size.width-276, 21, 100, 22)];
  1303. polabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  1304. polabel.textColor=UIColorFromRGB(color);
  1305. polabel.backgroundColor = [UIColor clearColor];
  1306. polabel.text=NSLocalizedString(@"PO#", nil);
  1307. [polabel sizeToFit];
  1308. [myView addSubview:polabel];
  1309. }
  1310. UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-163/*605*/,11, 148, 22)];
  1311. timelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  1312. timelabel.textColor=UIColorFromRGB(color);
  1313. timelabel.backgroundColor = [UIColor clearColor];
  1314. if(self.time_zone==nil)
  1315. timelabel.text=@"Create time";
  1316. else
  1317. timelabel.text=[NSString stringWithFormat:@"Create time (%@)",self.time_zone];
  1318. [timelabel sizeToFit];
  1319. [myView addSubview:timelabel];
  1320. myView.autoresizesSubviews=true;
  1321. // [myView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];
  1322. // modellabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1323. // pricelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1324. // timelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
  1325. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  1326. //
  1327. return myView;
  1328. }
  1329. else return nil;
  1330. }
  1331. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  1332. {
  1333. return 44;
  1334. }
  1335. //
  1336. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  1337. // if(section==0)
  1338. // return nil;
  1339. // else
  1340. // return @"detail section";
  1341. //}
  1342. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  1343. {
  1344. return 1;
  1345. }
  1346. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  1347. {
  1348. if(tableView==self.table_order)
  1349. {
  1350. return self.content_data.count;
  1351. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  1352. // if( self.content_data.count==0)
  1353. // return 0;
  1354. // return self.content_data.count+1;
  1355. }
  1356. if(tableView==self.table_submit)
  1357. {
  1358. return self.submit_content_data.count;
  1359. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  1360. // if( self.content_data.count==0)
  1361. // return 0;
  1362. // return self.content_data.count+1;
  1363. }
  1364. else
  1365. {
  1366. AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  1367. return Appdelegate.uploadManager.arr_queue.count;
  1368. }
  1369. }
  1370. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  1371. {
  1372. if(tableView==self.table_order)
  1373. {
  1374. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1375. // if(tableView==self.itemListTable)
  1376. // {
  1377. // if(indexPath.row>self.content_data.count)
  1378. // {
  1379. // int debug=true;
  1380. // }
  1381. // DebugLog(@"row %ld",(long)indexPath.row);
  1382. // if(indexPath.row==self.content_data.count)
  1383. // {
  1384. // UITableViewCell *moreCell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"mores"];
  1385. // UILabel *moreDataLabel=[[UILabel alloc] init];
  1386. //
  1387. // moreDataLabel.tag=200;
  1388. // moreDataLabel.text=self.load_more_hint;
  1389. // [moreDataLabel setFont:[UIFont systemFontOfSize:14.0f]];
  1390. // [moreDataLabel setTextAlignment:NSTextAlignmentCenter];
  1391. // moreDataLabel.frame=CGRectMake(0, 10, self.table_order.bounds.size.width, 20);
  1392. // [moreDataLabel setBackgroundColor:[UIColor clearColor]];
  1393. // moreDataLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
  1394. // // [moreDataLabel addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
  1395. //
  1396. // [moreCell.contentView addSubview:moreDataLabel];
  1397. // if([self.load_more_hint isEqualToString:@"Load more..."])
  1398. // [self performSelector:@selector(loadmore) withObject:nil afterDelay:1];
  1399. // // DebugLog(@"更多...");
  1400. // moreCell.backgroundColor = [UIColor whiteColor];
  1401. // return moreCell;
  1402. // }
  1403. // else
  1404. {
  1405. NSString *CellIdentifier = @"OrderListTableViewCell";
  1406. OrderListTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1407. NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"];
  1408. NSString* price= [self.content_data[indexPath.row] valueForKey:@"price"];
  1409. // if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  1410. // {
  1411. //
  1412. // }
  1413. // else
  1414. // {
  1415. // price=nil;
  1416. // }
  1417. //
  1418. // NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  1419. NSString* purchase_time= [self.content_data[indexPath.row] valueForKey:@"purchase_time"];
  1420. NSString* status = [self.content_data[indexPath.row] valueForKey:@"order_status"] ;
  1421. // if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1422. // status = [ERPUtils orderStatus:statusCode];
  1423. // }
  1424. NSString* customer_name = [self.content_data[indexPath.row] valueForKey:@"customer_name"];
  1425. NSString* model_count = [self.content_data[indexPath.row] valueForKey:@"model_count"];
  1426. NSString* sales = [self.content_data[indexPath.row] valueForKey:@"sales_rep"];
  1427. NSString* creator = [self.content_data[indexPath.row] valueForKey:@"create_by"];
  1428. NSString *po = [self.content_data[indexPath.row] valueForKey:@"po_id"];
  1429. CGRect price_frame = cell.labelprice.frame;
  1430. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType == 1) {
  1431. cell.label_po.hidden = NO;
  1432. price_frame.origin.y = 5;
  1433. cell.label_po.text = po;
  1434. } else {
  1435. cell.label_po.hidden = YES;
  1436. price_frame.origin.y = 21;
  1437. }
  1438. cell.labelprice.frame = price_frame;
  1439. cell.label_so.text=so;
  1440. cell.labelprice.text=price;//price;
  1441. cell.label_date.text=purchase_time;
  1442. cell.label_contact.text=customer_name;
  1443. cell.label_model.hidden = false;
  1444. cell.label_model.text = model_count;
  1445. cell.label_sales.text = sales;
  1446. cell.label_creator.text = creator;
  1447. cell.label_status.text=status;
  1448. cell.backgroundColor = [UIColor whiteColor];
  1449. return cell;
  1450. }
  1451. }
  1452. else if(tableView==self.table_submit)
  1453. {
  1454. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1455. {
  1456. NSString *CellIdentifier = @"OrderListTableViewCell";
  1457. OrderListTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1458. NSString* so= [self.submit_content_data[indexPath.row] valueForKey:@"so#"];
  1459. NSString* price= [self.submit_content_data[indexPath.row] valueForKey:@"price"];
  1460. // if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  1461. // {
  1462. //
  1463. // }
  1464. // else
  1465. // {
  1466. // price=nil;
  1467. // }
  1468. //
  1469. // NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  1470. NSString* purchase_time= [self.submit_content_data[indexPath.row] valueForKey:@"purchase_time"];
  1471. NSString* status = [self.submit_content_data[indexPath.row] valueForKey:@"order_status"] ;
  1472. // if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1473. // status = [ERPUtils orderStatus:statusCode];
  1474. // }
  1475. NSString* customer_name = [self.submit_content_data[indexPath.row] valueForKey:@"customer_name"];
  1476. NSString* model_count = [self.submit_content_data[indexPath.row] valueForKey:@"model_count"];
  1477. NSString* sales = [self.submit_content_data[indexPath.row] valueForKey:@"sales_rep"];
  1478. NSString* creator = [self.submit_content_data[indexPath.row] valueForKey:@"create_by"];
  1479. NSString *po = [self.submit_content_data[indexPath.row] valueForKey:@"po_id"];
  1480. CGRect price_frame = cell.labelprice.frame;
  1481. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore && self.orderType == 1) {
  1482. cell.label_po.hidden = NO;
  1483. price_frame.origin.y = 5;
  1484. cell.label_po.text = po;
  1485. } else {
  1486. cell.label_po.hidden = YES;
  1487. price_frame.origin.y = 21;
  1488. }
  1489. cell.labelprice.frame = price_frame;
  1490. cell.label_so.text=so;
  1491. cell.labelprice.text=price;//[RAConvertor currencyNumber:(price.floatValue)];//price;
  1492. cell.label_date.text=purchase_time;
  1493. cell.label_contact.text=customer_name;
  1494. cell.label_model.hidden = false;
  1495. cell.label_model.text = model_count;
  1496. cell.label_sales.text = sales;
  1497. cell.label_creator.text = creator;
  1498. cell.label_status.text=status;
  1499. cell.backgroundColor = [UIColor whiteColor];
  1500. return cell;
  1501. }
  1502. }
  1503. else
  1504. {
  1505. AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  1506. {
  1507. NSString *CellIdentifier = @"UploadCell";
  1508. UploadCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  1509. NSDictionary * item_json = Appdelegate.uploadManager.arr_queue[indexPath.row];
  1510. //
  1511. // if (cell.operation) {
  1512. // cell.operation.updateUI = nil;
  1513. // }
  1514. RAUploadOperation* op = item_json[@"operation"];
  1515. NSString* status =nil;
  1516. switch ([item_json[@"status"] intValue]) {
  1517. case TaskStatusStart:
  1518. status=@"uploading";
  1519. break;
  1520. case TaskStatusStop:
  1521. status=@"stop";
  1522. break;
  1523. case TaskStatusError:
  1524. status=@"warning";
  1525. break;
  1526. case TaskStatusWait:
  1527. status=@"waiting";
  1528. break;
  1529. case TaskStatusFinish:
  1530. status=@"finish";
  1531. break;
  1532. default:
  1533. status=@"warning";
  1534. break;
  1535. }
  1536. double progress =[item_json[@"progress"] doubleValue];
  1537. cell.progress=progress;
  1538. cell.name=item_json[@"file"];
  1539. cell.state= status;
  1540. cell.errorMsg = item_json[@"msg"];
  1541. // __block RAUploadOperation* block_op = op;
  1542. // __block UploadCell* block_cell = cell;
  1543. // __block NSIndexPath* block_index = indexPath;
  1544. // long idx = indexPath.row;
  1545. // __weak typeof(self) weakself = self;
  1546. op.updateUI=^(){
  1547. // blockDebugLog(@"updateUI @ row%ld %p \n operation %p",idx,block_cell,block_op);
  1548. NSString* status =nil;
  1549. switch ([item_json[@"status"] intValue]) {
  1550. case TaskStatusStart:
  1551. status=@"uploading";
  1552. break;
  1553. case TaskStatusStop:
  1554. status=@"stop";
  1555. break;
  1556. case TaskStatusError:
  1557. status=@"warning";
  1558. break;
  1559. case TaskStatusWait:
  1560. status=@"waiting";
  1561. break;
  1562. case TaskStatusFinish:
  1563. status=@"finish";
  1564. break;
  1565. default:
  1566. status=@"warning";
  1567. break;
  1568. }
  1569. double progress =[item_json[@"progress"] doubleValue];
  1570. cell.progress=progress;
  1571. cell.name=item_json[@"file"];
  1572. cell.state= status;
  1573. cell.errorMsg = item_json[@"msg"];
  1574. };
  1575. DebugLog(@"%@ set update ui",item_json[@"file"]);
  1576. // cell.operation = op;
  1577. //
  1578. return cell;
  1579. }
  1580. }
  1581. }
  1582. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  1583. {
  1584. if(tableView==self.table_order)
  1585. {
  1586. // RASingleton.sharedInstance.enable_OfflineOrder = true;
  1587. if (tableView.isEditing) { // 编辑模式下不响应
  1588. return;
  1589. }
  1590. //
  1591. if(indexPath.row==self.content_data.count)
  1592. return;
  1593. {
  1594. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1595. NSString *orderdir = [OLDataProvider getScanPath];
  1596. // NSMutableDictionary* order= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"order.json"]] mutableCopy];
  1597. NSMutableDictionary* cart= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"cart.json"]] mutableCopy];
  1598. if([appDelegate.available_price_group containsObject:cart[@"price_group"]] && [RADataProvider all_price_group][cart[@"price_group"]]!=nil)
  1599. {
  1600. NSMutableDictionary* orderitem =self.content_data[indexPath.row];
  1601. NSString* ordercode =orderitem[@"order_code"];
  1602. appDelegate.order_code = ordercode;
  1603. [appDelegate setUser:orderitem[@"create_by"]];
  1604. // appDelegate.user =;
  1605. // appDelegate.custo orderitem[@"customer_name"]
  1606. // appDelegate.user_type = USER_ROLE_EMPLOYEE;
  1607. appDelegate.can_set_cart_price = true;
  1608. appDelegate.can_see_price = true;
  1609. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1610. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1611. // NSString *documents = [paths objectAtIndex:0];
  1612. NSMutableDictionary* contact= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"contact.json"]] mutableCopy];
  1613. // NSMutableDictionary* app= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"app.json"]] mutableCopy];
  1614. [appDelegate setCustomerInfo: contact];
  1615. appDelegate.contact_id = contact[@"customer_cid"];
  1616. RASingleton.sharedInstance.scan_cart = cart;
  1617. appDelegate.price_group = cart[@"price_group"];
  1618. RASingleton.sharedInstance.price_type = [cart[@"price_type"] intValue];
  1619. [appDelegate update_count_mark];
  1620. // [appDelegate updateScanButton:true];
  1621. [appDelegate SetMode:@""];
  1622. #ifdef RA_NOTIFICATION
  1623. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1624. #else
  1625. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1626. #endif
  1627. // [self.navigationController pushViewController:orderinfoVC animated:true];
  1628. [((MainViewController*)appDelegate.main_vc) switchToCart];
  1629. return;
  1630. }
  1631. else
  1632. {
  1633. //价格组不存在 询问刷新
  1634. NSString * title =@"Price has changes";
  1635. NSString* message = @"Continue open order will replace all price with new setting";
  1636. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
  1637. //block代码块取代了delegate
  1638. // [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  1639. // textField.text = self.save_name;
  1640. //
  1641. //
  1642. // }];
  1643. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Continue" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1644. NSMutableDictionary* orderitem =self.content_data[indexPath.row];
  1645. NSString* ordercode =orderitem[@"order_code"];
  1646. appDelegate.order_code = ordercode;
  1647. [appDelegate setUser:orderitem[@"create_by"]];
  1648. // appDelegate.user =;
  1649. // appDelegate.custo orderitem[@"customer_name"]
  1650. // appDelegate.user_type = USER_ROLE_EMPLOYEE;
  1651. appDelegate.can_set_cart_price = true;
  1652. appDelegate.can_see_price = true;
  1653. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1654. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1655. // NSString *documents = [paths objectAtIndex:0];
  1656. NSMutableDictionary* contact= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"contact.json"]] mutableCopy];
  1657. // NSMutableDictionary* app= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"app.json"]] mutableCopy];
  1658. [appDelegate setCustomerInfo: contact];
  1659. appDelegate.contact_id = contact[@"customer_cid"];
  1660. //用默认价格组替换订单之前保存的价格组
  1661. [RADataProvider default_price_group];
  1662. cart[@"price_group"]=appDelegate.price_group;
  1663. RASingleton.sharedInstance.scan_cart = cart;
  1664. // appDelegate.price_group = cart[@"price_group"];
  1665. RASingleton.sharedInstance.price_type = [cart[@"price_type"] intValue];
  1666. [appDelegate update_count_mark];
  1667. // [appDelegate updateScanButton:true];
  1668. [appDelegate SetMode:@""];
  1669. #ifdef RA_NOTIFICATION
  1670. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1671. #else
  1672. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1673. #endif
  1674. // [self.navigationController pushViewController:orderinfoVC animated:true];
  1675. [((MainViewController*)appDelegate.main_vc) switchToCart];
  1676. return;
  1677. }];
  1678. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1679. DebugLog(@"Cancel");
  1680. return;
  1681. }];
  1682. [alertControl addAction:actionOne];
  1683. [alertControl addAction:alertthree];
  1684. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1685. [self presentViewController:alertControl animated:YES completion:nil];
  1686. }
  1687. }
  1688. }
  1689. else if(tableView==self.table_submit)
  1690. {
  1691. // RASingleton.sharedInstance.enable_OfflineOrder = true;
  1692. if (tableView.isEditing) { // 编辑模式下不响应
  1693. return;
  1694. }
  1695. //
  1696. // if(indexPath.row==self.content_data.count)
  1697. // return;
  1698. {
  1699. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1700. NSMutableDictionary* orderitem =self.submit_content_data[indexPath.row];
  1701. NSString* ordercode =orderitem[@"order_code"];
  1702. NSString *orderdir = [OLDataProvider getScanOrderPathByCode:ordercode];
  1703. // orderdir = [orderdir stringByAppendingPathComponent:ordercode];
  1704. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1705. CreateOrderViewController * orderinfoVC = [[CreateOrderViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1706. orderinfoVC.disable_dropdown_refresh=true;
  1707. orderinfoVC.url_type = URL_FILE;
  1708. orderinfoVC.request_url=[orderdir stringByAppendingPathComponent:@"order.json"];
  1709. orderinfoVC.params = params;
  1710. orderinfoVC.title=@"";
  1711. orderinfoVC.delegate=nil;
  1712. [self.navigationController pushViewController:orderinfoVC animated:true];
  1713. // if(checked.count==count)
  1714. // {
  1715. // orderinfoVC.have_tail = true
  1716. // }
  1717. // appDelegate.order_code = ordercode;
  1718. //
  1719. // [appDelegate setUser:orderitem[@"create_by"]];
  1720. //
  1721. // appDelegate.can_set_cart_price = true;
  1722. // appDelegate.can_see_price = true;
  1723. //
  1724. //
  1725. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1726. //
  1727. //
  1728. //
  1729. //
  1730. // NSString *orderdir = [OLDataProvider getScanPath];
  1731. // NSMutableDictionary* cart= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"cart.json"]] mutableCopy];
  1732. // NSMutableDictionary* contact= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"contact.json"]] mutableCopy];
  1733. //
  1734. // [appDelegate setCustomerInfo: contact];
  1735. // appDelegate.contact_id = contact[@"customer_cid"];
  1736. // RASingleton.sharedInstance.scan_cart = cart;
  1737. // RASingleton.sharedInstance.price_type = [cart[@"price_type"] intValue];
  1738. //
  1739. //
  1740. // [appDelegate update_count_mark];
  1741. // [appDelegate SetMode:@""];
  1742. //
  1743. //
  1744. //
  1745. //#ifdef RA_NOTIFICATION
  1746. // [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1747. //#else
  1748. //
  1749. //
  1750. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1751. //#endif
  1752. //
  1753. //// [self.navigationController pushViewController:orderinfoVC animated:true];
  1754. //
  1755. // [((MainViewController*)appDelegate.main_vc) switchToCart];
  1756. //
  1757. return;
  1758. }
  1759. }
  1760. }
  1761. #pragma mark - searchBar delegate;
  1762. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  1763. {
  1764. self.keywords=searchBar.text;
  1765. // self.offset = 0;
  1766. // [self.content_data removeAllObjects];
  1767. self.reset_result=true;
  1768. [self loadpage];
  1769. }
  1770. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  1771. {
  1772. if([searchText isEqualToString:@""] && !self.reset)
  1773. {
  1774. DebugLog(@"clear");
  1775. self.reset=true;
  1776. self.keywords=nil;
  1777. // self.offset = 0;
  1778. // [self.content_data removeAllObjects];
  1779. self.reset_result=true;
  1780. [self loadpage];
  1781. }
  1782. else
  1783. self.reset = false;
  1784. }
  1785. #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
  1786. - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
  1787. {
  1788. // 添加一个删除按钮
  1789. // self.indexPath=indexPath;
  1790. if(tableView==self.table_order)
  1791. {
  1792. if(indexPath.row==self.content_data.count)
  1793. return @[];
  1794. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1795. // NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"];
  1796. NSString* order_code= [self.content_data[indexPath.row] valueForKey:@"order_code"];
  1797. // NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  1798. // NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  1799. if(true/*appDelegate.user_type==USER_ROLE_EMPLOYEE || (appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeCustomer)*/) {
  1800. UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1801. DebugLog(@"delete click");
  1802. NSString * title =@"Are you sure to delete order?";
  1803. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
  1804. //block代码块取代了delegate
  1805. // [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  1806. // textField.text = self.save_name;
  1807. //
  1808. //
  1809. // }];
  1810. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1811. [OLDataProvider deleteScanOrder:order_code];
  1812. if([appDelegate.order_code isEqualToString:order_code])
  1813. [appDelegate closeOrder];
  1814. //
  1815. // [self prepareReturn:nil];
  1816. // [self.navigationController popViewControllerAnimated:true];
  1817. // [((MainViewController*)appDelegate.main_vc) switchToOrder];
  1818. return;
  1819. }];
  1820. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1821. DebugLog(@"Cancel");
  1822. }];
  1823. [alertControl addAction:actionOne];
  1824. [alertControl addAction:alertthree];
  1825. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1826. [self presentViewController:alertControl animated:YES completion:nil];
  1827. }];
  1828. deleteRowAction.backgroundColor = UIColor.redColor;//UIColorFromRGB(0x336699);
  1829. // 添加一个编辑按钮
  1830. //
  1831. // if(/*[order_status isEqualToString:@"Saved Order"]*/statusCode == 1&&appDelegate.can_cancel_order)
  1832. // return @[cancelAction];
  1833. //
  1834. // else
  1835. // {
  1836. {
  1837. NSMutableArray* arr=[@[] mutableCopy];
  1838. if(appDelegate.can_delete_order)
  1839. [arr addObject:deleteRowAction];
  1840. // if(appDelegate.can_cancel_order)
  1841. // [arr addObject:cancelAction];
  1842. return arr;
  1843. }
  1844. // }
  1845. }
  1846. return @[];
  1847. }
  1848. else if(tableView==self.table_submit)
  1849. {
  1850. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1851. // NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"];
  1852. NSString* order_code= [self.submit_content_data[indexPath.row] valueForKey:@"order_code"];
  1853. // NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  1854. // NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  1855. {
  1856. UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1857. DebugLog(@"delete click");
  1858. NSString * title =@"Are you sure to delete the submitted record?";
  1859. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
  1860. //block代码块取代了delegate
  1861. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1862. [OLDataProvider deleteSubmittedOrder:order_code];
  1863. return;
  1864. }];
  1865. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1866. DebugLog(@"Cancel");
  1867. }];
  1868. [alertControl addAction:actionOne];
  1869. [alertControl addAction:alertthree];
  1870. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1871. [self presentViewController:alertControl animated:YES completion:nil];
  1872. }];
  1873. deleteRowAction.backgroundColor = UIColorFromRGB(0x336699);
  1874. // 添加一个编辑按钮
  1875. {
  1876. NSMutableArray* arr=[@[] mutableCopy];
  1877. if(appDelegate.can_delete_order)
  1878. [arr addObject:deleteRowAction];
  1879. // if(appDelegate.can_cancel_order)
  1880. // [arr addObject:cancelAction];
  1881. return arr;
  1882. }
  1883. // }
  1884. }
  1885. }
  1886. else
  1887. {
  1888. AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  1889. NSMutableDictionary * task = Appdelegate.uploadManager.arr_queue[indexPath.row];
  1890. __weak typeof(self) weakself = self;
  1891. UITableViewRowAction *startAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Restart"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1892. if (Appdelegate.uploadManager.onlyWiFi && Appdelegate.uploadManager.reach.currentReachabilityStatus != ReachableViaWiFi) {
  1893. [weakself.view makeToast:@"Current Network is not WiFi" duration:3.0 position:CSToastPositionCenter];
  1894. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1895. return ;
  1896. }
  1897. DebugLog(@"Start click");
  1898. task[@"retry"]=[NSNumber numberWithInt:0];
  1899. [Appdelegate.uploadManager startTask:task];
  1900. [tableView reloadData];
  1901. }];
  1902. startAction.backgroundColor = UIColorFromRGB(0xff9933);
  1903. UITableViewRowAction *removeAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Remove" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1904. [Appdelegate.uploadManager removeTask:task];
  1905. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1906. }];
  1907. removeAction.backgroundColor = UIColorFromRGB(0x9BBF5A);
  1908. // UIColorFromRGB(0x336699);
  1909. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1910. switch ([task[@"status"] intValue]) {
  1911. case TaskStatusFinish:
  1912. return @[removeAction];
  1913. case TaskStatusError:
  1914. return @[startAction,removeAction];
  1915. case TaskStatusStop:
  1916. return @[startAction];
  1917. default:
  1918. return nil;
  1919. break;
  1920. }
  1921. }
  1922. }
  1923. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  1924. if(tableView==self.table_order)
  1925. {
  1926. if(indexPath.row==self.content_data.count)
  1927. return NO;
  1928. // // if(self.init_style==OL_OPEN)
  1929. // // return NO;
  1930. //
  1931. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1932. // // NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  1933. // NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  1934. //
  1935. // if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1936. // // saved && ((type==0 && merge_permission) || type == 1 || can_cancel)
  1937. //
  1938. // BOOL isSavedOrder = /*[order_status isEqualToString:@"Saved Order"]*/statusCode == 1;
  1939. // switch (self.orderType) {
  1940. // case 0:{ // Shop Order
  1941. //
  1942. // if (!isSavedOrder) {
  1943. // return NO;
  1944. // } else {
  1945. // if ([RASingleton sharedInstance].permissions_merge_order || appDelegate.can_cancel_order) {
  1946. // return YES;
  1947. // } else {
  1948. // return NO;
  1949. // }
  1950. // }
  1951. //
  1952. // }
  1953. // break;
  1954. // case 1:{ // Sales Order
  1955. // if (isSavedOrder && appDelegate.can_cancel_order) {
  1956. // return YES;
  1957. // }
  1958. // return NO;
  1959. // }
  1960. // break;
  1961. //
  1962. // default:
  1963. // break;
  1964. // }
  1965. //
  1966. // } else {
  1967. // return YES;
  1968. // }
  1969. return YES;
  1970. }
  1971. else if(tableView==self.table_submit)
  1972. {
  1973. return YES;
  1974. }
  1975. else
  1976. {
  1977. AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  1978. if(Appdelegate.uploadManager.arr_queue.count==0)
  1979. return false;
  1980. NSDictionary * item_json = Appdelegate.uploadManager.arr_queue[indexPath.row];
  1981. bool ret=false;
  1982. switch ([item_json[@"status"] intValue]) {
  1983. case TaskStatusStart:
  1984. case TaskStatusWait:
  1985. ret=false;
  1986. break;
  1987. case TaskStatusFinish:
  1988. case TaskStatusStop:
  1989. case TaskStatusError:
  1990. ret = true;
  1991. break;
  1992. default:
  1993. ret=false;
  1994. break;
  1995. }
  1996. return ret;
  1997. }
  1998. }
  1999. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  2000. if(tv==self.table_order)
  2001. {
  2002. if(indexPath.row==self.content_data.count)
  2003. return UITableViewCellEditingStyleNone;
  2004. bool offline_edit =[[self.content_data[indexPath.row] valueForKey:@"offline_edit"] boolValue];
  2005. // NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  2006. NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  2007. if(/*![order_status isEqualToString:@"Saved Order"]&&! [order_status isEqualToString:@"Quote Saved"]*/statusCode != 1 && statusCode != 0)
  2008. return UITableViewCellEditingStyleNone;
  2009. else
  2010. {
  2011. BOOL condition = offline_edit;
  2012. #ifdef OFFLINE_MODE
  2013. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2014. condition = condition || appDelegate.offline_mode==false;
  2015. #else
  2016. condition = YES;
  2017. #endif
  2018. if (condition)
  2019. return UITableViewCellEditingStyleDelete;
  2020. else
  2021. return UITableViewCellEditingStyleNone;
  2022. }
  2023. }
  2024. else
  2025. return UITableViewCellEditingStyleDelete;
  2026. }
  2027. /*
  2028. #pragma mark - Navigation
  2029. // In a storyboard-based application, you will often want to do a little preparation before navigation
  2030. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  2031. // Get the new view controller using [segue destinationViewController].
  2032. // Pass the selected object to the new view controller.
  2033. }
  2034. */
  2035. #pragma mark EnumSelectViewControllerDelegate
  2036. -(void) EnumValueChanged:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  2037. {
  2038. self.status_cadedate = value;
  2039. UIApplication * app = [UIApplication sharedApplication];
  2040. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2041. appDelegate.OrderFilter = value;
  2042. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  2043. // NSString *documents = [paths objectAtIndex:0];
  2044. // NSString *dist_path = [documents stringByAppendingPathComponent:@"status_filter_cadedate.json"];
  2045. //
  2046. //
  2047. // // if ([[NSFileManager defaultManager] fileExistsAtPath:dist_path]) {
  2048. // //
  2049. // // DebugLog(@"文件已经存在了");
  2050. // //
  2051. // // }
  2052. // // else
  2053. // // {
  2054. // //
  2055. // //
  2056. // //
  2057. // // DebugLog(@"resourceSampleImagesFolderPath=%@",resourceFolderPath);
  2058. //
  2059. //NSData *data = [NSJSONSerialization dataWithJSONObject:self.status_cadedate options:kNilOptions error:nil];
  2060. //
  2061. // // DebugLog(@"mainBundleFile==%@",mainBundleFile);
  2062. //
  2063. // [[NSFileManager defaultManager] createFileAtPath:dist_path
  2064. //
  2065. // contents:data
  2066. //
  2067. // attributes:nil];
  2068. //
  2069. // }
  2070. // self.keywords=searchBar.text;
  2071. // self.offset = 0;
  2072. // [self.content_data removeAllObjects];
  2073. self.reset_result=true;
  2074. [self loadpage];
  2075. //[self.btnStatusFilter setTitle:setTitle:alert ];
  2076. }
  2077. #pragma mark - button action
  2078. - (NSIndexPath *)indexPathOfDeleteOrder:(NSString *)orderID {
  2079. for (NSIndexPath *indexPath in self.table_order.indexPathsForSelectedRows) {
  2080. NSString* orderid= [NSString stringWithFormat:@"%@",[self.content_data[indexPath.row] valueForKey:@"order_id"]];
  2081. if ([orderid isEqualToString:orderID]) {
  2082. return indexPath;
  2083. }
  2084. }
  2085. return nil;
  2086. }
  2087. //
  2088. //- (IBAction)mergeListButtonClick:(UIBarButtonItem *)sender {
  2089. //
  2090. // if (!self.table_order.isEditing) {
  2091. //
  2092. // [RAUtils message_alert:@"You have to click select firstly then select some saved order" title:@"Warning" controller:self];
  2093. // return;
  2094. // }
  2095. //
  2096. // [self handleSelectedOrders];
  2097. //
  2098. // if (!self.mergeList.count) {
  2099. //
  2100. // // [RAUtils message_alert:@"Combine List is Empty" title:@"Warning" controller:self];
  2101. // return;
  2102. // }
  2103. //
  2104. // SelectUploadOrderViewController *mergeVC = [[UIStoryboard storyboardWithName:@"OLM" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SelectUploadOrderViewController"];
  2105. //
  2106. // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:mergeVC];
  2107. //
  2108. // mergeVC.mergeList = self.mergeList;
  2109. //
  2110. // mergeVC.title = @"Combine List";
  2111. //
  2112. // __weak typeof(self) weakself = self;
  2113. //
  2114. // mergeVC.mergeBlock = ^(NSDictionary *ret) {
  2115. //
  2116. //
  2117. // if (weakself) {
  2118. //
  2119. // __strong typeof(weakself) strongself = weakself;
  2120. //
  2121. // if([[ret objectForKey:@"result"]integerValue] == RESULT_TRUE) {
  2122. //
  2123. // [weakself.mergeList removeAllObjects];
  2124. // [strongself.table_order endEditing:YES];
  2125. // [strongself ReloadData];
  2126. //
  2127. // if ([RASingleton sharedInstance].customer_can_see_sales_Order) {
  2128. //
  2129. // [strongself openOrder:ret];
  2130. //
  2131. // }
  2132. //
  2133. // } else {
  2134. //
  2135. // NSString *msg = [ret objectForKey:@"err_msg"];
  2136. // [RAUtils message_alert:msg title:nil controller:strongself];
  2137. // }
  2138. // }
  2139. //
  2140. // };
  2141. //
  2142. // mergeVC.deleteBlock = ^(NSString *orderID){
  2143. // NSIndexPath *indexPath = [weakself indexPathOfDeleteOrder:orderID];
  2144. // [weakself.table_order deselectRowAtIndexPath:indexPath animated:YES];
  2145. // };
  2146. //
  2147. // mergeVC.clearBlock = ^{
  2148. // for (NSDictionary *order in self.mergeList) {
  2149. //
  2150. // NSString *order_id = [NSString stringWithFormat:@"%@",[order objectForKey:@"order_id"]];
  2151. // NSIndexPath *indexPath = [weakself indexPathOfDeleteOrder:order_id];
  2152. // [weakself.table_order deselectRowAtIndexPath:indexPath animated:YES];
  2153. // }
  2154. // };
  2155. //
  2156. // nav.modalPresentationStyle = UIModalPresentationFormSheet;
  2157. //
  2158. // [self presentViewController:nav animated:YES completion:nil];
  2159. //
  2160. //}
  2161. - (void)handleSelectedOrders {
  2162. [self.mergeList removeAllObjects];
  2163. if (!self.table_order.isEditing) {
  2164. return;
  2165. }
  2166. for (NSIndexPath *indexPath in self.table_order.indexPathsForSelectedRows) {
  2167. if(indexPath.row==self.content_data.count)
  2168. continue;
  2169. NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"];
  2170. NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"];
  2171. NSString *create_by = [self.content_data[indexPath.row] valueForKey:@"create_by"];
  2172. NSString *create_time = [self.content_data[indexPath.row] valueForKey:@"purchase_time"];
  2173. NSString *orderCode = [NSString stringWithFormat:@"%@",[self.content_data[indexPath.row] valueForKey:@"order_code"]];
  2174. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  2175. [dic setValue:orderid forKey:@"order_id"];
  2176. [dic setValue:orderCode forKey:@"order_code"];
  2177. [dic setValue:so forKey:@"so_id"];
  2178. [dic setValue:create_by forKey:@"create_by"];
  2179. [dic setValue:create_time forKey:@"create_time"];
  2180. [dic setValue:[NSNumber numberWithInteger:0] forKey:@"check"]; // 合并到
  2181. [self.mergeList addObject:dic];
  2182. }
  2183. }
  2184. - (IBAction)editOrderListButtonClick:(UIBarButtonItem *)sender {
  2185. // if ([RASingleton sharedInstance].global_lock) { // Order list 被锁
  2186. // [RAUtils message_alert:@"Permission Needed.\nGoto Menu -> Unlock" title:@"Warning" controller:self];
  2187. // return;
  2188. // }
  2189. //
  2190. // UIImage *gray = [UIImage imageNamed:@"Combinegray"];
  2191. // UIImage *green = [[UIImage imageNamed:@"converttopo"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//converttopo
  2192. //
  2193. // if (self.table_order.isEditing) {
  2194. // [self mergeListButtonClick:nil];
  2195. // // 结束选择时恢复
  2196. // if ([RASingleton sharedInstance].customer_can_see_sales_Order && ![RASingleton sharedInstance].global_lock) { // 有查看Sales order 权限,并且app没有锁
  2197. // if (self.orderTypeSegmentControl.numberOfSegments == 1) {
  2198. // [self.orderTypeSegmentControl insertSegmentWithTitle:[NSString stringWithFormat:@"Purchase Order to %@",COMPANY_SHORT_NAME] atIndex:1 animated:YES];
  2199. // }
  2200. // }
  2201. //
  2202. // self.status_cadedate = self.shop_order_filter;
  2203. // [self ReloadData];
  2204. //
  2205. // [self.table_order setEditing:NO animated:YES];
  2206. //// sender.title = @"Select";
  2207. //// [self.mergeList removeAllObjects];
  2208. // [sender setImage:gray];
  2209. //
  2210. // } else {
  2211. // // 选择时不能选择Sales Order
  2212. // if(self.orderTypeSegmentControl.numberOfSegments > 1) {
  2213. // [self.orderTypeSegmentControl removeSegmentAtIndex:1 animated:YES];
  2214. // [self changeOrderType:0];
  2215. // }
  2216. // // 切换filter
  2217. // NSData *data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"status_filter_cadedate_open" ofType:@"json" ]];
  2218. // NSError *error=nil;
  2219. // self.status_cadedate = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  2220. // // 刷新,取Saved Order
  2221. // [self ReloadData];
  2222. //
  2223. // [self.table_order setEditing:YES animated:YES];
  2224. //// sender.title = @"Exit";
  2225. // [sender setImage:green];
  2226. // }
  2227. }
  2228. - (IBAction)onSegmentChanged:(UISegmentedControl *)sender {
  2229. if(sender.selectedSegmentIndex==0)
  2230. {
  2231. self.table_order.hidden=false;
  2232. self.table_upload.hidden = true;
  2233. [self.table_order reloadData];
  2234. }
  2235. else if(sender.selectedSegmentIndex==1)
  2236. {
  2237. // self.table_order.hidden=true;
  2238. // self.table_upload.hidden = false;
  2239. // [self.table_upload reloadData];
  2240. self.table_order.hidden=true;
  2241. self.table_submit.hidden = false;
  2242. [self.table_submit reloadData];
  2243. }
  2244. // else
  2245. // {
  2246. // [self onNewOrderClicked:nil];
  2247. // }
  2248. //
  2249. }
  2250. //
  2251. //- (void)openOrder:(NSDictionary *)order {
  2252. //
  2253. // if (!order) {
  2254. // return;
  2255. // }
  2256. //
  2257. // NSString *orderCode = [order objectForKey:@"orderCode"];
  2258. // NSInteger orderStatus = [[order objectForKey:@"orderStatus"] integerValue];
  2259. // NSString *so = [order objectForKey:@"so#"];
  2260. //
  2261. // __weak typeof(self) weakself = self;
  2262. //
  2263. // [RANetwork request_open_order:orderCode completionHandler:^(NSMutableDictionary *result) {
  2264. // NSDictionary* order_json = result ;
  2265. //
  2266. //
  2267. // if([[order_json valueForKey:@"result"] intValue]==2)
  2268. // {
  2269. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2270. // appDelegate.order_code = orderCode;
  2271. // appDelegate.order_status = (int)orderStatus;
  2272. // [appDelegate SetSo:so];
  2273. //
  2274. // __weak MainViewController *mainVC = (MainViewController*)appDelegate.main_vc;
  2275. //
  2276. //#ifdef RA_NOTIFICATION
  2277. // [ActiveViewController Notify:@"CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2278. //#else
  2279. //
  2280. //
  2281. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2282. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  2283. // [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
  2284. //#endif
  2285. //
  2286. // [((MainViewController*)appDelegate.main_vc) switchToCart];
  2287. //
  2288. // mainVC.cartViewController.onFinishLoad=^{
  2289. // [mainVC.cartViewController placeOrder];
  2290. // mainVC.cartViewController.onFinishLoad=nil;
  2291. // };
  2292. //
  2293. // }
  2294. // else
  2295. // {
  2296. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order" controller:weakself] ;
  2297. // }
  2298. //
  2299. //
  2300. //
  2301. //
  2302. // }];
  2303. // // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2304. // //
  2305. // // NSDictionary* order_json = [RANetwork open_Order:orderCode];
  2306. // //
  2307. // // dispatch_async(dispatch_get_main_queue(), ^{
  2308. // //
  2309. // // if([[order_json valueForKey:@"result"] intValue]==2)
  2310. // // {
  2311. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2312. // // appDelegate.order_code = orderCode;
  2313. // // appDelegate.order_status = orderStatus;
  2314. // // [appDelegate SetSo:so];
  2315. // //
  2316. // // __weak MainViewController *mainVC = (MainViewController*)appDelegate.main_vc;
  2317. // //
  2318. // //#ifdef RA_NOTIFICATION
  2319. // // [ActiveViewController Notify:@"CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2320. // //#else
  2321. // //
  2322. // //
  2323. // // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2324. // // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  2325. // // [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
  2326. // //#endif
  2327. // //
  2328. // // [((MainViewController*)appDelegate.main_vc) switchToCart];
  2329. // //
  2330. // // mainVC.cartViewController.onFinishLoad=^{
  2331. // // [mainVC.cartViewController placeOrder];
  2332. // // mainVC.cartViewController.onFinishLoad=nil;
  2333. // // };
  2334. // //
  2335. // // }
  2336. // // else
  2337. // // {
  2338. // // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order" controller:weakself] ;
  2339. // // }
  2340. // //
  2341. // //
  2342. // //
  2343. // // });
  2344. // // });
  2345. //
  2346. //
  2347. //}
  2348. #pragma mark - notification action
  2349. - (void)changePriceType:(id)notification {
  2350. [self ReloadData];
  2351. }
  2352. - (void)lockOrderListNotification:(NSNotification *)notification {
  2353. if ([notification.name isEqual:Lock_Permission_Notification]) {
  2354. if (self.orderType == 1) {
  2355. self.orderTypeSegmentControl.selectedSegmentIndex = 0;
  2356. // [self changeOrderType:0];
  2357. [self.orderTypeSegmentControl sendActionsForControlEvents:UIControlEventValueChanged];
  2358. }
  2359. if(self.orderTypeSegmentControl.numberOfSegments > 1) {
  2360. [self.orderTypeSegmentControl removeSegmentAtIndex:1 animated:YES];
  2361. // [self changeOrderType:0];
  2362. }
  2363. } else { // 解锁
  2364. if ([RASingleton sharedInstance].customer_can_see_sales_Order) { // 有查看Sales order 权限
  2365. if (self.orderTypeSegmentControl.numberOfSegments == 1 && !self.table_order.isEditing) {
  2366. [self.orderTypeSegmentControl insertSegmentWithTitle:[NSString stringWithFormat:@"Purchase Order to %@",COMPANY_SHORT_NAME] atIndex:1 animated:YES];
  2367. }
  2368. }
  2369. }
  2370. }
  2371. - (void)handleUserLogin:(NSNotification *)notification {
  2372. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2373. self.orderType = 0;
  2374. if (self.table_order.isEditing) {
  2375. [self.table_order setEditing:NO animated:YES];
  2376. self.editOrderListButton.image = [UIImage imageNamed:@"Combinegray"];
  2377. }
  2378. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  2379. self.orderTypeSegmentControl.selectedSegmentIndex = 0;
  2380. [RASingleton sharedInstance].customer_order_type = 0;
  2381. }
  2382. }
  2383. - (void)reRefreshView {
  2384. [self.table_order reloadData];
  2385. }
  2386. #pragma mark - RA_NOTIFICAITON
  2387. -(void) refresh_ui
  2388. {
  2389. [self.table_order reloadData];
  2390. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2391. if(appDelegate.can_create_order)
  2392. {
  2393. [self.btn_newOrder setImage:[UIImage imageNamed:@"neworder"]];
  2394. self.btn_newOrder.enabled = true;
  2395. }
  2396. else
  2397. {
  2398. [self.btn_newOrder setImage:nil];
  2399. self.btn_newOrder.enabled = false;
  2400. }
  2401. }
  2402. -(void) reload_data
  2403. {
  2404. self.reset_result=true;
  2405. self.norefresh=true;
  2406. [self loadpage];
  2407. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2408. if(appDelegate.can_create_order)
  2409. {
  2410. [self.btn_newOrder setImage:[UIImage imageNamed:@"neworder"]];
  2411. self.btn_newOrder.enabled = true;
  2412. }
  2413. else
  2414. {
  2415. [self.btn_newOrder setImage:nil];
  2416. self.btn_newOrder.enabled = false;
  2417. }
  2418. }
  2419. -(void) refresh_price
  2420. {
  2421. [self refresh_ui];
  2422. }
  2423. @end