SubmitOrderVC.m 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170
  1. //
  2. // SubmitOrderVCViewController.m
  3. // IBOSSmini
  4. //
  5. // Created by guan hong hou on 2017/5/19.
  6. // Copyright © 2017年 elongtian. All rights reserved.
  7. //
  8. #import "SubmitOrderVC.h"
  9. #import "ShopCartCellDelegate.h"
  10. #import "SubmitOrderFrame.h"
  11. #import "SubmitOrderTableViewCell.h"
  12. #import "CustomerCodeSearchVC.h"
  13. #import "CustomerTypeSearchVC.h"
  14. #import "SBJsonWriter.h"
  15. #import "SalesManSearchVC.h"
  16. #import "ChannelSearchVC.h"
  17. #import "DepartmentSearchVC.h"
  18. #define txtReadOnlyColor [UIColor colorWithRed:82/255.0 green:53/255.0 blue:46/255.0 alpha:1.0]
  19. #define selectReadOnlyColor [UIColor colorWithRed:243/255.0 green:242/255.0 blue:226/255.0 alpha:1.0]
  20. @interface SubmitOrderVC ()<UITableViewDataSource,UITableViewDelegate,SubmitOrderCellDelegate,UITextFieldDelegate,OrderDelegate>{
  21. MBProgressHUD *HUD;
  22. }
  23. @end
  24. @implementation SubmitOrderVC
  25. @synthesize vCustomTableView;
  26. #pragma mark - 公共函数
  27. /**
  28. viewDidLoad函数
  29. */
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. self.navigationItem.title=@"提交订单";
  33. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  34. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  35. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  36. [button setBackgroundImage:[UIImage imageNamed:@"icon_back.png"]
  37. forState:UIControlStateNormal];
  38. [button addTarget:self action:@selector(goBack)
  39. forControlEvents:UIControlEventTouchUpInside];
  40. button.frame = CGRectMake(0, 0, 15, 18);
  41. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  42. self.navigationItem.leftBarButtonItem = menuButton;
  43. _departmentIdStr=@"";
  44. _departmentCodeStr=@"";
  45. _salesmanStr=@"";
  46. _channelStr=@"";
  47. _customerTypeStr=@"";
  48. _customerIDStr=@"";
  49. _strTelephone=@"";
  50. _strFilingID = @"";
  51. _strCustomerCode=@"";
  52. _strRemarks=@"";
  53. _strCustomerName=@"";
  54. _strAddress=@"";
  55. _cartItemArr=[NSMutableArray new];
  56. [self initUI];
  57. [self initNotification];
  58. [self refreshTotalAmount];
  59. }
  60. /**
  61. 修改:2017-9-25
  62. 适配机型
  63. 安全区视图发生变化
  64. */
  65. -(void)viewSafeAreaInsetsDidChange{
  66. self.view.backgroundColor = [UIColor whiteColor];
  67. _footerView.backgroundColor = [UIColor whiteColor];
  68. vCustomTableView.frame = CGRectMake(0, 0, SCREENWIDTH, self.view.safeAreaLayoutGuide.layoutFrame.size.height - 64);
  69. _footerView.frame=CGRectMake(0, self.view.safeAreaLayoutGuide.layoutFrame.size.height - 64, self.view.frame.size.width, 64);
  70. [super viewSafeAreaInsetsDidChange];
  71. }
  72. #pragma mark -委托函数
  73. //产品价格加载成功接口
  74. - (void)onSalesPriceLoadFinish:(ASIDownManager *)sender {
  75. NSDictionary *dic = [sender.mWebStr JSONValue];
  76. [self cancel];
  77. if (dic && [dic isKindOfClass:[NSDictionary class]]) {
  78. int iStatus = [[dic objectForKey:@"Status"] intValue];
  79. NSString *message=[dic objectForKey:@"Message"];
  80. if (iStatus == 0) {
  81. NSArray * approvArr=[dic objectForKey:@"Result"];
  82. if(approvArr!=nil&&approvArr.count>0)
  83. {
  84. [_cartModel updateGoodsSalePrice:approvArr];
  85. [self loadData];
  86. //接着更新商品标价
  87. double delayInSeconds = 0.5;
  88. dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
  89. dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
  90. [self updateGoodsMarkePrice];
  91. });
  92. }
  93. }
  94. else if(iStatus==ActionResultStatusAuthError
  95. ||iStatus==ActionResultStatusNoLogin
  96. ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  97. [self showReLoginDialog:message];
  98. return;
  99. }
  100. else {
  101. [self showAlertViewText:message];
  102. }
  103. }
  104. }
  105. //产品价格加载失败接口
  106. - (void)onSalesPriceLoadFail:(ASIDownManager *)sender {
  107. [self cancel];
  108. [self readOnly:NO];
  109. [self showAlertViewText:@"加载失败"];
  110. }
  111. //客户编码查询成功接口
  112. - (void)onLoadFinish:(ASIDownManager *)sender {
  113. NSDictionary *dic = [sender.mWebStr JSONValue];
  114. [self cancel];
  115. if (dic && [dic isKindOfClass:[NSDictionary class]]) {
  116. int iStatus = [[dic objectForKey:@"Status"] intValue];
  117. NSString *message=[dic objectForKey:@"Message"];
  118. if (iStatus == 0) {
  119. NSArray * approvArr=[dic objectForKey:@"Result"];
  120. if(approvArr!=nil&&approvArr.count>0)
  121. {
  122. NSDictionary *dic=approvArr[0];
  123. NSString *fillingid=[dic objectForKey:@"FilingID"];
  124. NSString *CustomerID=[dic objectForKey:@"CustomerID"];
  125. NSString *CustomerCode=[dic objectForKey:@"CustomerCode"];
  126. NSString *CustomerName=[dic objectForKey:@"CustomerName"];
  127. NSString *ChannelName=[dic objectForKey:@"ChannelName"];
  128. NSString *ChannelID=[dic objectForKey:@"ChannelID"];
  129. NSString *Telephone=[dic objectForKey:@"Telephone"];
  130. NSString *Address=[dic objectForKey:@"Address"];
  131. NSString *StaffName=[dic objectForKey:@"StaffName"];
  132. NSString *StaffID=[dic objectForKey:@"StaffID"];
  133. NSString *CustomerType=[dic objectForKey:@"CustomerType"];
  134. NSString *CustomerTypeName=[dic objectForKey:@"CustomerTypeName"];
  135. NSString *OrganizationID=[dic objectForKey:@"OrganizationID"];
  136. NSString *OrganizationName=[dic objectForKey:@"OrganizationName"];
  137. NSString *OrganizationCode=[dic objectForKey:@"OrganizationCode"];
  138. if (CustomerID==nil) {
  139. CustomerID= @"";
  140. }
  141. if (fillingid==nil) {
  142. fillingid= @"0";
  143. }
  144. _customerIDStr=CustomerID;
  145. if(![Telephone isEqualToString:@"-"]){
  146. _txtTelephone.text=Telephone;
  147. }
  148. _strFilingID = fillingid;
  149. _txtCustomerCode.text = CustomerCode == nil ? Telephone : CustomerCode;
  150. _txtCustomerName.text=CustomerName;
  151. _txtCustomerAddress.text=Address;
  152. _channelStr=ChannelID;
  153. [_btnChannel setTitle:ChannelName forState:UIControlStateNormal];
  154. _customerTypeStr=CustomerType;
  155. [_btnCustomerType setTitle:CustomerTypeName forState:UIControlStateNormal];
  156. _departmentIdStr=OrganizationID;
  157. _departmentCodeStr=OrganizationCode;
  158. [_btnDepartment setTitle:OrganizationName forState:UIControlStateNormal];
  159. _salesmanStr=StaffID;
  160. [_btnSalesMan setTitle:StaffName forState:UIControlStateNormal];
  161. [self readOnly:YES];
  162. //接着更新商品售价
  163. double delayInSeconds = 0.5;
  164. dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
  165. dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
  166. [self updateGoodsSalePrice];
  167. });
  168. }
  169. else {
  170. [self readOnly:NO];
  171. }
  172. }
  173. else if(iStatus==ActionResultStatusAuthError
  174. ||iStatus==ActionResultStatusNoLogin
  175. ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  176. [self showReLoginDialog:message];
  177. return;
  178. }
  179. else {
  180. [self showAlertViewText:message];
  181. [self readOnly:NO];
  182. }
  183. }
  184. }
  185. //客户编码查询失败接口
  186. - (void)onLoadFail:(ASIDownManager *)sender {
  187. [self cancel];
  188. [self readOnly:NO];
  189. [self showAlertViewText:@"加载失败"];
  190. }
  191. //文本编辑回調
  192. -(void)textValueChange:(SubmitOrderTableViewCell *)cell txtField:(UITextField*)txtfield
  193. {
  194. [_cartModel updateCellSaleText:txtfield checkeId:cell.lblCartId.text];
  195. [self refreshTotalAmount];
  196. }
  197. //tableview的分区数
  198. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  199. {
  200. return 1;
  201. }
  202. //tableview cell的高度
  203. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  204. {
  205. NSArray *checkArr=[_cartModel checkedArr];
  206. SubmitOrderFrame *frame= checkArr[indexPath.row];
  207. return frame.cellHeight;
  208. }
  209. //tableview的行数
  210. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  211. {
  212. return [_cartModel checkedArr].count;
  213. }
  214. //加载tableviewcell
  215. - (UITableViewCell *)tableView:(UITableView *)tableView
  216. cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  217. static NSString *cellIdentifier = @"SubmitOrderCell";
  218. SubmitOrderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  219. cell=[[SubmitOrderTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  220. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  221. SubmitOrderFrame *orderFrame=[_cartModel checkedArr][indexPath.row];
  222. cell.delegate=self;
  223. [cell parseOrderInfo:orderFrame];
  224. return cell;
  225. }
  226. //scrollview回调函数
  227. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
  228. [self.view endEditing:YES];
  229. }
  230. //提交订单成功
  231. - (void)onSubmitLoadFinish:(ASIDownManager *)sender {
  232. NSDictionary *dic = [sender.mWebStr JSONValue];
  233. [self cancelHUD];
  234. if (dic && [dic isKindOfClass:[NSDictionary class]]) {
  235. int iStatus = [[dic objectForKey:@"Status"] intValue];
  236. NSString *message=[dic objectForKey:@"Message"];
  237. if (iStatus == 0) {
  238. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"订单提交成功" preferredStyle:UIAlertControllerStyleAlert];
  239. UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"确定"
  240. style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  241. [self goBack];
  242. }];
  243. //[alertController addAction:cancelAction];
  244. [alertController addAction:otherAction];
  245. [self presentViewController:alertController animated:YES completion:nil];
  246. }
  247. else if(iStatus==ActionResultStatusAuthError
  248. ||iStatus==ActionResultStatusNoLogin
  249. ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  250. [self showReLoginDialog:message];
  251. return;
  252. }
  253. else {
  254. [self showAlertViewText:message];
  255. }
  256. }
  257. }
  258. //提交订单失败
  259. - (void)onSubmitLoadFail:(ASIDownManager *)sender {
  260. [self cancelHUD];
  261. [self showAlertViewText:@"请求失败"];
  262. }
  263. //更新商品标价成功
  264. - (void)onMarkedPriceLoadFinish:(ASIDownManager *)sender {
  265. NSDictionary *dic = [sender.mWebStr JSONValue];
  266. [self cancel];
  267. if (dic && [dic isKindOfClass:[NSDictionary class]]) {
  268. int iStatus = [[dic objectForKey:@"Status"] intValue];
  269. NSString *message=[dic objectForKey:@"Message"];
  270. if (iStatus == 0) {
  271. NSArray * approvArr=[dic objectForKey:@"Result"];
  272. if(approvArr!=nil&&approvArr.count>0)
  273. {
  274. [_cartModel updateGoodsMarkedPrice:approvArr];
  275. [self loadData];
  276. }
  277. }
  278. else if(iStatus==ActionResultStatusAuthError
  279. ||iStatus==ActionResultStatusNoLogin
  280. ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  281. [self showReLoginDialog:message];
  282. return;
  283. }
  284. else {
  285. [self showAlertViewText:message];
  286. }
  287. }
  288. }
  289. //提交订单失败
  290. - (void)onMarkedPriceLoadFail:(ASIDownManager *)sender {
  291. [self cancel];
  292. [self showAlertViewText:@"请求失败"];
  293. }
  294. //弹出消息回调
  295. -(void)alertMessage:(NSString *) message{
  296. [self showAlertViewText:@"请手动输入商品数量"];
  297. return;
  298. }
  299. //文本回调
  300. -(void)textEnd:(id)sender customerCode:(NSString *)code
  301. {
  302. UIButton *btn=(UIButton *)sender;
  303. if(code!=nil){
  304. _txtCustomerCode.text=code;
  305. }
  306. if(btn.tag==1301) //客户编码
  307. {
  308. if(_txtCustomerCode.text.length==0){
  309. return;
  310. }
  311. [self searchCustomerInfo:_txtCustomerCode.text];
  312. }
  313. else if (btn.tag==1302){//联系电话
  314. if(_txtTelephone.text.length==0)return;
  315. if(_txtCustomerCode.text.length>0)return;
  316. [self searchCustomerInfo:_txtTelephone.text];
  317. }
  318. }
  319. -(void)customerType:(NSString *)customerTypeId customerTypeName:(NSString *)customerTypeName{
  320. [_btnCustomerType setTitle:customerTypeName forState:UIControlStateNormal];
  321. _customerTypeStr=customerTypeId;
  322. [_btnCustomerType setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  323. }
  324. -(void)department:(NSString *)organizationId organizationCode:(NSString *)code organizationName:(NSString *)name{
  325. [_btnDepartment setTitle:name forState:UIControlStateNormal];
  326. [_btnDepartment setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  327. _departmentIdStr=organizationId;
  328. _departmentCodeStr=code;
  329. [self updatePrice];
  330. }
  331. -(void)salesman:(NSString *)salesmanId salesmanName:(NSString *)salesmanName{
  332. [_btnSalesMan setTitle:salesmanName forState:UIControlStateNormal];
  333. [_btnSalesMan setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  334. _salesmanStr=salesmanId;
  335. }
  336. -(void)channel:(NSString *)channelId channelName:(NSString *)channelName{
  337. [_btnChannel setTitle:channelName forState:UIControlStateNormal];
  338. [_btnChannel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  339. _channelStr=channelId;
  340. [self updatePrice];
  341. }
  342. #pragma mark -私有函数
  343. //初始化UI
  344. -(void)initUI{
  345. [self initTableView];
  346. [self initHeaderView];
  347. }
  348. //取消加载
  349. - (void)cancelHUD {
  350. [HUD hide:YES];
  351. }
  352. /**
  353. initNotification
  354. */
  355. -(void)initNotification{
  356. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onFocusEditingChanged:) name:@"UITextFieldTextDidChangeNotification" object:self.txtCustomerCode ];
  357. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onFocusEditingChanged:) name:@"UITextFieldTextDidChangeNotification" object:self.txtCustomerName ];
  358. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onFocusEditingChanged:) name:@"UITextFieldTextDidChangeNotification" object:self.txtCustomerAddress];
  359. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onFocusEditingChanged:) name:@"UITextFieldTextDidChangeNotification" object:self.txtTelephone];
  360. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onFocusEditingChanged:) name:@"UITextFieldTextDidChangeNotification" object:self.txtRemarks];
  361. }
  362. /**
  363. 文本框的长度限制 实现监听方法
  364. @param sender <#sender description#>
  365. */
  366. - (void)onFocusEditingChanged:(NSNotification *)sender
  367. {
  368. UITextField *textField = (UITextField *)sender.object;
  369. NSString *toBeString = textField.text;
  370. NSString *lang = [[UIApplication sharedApplication] textInputMode].primaryLanguage;
  371. // 长度
  372. int kMaxLength=10;
  373. if ([textField isEqual:self.txtCustomerCode]) {
  374. kMaxLength=100;
  375. }
  376. else if ([textField isEqual:self.txtCustomerName]) {
  377. kMaxLength=50;
  378. }
  379. else if ([textField isEqual:self.txtCustomerAddress]) {
  380. kMaxLength=100;
  381. }
  382. else if ([textField isEqual:self.txtTelephone]) {
  383. kMaxLength=12;
  384. }
  385. else if ([textField isEqual:self.txtRemarks]) {
  386. kMaxLength=100;
  387. }
  388. if ([lang isEqualToString:@"zh-Hans"]) {
  389. UITextRange *selectedRange = [textField markedTextRange];
  390. UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0];
  391. if (!position) {
  392. if (toBeString.length > kMaxLength) {
  393. textField.text = [toBeString substringToIndex:kMaxLength];
  394. }
  395. }
  396. }else{
  397. if (toBeString.length > kMaxLength) {
  398. textField.text = [toBeString substringToIndex:kMaxLength];
  399. }
  400. }
  401. }
  402. //更新商品标价
  403. -(void)updateGoodsMarkePrice
  404. {
  405. [self startLoading];
  406. NSString *urlStr = ServerURL;
  407. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  408. [dict setObject:@"GetMarkedPrice" forKey:@"Action"];
  409. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  410. [dict setObject:kkUserCode forKey:@"UserCode"];
  411. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  412. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  413. [dict setObject: _departmentCodeStr forKey:@"OrganizationCode"];
  414. [dict setObject:_channelStr forKey:@"ChannelID"];
  415. NSString * orderDetail=[_cartModel checkedSalePriceJSON];
  416. [dict setObject:orderDetail forKey:@"OrderDetail"];
  417. SBJsonWriter *write = [[SBJsonWriter alloc] init];
  418. NSString *value = [write stringWithObject:dict];
  419. NSLog(@"value=%@",value);
  420. self.mDownManager = [[ASIDownManager alloc] init];
  421. _mDownManager.delegate = self;
  422. _mDownManager.OnImageDown = @selector(onMarkedPriceLoadFinish:);
  423. _mDownManager.OnImageFail = @selector(onMarkedPriceLoadFail:);
  424. [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  425. }
  426. //初始化tableview
  427. -(void)initTableView
  428. {
  429. vCustomTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-60)];
  430. vCustomTableView.backgroundColor=[UIColor redColor];
  431. vCustomTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  432. vCustomTableView.backgroundColor = [UIColor whiteColor];
  433. vCustomTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
  434. vCustomTableView.delegate = self;
  435. vCustomTableView.dataSource=self;
  436. [self.view addSubview:vCustomTableView];
  437. }
  438. //返回函数
  439. -(void)goBack{
  440. [self.navigationController popViewControllerAnimated:YES];
  441. if([self.refreshDelegate respondsToSelector:@selector(refreshData)]){
  442. [self.refreshDelegate refreshData];
  443. }
  444. }
  445. /**
  446. 初始化headerview
  447. */
  448. - (void)initHeaderView
  449. {
  450. _headerView = [UIView new];
  451. _headerView.frame=CGRectZero;
  452. UIView *v1 = [UIView new];
  453. v1.frame=CGRectMake(0, 0,Screen_Width, 51);
  454. [_headerView addSubview:v1];
  455. UILabel *lblCustomerCode = [UILabel new];
  456. lblCustomerCode.frame=CGRectMake(15, 16, 100, 25);
  457. lblCustomerCode.text = @"客户编码";
  458. lblCustomerCode.font=orderTextFont;
  459. [v1 addSubview:lblCustomerCode];
  460. _txtCustomerCode = [UITextField new];
  461. _txtCustomerCode.frame=CGRectMake(CGRectGetMaxX(lblCustomerCode.frame)+10, 16, 150, 25);
  462. _txtCustomerCode.font=orderTextFont;
  463. _txtCustomerCode.placeholder = @"请输入客户编码";
  464. [_txtCustomerCode addTarget:self action:@selector(textEnd:customerCode:) forControlEvents:UIControlEventEditingDidEnd];
  465. _txtCustomerCode.tag=1301;
  466. [v1 addSubview:_txtCustomerCode];
  467. _btnCustomerCode = [UIButton buttonWithType:UIButtonTypeCustom];
  468. _btnCustomerCode.frame=CGRectMake(Screen_Width-50,10,32,30);
  469. UIImageView *customerCodeImg = [[UIImageView alloc]initWithFrame:CGRectMake(25,9,7, 12)];
  470. [customerCodeImg setImage:[UIImage imageNamed:@"rightarrow"]];
  471. [ _btnCustomerCode addSubview:customerCodeImg];
  472. customerCodeImg.userInteractionEnabled=NO;
  473. [v1 addSubview:_btnCustomerCode];
  474. [_btnCustomerCode addTarget:self action:@selector(searchCustomerCode) forControlEvents:UIControlEventTouchUpInside];
  475. UIView *separator = [UIView new];
  476. separator.backgroundColor=LineBackgroundColor;
  477. separator.frame=CGRectMake(CGRectGetMaxX(lblCustomerCode.frame)+10,CGRectGetMaxY(_txtCustomerCode.frame)+10,Screen_Width-CGRectGetMaxX(lblCustomerCode.frame)+10, 1);
  478. [v1 addSubview:separator];
  479. //客户名称
  480. UIView *v2 = [UIView new];
  481. v2.frame=CGRectMake(0,CGRectGetMaxY(v1.frame),Screen_Width, 51);
  482. [_headerView addSubview:v2];
  483. UILabel *lblCustomerName = [UILabel new];
  484. lblCustomerName.frame=CGRectMake(15, 16, 100, 25);
  485. lblCustomerName.text = @"客户名称";
  486. lblCustomerName.font=orderTextFont;
  487. [v2 addSubview: lblCustomerName];
  488. _txtCustomerName = [UITextField new];
  489. _txtCustomerName.frame=CGRectMake(CGRectGetMaxX(lblCustomerName.frame)+10, 16, SCREENWIDTH - CGRectGetMaxX(lblCustomerName.frame)-20, 25);
  490. _txtCustomerName.placeholder = @"请输入客户名称";
  491. _txtCustomerName.tag=1303;
  492. _txtCustomerName.font=orderTextFont;
  493. [v2 addSubview:_txtCustomerName];
  494. UIView *separator1 = [UIView new];
  495. separator1.backgroundColor=LineBackgroundColor;
  496. separator1.frame=CGRectMake(CGRectGetMaxX(lblCustomerName.frame)+10,CGRectGetMaxY(_txtCustomerName.frame)+10,Screen_Width-CGRectGetMaxX( lblCustomerName.frame)+10, 1);
  497. [v2 addSubview:separator1];
  498. UIView *v3 = [UIView new];
  499. v3.frame=CGRectMake(0,CGRectGetMaxY(v2.frame),Screen_Width, 51);
  500. [_headerView addSubview:v3];
  501. UILabel *lblCustomerAddress = [UILabel new];
  502. lblCustomerAddress.frame=CGRectMake(15, 16, 100, 25);
  503. lblCustomerAddress.text = @"客户地址";
  504. lblCustomerAddress.font=orderTextFont;
  505. [v3 addSubview: lblCustomerAddress];
  506. _txtCustomerAddress = [UITextField new];
  507. _txtCustomerAddress.frame=CGRectMake(CGRectGetMaxX(lblCustomerAddress.frame)+10, 16, SCREENWIDTH - CGRectGetMaxX(lblCustomerAddress.frame)-20, 25);
  508. _txtCustomerAddress.placeholder = @"请输入客户地址";
  509. _txtCustomerAddress.font=orderTextFont;
  510. _txtCustomerAddress.tag=1304;
  511. [v3 addSubview:_txtCustomerAddress];
  512. UIView *separator2 = [UIView new];
  513. separator2.backgroundColor=LineBackgroundColor;
  514. separator2.frame=CGRectMake(CGRectGetMaxX(lblCustomerAddress.frame)+10,CGRectGetMaxY(_txtCustomerAddress.frame)+10,Screen_Width-CGRectGetMaxX( lblCustomerAddress.frame)+10, 1);
  515. [v3 addSubview:separator2];
  516. UIView *v4 = [UIView new];
  517. v4.frame=CGRectMake(0,CGRectGetMaxY(v3.frame),Screen_Width, 51);
  518. [_headerView addSubview:v4];
  519. UILabel *lblTelephone = [UILabel new];
  520. lblTelephone.frame=CGRectMake(15, 16, 100, 25);
  521. lblTelephone.text = @"联系电话";
  522. lblTelephone.font=orderTextFont;
  523. [v4 addSubview: lblTelephone];
  524. _txtTelephone = [UITextField new];
  525. _txtTelephone.tag=1302;
  526. _txtTelephone.keyboardType = UIKeyboardTypeNumberPad;
  527. _txtTelephone.frame=CGRectMake(CGRectGetMaxX(lblTelephone.frame)+10, 16, 150, 25);
  528. _txtTelephone.placeholder = @"请输入联系电话";
  529. _txtTelephone.font=orderTextFont;
  530. [v4 addSubview:_txtTelephone];
  531. UIView *separator3 = [UIView new];
  532. separator3.backgroundColor=LineBackgroundColor;
  533. separator3.frame=CGRectMake(CGRectGetMaxX(lblTelephone.frame)+10,CGRectGetMaxY(_txtTelephone.frame)+10,Screen_Width-CGRectGetMaxX(lblTelephone.frame)+10, 1);
  534. [v4 addSubview:separator3];
  535. UIView *v5 = [UIView new];
  536. v5.frame=CGRectMake(0,CGRectGetMaxY(v4.frame),Screen_Width, 51);
  537. [_headerView addSubview:v5];
  538. UILabel *lblCustomerType = [UILabel new];
  539. lblCustomerType.frame=CGRectMake(15, 16, 100, 25);
  540. lblCustomerType.text = @"客户性质";
  541. lblCustomerType.font=orderTextFont;
  542. [v5 addSubview: lblCustomerType];
  543. _btnCustomerType = [UIButton buttonWithType:UIButtonTypeCustom];
  544. _btnCustomerType.frame=CGRectMake(CGRectGetMaxX(lblCustomerType.frame)+10, 16, 150, 25);
  545. _btnCustomerType.titleLabel.font=orderTextFont;
  546. _btnCustomerType.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  547. [_btnCustomerType setTitle:@"请选择客户性质" forState:UIControlStateNormal];
  548. [_btnCustomerType setTitleColor:ButtonTitleColor forState:UIControlStateNormal];
  549. [v5 addSubview:_btnCustomerType];
  550. [_btnCustomerType addTarget:self action:@selector(showCustomerTypeAlert) forControlEvents:UIControlEventTouchUpInside];
  551. UIImageView *customerTypeImg = [[UIImageView alloc] initWithFrame:CGRectMake(Screen_Width-25, 20,7,12)];
  552. [customerTypeImg setImage:[UIImage imageNamed:@"rightarrow"] ];
  553. [v5 addSubview:customerTypeImg];
  554. UIView *separator4 = [UIView new];
  555. separator4.backgroundColor=LineBackgroundColor;
  556. separator4.frame=CGRectMake(CGRectGetMaxX( lblCustomerType.frame)+10,CGRectGetMaxY(_btnCustomerType.frame)+10,Screen_Width-CGRectGetMaxX( lblCustomerType.frame)+10, 1);
  557. [v5 addSubview:separator4];
  558. UIView *v6 = [UIView new];
  559. v6.frame=CGRectMake(0,CGRectGetMaxY(v5.frame),Screen_Width, 51);
  560. [_headerView addSubview:v6];
  561. UILabel *lblChannel = [UILabel new];
  562. lblChannel.frame=CGRectMake(15, 16, 100, 25);
  563. lblChannel.text = @"渠 道";
  564. lblChannel.font=orderTextFont;
  565. [v6 addSubview: lblChannel];
  566. _btnChannel = [UIButton buttonWithType:UIButtonTypeCustom];
  567. _btnChannel.frame=CGRectMake(CGRectGetMaxX(lblChannel.frame)+10, 16, 150, 25);
  568. [_btnChannel setTitle:@"请选择渠道" forState:UIControlStateNormal];
  569. [_btnChannel setTitleColor:ButtonTitleColor forState:UIControlStateNormal];
  570. [v6 addSubview:_btnChannel];
  571. _btnChannel.titleLabel.font=orderTextFont;
  572. _btnChannel.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  573. [_btnChannel addTarget:self action:@selector(showChannelAlert) forControlEvents:UIControlEventTouchUpInside];
  574. UIImageView *channelImg = [[UIImageView alloc] initWithFrame:CGRectMake(Screen_Width-25, 20,7,12)];
  575. [channelImg setImage:[UIImage imageNamed:@"rightarrow"] ];
  576. [v6 addSubview:channelImg];
  577. UIView *separator5 = [UIView new];
  578. separator5.backgroundColor=LineBackgroundColor;
  579. separator5.frame=CGRectMake(CGRectGetMaxX( lblChannel.frame)+10,CGRectGetMaxY(_btnChannel.frame)+10,Screen_Width-CGRectGetMaxX( lblChannel.frame)+10, 1);
  580. [v6 addSubview:separator5];
  581. UIView *v7 = [UIView new];
  582. v7.frame=CGRectMake(0,CGRectGetMaxY(v6.frame),Screen_Width, 51);
  583. [_headerView addSubview:v7];
  584. UILabel *lblDepartment = [UILabel new];
  585. lblDepartment.frame=CGRectMake(15, 16, 100, 25);
  586. lblDepartment.text = @"业务部门";
  587. lblDepartment.font=orderTextFont;
  588. [v7 addSubview: lblDepartment];
  589. _btnDepartment = [UIButton buttonWithType:UIButtonTypeCustom];
  590. _btnDepartment.frame=CGRectMake(CGRectGetMaxX(lblDepartment.frame)+10, 16, 250, 25);
  591. [_btnDepartment setTitle:@"请选择业务部门" forState:UIControlStateNormal];
  592. [_btnDepartment setTitleColor:ButtonTitleColor forState:UIControlStateNormal];
  593. [v7 addSubview:_btnDepartment];
  594. [_btnDepartment addTarget:self action:@selector(showDepartmentAlert) forControlEvents:UIControlEventTouchUpInside];
  595. _btnDepartment.titleLabel.font=orderTextFont;
  596. _btnDepartment.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  597. UIImageView *departmentImg = [[UIImageView alloc] initWithFrame:CGRectMake(Screen_Width-25, 20,7,12)];
  598. [departmentImg setImage:[UIImage imageNamed:@"rightarrow"] ];
  599. [v7 addSubview:departmentImg];
  600. UIView *separator6 = [UIView new];
  601. separator6.backgroundColor=LineBackgroundColor;
  602. separator6.frame=CGRectMake(CGRectGetMaxX( lblDepartment.frame)+10,CGRectGetMaxY(_btnDepartment.frame)+10,Screen_Width-CGRectGetMaxX(lblDepartment.frame)+10, 1);
  603. [v7 addSubview:separator6];
  604. UIView *v8 = [UIView new];
  605. v8.frame=CGRectMake(0,CGRectGetMaxY(v7.frame),Screen_Width, 51);
  606. [_headerView addSubview:v8];
  607. UILabel *lblSalesMan = [UILabel new];
  608. lblSalesMan.frame=CGRectMake(15, 16, 100, 25);
  609. lblSalesMan.text = @"业 务 员";
  610. lblSalesMan.font=orderTextFont;
  611. [v8 addSubview: lblSalesMan];
  612. _btnSalesMan = [UIButton buttonWithType:UIButtonTypeCustom];
  613. _btnSalesMan.frame=CGRectMake(CGRectGetMaxX(lblSalesMan.frame)+10, 16, 150, 25);
  614. [_btnSalesMan setTitle:@"请选择业务员" forState:UIControlStateNormal];
  615. [_btnSalesMan setTitleColor:ButtonTitleColor forState:UIControlStateNormal];
  616. [v8 addSubview:_btnSalesMan];
  617. _btnSalesMan.titleLabel.font=orderTextFont;
  618. _btnSalesMan.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  619. [_btnSalesMan addTarget:self action:@selector(showSalesManAlert) forControlEvents:UIControlEventTouchUpInside];
  620. UIImageView *salesmanImg = [[UIImageView alloc] initWithFrame:CGRectMake(Screen_Width-25, 20,7,12)];
  621. [salesmanImg setImage:[UIImage imageNamed:@"rightarrow"] ];
  622. [v8 addSubview:salesmanImg];
  623. UIView *separator7 = [UIView new];
  624. separator7.backgroundColor=LineBackgroundColor;
  625. separator7.frame=CGRectMake(CGRectGetMaxX(lblSalesMan.frame)+10,CGRectGetMaxY(_btnSalesMan.frame)+10,Screen_Width-CGRectGetMaxX(lblSalesMan.frame)+10, 1);
  626. [v8 addSubview:separator7];
  627. UIView *v9 = [UIView new];
  628. v9.frame=CGRectMake(0,CGRectGetMaxY(v8.frame),Screen_Width, 51);
  629. [_headerView addSubview:v9];
  630. UILabel *lblRemarks = [UILabel new];
  631. lblRemarks.frame=CGRectMake(15, 16, 100, 25);
  632. lblRemarks.text = @"备 注";
  633. lblRemarks.font=orderTextFont;
  634. [v9 addSubview: lblRemarks];
  635. _txtRemarks = [UITextField new];
  636. _txtRemarks.frame=CGRectMake(CGRectGetMaxX(lblRemarks.frame)+10, 16,Screen_Width-CGRectGetMaxX(lblRemarks.frame)-10, 25);
  637. _txtRemarks.placeholder = @"请输入备注";
  638. _txtRemarks.tag=1305;
  639. _txtRemarks.font=orderTextFont;
  640. [v9 addSubview:_txtRemarks];
  641. UIView *separator8 = [UIView new];
  642. separator8.backgroundColor=LineBackgroundColor;
  643. separator8.frame=CGRectMake(0,CGRectGetMaxY(v9.frame)+10,Screen_Width, 10);
  644. [_headerView addSubview:separator8];
  645. _headerView.frame=CGRectMake(0,0, Screen_Width, CGRectGetMaxY(separator8.frame));
  646. vCustomTableView.tableHeaderView=_headerView;
  647. _footerView = [UIView new];
  648. _footerView.frame=CGRectMake(0, Screen_Height-64-rectStatusHeight-rectNavHeight, self.view.frame.size.width,64);
  649. _footerView.backgroundColor = [UIColor whiteColor];
  650. [self.view addSubview: _footerView];
  651. [self.view setBackgroundColor:[UIColor whiteColor]];
  652. //总计
  653. UILabel *lblamountname = [UILabel new];
  654. lblamountname.font = [UIFont systemFontOfSize:15];
  655. lblamountname.text = @"合计金额:";
  656. lblamountname.frame=CGRectMake(10,20,70, 23);
  657. [_footerView addSubview:lblamountname];
  658. UILabel *lblYuan = [UILabel new];
  659. lblYuan.text = @"¥";
  660. lblYuan.font=orderTextFont;
  661. lblYuan.frame=CGRectMake(CGRectGetMaxX(lblamountname.frame),20,15, 23);
  662. [_footerView addSubview:lblYuan];
  663. //价格
  664. _lblTotalAmount = [UILabel new];
  665. _lblTotalAmount.font=orderTextFont;
  666. _lblTotalAmount.frame=CGRectMake(CGRectGetMaxX(lblYuan.frame),20, 150, 23);
  667. [_footerView addSubview:_lblTotalAmount];
  668. //提交订单
  669. UIButton *btnBalance = [UIButton buttonWithType:UIButtonTypeCustom];
  670. btnBalance.frame=CGRectMake(Screen_Width-114,0, 114, 64);
  671. [btnBalance setBackgroundImage:[UIImage imageNamed:@"bt_submit"] forState:UIControlStateNormal];
  672. [btnBalance addTarget:self action:@selector(reallySubmitOrder) forControlEvents:UIControlEventTouchUpInside];
  673. [_footerView addSubview:btnBalance];
  674. }
  675. //进度条取消函数
  676. - (void)cancel {
  677. [self stopLoading];
  678. }
  679. //提交订单
  680. -(void)reallySubmitOrder
  681. {
  682. [self.view endEditing:YES];
  683. if(_txtCustomerCode.text.length==0){
  684. [self showAlertViewText:@"客户编码不能为空"];
  685. return;
  686. }
  687. if(_txtCustomerName.text.length==0){
  688. [self showAlertViewText:@"客户名称不能为空"];
  689. return;
  690. }
  691. if(_txtTelephone.text.length==0)
  692. {
  693. [self showAlertViewText:@"联系电话不能为空"];
  694. return;
  695. }
  696. if(_customerTypeStr==nil||[NSString stringWithFormat:@"%@",_customerTypeStr].length==0){
  697. [self showAlertViewText:@"客户性质不能为空"];
  698. return;
  699. }
  700. if(_channelStr==nil|| [NSString stringWithFormat:@"%@", _channelStr].length==0){
  701. [self showAlertViewText:@"渠道不能为空"];
  702. return;
  703. }
  704. if(_departmentIdStr==nil||[NSString stringWithFormat:@"%@",_departmentIdStr].length==0){
  705. [self showAlertViewText:@"业务部门不能为空"];
  706. return;
  707. }
  708. if(_salesmanStr==nil||[NSString stringWithFormat:@"%@",_salesmanStr ].length==0){
  709. [self showAlertViewText:@"业务员不能为空"];
  710. return;
  711. }
  712. if(!_cartModel){
  713. return;
  714. }
  715. if(![_cartModel isSelectAtLeastOne])
  716. {
  717. [self showAlertViewText:@"至少选择一种商品"];
  718. return;
  719. }
  720. if(![_cartModel checkFormat])
  721. {
  722. [self showAlertViewText:@"每件商品的数量不能为0"];
  723. return;
  724. }
  725. NSString *totalAmount= _lblTotalAmount.text;
  726. if(totalAmount!=nil){
  727. if(totalAmount.doubleValue>MAXIMUM_QUANTITY){
  728. [self showAlertViewText:@"合计金额不能大于9999999999.999999"];
  729. return;
  730. }
  731. }
  732. _cartItemArr=[_cartModel checkedArr];
  733. //其他参数
  734. _strCustomerCode=_txtCustomerCode.text;
  735. _strOrganizationID=_departmentIdStr;
  736. _strTelephone=_txtTelephone.text;
  737. _strCustomerName=_txtCustomerName.text;
  738. _strAddress=_txtCustomerAddress.text;
  739. _strRemarks=_txtRemarks.text;
  740. [self submitOrder];
  741. }
  742. -(void)submitOrder
  743. {
  744. self.mDownManager = [[ASIDownManager alloc] init];
  745. _mDownManager.delegate = self;
  746. _mDownManager.OnImageDown = @selector(onSubmitLoadFinish:);
  747. _mDownManager.OnImageFail = @selector(onSubmitLoadFail:);
  748. HUD = [[MBProgressHUD alloc] initWithView:self.view];
  749. [self.view addSubview:HUD];
  750. HUD.dimBackground = YES;
  751. HUD.labelText = @"正在提交订单";
  752. [HUD show:YES];
  753. NSString *urlStr = ServerURL;
  754. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  755. [dict setObject:@"SaveIOrderIphone" forKey:@"Action"];
  756. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  757. [dict setObject:kkUserCode forKey:@"UserCode"];
  758. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  759. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  760. if (kkLicenseCode !=nil) {
  761. [dict setObject:kkLicenseCode forKey:@"LicenseCode"];
  762. }
  763. [dict setObject:[NSString stringWithFormat:@"%@", _strFilingID ] forKey:@"FilingID"];
  764. [dict setObject:[NSString stringWithFormat:@"%@", _customerIDStr ] forKey:@"CustomerID"]; //客户编码ID,如果是新客户,为0
  765. [dict setObject:[NSString stringWithFormat:@"%@", _strCustomerCode] forKey:@"CustomerCode"];// 客户编码
  766. [dict setObject:[NSString stringWithFormat:@"%@", _strCustomerName] forKey:@"CustomerName"];
  767. // [dict setObject:@"15840356984" forKey:@"Telephone"];
  768. [dict setObject:[NSString stringWithFormat:@"%@", _strTelephone] forKey:@"Telephone"];
  769. [dict setObject:[NSString stringWithFormat:@"%@", _channelStr] forKey:@"ChannelID"];
  770. [dict setObject:[NSString stringWithFormat:@"%@", _customerTypeStr] forKey:@"CustomerType"];
  771. [dict setObject:[NSString stringWithFormat:@"%@",_departmentIdStr] forKey:@"OrganizationID"];
  772. [dict setObject:[NSString stringWithFormat:@"%@",_salesmanStr] forKey:@"StaffID"];
  773. [dict setObject:_strAddress forKey:@"Address"];
  774. [dict setObject:_strRemarks forKey:@"Remarks"];
  775. NSMutableArray *cartItemArr2=[NSMutableArray new];
  776. for(int i=0;i<_cartItemArr.count;i++) {
  777. SubmitOrderFrame *frame= _cartItemArr[i];
  778. ShopCartItemModel *model=frame.cartModel;
  779. NSDictionary *dic=[NSDictionary new];
  780. NSString *cartId=[NSString stringWithFormat:@"%@", model.cartId];
  781. NSString *code=[NSString stringWithFormat:@"%@", model.code];
  782. NSString *onlyCode=[NSString stringWithFormat:@"%@", model.onlyCode];
  783. NSString *brandName=[NSString stringWithFormat:@"%@", model.brandName];
  784. NSString *gradeName=[NSString stringWithFormat:@"%@", model.gradeName];
  785. NSString *specification=[NSString stringWithFormat:@"%@", model.specification];
  786. NSString *colorNumber=[NSString stringWithFormat:@"%@", model.colorNumber];
  787. NSString *warehouseName=[NSString stringWithFormat:@"%@", model.warehouseName];
  788. NSString *positionNumber=[NSString stringWithFormat:@"%@", model.positionNumber];
  789. NSString *balanceQuantity=[NSString stringWithFormat:@"%@", model.balanceQuantity];
  790. NSString *inventoryId=[NSString stringWithFormat:@"%@", model.inventoryId];
  791. NSString *salesQuantity=[NSString stringWithFormat:@"%@", model.salesQuantity];
  792. NSString *salesPrice=[NSString stringWithFormat:@"%@", model.salesPrice];
  793. NSString *remarks=[NSString stringWithFormat:@"%@", model.remarks];
  794. NSString *acreage=[NSString stringWithFormat:@"%@", model.acreage];
  795. NSString *volume=[NSString stringWithFormat:@"%@", model.volume];
  796. NSString *codeId=[NSString stringWithFormat:@"%@", model.codeId];
  797. NSString *gradeId=[NSString stringWithFormat:@"%@", model.gradeId];
  798. NSString *warehouseId=[NSString stringWithFormat:@"%@", model.warehouseId];
  799. NSString *brandId=[NSString stringWithFormat:@"%@", model.brandId];
  800. NSString *kindId=[NSString stringWithFormat:@"%@", model.kindId];
  801. NSString *kindName=[NSString stringWithFormat:@"%@", model.kindName];
  802. NSString *varietyId=[NSString stringWithFormat:@"%@", model.varietyId];
  803. NSString *varietyName=[NSString stringWithFormat:@"%@", model.varietyName];
  804. NSString *seriesId=[NSString stringWithFormat:@"%@", model.seriesId];
  805. NSString *seriesName=[NSString stringWithFormat:@"%@", model.seriesName];
  806. NSString *unitId=[NSString stringWithFormat:@"%@", model.unitId];
  807. NSString *unitName=[NSString stringWithFormat:@"%@", model.unitName];
  808. NSString *markedPrice=[NSString stringWithFormat:@"%@", model.markedPrice];
  809. NSString *weight=[NSString stringWithFormat:@"%@", model.weight];
  810. NSString *package=[NSString stringWithFormat:@"%@", model.package];
  811. // Weight,MarkedPrice,SalesQuantity,BalanceQuantity,SalesPrice
  812. //标价
  813. if([markedPrice isEqualToString:@""]||[markedPrice isEqualToString:@"(null)"]||markedPrice==nil){
  814. markedPrice=@"0";
  815. }
  816. NSNumber *markedPriceNum=[NSNumber numberWithFloat:[markedPrice floatValue]];
  817. if([weight isEqualToString:@""]||[weight isEqualToString:@"(null)"]||weight==nil){
  818. weight=@"0";
  819. }
  820. NSNumber *weightNum=[NSNumber numberWithFloat:[weight floatValue]];
  821. if([salesQuantity isEqualToString:@""]||[salesQuantity isEqualToString:@"(null)"]||salesQuantity==nil){
  822. salesQuantity=@"0";
  823. }
  824. NSNumber *salesQuantityNum=[NSNumber numberWithFloat:[salesQuantity floatValue]];
  825. if([balanceQuantity isEqualToString:@""]||[balanceQuantity isEqualToString:@"(null)"]||balanceQuantity==nil){
  826. balanceQuantity=@"0";
  827. }
  828. NSNumber *balanceQuantityNum=[NSNumber numberWithFloat:[balanceQuantity floatValue]];
  829. if([salesPrice isEqualToString:@""]||[salesPrice isEqualToString:@"(null)"]||salesPrice==nil){
  830. salesPrice=@"0";
  831. }
  832. NSNumber *salesPriceNum=[NSNumber numberWithFloat:[salesPrice floatValue]];
  833. if([package isEqualToString:@""]||[package isEqualToString:@"(null)"]||package==nil){
  834. package=@"0";
  835. }
  836. NSNumber *packageNum=[NSNumber numberWithInt:[salesPrice intValue]];
  837. dic=@{@"CartID":cartId,@"Code":code,@"OnlyCode":onlyCode,@"BrandName":brandName,@"GradeName":gradeName,@"Specification":specification,@"ColorNumber":colorNumber,@"WarehouseName":warehouseName,@"PositionNumber":positionNumber,@"BalanceQuantity":balanceQuantityNum,@"InventoryID":inventoryId,@"SalesQuantity":salesQuantityNum,@"SalesPrice":salesPriceNum,@"Remarks":remarks,
  838. @"Acreage":acreage,@"Volume":volume,@"CodeID":codeId,@"GradeID":gradeId,@"WarehouseID":warehouseId,@"BrandID":brandId, @"KindID":kindId,@"KindName":kindName,@"VarietyID":varietyId,@"VarietyName":varietyName,@"SeriesID":seriesId,
  839. @"SeriesName":seriesName,@"UnitID":unitId,@"UnitName":unitName,@"MarkedPrice": markedPriceNum ,@"Weight":weightNum,@"Package":packageNum };
  840. [cartItemArr2 addObject:dic];
  841. }
  842. SBJsonWriter *write = [[SBJsonWriter alloc] init];
  843. NSString *value = [write stringWithObject:cartItemArr2];
  844. [dict setObject:value forKey:@"ShoppingCartData"];
  845. [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  846. }
  847. //显示客户性质
  848. -(void)showCustomerTypeAlert{
  849. CustomerTypeSearchVC *customerType=[[CustomerTypeSearchVC alloc] init];
  850. UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:customerType];
  851. navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
  852. customerType.orderDelegate=self;
  853. [self presentViewController:navigationController animated:YES completion:nil];
  854. }
  855. //更新合计金额
  856. -(void)refreshTotalAmount
  857. {
  858. double price=[_cartModel calculatePrice];
  859. if(price>MAXIMUM_QUANTITY){
  860. price=MAXIMUM_QUANTITY;
  861. }
  862. _lblTotalAmount.text=[NSString stringWithFormat:@"%.2lf",price ];
  863. }
  864. //更新商品售价
  865. -(void)updatePrice
  866. {
  867. //接着更新商品售价
  868. double delayInSeconds = 0.5;
  869. dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
  870. dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
  871. [self updateGoodsSalePrice];
  872. });
  873. }
  874. //业务部门查询
  875. -(void)showDepartmentAlert
  876. {
  877. DepartmentSearchVC *department=[[DepartmentSearchVC alloc] init];
  878. UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:department];
  879. navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
  880. department.departmentDelegate=self;
  881. [self presentViewController:navigationController animated:YES completion:nil];
  882. }
  883. //业务员查询
  884. -(void)showSalesManAlert{
  885. SalesManSearchVC *salesman=[[SalesManSearchVC alloc] init];
  886. UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:salesman];
  887. navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
  888. salesman.salesmanDelegate=self;
  889. [self presentViewController:navigationController animated:YES completion:nil];
  890. }
  891. //渠道查询
  892. -(void)showChannelAlert{
  893. ChannelSearchVC *channel=[[ChannelSearchVC alloc] init];
  894. UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:channel];
  895. navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
  896. channel.channelDelegate=self;
  897. [self presentViewController:navigationController animated:YES completion:nil];
  898. }
  899. //更新商品售价
  900. -(void)updateGoodsSalePrice
  901. {
  902. [self startLoading];
  903. NSString *urlStr = ServerURL;
  904. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  905. [dict setObject:@"GetOrderPriceIphone" forKey:@"Action"];
  906. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  907. [dict setObject:kkUserCode forKey:@"UserCode"];
  908. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  909. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  910. [dict setObject:_customerIDStr forKey:@"CustomerID"];
  911. NSString * OrderDetail=[_cartModel checkedSalePriceJSON];
  912. [dict setObject:OrderDetail forKey:@"OrderDetail"];
  913. self.mDownManager = [[ASIDownManager alloc] init];
  914. _mDownManager.delegate = self;
  915. _mDownManager.OnImageDown = @selector(onSalesPriceLoadFinish:);
  916. _mDownManager.OnImageFail = @selector(onSalesPriceLoadFail:);
  917. [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  918. }
  919. //tableview刷新数据
  920. -(void) loadData
  921. {
  922. [self.vCustomTableView reloadData];
  923. [self refreshTotalAmount];
  924. }
  925. /**
  926. 键盘弹出
  927. @param note <#note description#>
  928. */
  929. -(void)keyboardWillShow:(NSNotification *)note
  930. {
  931. CGRect keyBoardRect=[note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  932. vCustomTableView.contentInset = UIEdgeInsetsMake(0, 0, keyBoardRect.size.height, 0);
  933. }
  934. /**
  935. 键盘隐藏
  936. @param note <#note description#>
  937. */
  938. -(void)keyboardWillHide:(NSNotification *)note
  939. {
  940. vCustomTableView.contentInset = UIEdgeInsetsZero;
  941. }
  942. //只读设置
  943. -(void)readOnly:(BOOL)end
  944. {
  945. if(end){
  946. // 客户名称、渠道、客户性质都是只读
  947. // 客户编码、联系电话、联系人、客户地址、备注、业务部门、业务员为可编辑
  948. _txtCustomerName.enabled=NO;
  949. _btnChannel.enabled=NO;
  950. _btnCustomerType.enabled=NO;
  951. _btnSalesMan.enabled=YES;
  952. [_btnSalesMan setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  953. _btnDepartment.enabled=YES;
  954. [_btnDepartment setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  955. _txtCustomerName.textColor=LabelGrayTextColor;
  956. [_btnChannel setTitleColor:LabelGrayTextColor forState:UIControlStateNormal];
  957. [_btnCustomerType setTitleColor:LabelGrayTextColor forState:UIControlStateNormal];
  958. _btnSalesMan.backgroundColor=[UIColor clearColor];
  959. _btnDepartment.backgroundColor=[UIColor clearColor];
  960. _txtCustomerCode.enabled=YES;
  961. _txtTelephone.enabled=YES;
  962. _txtCustomerAddress.enabled=YES;
  963. _txtRemarks.enabled=YES;
  964. }
  965. else
  966. {
  967. _txtCustomerName.enabled=YES;
  968. _btnChannel.enabled=YES;
  969. [_btnChannel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  970. _btnCustomerType.enabled=YES;
  971. [_btnCustomerType setTitleColor:[UIColor blackColor ] forState:UIControlStateNormal];
  972. _btnSalesMan.enabled=YES;
  973. [_btnSalesMan setTitleColor:[UIColor blackColor ] forState:UIControlStateNormal];
  974. _btnDepartment.enabled=YES;
  975. [_btnDepartment setTitleColor:[UIColor blackColor ] forState:UIControlStateNormal];
  976. _txtCustomerName.textColor=[UIColor blackColor];
  977. _btnChannel.backgroundColor=[UIColor clearColor];
  978. _btnCustomerType.backgroundColor=[UIColor clearColor];
  979. _btnSalesMan.backgroundColor=[UIColor clearColor];
  980. _btnDepartment.backgroundColor=[UIColor clearColor];
  981. _txtCustomerCode.enabled=YES;
  982. _txtTelephone.enabled=YES;
  983. _txtCustomerAddress.enabled=YES;
  984. _txtRemarks.enabled=YES;
  985. }
  986. }
  987. //获取客户基本信息
  988. -(void)searchCustomerInfo:(NSString *)codeOrPhone
  989. {
  990. NSString *urlStr = ServerURL;
  991. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  992. [dict setObject:@"GetCutomersDataSourceIphone" forKey:@"Action"];
  993. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  994. [dict setObject:kkUserCode forKey:@"UserCode"];
  995. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  996. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  997. [dict setObject:codeOrPhone forKey:@"CustomerCode"];
  998. [dict setObject:@"" forKey:@"CustomerName"];
  999. [dict setObject:@"" forKey:@"ChannelID"];
  1000. [dict setObject:@"" forKey:@"CustomerType"];
  1001. self.mDownManager = [[ASIDownManager alloc] init];
  1002. _mDownManager.delegate = self;
  1003. _mDownManager.OnImageDown = @selector(onLoadFinish:);
  1004. _mDownManager.OnImageFail = @selector(onLoadFail:);
  1005. [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  1006. }
  1007. //客户编码列表查询
  1008. -(void)searchCustomerCode{
  1009. CustomerCodeSearchVC *customerCodeVC=[[ CustomerCodeSearchVC alloc] init];
  1010. UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:customerCodeVC];
  1011. navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
  1012. navigationController.preferredContentSize = CGSizeMake(frameSize.x, frameSize.y);
  1013. customerCodeVC.orderDelegate=self;
  1014. [self presentViewController:navigationController animated:YES completion:nil];
  1015. }
  1016. @end