InventoryDetailViewController.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. //
  2. // InventoryDetailViewController.m
  3. // IBOSSmini
  4. //
  5. // Created by apple on 2017/5/16.
  6. // Copyright © 2017年 elongtian. All rights reserved.
  7. //
  8. #import "InventoryDetailViewController.h"
  9. #import "ImageModel.h"
  10. #import "AlbumPhotoCollectionViewCell.h"
  11. @interface InventoryDetailViewController (){
  12. UIScrollView *_scrollView;
  13. }
  14. @end
  15. @implementation InventoryDetailViewController
  16. /**
  17. viewDidLoad函数
  18. */
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. [self showTitle:@""];
  22. _detailImgList=[[NSMutableArray alloc]init];
  23. // [self loadData];
  24. [self initUI];
  25. }
  26. /**
  27. didReceiveMemoryWarning函数
  28. */
  29. - (void)didReceiveMemoryWarning {
  30. [super didReceiveMemoryWarning];
  31. }
  32. /**
  33. 安全区视图发生变化
  34. */
  35. -(void)viewSafeAreaInsetsDidChange{
  36. _scrollView.frame = self.view.safeAreaLayoutGuide.layoutFrame;
  37. [super viewSafeAreaInsetsDidChange];
  38. }
  39. #pragma mark - 私有函数
  40. -(void)loadData
  41. {
  42. [self startLoading];
  43. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  44. [dict setObject:@"GetNewInventoryDetailIphone" forKey:@"Action"];
  45. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  46. [dict setObject:kkUserCode forKey:@"UserCode"];
  47. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  48. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  49. [dict setObject:_inventoryId forKeyedSubscript:@"InventoryID"];
  50. _downManager = [[ASIDownManager alloc] init];
  51. _downManager.delegate = self;
  52. _downManager.OnImageDown = @selector(onLoadFinish:);
  53. _downManager.OnImageFail = @selector(onLoadFail:);
  54. [_downManager postHttpRequest:ServerURL dic:dict path:nil fileName:nil];
  55. }
  56. /**
  57. 隐藏进度条
  58. */
  59. - (void)cancel {
  60. [self stopLoading];
  61. }
  62. /**
  63. 加载列表数据成功回调
  64. @param sender <#sender description#>
  65. */
  66. - (void)onLoadFinish:(ASIDownManager *)sender {
  67. // 取消进度条
  68. [self cancel];
  69. // 服务器返回数据
  70. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  71. // 服务器返回数据状态值
  72. int iStatus = resultModel.status;
  73. // 服务器返回数据消息
  74. NSString *message = resultModel.message;
  75. // 服务器返回数据状态值正确
  76. if (iStatus == 0) {
  77. NSDictionary * infoDic = (NSDictionary *)resultModel.result;
  78. if(infoDic != nil)
  79. {
  80. NSArray *infoArray=[infoDic objectForKey:@"Table"];
  81. if(infoArray!=nil&&infoArray.count>0){
  82. NSDictionary *dic=[infoArray objectAtIndex:0];
  83. _detailModel = [InventoryDetailModel dk_modelWithDictionary:dic];
  84. _canSaleQuantity=_detailModel.canSaleQuantity;
  85. NSInteger decimalPlaces=[_detailModel.decimalPlaces integerValue];
  86. if(decimalPlaces!=0)
  87. {
  88. _canSaleQuantity=[NSString stringWithFormat:[NSString stringWithFormat:@"%%.%ldf",(long)decimalPlaces ],[_detailModel.canSaleQuantity doubleValue]];
  89. }
  90. if(_canSaleQuantity != nil && ![_canSaleQuantity isEqualToString:@""]){
  91. if(_detailModel.circulateType!=0){
  92. _detailModel.boxPieceFlag = YES;
  93. if(_detailModel.package != nil && ![_detailModel.package isEqualToString:@""]){
  94. _detailModel.box = [NSString stringWithFormat:@"%ld",(long)floor([_detailModel.canSaleQuantity doubleValue]/[_detailModel.package doubleValue])];
  95. _detailModel.piece = [NSString stringWithFormat:@"%ld",(long)floor([_detailModel.canSaleQuantity intValue]%[_detailModel.package intValue])];
  96. }else{
  97. _detailModel.box = @"0";
  98. _detailModel.piece = @"0";
  99. }
  100. }else{
  101. _detailModel.boxPieceFlag = NO;
  102. }
  103. }else{
  104. _detailModel.boxPieceFlag = NO;
  105. }
  106. _code=_detailModel.code;
  107. _onlyCode=_detailModel.onlyCode;
  108. _goodName=_detailModel.goodName;
  109. _brandName=_detailModel.brandName;
  110. _colorNumber=_detailModel.colorNumber;
  111. _specification= _detailModel.specification;
  112. _gradeName=_detailModel.gradeName;
  113. _wareHouseName=_detailModel.wareHouseName;
  114. _positionNumber=_detailModel.positionNumber;
  115. _box=_detailModel.box;
  116. _piece=_detailModel.piece;
  117. _inventoryQuantity= _detailModel.inventoryQuantity;
  118. _price= _detailModel.price;
  119. _boxPieceFlag=_detailModel.boxPieceFlag;
  120. _varietyName=_detailModel.varietyName;
  121. _package=_detailModel.package;
  122. if(_detailModel.photo!=nil&&_detailModel.photo.length>0)
  123. {
  124. ImageModel *imgModel=[ImageModel new];
  125. imgModel.imageName=_detailModel.photo;
  126. [_detailImgList addObject:imgModel];
  127. }
  128. [self initUI];
  129. }
  130. }
  131. }
  132. // 服务器返回数据状态值异常
  133. // 服务器返回数据状态值异常
  134. else if(iStatus==ActionResultStatusAuthError
  135. ||iStatus==ActionResultStatusNoLogin
  136. ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
  137. [self showReLoginDialog:message];
  138. }
  139. }
  140. /**
  141. 初始化ui
  142. */
  143. - (void)initUI { ;
  144. self.navigationItem.title=@"库存商品明细";
  145. self.view.backgroundColor = LineBackgroundColor;
  146. CGFloat heightRow = 30;
  147. CGFloat lblx = 10;
  148. CGFloat lbly = 3;
  149. CGFloat lblwidth = 70;
  150. CGFloat lblheight = 25;
  151. CGFloat valuex = 80;
  152. CGFloat valuey = 3;
  153. CGFloat valueheight = 25;
  154. _scrollView=[UIScrollView new];
  155. _scrollView.frame=self.view.bounds;
  156. [self.view addSubview:_scrollView];
  157. UIView *vTitle = [UIView new];
  158. [_scrollView addSubview:vTitle];
  159. vTitle.backgroundColor = [UIColor whiteColor];
  160. //商品编码==================
  161. UIView *vcode = [UIView new];
  162. vcode.frame=CGRectMake(0, CGRectGetMaxY(vTitle.frame), Screen_Width, heightRow);
  163. [vTitle addSubview:vcode];
  164. UILabel *lblcode=[UILabel new];
  165. lblcode.frame=CGRectMake(lblx, lbly, lblwidth, lblheight);
  166. lblcode.text=@"商品编码:";
  167. lblcode.textColor = [UIColor blackColor];
  168. lblcode.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  169. [vcode addSubview:lblcode];
  170. UILabel *code = [UILabel new];
  171. code.frame=CGRectMake(valuex, valuey, Screen_Width - valuex - lblx, valueheight);
  172. code.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  173. code.text = self.code;
  174. [vcode addSubview:code];
  175. //唯一编码==================
  176. UIView *vonlyCode = [UIView new];
  177. vonlyCode.frame=CGRectMake(0, CGRectGetMaxY(vcode.frame), Screen_Width, heightRow);
  178. [vTitle addSubview:vonlyCode];
  179. UILabel *lblonlyCode=[UILabel new];
  180. lblonlyCode.frame=CGRectMake(lblx, lbly, lblwidth, lblheight);
  181. lblonlyCode.text=@"唯一编码:";
  182. lblonlyCode.textColor = [UIColor blackColor];
  183. lblonlyCode.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  184. [vonlyCode addSubview:lblonlyCode];
  185. UILabel *onlyCode = [UILabel new];
  186. onlyCode.frame=CGRectMake(valuex, valuey, Screen_Width - valuex - lblx, valueheight);
  187. onlyCode.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  188. onlyCode.text = self.onlyCode;
  189. [vonlyCode addSubview:onlyCode];
  190. //==================
  191. UIView *vgoodName = [UIView new];
  192. vgoodName.frame=CGRectMake(0, CGRectGetMaxY(vonlyCode.frame), Screen_Width, heightRow);
  193. [vTitle addSubview:vgoodName];
  194. UILabel *lblgoodName=[UILabel new];
  195. lblgoodName.frame=CGRectMake(lblx, lbly, lblwidth, lblheight);
  196. lblgoodName.text=@"商品名称:";
  197. lblgoodName.textColor = [UIColor blackColor];
  198. lblgoodName.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  199. [vgoodName addSubview:lblgoodName];
  200. UILabel *goodName = [UILabel new];
  201. goodName.frame=CGRectMake(valuex, valuey, Screen_Width - valuex - lblx, valueheight);
  202. goodName.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  203. goodName.text = self.goodName;
  204. [vgoodName addSubview:goodName];
  205. // 品牌==================
  206. UIView *vbrandName = [UIView new];
  207. vbrandName.frame=CGRectMake(0, CGRectGetMaxY(vgoodName.frame), Screen_Width, heightRow);
  208. [vTitle addSubview:vbrandName];
  209. UILabel *lblbrandName=[UILabel new];
  210. lblbrandName.frame=CGRectMake(lblx, lbly, lblwidth, lblheight);
  211. lblbrandName.text=@"品 牌:";
  212. lblbrandName.textColor = [UIColor blackColor];
  213. lblbrandName.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  214. [vbrandName addSubview:lblbrandName];
  215. UILabel *brandName = [UILabel new];
  216. brandName.frame=CGRectMake(valuex, valuey, Screen_Width - valuex - lblx, valueheight);
  217. brandName.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  218. brandName.text = self.brandName;
  219. [vbrandName addSubview:brandName];
  220. //色号==================
  221. UIView *vcolorNumber = [UIView new];
  222. vcolorNumber.frame=CGRectMake(0, CGRectGetMaxY(vbrandName.frame), Screen_Width, heightRow);
  223. [vTitle addSubview:vcolorNumber];
  224. UILabel *lblcolorNumber=[UILabel new];
  225. lblcolorNumber.frame=CGRectMake(lblx, lbly, lblwidth, lblheight);
  226. lblcolorNumber.text=@"色 号:";
  227. lblcolorNumber.textColor = [UIColor blackColor];
  228. lblcolorNumber.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  229. [vcolorNumber addSubview:lblcolorNumber];
  230. UILabel *colorNumber = [UILabel new];
  231. colorNumber.frame=CGRectMake(valuex, valuey, Screen_Width - valuex - lblx, valueheight);
  232. colorNumber.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  233. colorNumber.text = self.colorNumber;
  234. [vcolorNumber addSubview:colorNumber];
  235. //规格==================
  236. UIView *vspecification = [UIView new];
  237. vspecification.frame=CGRectMake(0, CGRectGetMaxY(vcolorNumber.frame), Screen_Width, heightRow);
  238. [vTitle addSubview:vspecification];
  239. UILabel *lblspecification=[UILabel new];
  240. lblspecification.frame=CGRectMake(lblx, lbly, lblwidth, lblheight);
  241. lblspecification.text=@"规 格:";
  242. lblspecification.textColor = [UIColor blackColor];
  243. lblspecification.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  244. [vspecification addSubview:lblspecification];
  245. UILabel *specification = [UILabel new];
  246. specification.frame=CGRectMake(valuex, valuey, Screen_Width - valuex - lblx, valueheight);
  247. specification.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  248. specification.text = self.specification;
  249. [vspecification addSubview:specification];
  250. //==================
  251. UIView *vgradeName = [UIView new];
  252. vgradeName.frame=CGRectMake(0, CGRectGetMaxY(vspecification.frame), Screen_Width, heightRow);
  253. [vTitle addSubview:vgradeName];
  254. UILabel *lblgradeName=[UILabel new];
  255. lblgradeName.frame=CGRectMake(lblx, lbly, lblwidth, lblheight);
  256. lblgradeName.text=@"等 级:";
  257. lblgradeName.textColor = [UIColor blackColor];
  258. lblgradeName.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  259. [vgradeName addSubview:lblgradeName];
  260. UILabel *gradeName = [UILabel new];
  261. gradeName.frame=CGRectMake(valuex, valuey, Screen_Width - valuex - lblx, valueheight);
  262. gradeName.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  263. gradeName.text = self.gradeName;
  264. [vgradeName addSubview:gradeName];
  265. //==================
  266. UIView *vwareHouseName = [UIView new];
  267. vwareHouseName.frame=CGRectMake(0, CGRectGetMaxY(vgradeName.frame), Screen_Width, heightRow);
  268. [vTitle addSubview:vwareHouseName];
  269. UILabel *lblwareHouseName=[UILabel new];
  270. lblwareHouseName.frame=CGRectMake(lblx, lbly, lblwidth, lblheight);
  271. lblwareHouseName.text=@"库 区:";
  272. lblwareHouseName.textColor = [UIColor blackColor];
  273. lblwareHouseName.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  274. [vwareHouseName addSubview:lblwareHouseName];
  275. UILabel *wareHouseName = [UILabel new];
  276. wareHouseName.frame=CGRectMake(valuex, valuey, Screen_Width - valuex - lblx, valueheight);
  277. wareHouseName.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  278. wareHouseName.text = self.wareHouseName;
  279. [vwareHouseName addSubview:wareHouseName];
  280. //==================
  281. UIView *vpositionNumber = [UIView new];
  282. vpositionNumber.frame=CGRectMake(0, CGRectGetMaxY(vwareHouseName.frame), Screen_Width, heightRow);
  283. [vTitle addSubview:vpositionNumber];
  284. UILabel *lblpositionNumber=[UILabel new];
  285. lblpositionNumber.frame=CGRectMake(lblx, lbly, lblwidth, lblheight);
  286. lblpositionNumber.text=@"仓 位:";
  287. lblpositionNumber.textColor = [UIColor blackColor];
  288. lblpositionNumber.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  289. [vpositionNumber addSubview:lblpositionNumber];
  290. UILabel *positionNumber = [UILabel new];
  291. positionNumber.frame=CGRectMake(valuex, valuey, Screen_Width - valuex - lblx, valueheight);
  292. positionNumber.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  293. positionNumber.text = self.positionNumber;
  294. [vpositionNumber addSubview:positionNumber];
  295. //==================
  296. UIView *vPackage = [UIView new];
  297. vPackage.frame=CGRectMake(0, CGRectGetMaxY(vpositionNumber.frame), Screen_Width, heightRow);
  298. [vTitle addSubview:vPackage];
  299. UILabel *lblPackage=[UILabel new];
  300. lblPackage.frame=CGRectMake(lblx, lbly, lblwidth, lblheight);
  301. lblPackage.text=@"包 装:";
  302. lblPackage.textColor = [UIColor blackColor];
  303. lblPackage.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  304. [vPackage addSubview:lblPackage];
  305. UILabel *package = [UILabel new];
  306. package.frame=CGRectMake(valuex, valuey, Screen_Width - valuex - lblx, valueheight);
  307. package.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  308. package.text = _package;
  309. [vPackage addSubview:package];
  310. CGFloat height = CGRectGetMaxY(vPackage.frame);
  311. if(_boxPieceFlag){
  312. UIView *vBox = [UIView new];
  313. vBox.frame=CGRectMake(0, height, Screen_Width, heightRow);
  314. [vTitle addSubview:vBox];
  315. UILabel *titleBox = [[UILabel alloc] init];
  316. titleBox.text = @"可 售 箱:";
  317. titleBox.frame = CGRectMake(lblx, lbly, lblwidth, lblheight);
  318. titleBox.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  319. [vBox addSubview:titleBox];
  320. UILabel *lBox = [[UILabel alloc] init];
  321. lBox.frame = CGRectMake(valuex, valuey, Screen_Width - valuex - lblx, valueheight);
  322. lBox.text =_box;
  323. lBox.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  324. [vBox addSubview:lBox];
  325. UIView *vPiece = [UIView new];
  326. vPiece.frame=CGRectMake(0, CGRectGetMaxY(vBox.frame), Screen_Width, heightRow);
  327. [vTitle addSubview:vPiece];
  328. UILabel *titlepic = [[UILabel alloc] init];
  329. titlepic.text = @"可 售 片:";
  330. titlepic.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  331. titlepic.frame = CGRectMake(lblx, lbly, lblwidth, lblheight);;
  332. [vPiece addSubview:titlepic];
  333. UILabel *lpic = [[UILabel alloc] init];
  334. lpic.frame = CGRectMake(valuex, valuey, Screen_Width - valuex - lblx, valueheight);
  335. lpic.text = _piece;
  336. lpic.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  337. [vPiece addSubview:lpic];
  338. height = CGRectGetMaxY(vPiece.frame);
  339. }
  340. UIView *vcanSaleQuantity = [UIView new];
  341. vcanSaleQuantity.frame=CGRectMake(0,height, Screen_Width, heightRow);
  342. [vTitle addSubview:vcanSaleQuantity];
  343. UILabel *lblcanSaleQuantity=[UILabel new];
  344. lblcanSaleQuantity.frame=CGRectMake(lblx, lbly, lblwidth, lblheight);
  345. lblcanSaleQuantity.text=@"可 售 量:";
  346. lblcanSaleQuantity.textColor = [UIColor blackColor];
  347. lblcanSaleQuantity.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  348. [vcanSaleQuantity addSubview:lblcanSaleQuantity];
  349. UILabel *canSaleQuantity = [UILabel new];
  350. canSaleQuantity.frame=CGRectMake(valuex, valuey, Screen_Width - valuex - lblx, valueheight);
  351. canSaleQuantity.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  352. canSaleQuantity.text = self.canSaleQuantity;
  353. [vcanSaleQuantity addSubview:canSaleQuantity];
  354. UIView *vinventoryQuantity = [UIView new];
  355. vinventoryQuantity.frame=CGRectMake(0, CGRectGetMaxY(vcanSaleQuantity.frame), Screen_Width, heightRow);
  356. [vTitle addSubview:vinventoryQuantity];
  357. UILabel *lblinventoryQuantity=[UILabel new];
  358. lblinventoryQuantity.frame=CGRectMake(lblx, lbly, lblwidth, lblheight);
  359. lblinventoryQuantity.text=@"结 存 量:";
  360. lblinventoryQuantity.textColor = [UIColor blackColor];
  361. lblinventoryQuantity.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  362. [vinventoryQuantity addSubview:lblinventoryQuantity];
  363. UILabel *inventoryQuantity = [UILabel new];
  364. inventoryQuantity.frame=CGRectMake(valuex, valuey, Screen_Width - valuex - lblx, valueheight);
  365. inventoryQuantity.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  366. inventoryQuantity.text = self.inventoryQuantity;
  367. [vinventoryQuantity addSubview:inventoryQuantity];
  368. UIView *vVariety = [UIView new];
  369. vVariety.frame=CGRectMake(0, CGRectGetMaxY(vinventoryQuantity.frame), Screen_Width, heightRow);
  370. [vTitle addSubview:vVariety];
  371. UILabel *lblVariety=[UILabel new];
  372. lblVariety.frame=CGRectMake(lblx, lbly, lblwidth, lblheight);
  373. lblVariety.text=@"品 种:";
  374. lblVariety.textColor = [UIColor blackColor];
  375. lblVariety.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  376. [vVariety addSubview:lblVariety];
  377. UILabel *variety = [UILabel new];
  378. variety.frame=CGRectMake(valuex, valuey, Screen_Width - valuex - lblx, valueheight);
  379. variety.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  380. variety.text = _varietyName;
  381. [vVariety addSubview:variety];
  382. // // 20201026 jiang修改
  383. if (self.price!=nil) {
  384. UIView *vprice = [UIView new];
  385. vprice.frame=CGRectMake(0, CGRectGetMaxY(vVariety.frame), Screen_Width, heightRow);
  386. [vTitle addSubview:vprice];
  387. UILabel *lblprice=[UILabel new];
  388. lblprice.frame=CGRectMake(lblx, lbly, lblwidth, lblheight);
  389. lblprice.text=@"标 价:";
  390. lblprice.textColor = [UIColor blackColor];
  391. lblprice.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  392. [vprice addSubview:lblprice];
  393. UILabel *price = [UILabel new];
  394. price.frame=CGRectMake(valuex, valuey, Screen_Width - valuex - lblx, valueheight);
  395. price.font = [UIFont systemFontOfSize: LabelAndTextFontOfSize];
  396. price.text = self.price;
  397. [vprice addSubview:price];
  398. vTitle.frame=CGRectMake(10, 10, Screen_Width-20, CGRectGetMaxY(vprice.frame) );
  399. }else{
  400. vTitle.frame=CGRectMake(10, 10, Screen_Width-20, CGRectGetMaxY(vVariety.frame) );
  401. }
  402. if(_detailImgList!=nil&&_detailImgList.count>0)
  403. {
  404. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  405. flowLayout.itemSize = CGSizeMake(85, 85);
  406. flowLayout.minimumInteritemSpacing = 5;
  407. flowLayout.minimumLineSpacing = 10;
  408. flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  409. flowLayout.sectionInset = UIEdgeInsetsMake(7, 20, 0, 20);
  410. self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(20,CGRectGetMaxY(vVariety.frame), self.view.bounds.size.width-40, [self getPhotoCollectionViewHeightWithPhotos:_detailImgList]) collectionViewLayout:flowLayout];
  411. self.collectionView.dataSource=self;
  412. self.collectionView.delegate=self;
  413. self.collectionView.scrollEnabled=NO;
  414. self.collectionView.backgroundColor=[UIColor whiteColor];
  415. [self.collectionView registerClass:[AlbumPhotoCollectionViewCell class] forCellWithReuseIdentifier:@"PhotoCollectionViewCellIdentifier"];
  416. [vTitle addSubview:self.collectionView];
  417. vTitle.frame=CGRectMake(10,10,Screen_Width-20,CGRectGetMaxY(self.collectionView.frame)+10);
  418. }
  419. vTitle.layer.cornerRadius = CornerRadius;
  420. _scrollView.contentSize = CGSizeMake(self.view.frame.size.width, CGRectGetMaxY(vTitle.frame)+rectStatusHeight+rectNavHeight);
  421. }
  422. #pragma mark - UICollectionView回调函数
  423. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  424. return _detailImgList.count;
  425. }
  426. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  427. static NSString *PhotoCollectionViewCellIdentifier=@"PhotoCollectionViewCellIdentifier";
  428. AlbumPhotoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:PhotoCollectionViewCellIdentifier forIndexPath:indexPath];
  429. NSArray *followInfoarray=_detailImgList;
  430. cell.indexPath = indexPath;
  431. ImageModel *image1 = [followInfoarray objectAtIndex:indexPath.row];
  432. NSString *imagepath=[image1 imageName];
  433. if(imagepath!=nil&&[imagepath length]>0){
  434. NSData *decodedImageData = [[NSData alloc] initWithBase64Encoding:imagepath];
  435. UIImage *_decodedImage = [UIImage imageWithData:decodedImageData];
  436. [cell.photoImageView setImage:_decodedImage];
  437. }
  438. return cell;
  439. };
  440. /**
  441. 定义每个UICollectionView 的大小
  442. @param collectionView <#collectionView description#>
  443. @param collectionViewLayout <#collectionViewLayout description#>
  444. @param indexPath <#indexPath description#>
  445. @return <#return value description#>
  446. */
  447. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  448. {
  449. return CGSizeMake(85, 85);
  450. }
  451. /**
  452. 定义每个UICollectionView 的 margin
  453. @param collectionView <#collectionView description#>
  454. @param collectionViewLayout <#collectionViewLayout description#>
  455. @param section <#section description#>
  456. @return <#return value description#>
  457. */
  458. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  459. {
  460. return UIEdgeInsetsMake(5, 5, 5, 5);
  461. }
  462. #pragma mark --UICollectionViewDelegate
  463. /**
  464. UICollectionView被选中时调用的方法
  465. @param collectionView <#collectionView description#>
  466. @param indexPath <#indexPath description#>
  467. */
  468. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  469. [self showImageViewerAtIndexPath:indexPath];
  470. }
  471. /**
  472. 返回这个UICollectionView是否可以被选择
  473. @param collectionView <#collectionView description#>
  474. @param indexPath <#indexPath description#>
  475. @return <#return value description#>
  476. */
  477. -(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
  478. {
  479. return YES;
  480. }
  481. #pragma mark - 私有函数
  482. /**
  483. 选择图片
  484. @param indexPath <#indexPath description#>
  485. */
  486. - (void)showImageViewerAtIndexPath:(NSIndexPath *)indexPath {
  487. AlbumPhotoCollectionViewCell *cell = (AlbumPhotoCollectionViewCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
  488. NSMutableArray *imageViews = [NSMutableArray array];
  489. NSArray *visibleCell = [self.collectionView visibleCells];
  490. NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"indexPath" ascending:YES];
  491. visibleCell = [visibleCell sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]];
  492. [visibleCell enumerateObjectsUsingBlock:^(AlbumPhotoCollectionViewCell *cell, NSUInteger idx, BOOL *stop) {
  493. [imageViews addObject:[[cell.contentView subviews] lastObject]];
  494. }];
  495. XHImageViewer *imageViewer = [[XHImageViewer alloc] init];
  496. [imageViewer showWithImageViews:imageViews selectedView:[[cell.contentView subviews] lastObject]];
  497. }
  498. /**
  499. 图片高度
  500. @param photos <#photos description#>
  501. @return <#return value description#>
  502. */
  503. - (CGFloat)getPhotoCollectionViewHeightWithPhotos:(NSArray *)photos {
  504. // 上下间隔已经在frame上做了
  505. NSInteger row = (photos.count / 3 + (photos.count % 3 ? 1 : 0));
  506. return (row *85 + (row *5));
  507. }
  508. @end