SalesAnalysisSearchCell.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. //
  2. // SalesAnalysisSearchCell
  3. // IBOSS
  4. //
  5. // Created by apple on 2017/5/15.
  6. // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved.
  7. //
  8. // 功能描述:商品畅滞销分析抽屉Cell
  9. #import "SalesAnalysisSearchCell.h"
  10. #import "UIColor+hexColor.h"
  11. #import "SideSlipConfig.h"
  12. #import "SalesAnalysisSearchModel.h"
  13. #import "BRDatePickerView.h"
  14. #import "DateFormat.h"
  15. #import "BrandSearchViewController.h"
  16. @interface SalesAnalysisSearchCell() <UITextFieldDelegate ,BaseIDAndNameProtocol>{
  17. /**
  18. 存储选择的排序方式
  19. */
  20. UILabel *_selectLable;
  21. /**
  22. 开始时间
  23. */
  24. NSString *_strStartDate;
  25. /**
  26. 结束时间
  27. */
  28. NSString * _strEndDate;
  29. /**
  30. 品牌ID
  31. */
  32. NSString * _strCommodityBrandID;
  33. /**
  34. 品牌名称
  35. */
  36. NSString *_strCommodityBrand;
  37. /**
  38. 时间控件
  39. */
  40. BRDatePickerView *_brdatePicker;
  41. }
  42. /**
  43. 抽屉对象model
  44. */
  45. @property (strong,nonatomic) SideSlipModel *regionModel;
  46. @end
  47. @implementation SalesAnalysisSearchCell
  48. /**
  49. cell
  50. @param indexPath <#indexPath description#>
  51. @return <#return value description#>
  52. */
  53. + (instancetype)createCellWithIndexPath:(NSIndexPath *)indexPath {
  54. SalesAnalysisSearchCell *cell = [[NSBundle mainBundle] loadNibNamed:@"SalesAnalysisSearchCell" owner:nil options:nil][0];
  55. cell.fieldOnlyCode.delegate = cell;
  56. cell.fieldCommodityName.delegate = cell;
  57. [cell configureKeyboard];
  58. return cell;
  59. }
  60. /**
  61. 初始化Cell
  62. @param model <#model description#>
  63. @param indexPath <#indexPath description#>
  64. */
  65. - (void)updateCellWithModel:(SideSlipModel *__autoreleasing *)model indexPath:(NSIndexPath *)indexPath{
  66. self.regionModel = *model;
  67. [self initUI];
  68. [self updateModel];
  69. }
  70. /**
  71. 弹出商品品牌
  72. @param sender sender description
  73. */
  74. - (IBAction)showCommodityBrand:(id)sender {
  75. BrandSearchViewController *tc = [[BrandSearchViewController alloc ]init];
  76. tc.bDelegate = self;
  77. tc.isPresentViewFlag = YES;
  78. tc.showDialogViewTag = baseIdAndNameBrand;
  79. if ([self.delegate respondsToSelector:@selector(sideSlipTableViewCellNeedsDismissViewController:animated:)]) {
  80. [self.delegate sideSlipTableViewCellNeedsDismissViewController:tc animated:YES];
  81. }
  82. }
  83. /**
  84. 品牌回调函数
  85. @param model <#model description#>
  86. @param value <#value description#>
  87. */
  88. - (void)baseIDAndNameDoneDatas:(BaseIDAndNameModel *)m BaseIDAndName:(baseIdAndName)value{
  89. if (value == baseIdAndNameBrand) {
  90. _strCommodityBrandID = m.id;
  91. _strCommodityBrand = m.name;
  92. [self.btnCommodityBrand setTitle:m.name forState:UIControlStateNormal];
  93. }
  94. [self updateModel];
  95. }
  96. /**
  97. 显示开始时间
  98. @param sender <#sender description#>
  99. */
  100. - (IBAction)showStartDate:(id)sender {
  101. _brdatePicker = [BRDatePickerView PickerAlertWithTitle:@""];
  102. [_brdatePicker configureSelectionBlock:^(NSString *date){
  103. _strStartDate = date;
  104. } andCompletionBlock:^(void){
  105. [_btnStartDate setTitle:_strStartDate forState:UIControlStateNormal];
  106. [self updateModel];
  107. } andCancelBlock:^(void){
  108. _strStartDate= _btnStartDate.titleLabel.text;
  109. [self updateModel];
  110. }];
  111. [_brdatePicker show];
  112. }
  113. /**
  114. 显示结束时间
  115. @param sender <#sender description#>
  116. */
  117. - (IBAction)showEndDate:(id)sender {
  118. _brdatePicker = [BRDatePickerView PickerAlertWithTitle:@""];
  119. [_brdatePicker configureSelectionBlock:^(NSString *date){
  120. _strEndDate = date;
  121. } andCompletionBlock:^(void){
  122. [_btnEndDate setTitle:_strEndDate forState:UIControlStateNormal];
  123. [self updateModel];
  124. } andCancelBlock:^(void){
  125. _strEndDate = _btnEndDate.titleLabel.text;
  126. [self updateModel];
  127. }];
  128. [_brdatePicker show];
  129. }
  130. /**
  131. 选中销售数量
  132. */
  133. - (void) selectSalesVolumes{
  134. [self selectSort:self.btnSalesVolumes];
  135. }
  136. /**
  137. 选中销售金额
  138. */
  139. - (void) selectSalesAmount {
  140. [self selectSort:self.btnSalesAmount];
  141. }
  142. /**
  143. 选中销售次数
  144. */
  145. - (void) selectSalesTimes {
  146. [self selectSort:self.btnSalesTimes];
  147. }
  148. /**
  149. 切换排序
  150. @param lab <#lab description#>
  151. */
  152. - (void)selectSort: (UILabel *) lab {
  153. if(_selectLable == lab){
  154. return;
  155. }else{
  156. _selectLable.layer.borderColor = [NavBarUnEnbleItemColor CGColor];
  157. _selectLable.textColor = NavBarUnEnbleItemColor;
  158. _selectLable = lab;
  159. _selectLable.layer.borderColor = [[UIColor redColor] CGColor];
  160. _selectLable.textColor = [UIColor redColor];
  161. [self updateModel];
  162. }
  163. }
  164. /**
  165. 区分渠道
  166. */
  167. - (void)selectChannel{
  168. [self distinguish:self.btnChannel];
  169. }
  170. /**
  171. 区分等级
  172. */
  173. - (void)selectGrade{
  174. [self distinguish:self.btnGrade];
  175. }
  176. /**
  177. 区分色号
  178. */
  179. - (void)selectAreaColor{
  180. [self distinguish:self.btnAreaColor];
  181. }
  182. /**
  183. 区分规格
  184. */
  185. - (void)selectSpecification{
  186. [self distinguish:self.btnSpecification];
  187. }
  188. /**
  189. 区分规格
  190. */
  191. - (void)distinguish:(UILabel *) lbl{
  192. switch (lbl.tag) {
  193. case 0:
  194. lbl.tag = 1;
  195. lbl.layer.borderColor = [[UIColor redColor] CGColor];
  196. lbl.textColor = [UIColor redColor];
  197. break;
  198. case 1:
  199. lbl.tag = 0;
  200. lbl.layer.borderColor = [NavBarUnEnbleItemColor CGColor];
  201. lbl.textColor = NavBarUnEnbleItemColor;
  202. break;
  203. default:
  204. break;
  205. }
  206. [self updateModel];
  207. }
  208. /**
  209. awakeFromNib
  210. */
  211. - (void)awakeFromNib {
  212. [super awakeFromNib];
  213. }
  214. /**
  215. 键盘配置
  216. */
  217. - (void)configureKeyboard {
  218. UIView *keyBoardAccessoryView = [self createKeyBoardAccessoryView];
  219. _fieldOnlyCode.inputAccessoryView = keyBoardAccessoryView;
  220. _fieldCommodityName.inputAccessoryView = keyBoardAccessoryView;
  221. }
  222. /**
  223. 文本编辑时候 弹出取消完成按钮
  224. @return <#return value description#>
  225. */
  226. - (UIView *)createKeyBoardAccessoryView {
  227. UIView *keyBoardAccessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, ACCESSORY_VIEW_HEIGHT)];
  228. [keyBoardAccessoryView setBackgroundColor:[UIColor hexColor:@"e1e1e1"]];
  229. UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(ACCESSORY_BUTTON_LEADING_TRAILING, 0, ACCESSORY_BUTTON_WIDTH, ACCESSORY_VIEW_HEIGHT)];
  230. [backButton setTitle:@"取消" forState:UIControlStateNormal];
  231. [backButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
  232. [backButton.titleLabel setFont:[UIFont systemFontOfSize:14.f]];
  233. [backButton addTarget:self action:@selector(accessoryButtonBack) forControlEvents:UIControlEventTouchUpInside];
  234. UIButton *doneButton = [[UIButton alloc] initWithFrame:CGRectMake(Screen_Width - ACCESSORY_BUTTON_LEADING_TRAILING - ACCESSORY_BUTTON_WIDTH, 0, ACCESSORY_BUTTON_WIDTH, ACCESSORY_VIEW_HEIGHT)];
  235. [doneButton setTitle:@"完成" forState:UIControlStateNormal];
  236. [doneButton setTitleColor:[UIColor hexColor:FILTER_RED_STRING] forState:UIControlStateNormal];
  237. [doneButton.titleLabel setFont:[UIFont systemFontOfSize:14.f]];
  238. [doneButton addTarget:self action:@selector(accessoryButtonDone) forControlEvents:UIControlEventTouchUpInside];
  239. [keyBoardAccessoryView addSubview:backButton];
  240. [keyBoardAccessoryView addSubview:doneButton];
  241. return keyBoardAccessoryView;
  242. }
  243. /**
  244. 取消文本
  245. */
  246. - (void)accessoryButtonBack {
  247. [self hideKey];
  248. }
  249. /**
  250. 确定文本
  251. */
  252. - (void)accessoryButtonDone {
  253. [_fieldOnlyCode resignFirstResponder];
  254. [_fieldCommodityName resignFirstResponder];
  255. [self hideKey];
  256. }
  257. /**
  258. * 隐藏键盘
  259. */
  260. - (void)hideKey
  261. {
  262. [self.contentView endEditing:YES];
  263. }
  264. /**
  265. 重置按钮 事件
  266. */
  267. - (void)resetData {
  268. [_fieldOnlyCode setText:@""];
  269. [_fieldCommodityName setText:@""];
  270. }
  271. /**
  272. 更新model
  273. */
  274. - (void)updateModel{
  275. SalesAnalysisSearchModel *model = [[SalesAnalysisSearchModel alloc] init];
  276. model.strOnlyCode = [_fieldOnlyCode.text stringByReplacingOccurrencesOfString:@" " withString:@""];
  277. model.strCommodityName = [_fieldCommodityName.text stringByReplacingOccurrencesOfString:@" " withString:@""];
  278. model.strCommodityBrandID = _strCommodityBrandID;
  279. model.strCommodityBrand = _strCommodityBrand;
  280. model.strStartDate = _strStartDate;
  281. model.strEndDate = _strEndDate;
  282. model.strType = [NSString stringWithFormat:@"%ld",(long)_selectLable.tag];
  283. model.strGrade = [NSString stringWithFormat:@"%ld",(long)_btnGrade.tag];
  284. model.strChannel = [NSString stringWithFormat:@"%ld",(long)_btnChannel.tag];
  285. model.strSpecification = [NSString stringWithFormat:@"%ld",(long)_btnSpecification.tag];
  286. model.strAreaColor = [NSString stringWithFormat:@"%ld",(long)_btnAreaColor.tag];
  287. NSMutableDictionary *mutDict = [NSMutableDictionary dictionaryWithDictionary:_regionModel.customDict];
  288. [mutDict setValue:model forKey:SALESANALYSIS_SEARCH_RANGE_MODEL];
  289. _regionModel.customDict = [mutDict copy];
  290. }
  291. /**
  292. Identifier
  293. @return
  294. */
  295. + (NSString *)cellReuseIdentifier {
  296. return @"SalesAnalysisSearchCell";
  297. }
  298. /**
  299. 高度
  300. @return return value description
  301. */
  302. - (CGFloat)cellHeight {
  303. return 669;
  304. }
  305. /**
  306. 文本编辑结束事件
  307. @param textField <#textField description#>
  308. */
  309. - (void)textFieldDidEndEditing:(UITextField *)textField {
  310. [self updateModel];
  311. }
  312. /**
  313. 触摸事件
  314. @param touches <#touches description#>
  315. @param event <#event description#>
  316. */
  317. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  318. [self hideKey];
  319. [_fieldOnlyCode resignFirstResponder];
  320. [_fieldCommodityName resignFirstResponder];
  321. }
  322. /**
  323. 初始化布局
  324. */
  325. - (void)initUI {
  326. self.btnSalesVolumes.layer.borderWidth = 0.5;
  327. self.btnSalesVolumes.layer.cornerRadius = 5;
  328. self.btnSalesVolumes.tag = 1;
  329. self.btnSalesVolumes.layer.borderColor = [NavBarUnEnbleItemColor CGColor];
  330. self.btnSalesVolumes.textColor = NavBarUnEnbleItemColor;
  331. self.btnSalesAmount.layer.borderWidth = 0.5;
  332. self.btnSalesAmount.layer.cornerRadius = 5;
  333. self.btnSalesAmount.tag = 2;
  334. self.btnSalesAmount.layer.borderColor = [NavBarUnEnbleItemColor CGColor];
  335. self.btnSalesAmount.textColor = NavBarUnEnbleItemColor;
  336. self.btnSalesTimes.layer.borderWidth = 0.5;
  337. self.btnSalesTimes.layer.cornerRadius = 5;
  338. self.btnSalesTimes.tag = 3;
  339. self.btnSalesTimes.layer.borderColor = [NavBarUnEnbleItemColor CGColor];
  340. self.btnSalesTimes.textColor = NavBarUnEnbleItemColor;
  341. [self selectSort:self.btnSalesVolumes];
  342. self.btnChannel.layer.borderWidth = 0.5;
  343. self.btnChannel.layer.cornerRadius = 5;
  344. self.btnChannel.tag = 0;
  345. self.btnChannel.layer.borderColor = [NavBarUnEnbleItemColor CGColor];
  346. self.btnChannel.textColor = NavBarUnEnbleItemColor;
  347. self.btnGrade.layer.borderWidth = 0.5;
  348. self.btnGrade.layer.cornerRadius = 5;
  349. self.btnGrade.tag = 0;
  350. self.btnGrade.layer.borderColor = [NavBarUnEnbleItemColor CGColor];
  351. self.btnGrade.textColor = NavBarUnEnbleItemColor;
  352. self.btnAreaColor.layer.borderWidth = 0.5;
  353. self.btnAreaColor.layer.cornerRadius = 5;
  354. self.btnAreaColor.tag = 0;
  355. self.btnAreaColor.layer.borderColor = [NavBarUnEnbleItemColor CGColor];
  356. self.btnAreaColor.textColor = NavBarUnEnbleItemColor;
  357. self.btnSpecification.layer.borderWidth = 0.5;
  358. self.btnSpecification.layer.cornerRadius = 5;
  359. self.btnSpecification.tag = 0;
  360. self.btnSpecification.layer.borderColor = [NavBarUnEnbleItemColor CGColor];
  361. self.btnSpecification.textColor = NavBarUnEnbleItemColor;
  362. UITapGestureRecognizer *channelTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectChannel)];
  363. // 2. 将点击事件添加到label上
  364. [self.btnChannel addGestureRecognizer:channelTapGestureRecognizer];
  365. self.btnChannel.userInteractionEnabled = YES; // 可以理解为设置label可被点击
  366. UITapGestureRecognizer *gradeTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectGrade)];
  367. // 2. 将点击事件添加到label上
  368. [self.btnGrade addGestureRecognizer:gradeTapGestureRecognizer];
  369. self.btnGrade.userInteractionEnabled = YES; // 可以理解为设置label可被点击
  370. UITapGestureRecognizer *areaColorTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectAreaColor)];
  371. // 2. 将点击事件添加到label上
  372. [self.btnAreaColor addGestureRecognizer:areaColorTapGestureRecognizer];
  373. self.btnAreaColor.userInteractionEnabled = YES; // 可以理解为设置label可被点击
  374. UITapGestureRecognizer *specificationTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectSpecification)];
  375. // 2. 将点击事件添加到label上
  376. [self.btnSpecification addGestureRecognizer:specificationTapGestureRecognizer];
  377. self.btnSpecification.userInteractionEnabled = YES; // 可以理解为设置label可被点击
  378. UITapGestureRecognizer *salesVolumesTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectSalesVolumes)];
  379. // 2. 将点击事件添加到label上
  380. [self.btnSalesVolumes addGestureRecognizer:salesVolumesTapGestureRecognizer];
  381. self.btnSalesVolumes.userInteractionEnabled = YES; // 可以理解为设置label可被点击
  382. UITapGestureRecognizer *salesAmountTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectSalesAmount)];
  383. // 2. 将点击事件添加到label上
  384. [self.btnSalesAmount addGestureRecognizer:salesAmountTapGestureRecognizer];
  385. self.btnSalesAmount.userInteractionEnabled = YES; // 可以理解为设置label可被点击
  386. UITapGestureRecognizer *salesTimesTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectSalesTimes)];
  387. // 2. 将点击事件添加到label上
  388. [self.btnSalesTimes addGestureRecognizer:salesTimesTapGestureRecognizer];
  389. self.btnSalesTimes.userInteractionEnabled = YES; // 可以理解为设置label可被点击
  390. _strCommodityBrandID = @"";
  391. _strEndDate = [DateFormat getCurrentDate];
  392. _strStartDate = [DateFormat getDateBefore:31];
  393. [_btnEndDate setTitle:_strEndDate forState:UIControlStateNormal];
  394. [_btnStartDate setTitle:_strStartDate forState:UIControlStateNormal];
  395. }
  396. @end