SalesOutStorageSalesSlipSearchCell.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. //
  2. // SalesOutStorageSalesSlipSearchCell.m
  3. // IBOSSmini
  4. //
  5. // Created by guan hong hou on 2018/4/12.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "SalesOutStorageSalesSlipSearchCell.h"
  9. #import "UIColor+hexColor.h"
  10. #import "SideSlipConfig.h"
  11. #import "SalesSlipSearchModel.h"
  12. @implementation SalesOutStorageSalesSlipSearchCell
  13. #pragma mark 公共函数
  14. /**
  15. 加载xib
  16. */
  17. - (void)awakeFromNib {
  18. [super awakeFromNib];
  19. }
  20. #pragma mark 委托函数
  21. /**
  22. 高度
  23. @return return value description
  24. */
  25. - (CGFloat)cellHeight {
  26. return 623.5;
  27. }
  28. /**
  29. Identifier
  30. @return <#return value description#>
  31. */
  32. + (NSString *)cellReuseIdentifier {
  33. return @"SalesOutStorageSalesSlipSearchCell";
  34. }
  35. /**
  36. 重置按钮 事件
  37. */
  38. - (void)resetData {
  39. [_txtSalesNo setText:@""];
  40. [_txtCustomerName setText:@""];
  41. [_btnStartDate setTitle:@"请选择开始账务日期" forState:UIControlStateNormal];
  42. _startDate = @"";
  43. [_btnEndDate setTitle:@"请选择结束账务日期" forState:UIControlStateNormal];
  44. _endDate = @"";
  45. [_txtGoodsCode setText:@""];
  46. [_txtCustomerCode setText:@""];
  47. [_txtCustomerAddress setText:@""];
  48. _sureBtn.tag=0;
  49. _inCompleteBtn.tag=0;
  50. _invoiceStatus=@"";
  51. }
  52. /**
  53. textfield回调
  54. @param textField <#textField description#>
  55. @param range <#range description#>
  56. @param string <#string description#>
  57. @return <#return value description#>
  58. */
  59. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  60. return YES;
  61. }
  62. /**
  63. 文本编辑结束事件
  64. @param textField <#textField description#>
  65. */
  66. - (void)textFieldDidEndEditing:(UITextField *)textField {
  67. [self updateModel];
  68. }
  69. /**
  70. cell
  71. @param indexPath <#indexPath description#>
  72. @return <#return value description#>
  73. */
  74. + (instancetype)createCellWithIndexPath:(NSIndexPath *)indexPath {
  75. SalesOutStorageSalesSlipSearchCell *cell = [[NSBundle mainBundle]
  76. loadNibNamed:@"SalesOutStorageSalesSlipSearchCell"
  77. owner:nil
  78. options:nil][0];
  79. cell.sureBtn.layer.borderColor=NavBarUnEnbleItemColor.CGColor;
  80. cell.sureBtn.layer.borderWidth=1;
  81. cell.sureBtn.tag=0;
  82. cell.sureBtn.layer.cornerRadius=4;
  83. [ cell.sureBtn setTitleColor:NavBarUnEnbleItemColor forState:UIControlStateNormal];
  84. [cell.sureBtn addTarget:cell action:@selector(sureStatus) forControlEvents:UIControlEventTouchUpInside];
  85. cell.inCompleteBtn.layer.borderColor=NavBarUnEnbleItemColor.CGColor;
  86. cell.inCompleteBtn.layer.borderWidth=1;
  87. cell.inCompleteBtn.layer.cornerRadius=4;
  88. cell.inCompleteBtn.titleLabel.textColor=NavBarUnEnbleItemColor;
  89. cell.inCompleteBtn.tag=0;
  90. [ cell.inCompleteBtn setTitleColor:NavBarUnEnbleItemColor forState:UIControlStateNormal];
  91. [ cell.inCompleteBtn addTarget:cell action:@selector(incompleteStatus)
  92. forControlEvents:UIControlEventTouchUpInside];
  93. cell.txtSalesNo.delegate = cell;
  94. cell.txtCustomerName.delegate=cell;
  95. cell.txtGoodsCode.delegate=cell;
  96. cell.txtCustomerCode.delegate=cell;
  97. cell.txtCustomerAddress.delegate=cell;
  98. [cell configureKeyboard];
  99. return cell;
  100. }
  101. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  102. [super setSelected:selected animated:animated];
  103. }
  104. #pragma mark 私有函数
  105. /**
  106. 点击开始日期
  107. @param sender <#sender description#>
  108. */
  109. - (IBAction)showStartDate:(id)sender {
  110. __weak typeof(self) weakself=self;
  111. _dealDatePicker = [BRDatePickerView PickerAlertWithTitle:@""];
  112. [_dealDatePicker configureSelectionBlock:^(NSString *date){
  113. _tempStartDate=date;
  114. } andCompletionBlock:^(void){
  115. weakself.startDate = _tempStartDate;
  116. [weakself.btnStartDate setTitle:weakself.startDate forState:UIControlStateNormal];
  117. [self updateModel];
  118. } andCancelBlock:^(void){
  119. }];
  120. [_dealDatePicker show];
  121. }
  122. /**
  123. 点击结束日期
  124. @param sender <#sender description#>
  125. */
  126. - (IBAction)showEndDate:(id)sender {
  127. __weak typeof(self) weakself=self;
  128. _dealDatePicker = [BRDatePickerView PickerAlertWithTitle:@""];
  129. [_dealDatePicker configureSelectionBlock:^(NSString *date){
  130. _tempEndDate=date;
  131. } andCompletionBlock:^(void){
  132. weakself.endDate = _tempEndDate;
  133. [weakself.btnEndDate setTitle:weakself.endDate forState:UIControlStateNormal];
  134. [self updateModel];
  135. } andCancelBlock:^(void){
  136. }];
  137. [_dealDatePicker show];
  138. }
  139. /**
  140. 按钮状态切换
  141. */
  142. - (void)distinguish:(UIButton *) btn{
  143. switch (btn.tag) {
  144. case 0:
  145. btn.tag = 1;
  146. btn.layer.borderColor = [[UIColor redColor] CGColor];
  147. [btn setTitleColor: [UIColor redColor] forState:UIControlStateNormal];
  148. break;
  149. case 1:
  150. btn.tag = 0;
  151. btn.layer.borderColor = [UIColor lightGrayColor].CGColor;
  152. [btn setTitleColor: NavBarUnEnbleItemColor forState:UIControlStateNormal];
  153. break;
  154. default:
  155. break;
  156. }
  157. [self updateModel];
  158. }
  159. /**
  160. 确定状态
  161. */
  162. -(void)sureStatus{
  163. [self distinguish:_sureBtn];
  164. }
  165. /**
  166. 未完成状态
  167. */
  168. -(void)incompleteStatus{
  169. [self distinguish:_inCompleteBtn];
  170. }
  171. /**
  172. 更新model
  173. */
  174. - (void)updateModel{
  175. SalesSlipSearchModel *model = [[SalesSlipSearchModel alloc] init];
  176. NSString *orderNoStr=[_txtSalesNo.text stringByReplacingOccurrencesOfString:@" " withString:@""];
  177. model.SalesNo =orderNoStr;
  178. NSString *customerNameStr=@"";
  179. customerNameStr= [_txtCustomerName.text stringByReplacingOccurrencesOfString:@" " withString:@""];
  180. model.customerName =customerNameStr;
  181. NSString *startDateStr=@"";
  182. startDateStr=_btnStartDate.currentTitle;;
  183. model.startDate =startDateStr ;
  184. NSString *endDateStr=@"";
  185. endDateStr=_btnEndDate.currentTitle;
  186. model.endDate=endDateStr;
  187. NSString *goodsCodeStr=@"";
  188. goodsCodeStr= _txtGoodsCode.text;
  189. model.goodsCode=goodsCodeStr;
  190. NSString *customerCodeStr=@"";
  191. customerCodeStr=_txtCustomerCode.text;
  192. model.customerCode=customerCodeStr;
  193. NSString *customerAddressStr=@"";
  194. customerAddressStr=_txtCustomerAddress.text;
  195. model.customerAddress=customerAddressStr;
  196. _invoiceStatus=@"";
  197. if(_sureBtn.tag==1 ){
  198. _invoiceStatus= [NSString stringWithFormat:@"%@%@",_invoiceStatus,@"4,"];
  199. }
  200. if(_inCompleteBtn.tag==1){
  201. _invoiceStatus= [NSString stringWithFormat:@"%@%@",_invoiceStatus,@"5,"];
  202. }
  203. if(_invoiceStatus.length>0){
  204. _invoiceStatus= [NSString stringWithFormat:@"%@",_invoiceStatus];
  205. _invoiceStatus= [_invoiceStatus substringToIndex:_invoiceStatus.length-1];
  206. model.invoiceStatus=_invoiceStatus;
  207. }
  208. NSMutableDictionary *mutDict = [NSMutableDictionary dictionaryWithDictionary:_regionModel.customDict];
  209. [mutDict setValue:model forKey:SALES_SLIP_SEARCH_RANGE_MODEL];
  210. _regionModel.customDict = [mutDict copy];
  211. }
  212. /**
  213. * 隐藏键盘
  214. */
  215. -(void)hideKey
  216. {
  217. [self.contentView endEditing:YES];
  218. }
  219. /**
  220. 取消文本
  221. */
  222. - (void)accessoryButtonBack {
  223. [self hideKey];}
  224. /**
  225. 确定文本
  226. */
  227. - (void)accessoryButtonDone {
  228. [_txtSalesNo resignFirstResponder];
  229. [_txtCustomerName resignFirstResponder];
  230. [_txtGoodsCode resignFirstResponder];
  231. [_txtCustomerCode resignFirstResponder];
  232. [_txtCustomerAddress resignFirstResponder];
  233. [self hideKey];
  234. }
  235. /**
  236. 触摸事件
  237. @param touches <#touches description#>
  238. @param event <#event description#>
  239. */
  240. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  241. [self hideKey];
  242. [_txtSalesNo resignFirstResponder];
  243. [_txtCustomerName resignFirstResponder];
  244. [_txtGoodsCode resignFirstResponder];
  245. [_txtCustomerCode resignFirstResponder];
  246. [_txtCustomerAddress resignFirstResponder];
  247. }
  248. /**
  249. 更新model
  250. @param model <#model description#>
  251. @param indexPath <#indexPath description#>
  252. */
  253. - (void)updateCellWithModel:(SideSlipModel *__autoreleasing *)model
  254. indexPath:(NSIndexPath *)indexPath{
  255. self.regionModel = *model;
  256. }
  257. /**
  258. 键盘配置
  259. */
  260. - (void)configureKeyboard {
  261. UIView *keyBoardAccessoryView = [self createKeyBoardAccessoryView];
  262. _txtSalesNo.inputAccessoryView = keyBoardAccessoryView;
  263. _txtCustomerName.inputAccessoryView = keyBoardAccessoryView;
  264. _txtGoodsCode.inputAccessoryView = keyBoardAccessoryView;
  265. _txtCustomerCode.inputAccessoryView = keyBoardAccessoryView;
  266. _txtCustomerAddress.inputAccessoryView = keyBoardAccessoryView;
  267. }
  268. /**
  269. 文本编辑时候 弹出取消完成按钮
  270. @return <#return value description#>
  271. */
  272. - (UIView *)createKeyBoardAccessoryView {
  273. UIView *keyBoardAccessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, ACCESSORY_VIEW_HEIGHT)];
  274. [keyBoardAccessoryView setBackgroundColor:[UIColor hexColor:@"e1e1e1"]];
  275. UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(ACCESSORY_BUTTON_LEADING_TRAILING, 0, ACCESSORY_BUTTON_WIDTH, ACCESSORY_VIEW_HEIGHT)];
  276. [backButton setTitle:@"取消" forState:UIControlStateNormal];
  277. [backButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
  278. [backButton.titleLabel setFont:[UIFont systemFontOfSize:14.f]];
  279. [backButton addTarget:self action:@selector(accessoryButtonBack) forControlEvents:UIControlEventTouchUpInside];
  280. UIButton *doneButton = [[UIButton alloc] initWithFrame:CGRectMake(Screen_Width - ACCESSORY_BUTTON_LEADING_TRAILING - ACCESSORY_BUTTON_WIDTH, 0, ACCESSORY_BUTTON_WIDTH, ACCESSORY_VIEW_HEIGHT)];
  281. [doneButton setTitle:@"完成" forState:UIControlStateNormal];
  282. [doneButton setTitleColor:[UIColor hexColor:FILTER_RED_STRING] forState:UIControlStateNormal];
  283. [doneButton.titleLabel setFont:[UIFont systemFontOfSize:14.f]];
  284. [doneButton addTarget:self action:@selector(accessoryButtonDone) forControlEvents:UIControlEventTouchUpInside];
  285. [keyBoardAccessoryView addSubview:backButton];
  286. [keyBoardAccessoryView addSubview:doneButton];
  287. return keyBoardAccessoryView;
  288. }
  289. @end