ScanOrderListViewController.m 115 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987
  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. NSString *userdir = [OLDataProvider getUserPath];
  1597. NSMutableDictionary* orderitem =self.content_data[indexPath.row];
  1598. NSString* ordercode =orderitem[@"order_code"];
  1599. NSString *orderdir = [userdir stringByAppendingPathComponent:ordercode];
  1600. // NSMutableDictionary* order= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"order.json"]] mutableCopy];
  1601. NSMutableDictionary* cart= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"cart.json"]] mutableCopy];
  1602. if([appDelegate.available_price_group containsObject:cart[@"price_group"]] && [RADataProvider all_price_group][cart[@"price_group"]]!=nil)
  1603. {
  1604. appDelegate.order_code = ordercode;
  1605. [appDelegate setUser:orderitem[@"create_by"]];
  1606. // appDelegate.user =;
  1607. // appDelegate.custo orderitem[@"customer_name"]
  1608. // appDelegate.user_type = USER_ROLE_EMPLOYEE;
  1609. appDelegate.can_set_cart_price = true;
  1610. appDelegate.can_see_price = true;
  1611. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1612. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1613. // NSString *documents = [paths objectAtIndex:0];
  1614. NSMutableDictionary* contact= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"contact.json"]] mutableCopy];
  1615. // NSMutableDictionary* app= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"app.json"]] mutableCopy];
  1616. [appDelegate setCustomerInfo: contact];
  1617. appDelegate.contact_id = contact[@"customer_cid"];
  1618. RASingleton.sharedInstance.scan_cart = cart;
  1619. appDelegate.price_group = cart[@"price_group"];
  1620. RASingleton.sharedInstance.price_type = [cart[@"price_type"] intValue];
  1621. [appDelegate update_count_mark];
  1622. // [appDelegate updateScanButton:true];
  1623. [appDelegate SetMode:@""];
  1624. #ifdef RA_NOTIFICATION
  1625. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1626. #else
  1627. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1628. #endif
  1629. // [self.navigationController pushViewController:orderinfoVC animated:true];
  1630. [((MainViewController*)appDelegate.main_vc) switchToCart];
  1631. return;
  1632. }
  1633. else
  1634. {
  1635. //价格组不存在 询问刷新
  1636. NSString * title =@"Price Has Changed";
  1637. NSString* message = @"Shopping cart items will show updated prices. ";
  1638. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
  1639. //block代码块取代了delegate
  1640. // [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  1641. // textField.text = self.save_name;
  1642. //
  1643. //
  1644. // }];
  1645. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Continue" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1646. NSMutableDictionary* orderitem =self.content_data[indexPath.row];
  1647. NSString* ordercode =orderitem[@"order_code"];
  1648. appDelegate.order_code = ordercode;
  1649. [appDelegate setUser:orderitem[@"create_by"]];
  1650. // appDelegate.user =;
  1651. // appDelegate.custo orderitem[@"customer_name"]
  1652. // appDelegate.user_type = USER_ROLE_EMPLOYEE;
  1653. appDelegate.can_set_cart_price = true;
  1654. appDelegate.can_see_price = true;
  1655. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1656. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1657. // NSString *documents = [paths objectAtIndex:0];
  1658. NSMutableDictionary* contact= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"contact.json"]] mutableCopy];
  1659. // NSMutableDictionary* app= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"app.json"]] mutableCopy];
  1660. [appDelegate setCustomerInfo: contact];
  1661. appDelegate.contact_id = contact[@"customer_cid"];
  1662. //用默认价格组替换订单之前保存的价格组
  1663. [RADataProvider default_price_group];
  1664. cart[@"price_group"]=appDelegate.price_group;
  1665. RASingleton.sharedInstance.scan_cart = cart;
  1666. // appDelegate.price_group = cart[@"price_group"];
  1667. RASingleton.sharedInstance.price_type = [cart[@"price_type"] intValue];
  1668. [appDelegate update_count_mark];
  1669. // [appDelegate updateScanButton:true];
  1670. [appDelegate SetMode:@""];
  1671. #ifdef RA_NOTIFICATION
  1672. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_CART_REFRESH];
  1673. #else
  1674. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1675. #endif
  1676. // [self.navigationController pushViewController:orderinfoVC animated:true];
  1677. [((MainViewController*)appDelegate.main_vc) switchToCart];
  1678. return;
  1679. }];
  1680. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Close" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1681. DebugLog(@"Cancel");
  1682. return;
  1683. }];
  1684. [alertControl addAction:actionOne];
  1685. [alertControl addAction:alertthree];
  1686. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1687. [self presentViewController:alertControl animated:YES completion:nil];
  1688. }
  1689. }
  1690. }
  1691. else if(tableView==self.table_submit)
  1692. {
  1693. // RASingleton.sharedInstance.enable_OfflineOrder = true;
  1694. if (tableView.isEditing) { // 编辑模式下不响应
  1695. return;
  1696. }
  1697. //
  1698. // if(indexPath.row==self.content_data.count)
  1699. // return;
  1700. {
  1701. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1702. NSMutableDictionary* orderitem =self.submit_content_data[indexPath.row];
  1703. NSString* ordercode =orderitem[@"order_code"];
  1704. NSString *orderdir = [OLDataProvider getScanOrderPathByCode:ordercode];
  1705. // orderdir = [orderdir stringByAppendingPathComponent:ordercode];
  1706. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1707. CreateOrderViewController * orderinfoVC = [[CreateOrderViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1708. orderinfoVC.disable_dropdown_refresh=true;
  1709. orderinfoVC.url_type = URL_FILE;
  1710. orderinfoVC.request_url=[orderdir stringByAppendingPathComponent:@"order.json"];
  1711. orderinfoVC.params = params;
  1712. orderinfoVC.title=@"";
  1713. orderinfoVC.delegate=nil;
  1714. [self.navigationController pushViewController:orderinfoVC animated:true];
  1715. // if(checked.count==count)
  1716. // {
  1717. // orderinfoVC.have_tail = true
  1718. // }
  1719. // appDelegate.order_code = ordercode;
  1720. //
  1721. // [appDelegate setUser:orderitem[@"create_by"]];
  1722. //
  1723. // appDelegate.can_set_cart_price = true;
  1724. // appDelegate.can_see_price = true;
  1725. //
  1726. //
  1727. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1728. //
  1729. //
  1730. //
  1731. //
  1732. // NSString *orderdir = [OLDataProvider getScanPath];
  1733. // NSMutableDictionary* cart= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"cart.json"]] mutableCopy];
  1734. // NSMutableDictionary* contact= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"contact.json"]] mutableCopy];
  1735. //
  1736. // [appDelegate setCustomerInfo: contact];
  1737. // appDelegate.contact_id = contact[@"customer_cid"];
  1738. // RASingleton.sharedInstance.scan_cart = cart;
  1739. // RASingleton.sharedInstance.price_type = [cart[@"price_type"] intValue];
  1740. //
  1741. //
  1742. // [appDelegate update_count_mark];
  1743. // [appDelegate SetMode:@""];
  1744. //
  1745. //
  1746. //
  1747. //#ifdef RA_NOTIFICATION
  1748. // [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1749. //#else
  1750. //
  1751. //
  1752. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  1753. //#endif
  1754. //
  1755. //// [self.navigationController pushViewController:orderinfoVC animated:true];
  1756. //
  1757. // [((MainViewController*)appDelegate.main_vc) switchToCart];
  1758. //
  1759. return;
  1760. }
  1761. }
  1762. }
  1763. #pragma mark - searchBar delegate;
  1764. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  1765. {
  1766. self.keywords=searchBar.text;
  1767. // self.offset = 0;
  1768. // [self.content_data removeAllObjects];
  1769. self.reset_result=true;
  1770. [self loadpage];
  1771. }
  1772. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  1773. {
  1774. if([searchText isEqualToString:@""] && !self.reset)
  1775. {
  1776. DebugLog(@"clear");
  1777. self.reset=true;
  1778. self.keywords=nil;
  1779. // self.offset = 0;
  1780. // [self.content_data removeAllObjects];
  1781. self.reset_result=true;
  1782. [self loadpage];
  1783. }
  1784. else
  1785. self.reset = false;
  1786. }
  1787. #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
  1788. - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
  1789. {
  1790. // 添加一个删除按钮
  1791. // self.indexPath=indexPath;
  1792. if(tableView==self.table_order)
  1793. {
  1794. if(indexPath.row==self.content_data.count)
  1795. return @[];
  1796. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1797. // NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"];
  1798. NSString* order_code= [self.content_data[indexPath.row] valueForKey:@"order_code"];
  1799. // NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  1800. // NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  1801. if(true/*appDelegate.user_type==USER_ROLE_EMPLOYEE || (appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeCustomer)*/) {
  1802. UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1803. DebugLog(@"delete click");
  1804. NSString * title =@"Are you sure to delete order?";
  1805. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
  1806. //block代码块取代了delegate
  1807. // [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  1808. // textField.text = self.save_name;
  1809. //
  1810. //
  1811. // }];
  1812. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1813. [OLDataProvider deleteScanOrder:order_code];
  1814. if([appDelegate.order_code isEqualToString:order_code])
  1815. [appDelegate closeOrder];
  1816. //
  1817. // [self prepareReturn:nil];
  1818. // [self.navigationController popViewControllerAnimated:true];
  1819. // [((MainViewController*)appDelegate.main_vc) switchToOrder];
  1820. return;
  1821. }];
  1822. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1823. DebugLog(@"Cancel");
  1824. }];
  1825. [alertControl addAction:actionOne];
  1826. [alertControl addAction:alertthree];
  1827. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1828. [self presentViewController:alertControl animated:YES completion:nil];
  1829. }];
  1830. deleteRowAction.backgroundColor = UIColor.redColor;//UIColorFromRGB(0x336699);
  1831. // 添加一个编辑按钮
  1832. //
  1833. // if(/*[order_status isEqualToString:@"Saved Order"]*/statusCode == 1&&appDelegate.can_cancel_order)
  1834. // return @[cancelAction];
  1835. //
  1836. // else
  1837. // {
  1838. {
  1839. NSMutableArray* arr=[@[] mutableCopy];
  1840. if(appDelegate.can_delete_order)
  1841. [arr addObject:deleteRowAction];
  1842. // if(appDelegate.can_cancel_order)
  1843. // [arr addObject:cancelAction];
  1844. return arr;
  1845. }
  1846. // }
  1847. }
  1848. return @[];
  1849. }
  1850. else if(tableView==self.table_submit)
  1851. {
  1852. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1853. // NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"];
  1854. NSString* order_code= [self.submit_content_data[indexPath.row] valueForKey:@"order_code"];
  1855. // NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  1856. // NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  1857. {
  1858. UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1859. DebugLog(@"delete click");
  1860. NSString * title =@"Are you sure to delete the submitted record?";
  1861. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
  1862. //block代码块取代了delegate
  1863. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1864. [OLDataProvider deleteSubmittedOrder:order_code];
  1865. return;
  1866. }];
  1867. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1868. DebugLog(@"Cancel");
  1869. }];
  1870. [alertControl addAction:actionOne];
  1871. [alertControl addAction:alertthree];
  1872. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1873. [self presentViewController:alertControl animated:YES completion:nil];
  1874. }];
  1875. deleteRowAction.backgroundColor = UIColorFromRGB(0x336699);
  1876. // 添加一个编辑按钮
  1877. {
  1878. NSMutableArray* arr=[@[] mutableCopy];
  1879. if(appDelegate.can_delete_order)
  1880. [arr addObject:deleteRowAction];
  1881. // if(appDelegate.can_cancel_order)
  1882. // [arr addObject:cancelAction];
  1883. return arr;
  1884. }
  1885. // }
  1886. }
  1887. }
  1888. else
  1889. {
  1890. AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  1891. NSMutableDictionary * task = Appdelegate.uploadManager.arr_queue[indexPath.row];
  1892. __weak typeof(self) weakself = self;
  1893. UITableViewRowAction *startAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Restart"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1894. if (Appdelegate.uploadManager.onlyWiFi && Appdelegate.uploadManager.reach.currentReachabilityStatus != ReachableViaWiFi) {
  1895. [weakself.view makeToast:@"Current Network is not WiFi" duration:3.0 position:CSToastPositionCenter];
  1896. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1897. return ;
  1898. }
  1899. DebugLog(@"Start click");
  1900. task[@"retry"]=[NSNumber numberWithInt:0];
  1901. [Appdelegate.uploadManager startTask:task];
  1902. [tableView reloadData];
  1903. }];
  1904. startAction.backgroundColor = UIColorFromRGB(0xff9933);
  1905. UITableViewRowAction *removeAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Remove" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  1906. [Appdelegate.uploadManager removeTask:task];
  1907. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1908. }];
  1909. removeAction.backgroundColor = UIColorFromRGB(0x9BBF5A);
  1910. // UIColorFromRGB(0x336699);
  1911. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1912. switch ([task[@"status"] intValue]) {
  1913. case TaskStatusFinish:
  1914. return @[removeAction];
  1915. case TaskStatusError:
  1916. return @[startAction,removeAction];
  1917. case TaskStatusStop:
  1918. return @[startAction];
  1919. default:
  1920. return nil;
  1921. break;
  1922. }
  1923. }
  1924. }
  1925. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  1926. if(tableView==self.table_order)
  1927. {
  1928. if(indexPath.row==self.content_data.count)
  1929. return NO;
  1930. // // if(self.init_style==OL_OPEN)
  1931. // // return NO;
  1932. //
  1933. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1934. // // NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  1935. // NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  1936. //
  1937. // if(appDelegate.user_type==USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1938. // // saved && ((type==0 && merge_permission) || type == 1 || can_cancel)
  1939. //
  1940. // BOOL isSavedOrder = /*[order_status isEqualToString:@"Saved Order"]*/statusCode == 1;
  1941. // switch (self.orderType) {
  1942. // case 0:{ // Shop Order
  1943. //
  1944. // if (!isSavedOrder) {
  1945. // return NO;
  1946. // } else {
  1947. // if ([RASingleton sharedInstance].permissions_merge_order || appDelegate.can_cancel_order) {
  1948. // return YES;
  1949. // } else {
  1950. // return NO;
  1951. // }
  1952. // }
  1953. //
  1954. // }
  1955. // break;
  1956. // case 1:{ // Sales Order
  1957. // if (isSavedOrder && appDelegate.can_cancel_order) {
  1958. // return YES;
  1959. // }
  1960. // return NO;
  1961. // }
  1962. // break;
  1963. //
  1964. // default:
  1965. // break;
  1966. // }
  1967. //
  1968. // } else {
  1969. // return YES;
  1970. // }
  1971. return YES;
  1972. }
  1973. else if(tableView==self.table_submit)
  1974. {
  1975. return YES;
  1976. }
  1977. else
  1978. {
  1979. AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  1980. if(Appdelegate.uploadManager.arr_queue.count==0)
  1981. return false;
  1982. NSDictionary * item_json = Appdelegate.uploadManager.arr_queue[indexPath.row];
  1983. bool ret=false;
  1984. switch ([item_json[@"status"] intValue]) {
  1985. case TaskStatusStart:
  1986. case TaskStatusWait:
  1987. ret=false;
  1988. break;
  1989. case TaskStatusFinish:
  1990. case TaskStatusStop:
  1991. case TaskStatusError:
  1992. ret = true;
  1993. break;
  1994. default:
  1995. ret=false;
  1996. break;
  1997. }
  1998. return ret;
  1999. }
  2000. }
  2001. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  2002. if(tv==self.table_order)
  2003. {
  2004. if(indexPath.row==self.content_data.count)
  2005. return UITableViewCellEditingStyleNone;
  2006. bool offline_edit =[[self.content_data[indexPath.row] valueForKey:@"offline_edit"] boolValue];
  2007. // NSString* order_status= [self.content_data[indexPath.row] valueForKey:@"order_status"];
  2008. NSInteger statusCode = [[self.content_data[indexPath.row] valueForKey:@"orderStatus"] integerValue];
  2009. if(/*![order_status isEqualToString:@"Saved Order"]&&! [order_status isEqualToString:@"Quote Saved"]*/statusCode != 1 && statusCode != 0)
  2010. return UITableViewCellEditingStyleNone;
  2011. else
  2012. {
  2013. BOOL condition = offline_edit;
  2014. #ifdef OFFLINE_MODE
  2015. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2016. condition = condition || appDelegate.offline_mode==false;
  2017. #else
  2018. condition = YES;
  2019. #endif
  2020. if (condition)
  2021. return UITableViewCellEditingStyleDelete;
  2022. else
  2023. return UITableViewCellEditingStyleNone;
  2024. }
  2025. }
  2026. else
  2027. return UITableViewCellEditingStyleDelete;
  2028. }
  2029. /*
  2030. #pragma mark - Navigation
  2031. // In a storyboard-based application, you will often want to do a little preparation before navigation
  2032. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  2033. // Get the new view controller using [segue destinationViewController].
  2034. // Pass the selected object to the new view controller.
  2035. }
  2036. */
  2037. #pragma mark EnumSelectViewControllerDelegate
  2038. -(void) EnumValueChanged:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  2039. {
  2040. self.status_cadedate = value;
  2041. UIApplication * app = [UIApplication sharedApplication];
  2042. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  2043. appDelegate.OrderFilter = value;
  2044. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  2045. // NSString *documents = [paths objectAtIndex:0];
  2046. // NSString *dist_path = [documents stringByAppendingPathComponent:@"status_filter_cadedate.json"];
  2047. //
  2048. //
  2049. // // if ([[NSFileManager defaultManager] fileExistsAtPath:dist_path]) {
  2050. // //
  2051. // // DebugLog(@"文件已经存在了");
  2052. // //
  2053. // // }
  2054. // // else
  2055. // // {
  2056. // //
  2057. // //
  2058. // //
  2059. // // DebugLog(@"resourceSampleImagesFolderPath=%@",resourceFolderPath);
  2060. //
  2061. //NSData *data = [NSJSONSerialization dataWithJSONObject:self.status_cadedate options:kNilOptions error:nil];
  2062. //
  2063. // // DebugLog(@"mainBundleFile==%@",mainBundleFile);
  2064. //
  2065. // [[NSFileManager defaultManager] createFileAtPath:dist_path
  2066. //
  2067. // contents:data
  2068. //
  2069. // attributes:nil];
  2070. //
  2071. // }
  2072. // self.keywords=searchBar.text;
  2073. // self.offset = 0;
  2074. // [self.content_data removeAllObjects];
  2075. self.reset_result=true;
  2076. [self loadpage];
  2077. //[self.btnStatusFilter setTitle:setTitle:alert ];
  2078. }
  2079. #pragma mark - button action
  2080. - (NSIndexPath *)indexPathOfDeleteOrder:(NSString *)orderID {
  2081. for (NSIndexPath *indexPath in self.table_order.indexPathsForSelectedRows) {
  2082. NSString* orderid= [NSString stringWithFormat:@"%@",[self.content_data[indexPath.row] valueForKey:@"order_id"]];
  2083. if ([orderid isEqualToString:orderID]) {
  2084. return indexPath;
  2085. }
  2086. }
  2087. return nil;
  2088. }
  2089. //
  2090. //- (IBAction)mergeListButtonClick:(UIBarButtonItem *)sender {
  2091. //
  2092. // if (!self.table_order.isEditing) {
  2093. //
  2094. // [RAUtils message_alert:@"You have to click select firstly then select some saved order" title:@"Warning" controller:self];
  2095. // return;
  2096. // }
  2097. //
  2098. // [self handleSelectedOrders];
  2099. //
  2100. // if (!self.mergeList.count) {
  2101. //
  2102. // // [RAUtils message_alert:@"Combine List is Empty" title:@"Warning" controller:self];
  2103. // return;
  2104. // }
  2105. //
  2106. // SelectUploadOrderViewController *mergeVC = [[UIStoryboard storyboardWithName:@"OLM" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SelectUploadOrderViewController"];
  2107. //
  2108. // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:mergeVC];
  2109. //
  2110. // mergeVC.mergeList = self.mergeList;
  2111. //
  2112. // mergeVC.title = @"Combine List";
  2113. //
  2114. // __weak typeof(self) weakself = self;
  2115. //
  2116. // mergeVC.mergeBlock = ^(NSDictionary *ret) {
  2117. //
  2118. //
  2119. // if (weakself) {
  2120. //
  2121. // __strong typeof(weakself) strongself = weakself;
  2122. //
  2123. // if([[ret objectForKey:@"result"]integerValue] == RESULT_TRUE) {
  2124. //
  2125. // [weakself.mergeList removeAllObjects];
  2126. // [strongself.table_order endEditing:YES];
  2127. // [strongself ReloadData];
  2128. //
  2129. // if ([RASingleton sharedInstance].customer_can_see_sales_Order) {
  2130. //
  2131. // [strongself openOrder:ret];
  2132. //
  2133. // }
  2134. //
  2135. // } else {
  2136. //
  2137. // NSString *msg = [ret objectForKey:@"err_msg"];
  2138. // [RAUtils message_alert:msg title:nil controller:strongself];
  2139. // }
  2140. // }
  2141. //
  2142. // };
  2143. //
  2144. // mergeVC.deleteBlock = ^(NSString *orderID){
  2145. // NSIndexPath *indexPath = [weakself indexPathOfDeleteOrder:orderID];
  2146. // [weakself.table_order deselectRowAtIndexPath:indexPath animated:YES];
  2147. // };
  2148. //
  2149. // mergeVC.clearBlock = ^{
  2150. // for (NSDictionary *order in self.mergeList) {
  2151. //
  2152. // NSString *order_id = [NSString stringWithFormat:@"%@",[order objectForKey:@"order_id"]];
  2153. // NSIndexPath *indexPath = [weakself indexPathOfDeleteOrder:order_id];
  2154. // [weakself.table_order deselectRowAtIndexPath:indexPath animated:YES];
  2155. // }
  2156. // };
  2157. //
  2158. // nav.modalPresentationStyle = UIModalPresentationFormSheet;
  2159. //
  2160. // [self presentViewController:nav animated:YES completion:nil];
  2161. //
  2162. //}
  2163. - (void)handleSelectedOrders {
  2164. [self.mergeList removeAllObjects];
  2165. if (!self.table_order.isEditing) {
  2166. return;
  2167. }
  2168. for (NSIndexPath *indexPath in self.table_order.indexPathsForSelectedRows) {
  2169. if(indexPath.row==self.content_data.count)
  2170. continue;
  2171. NSString* so= [self.content_data[indexPath.row] valueForKey:@"so#"];
  2172. NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"];
  2173. NSString *create_by = [self.content_data[indexPath.row] valueForKey:@"create_by"];
  2174. NSString *create_time = [self.content_data[indexPath.row] valueForKey:@"purchase_time"];
  2175. NSString *orderCode = [NSString stringWithFormat:@"%@",[self.content_data[indexPath.row] valueForKey:@"order_code"]];
  2176. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  2177. [dic setValue:orderid forKey:@"order_id"];
  2178. [dic setValue:orderCode forKey:@"order_code"];
  2179. [dic setValue:so forKey:@"so_id"];
  2180. [dic setValue:create_by forKey:@"create_by"];
  2181. [dic setValue:create_time forKey:@"create_time"];
  2182. [dic setValue:[NSNumber numberWithInteger:0] forKey:@"check"]; // 合并到
  2183. [self.mergeList addObject:dic];
  2184. }
  2185. }
  2186. - (IBAction)editOrderListButtonClick:(UIBarButtonItem *)sender {
  2187. // if ([RASingleton sharedInstance].global_lock) { // Order list 被锁
  2188. // [RAUtils message_alert:@"Permission Needed.\nGoto Menu -> Unlock" title:@"Warning" controller:self];
  2189. // return;
  2190. // }
  2191. //
  2192. // UIImage *gray = [UIImage imageNamed:@"Combinegray"];
  2193. // UIImage *green = [[UIImage imageNamed:@"converttopo"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//converttopo
  2194. //
  2195. // if (self.table_order.isEditing) {
  2196. // [self mergeListButtonClick:nil];
  2197. // // 结束选择时恢复
  2198. // if ([RASingleton sharedInstance].customer_can_see_sales_Order && ![RASingleton sharedInstance].global_lock) { // 有查看Sales order 权限,并且app没有锁
  2199. // if (self.orderTypeSegmentControl.numberOfSegments == 1) {
  2200. // [self.orderTypeSegmentControl insertSegmentWithTitle:[NSString stringWithFormat:@"Purchase Order to %@",COMPANY_SHORT_NAME] atIndex:1 animated:YES];
  2201. // }
  2202. // }
  2203. //
  2204. // self.status_cadedate = self.shop_order_filter;
  2205. // [self ReloadData];
  2206. //
  2207. // [self.table_order setEditing:NO animated:YES];
  2208. //// sender.title = @"Select";
  2209. //// [self.mergeList removeAllObjects];
  2210. // [sender setImage:gray];
  2211. //
  2212. // } else {
  2213. // // 选择时不能选择Sales Order
  2214. // if(self.orderTypeSegmentControl.numberOfSegments > 1) {
  2215. // [self.orderTypeSegmentControl removeSegmentAtIndex:1 animated:YES];
  2216. // [self changeOrderType:0];
  2217. // }
  2218. // // 切换filter
  2219. // NSData *data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"status_filter_cadedate_open" ofType:@"json" ]];
  2220. // NSError *error=nil;
  2221. // self.status_cadedate = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  2222. // // 刷新,取Saved Order
  2223. // [self ReloadData];
  2224. //
  2225. // [self.table_order setEditing:YES animated:YES];
  2226. //// sender.title = @"Exit";
  2227. // [sender setImage:green];
  2228. // }
  2229. }
  2230. - (IBAction)onSegmentChanged:(UISegmentedControl *)sender {
  2231. if(sender.selectedSegmentIndex==0)
  2232. {
  2233. self.table_order.hidden=false;
  2234. self.table_upload.hidden = true;
  2235. [self.table_order reloadData];
  2236. }
  2237. else if(sender.selectedSegmentIndex==1)
  2238. {
  2239. // self.table_order.hidden=true;
  2240. // self.table_upload.hidden = false;
  2241. // [self.table_upload reloadData];
  2242. self.table_order.hidden=true;
  2243. self.table_submit.hidden = false;
  2244. [self.table_submit reloadData];
  2245. }
  2246. // else
  2247. // {
  2248. // [self onNewOrderClicked:nil];
  2249. // }
  2250. //
  2251. }
  2252. //
  2253. //- (void)openOrder:(NSDictionary *)order {
  2254. //
  2255. // if (!order) {
  2256. // return;
  2257. // }
  2258. //
  2259. // NSString *orderCode = [order objectForKey:@"orderCode"];
  2260. // NSInteger orderStatus = [[order objectForKey:@"orderStatus"] integerValue];
  2261. // NSString *so = [order objectForKey:@"so#"];
  2262. //
  2263. // __weak typeof(self) weakself = self;
  2264. //
  2265. // [RANetwork request_open_order:orderCode completionHandler:^(NSMutableDictionary *result) {
  2266. // NSDictionary* order_json = result ;
  2267. //
  2268. //
  2269. // if([[order_json valueForKey:@"result"] intValue]==2)
  2270. // {
  2271. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2272. // appDelegate.order_code = orderCode;
  2273. // appDelegate.order_status = (int)orderStatus;
  2274. // [appDelegate SetSo:so];
  2275. //
  2276. // __weak MainViewController *mainVC = (MainViewController*)appDelegate.main_vc;
  2277. //
  2278. //#ifdef RA_NOTIFICATION
  2279. // [ActiveViewController Notify:@"CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2280. //#else
  2281. //
  2282. //
  2283. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2284. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  2285. // [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
  2286. //#endif
  2287. //
  2288. // [((MainViewController*)appDelegate.main_vc) switchToCart];
  2289. //
  2290. // mainVC.cartViewController.onFinishLoad=^{
  2291. // [mainVC.cartViewController placeOrder];
  2292. // mainVC.cartViewController.onFinishLoad=nil;
  2293. // };
  2294. //
  2295. // }
  2296. // else
  2297. // {
  2298. // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order" controller:weakself] ;
  2299. // }
  2300. //
  2301. //
  2302. //
  2303. //
  2304. // }];
  2305. // // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2306. // //
  2307. // // NSDictionary* order_json = [RANetwork open_Order:orderCode];
  2308. // //
  2309. // // dispatch_async(dispatch_get_main_queue(), ^{
  2310. // //
  2311. // // if([[order_json valueForKey:@"result"] intValue]==2)
  2312. // // {
  2313. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2314. // // appDelegate.order_code = orderCode;
  2315. // // appDelegate.order_status = orderStatus;
  2316. // // [appDelegate SetSo:so];
  2317. // //
  2318. // // __weak MainViewController *mainVC = (MainViewController*)appDelegate.main_vc;
  2319. // //
  2320. // //#ifdef RA_NOTIFICATION
  2321. // // [ActiveViewController Notify:@"CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2322. // //#else
  2323. // //
  2324. // //
  2325. // // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2326. // // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  2327. // // [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
  2328. // //#endif
  2329. // //
  2330. // // [((MainViewController*)appDelegate.main_vc) switchToCart];
  2331. // //
  2332. // // mainVC.cartViewController.onFinishLoad=^{
  2333. // // [mainVC.cartViewController placeOrder];
  2334. // // mainVC.cartViewController.onFinishLoad=nil;
  2335. // // };
  2336. // //
  2337. // // }
  2338. // // else
  2339. // // {
  2340. // // [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order" controller:weakself] ;
  2341. // // }
  2342. // //
  2343. // //
  2344. // //
  2345. // // });
  2346. // // });
  2347. //
  2348. //
  2349. //}
  2350. #pragma mark - notification action
  2351. - (void)changePriceType:(id)notification {
  2352. [self ReloadData];
  2353. }
  2354. - (void)lockOrderListNotification:(NSNotification *)notification {
  2355. if ([notification.name isEqual:Lock_Permission_Notification]) {
  2356. if (self.orderType == 1) {
  2357. self.orderTypeSegmentControl.selectedSegmentIndex = 0;
  2358. // [self changeOrderType:0];
  2359. [self.orderTypeSegmentControl sendActionsForControlEvents:UIControlEventValueChanged];
  2360. }
  2361. if(self.orderTypeSegmentControl.numberOfSegments > 1) {
  2362. [self.orderTypeSegmentControl removeSegmentAtIndex:1 animated:YES];
  2363. // [self changeOrderType:0];
  2364. }
  2365. } else { // 解锁
  2366. if ([RASingleton sharedInstance].customer_can_see_sales_Order) { // 有查看Sales order 权限
  2367. if (self.orderTypeSegmentControl.numberOfSegments == 1 && !self.table_order.isEditing) {
  2368. [self.orderTypeSegmentControl insertSegmentWithTitle:[NSString stringWithFormat:@"Purchase Order to %@",COMPANY_SHORT_NAME] atIndex:1 animated:YES];
  2369. }
  2370. }
  2371. }
  2372. }
  2373. - (void)handleUserLogin:(NSNotification *)notification {
  2374. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2375. self.orderType = 0;
  2376. if (self.table_order.isEditing) {
  2377. [self.table_order setEditing:NO animated:YES];
  2378. self.editOrderListButton.image = [UIImage imageNamed:@"Combinegray"];
  2379. }
  2380. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  2381. self.orderTypeSegmentControl.selectedSegmentIndex = 0;
  2382. [RASingleton sharedInstance].customer_order_type = 0;
  2383. }
  2384. }
  2385. - (void)reRefreshView {
  2386. [self.table_order reloadData];
  2387. }
  2388. #pragma mark - RA_NOTIFICAITON
  2389. -(void) refresh_ui
  2390. {
  2391. [self.table_order reloadData];
  2392. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2393. if(appDelegate.can_create_order)
  2394. {
  2395. [self.btn_newOrder setImage:[UIImage imageNamed:@"neworder"]];
  2396. self.btn_newOrder.enabled = true;
  2397. }
  2398. else
  2399. {
  2400. [self.btn_newOrder setImage:nil];
  2401. self.btn_newOrder.enabled = false;
  2402. }
  2403. }
  2404. -(void) reload_data
  2405. {
  2406. self.reset_result=true;
  2407. self.norefresh=true;
  2408. [self loadpage];
  2409. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2410. if(appDelegate.can_create_order)
  2411. {
  2412. [self.btn_newOrder setImage:[UIImage imageNamed:@"neworder"]];
  2413. self.btn_newOrder.enabled = true;
  2414. }
  2415. else
  2416. {
  2417. [self.btn_newOrder setImage:nil];
  2418. self.btn_newOrder.enabled = false;
  2419. }
  2420. }
  2421. -(void) refresh_price
  2422. {
  2423. [self refresh_ui];
  2424. }
  2425. @end