AddCommodityVC.m 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. //
  2. // AddCommodityVC.m
  3. // yunbaolive
  4. //
  5. // Created by ybRRR on 2020/2/24.
  6. // Copyright © 2020 cat. All rights reserved.
  7. //
  8. #import "AddCommodityVC.h"
  9. #import "CommodityTitleView.h"
  10. #import "CommodityDetailView.h"
  11. #import "StandardsView.h"
  12. #import "SelCommodityClassVC.h"
  13. #import <Qiniu/QiniuSDK.h>
  14. #import "CommodityDetailModel.h"
  15. #import "YBStorageObj.h"
  16. @interface AddCommodityVC ()<commodityTitleDelegate,commodityDetailDelegate,UITextFieldDelegate,UIScrollViewDelegate>
  17. {
  18. UILabel *_classLb; //选择类别
  19. CGFloat titleViewHeight;
  20. CGFloat detailViewHeight;
  21. CGFloat standardsHeight;
  22. CGFloat postageHeight;
  23. CGFloat commissionHeight;
  24. UISwitch *postageSwitch;
  25. NSMutableArray* standarsArr;
  26. NSString *one_classidStr;
  27. NSString *two_classidStr;
  28. NSString *three_classidStr;
  29. UIView *postageback;
  30. UITextField *postageField;
  31. UITextField *commissionField;
  32. NSString *thumbs;// 商品展示图集 英文逗号分隔
  33. NSString *pictures;//商品内容图集 英文逗号分隔
  34. NSString *videoCorverStr;//视频封面
  35. NSString *videoHerfStr;//视频链接
  36. BOOL thumbsBool;
  37. BOOL picturesBool;
  38. BOOL standardsBool;
  39. CGFloat currentScrollY;
  40. }
  41. @property (nonatomic, strong)UIScrollView *backScroll;
  42. @property (nonatomic, strong)UIView *commodityClassView;
  43. @property (nonatomic, strong)UIView *bottomView;
  44. @property (nonatomic, strong)CommodityTitleView *titleView;
  45. @property (nonatomic, strong)CommodityDetailView *contentView;
  46. @property (nonatomic, strong)UIView *standardsBackView;
  47. @property (nonatomic, strong)StandardsView *standardsView;
  48. @property (nonatomic, strong)UIView *postageView; //邮费界面
  49. @property (nonatomic, strong)UIView *commissionView;//佣金
  50. @property (nonatomic, strong)UIButton *addStdBtn;
  51. @property (nonatomic, strong)NSArray*titleImgArr;//商品标题图集数组
  52. @property (nonatomic, strong)NSMutableArray *upTitleImgArr;//上传用标题数组
  53. @property (nonatomic, strong)NSArray*detailImgArr;//商品详情图集数组
  54. @property (nonatomic, strong)NSMutableArray *upDetailImgArr;//上传用详情数组
  55. @property (nonatomic, strong)NSMutableArray*standardsImgArr;//商品详情图集数组
  56. @property (nonatomic, strong)CommodityDetailModel *commodityModel;
  57. @end
  58. @implementation AddCommodityVC
  59. #pragma mark----获取商品详情------
  60. -(void)getGoodInfo{
  61. NSString *url = [purl stringByAppendingFormat:@"?service="];
  62. NSDictionary *dic = @{
  63. @"uid":[Config getOwnID],
  64. @"token":[Config getOwnToken],
  65. @"goodsid":self.goodsID,
  66. };
  67. [YBNetworking postWithUrl:@"Shop.getGoodsInfo" Dic:dic Suc:^(int code, id info, NSString *msg) {
  68. if (code ==0) {
  69. self.commodityModel = [CommodityDetailModel modelWithDic:[info firstObject]];
  70. [self reloadUIData];
  71. }else{
  72. [MBProgressHUD showError:msg];
  73. }
  74. } Fail:^(id fail) {
  75. }];
  76. }
  77. -(void)initData{
  78. standarsArr = [NSMutableArray array];
  79. titleViewHeight = 170;
  80. detailViewHeight = 330;
  81. standardsHeight = 330;
  82. postageHeight = 100;
  83. commissionHeight = 100;
  84. currentScrollY = 0;
  85. self.titleImgArr = [NSArray array];
  86. self.detailImgArr = [NSArray array];
  87. self.standardsImgArr = [NSMutableArray array];
  88. thumbs = @"";
  89. pictures = @"";
  90. thumbsBool = NO;
  91. picturesBool = NO;
  92. standardsBool = NO;
  93. }
  94. - (UIStatusBarStyle)preferredStatusBarStyle {
  95. if (@available(iOS 13.0,*)) {
  96. return UIStatusBarStyleDarkContent;
  97. }
  98. return UIStatusBarStyleDefault;
  99. }
  100. - (void)viewDidLoad {
  101. [super viewDidLoad];
  102. self.subNavi.backgroundColor = UIColor.whiteColor;
  103. self.titleL.textColor = UIColor.blackColor;
  104. [self.leftBtn setImage:[UIImage imageNamed:@"pub_back_black"] forState:0];
  105. self.naviLine.hidden = NO;
  106. self.naviLine.backgroundColor = RGB(245, 245, 245);
  107. if ([self.fromWhere isEqual:@"seller"]) {
  108. self.titleL.text = YZMsg(@"编辑商品");
  109. [self getGoodInfo];
  110. }else{
  111. self.titleL.text = YZMsg(@"添加商品");
  112. }
  113. [self initData];
  114. _backScroll = [[UIScrollView alloc]init];
  115. _backScroll.frame= CGRectMake(0, 64+statusbarHeight, _window_width, _window_height-60);
  116. _backScroll.backgroundColor = RGB(235, 235, 235);
  117. _backScroll.delegate = self;
  118. [self.view addSubview:_backScroll];
  119. UITapGestureRecognizer *hideBoardTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideKeyBoardClick)];
  120. [_backScroll addGestureRecognizer:hideBoardTap];
  121. [self.view addSubview:self.bottomView];
  122. [self.backScroll addSubview:self.commodityClassView];
  123. [self.backScroll addSubview:self.titleView];
  124. [self.backScroll addSubview:self.contentView];
  125. [self.backScroll addSubview:self.standardsBackView];
  126. [self.backScroll addSubview:self.postageView];
  127. [self.backScroll addSubview:self.commissionView];
  128. _backScroll.contentSize = CGSizeMake(_window_width, self.titleView.height+self.contentView.height+self.commodityClassView.height+self.standardsBackView.height+self.postageView.height+self.commissionView.height+64+statusbarHeight+60);
  129. //增加监听,当键盘出现或改变时收出消息
  130. [[NSNotificationCenter defaultCenter] addObserver:self
  131. selector:@selector(keyboardWillShow:)
  132. name:UIKeyboardWillShowNotification
  133. object:nil];
  134. [[NSNotificationCenter defaultCenter] addObserver:self
  135. selector:@selector(keyboardWillHide:)
  136. name:UIKeyboardWillHideNotification
  137. object:nil];
  138. }
  139. -(void)hideKeyBoardClick{
  140. [self.view endEditing:YES];
  141. }
  142. -(UIView*)bottomView{
  143. if (!_bottomView) {
  144. _bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, _window_height-60, _window_width, 60)];
  145. _bottomView.backgroundColor = UIColor.whiteColor;
  146. UIButton *upBtn = [UIButton buttonWithType:0];
  147. upBtn.frame= CGRectMake(15, 10, _window_width-30, 40);
  148. [upBtn setBackgroundColor:Pink_Cor];
  149. [upBtn setTitle:YZMsg(@"提交审核") forState:0];
  150. [upBtn setTitleColor:[UIColor whiteColor] forState:0];
  151. upBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  152. upBtn.layer.cornerRadius = 5;
  153. upBtn.layer.masksToBounds = YES;
  154. [upBtn addTarget:self action:@selector(upBtnClick) forControlEvents:UIControlEventTouchUpInside];
  155. [_bottomView addSubview:upBtn];
  156. }
  157. return _bottomView;
  158. }
  159. //商品标题
  160. -(CommodityTitleView *)titleView{
  161. YBWeakSelf;
  162. if (!_titleView) {
  163. _titleView = [[CommodityTitleView alloc]initWithFrame:CGRectMake(0, self.commodityClassView.bottom+5, _window_width, 170)];
  164. _titleView.delegate = self;
  165. _titleView.heightEvent = ^(CGFloat height) {
  166. titleViewHeight = height;
  167. weakSelf.titleView.size = CGSizeMake(_window_width, height);
  168. [weakSelf reloadUIHeight];
  169. };
  170. }
  171. return _titleView;
  172. }
  173. //商品详情
  174. -(CommodityDetailView *)contentView{
  175. YBWeakSelf;
  176. if (!_contentView) {
  177. _contentView =[[CommodityDetailView alloc]initWithFrame:CGRectMake(0, self.titleView.bottom+5, _window_width, 330)];
  178. _contentView.delegate = self;
  179. _contentView.heightEvent = ^(CGFloat height) {
  180. detailViewHeight = height;
  181. weakSelf.contentView.size = CGSizeMake(_window_width, height);
  182. [weakSelf reloadUIHeight];
  183. };
  184. }
  185. return _contentView;
  186. }
  187. //商品规格
  188. -(UIView *)standardsBackView
  189. {
  190. if (!_standardsBackView) {
  191. _standardsBackView = [[UIView alloc]init];
  192. _standardsBackView.frame = CGRectMake(0, self.contentView.bottom+5, _window_width, 330);
  193. _standardsBackView.backgroundColor = UIColor.whiteColor;
  194. UILabel*title = [[UILabel alloc]init];
  195. title.frame = CGRectMake(12, 10, 180, 20);
  196. title.font = [UIFont boldSystemFontOfSize:14];
  197. title.text = YZMsg(@"编辑规格");
  198. title.textColor = [UIColor blackColor];
  199. [_standardsBackView addSubview:title];
  200. [standarsArr addObject:self.standardsView];
  201. [_standardsBackView addSubview:self.standardsView];
  202. [_standardsBackView addSubview:self.addStdBtn];
  203. }
  204. return _standardsBackView;
  205. }
  206. -(StandardsView *)standardsView{
  207. if (!_standardsView) {
  208. _standardsView = [[StandardsView alloc]initWithFrame:CGRectMake(0, 40, _window_width, 240)];
  209. _standardsView.titleLb.text =[NSString stringWithFormat:@"%@%@",YZMsg(@"规格"),@"1"];
  210. }
  211. return _standardsView;
  212. }
  213. //新增规格按钮
  214. -(UIButton *)addStdBtn{
  215. if (!_addStdBtn) {
  216. _addStdBtn = [UIButton buttonWithType:0];
  217. _addStdBtn.frame = CGRectMake(0, self.standardsView.bottom+5, _window_width, 40);
  218. [_addStdBtn setTitle:YZMsg(@"新增规格") forState:0];
  219. [_addStdBtn setImage:[UIImage imageNamed:@"addStard"] forState:0];
  220. [_addStdBtn setTitleColor:UIColor.blackColor forState:0];
  221. _addStdBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  222. [_addStdBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 0 )];
  223. [_addStdBtn addTarget:self action:@selector(addStdClick) forControlEvents:UIControlEventTouchUpInside];
  224. }
  225. return _addStdBtn;
  226. }
  227. //邮费设置界面
  228. -(UIView *)postageView
  229. {
  230. if (!_postageView) {
  231. _postageView = [[UIView alloc]initWithFrame:CGRectMake(0, self.standardsBackView.bottom+5, _window_width, 100)];
  232. _postageView.backgroundColor = UIColor.whiteColor;
  233. UILabel*title = [[UILabel alloc]init];
  234. title.frame = CGRectMake(12, 10, 180, 30);
  235. title.font = [UIFont boldSystemFontOfSize:14];
  236. title.text = YZMsg(@"运费设置");
  237. title.textColor = [UIColor blackColor];
  238. [_postageView addSubview:title];
  239. UILabel*title2 = [[UILabel alloc]init];
  240. title2.frame = CGRectMake(12, title.bottom+10, 180, 30);
  241. title2.font = [UIFont systemFontOfSize:14];
  242. title2.text = YZMsg(@"包邮");
  243. title2.textColor = UIColor.grayColor;
  244. [_postageView addSubview:title2];
  245. postageSwitch = [[UISwitch alloc]initWithFrame:CGRectMake(_window_width-90, title.bottom+10, 70, 30)];
  246. postageSwitch.centerY = title2.centerY;
  247. postageSwitch.on = YES;
  248. postageSwitch.onTintColor = Pink_Cor;
  249. [postageSwitch addTarget:self action:@selector(openPostage) forControlEvents:UIControlEventValueChanged];
  250. [_postageView addSubview:postageSwitch];
  251. postageback = [[UIView alloc]init];
  252. postageback.frame = CGRectMake(0, title2.bottom, _window_width, 50);
  253. postageback.backgroundColor = UIColor.whiteColor;
  254. postageback.hidden = YES;
  255. [_postageView addSubview:postageback];
  256. UILabel*title3 = [[UILabel alloc]init];
  257. title3.frame = CGRectMake(12, 10, 130, 30);
  258. title3.font = [UIFont boldSystemFontOfSize:14];
  259. title3.text = YZMsg(@"运费(元)");
  260. title3.textColor = UIColor.grayColor;
  261. [postageback addSubview:title3];
  262. postageField = [[UITextField alloc]init];
  263. postageField.frame = CGRectMake(title3.right+5, 10, _window_width-title3.right-25, 30);
  264. postageField.backgroundColor =RGB(245, 245, 245);// RGB_COLOR(@"#302D41", 1);
  265. postageField.textColor = [UIColor blackColor];
  266. postageField.font = [UIFont systemFontOfSize:14];
  267. NSMutableAttributedString*holderString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",YZMsg(@"最少1.00元")] attributes:@{NSForegroundColorAttributeName:[UIColor lightGrayColor]}];
  268. postageField.attributedPlaceholder = holderString;
  269. // postageField.placeholder = YZMsg(@"最少1.00元");
  270. postageField.layer.cornerRadius = 3;
  271. postageField.layer.masksToBounds = YES;
  272. postageField.returnKeyType = UIReturnKeyDone;
  273. postageField.keyboardType = UIKeyboardTypeNumberPad;
  274. postageField.delegate = self;
  275. [postageback addSubview:postageField];
  276. }
  277. return _postageView;
  278. }
  279. -(void)openPostage{
  280. // postageSwitch.on = !postageSwitch.on;
  281. if (postageSwitch.on) {
  282. postageHeight = 100;
  283. _postageView.frame =CGRectMake(0, self.standardsBackView.bottom+5, _window_width, 100);
  284. postageback.hidden = YES;
  285. }else{
  286. postageHeight = 150;
  287. _postageView.frame = CGRectMake(0, self.standardsBackView.bottom+5, _window_width, 150);
  288. postageback.hidden = NO;
  289. }
  290. [self reloadUIHeight];
  291. }
  292. #pragma mark--佣金
  293. -(UIView *)commissionView
  294. {
  295. if (!_commissionView) {
  296. _commissionView = [[UIView alloc]init];
  297. _commissionView = [[UIView alloc]initWithFrame:CGRectMake(0, self.postageView.bottom+5, _window_width, 100)];
  298. _commissionView.backgroundColor = UIColor.whiteColor;
  299. UILabel*title = [[UILabel alloc]init];
  300. title.frame = CGRectMake(12, 10, 280, 30);
  301. title.font = [UIFont boldSystemFontOfSize:14];
  302. title.text = YZMsg(@"分享佣金设置");
  303. title.textColor = [UIColor blackColor];
  304. [_commissionView addSubview:title];
  305. UILabel*title3 = [[UILabel alloc]init];
  306. title3.frame = CGRectMake(12, title.bottom+10, 130, 30);
  307. if (![lagType isEqual:ZH_CN]) {
  308. title3.frame = CGRectMake(12, title.bottom+10, 180, 30);
  309. }
  310. title3.font = [UIFont boldSystemFontOfSize:14];
  311. title3.text = YZMsg(@"佣金(元)");
  312. title3.textColor = UIColor.grayColor;
  313. [_commissionView addSubview:title3];
  314. commissionField = [[UITextField alloc]init];
  315. commissionField.frame = CGRectMake(title3.right+5, title.bottom+10, _window_width-title3.right-25, 30);
  316. commissionField.backgroundColor =RGB(245, 245, 245);// RGB_COLOR(@"#302D41", 1);
  317. commissionField.textColor = [UIColor blackColor];
  318. commissionField.font = [UIFont systemFontOfSize:14];
  319. commissionField.layer.cornerRadius = 3;
  320. commissionField.layer.masksToBounds = YES;
  321. commissionField.returnKeyType = UIReturnKeyDone;
  322. commissionField.delegate = self;
  323. [_commissionView addSubview:commissionField];
  324. }
  325. return _commissionView;
  326. }
  327. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  328. if (textField == commissionField) {
  329. if (string.length == 0) {
  330. return YES;
  331. }
  332. NSString *checkStr = [textField.text stringByReplacingCharactersInRange:range withString:string];
  333. NSString *regex = @"^\\-?([1-9]\\d*|0)(\\.\\d{0,2})?$";
  334. return [self isValid:checkStr withRegex:regex];
  335. }
  336. return YES;
  337. }
  338. - (BOOL) isValid:(NSString*)checkStr withRegex:(NSString*)regex {
  339. NSPredicate *predicte = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
  340. return [predicte evaluateWithObject:checkStr];
  341. }
  342. //刷新界面
  343. -(void)reloadUIHeight{
  344. self.titleView.frame = CGRectMake(0, self.commodityClassView.bottom+5, _window_width, titleViewHeight);
  345. self.contentView.frame = CGRectMake(0, self.titleView.bottom+5, _window_width, detailViewHeight);
  346. self.standardsBackView.frame = CGRectMake(0, self.contentView.bottom+5, _window_width, standardsHeight);
  347. self.postageView.frame = CGRectMake(0, self.standardsBackView.bottom+5, _window_width, postageHeight);
  348. self.commissionView.frame = CGRectMake(0, self.postageView.bottom+5, _window_width, commissionHeight);
  349. _backScroll.contentSize = CGSizeMake(_window_width, self.titleView.height+self.contentView.height+self.commodityClassView.height+standardsHeight+postageHeight+commissionHeight+64+statusbarHeight+60);
  350. NSLog(@"------------_backSscoll:%f",_backScroll.contentSize.height);
  351. }
  352. //商品类别
  353. -(UIView *)commodityClassView{
  354. if (!_commodityClassView) {
  355. _commodityClassView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, 55)];
  356. _commodityClassView.backgroundColor = UIColor.whiteColor;
  357. [_backScroll addSubview:_commodityClassView];
  358. UILabel*title = [[UILabel alloc]init];
  359. title.frame = CGRectMake(12, 55/2-10, 180, 20);
  360. title.centerY = _commodityClassView.centerY;
  361. title.font = [UIFont boldSystemFontOfSize:14];
  362. title.text = YZMsg(@"商品类别");
  363. title.textColor = [UIColor blackColor];
  364. [_commodityClassView addSubview:title];
  365. UIImageView *rightImg = [[UIImageView alloc]init];
  366. rightImg.frame = CGRectMake(_window_width-30, 0, 16, 16);
  367. rightImg.centerY = _commodityClassView.centerY;
  368. rightImg.image = [UIImage imageNamed:@"shop_right"];
  369. [_commodityClassView addSubview:rightImg];
  370. _classLb = [[UILabel alloc]init];
  371. _classLb.frame = CGRectMake(rightImg.left-150, 0, 150, 20);
  372. _classLb.centerY = _commodityClassView.centerY;
  373. _classLb.font = [UIFont systemFontOfSize:14];
  374. _classLb.text = YZMsg(@"请选择");
  375. _classLb.textColor = [UIColor grayColor];
  376. _classLb.textAlignment = NSTextAlignmentRight;
  377. [_commodityClassView addSubview:_classLb];
  378. UITapGestureRecognizer *classTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(classClick)];
  379. [_commodityClassView addGestureRecognizer:classTap];
  380. }
  381. return _commodityClassView;
  382. }
  383. -(void)classClick{
  384. SelCommodityClassVC *class = [[SelCommodityClassVC alloc]init];
  385. class.selClassEvent = ^(NSDictionary * _Nonnull firstDic, NSDictionary * _Nonnull twoDic, NSDictionary * _Nonnull threeDic) {
  386. one_classidStr = minstr([firstDic valueForKey:@"gc_id"]);
  387. two_classidStr = minstr([twoDic valueForKey:@"gc_id"]);
  388. three_classidStr =minstr([threeDic valueForKey:@"gc_id"]);
  389. _classLb.text = minstr([threeDic valueForKey:@"gc_name"]);
  390. };
  391. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:class animated:YES];
  392. }
  393. //添加规格
  394. -(void)addStdClick{
  395. YBWeakSelf;
  396. StandardsView *standardsView = [[StandardsView alloc]initWithFrame:CGRectMake(0, 40+standarsArr.count *240, _window_width, 240)];
  397. [_standardsBackView addSubview:standardsView];
  398. [standarsArr addObject:standardsView];
  399. standardsView.deleteBtn.hidden = NO;
  400. standardsView.index = (int)standarsArr.count;
  401. standardsView.titleLb.text = [NSString stringWithFormat:@"%@%d",YZMsg(@"规格"),standardsView.index];
  402. standardsView.deleteEvent = ^(NSInteger tags) {
  403. NSLog(@"add--------:%ld",tags);
  404. for(id tmpView in [weakSelf.standardsBackView subviews])
  405. {
  406. if([tmpView isKindOfClass:[StandardsView class]]){
  407. StandardsView *selView = (StandardsView *)tmpView;
  408. if (selView.index == tags) {
  409. [selView removeFromSuperview];
  410. [standarsArr removeObjectAtIndex:tags-1];
  411. }
  412. }
  413. }
  414. for (int i = 0; i < standarsArr.count; i ++) {
  415. StandardsView *imgVVVV = standarsArr[i];
  416. imgVVVV.y = 40+240 * i;
  417. imgVVVV.index = i+1;
  418. imgVVVV.titleLb.text = [NSString stringWithFormat:@"%@%d",YZMsg(@"规格"),imgVVVV.index];
  419. }
  420. standardsHeight = 330+240 *(standarsArr.count-1);
  421. self.addStdBtn.frame = CGRectMake(0, 40+standarsArr.count *240+5, _window_width, 40);
  422. [self reloadUIHeight];
  423. };
  424. standardsHeight = 330+240 *(standarsArr.count-1);
  425. self.addStdBtn.frame = CGRectMake(0, 40+standarsArr.count *240+5, _window_width, 40);
  426. [self reloadUIHeight];
  427. }
  428. #pragma mark------textFeildDelegate----------
  429. -(BOOL)textFieldShouldReturn:(UITextField *)textField
  430. {
  431. [postageField resignFirstResponder];
  432. return YES;
  433. }
  434. -(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  435. {
  436. [self.view endEditing:YES];
  437. }
  438. //获取商品标题图集
  439. -(void)setCommodityImg:(NSMutableArray *)imgArr
  440. {
  441. self.titleImgArr = [NSArray arrayWithArray:imgArr];
  442. }
  443. //获取商品详情图集
  444. -(void)setCommodityDetailImg:(NSMutableArray *)imgArr
  445. {
  446. self.detailImgArr = [NSArray arrayWithArray:imgArr];
  447. }
  448. #pragma mark------上传信息----------
  449. -(void)upBtnClick{
  450. [self.standardsImgArr removeAllObjects];
  451. if ([_classLb.text isEqual:YZMsg(@"请选择")]) {
  452. [MBProgressHUD showError:YZMsg(@"请选择商品类别")];
  453. return;
  454. }
  455. if (self.titleView.titleText.text.length < 1) {
  456. [MBProgressHUD showError:YZMsg(@"请填写商品标题")];
  457. return;
  458. }
  459. if (self.titleImgArr.count < 1){
  460. [MBProgressHUD showError:YZMsg(@"请先上传图片信息")];
  461. return;
  462. }
  463. if (self.contentView.contentText.text.length < 1) {
  464. [MBProgressHUD showError:YZMsg(@"请填写商品详情")];
  465. return;
  466. }
  467. for (int i = 0; i < standarsArr.count; i ++) {
  468. StandardsView *imgVVVV = standarsArr[i];
  469. NSLog(@"adddddddd=====:%@",imgVVVV.imageArray);
  470. if (imgVVVV.nameField.text.length < 1) {
  471. [MBProgressHUD showError:YZMsg(@"请填写规格名称")];
  472. return;
  473. }else if(imgVVVV.countField.text.length < 1){
  474. [MBProgressHUD showError:YZMsg(@"请填写库存")];
  475. return;
  476. }else if(imgVVVV.priceField.text.length < 1){
  477. [MBProgressHUD showError:YZMsg(@"请填写单价")];
  478. return;
  479. }
  480. if (imgVVVV.imageArray.count < 1) {
  481. [MBProgressHUD showError:YZMsg(@"请先上传规格图片")];
  482. return;
  483. }
  484. }
  485. [MBProgressHUD showMessage:@""];
  486. YBWeakSelf;
  487. [[YBStorageObj storageManeger]getCOSType:^(int code) {
  488. dispatch_async(dispatch_get_main_queue(), ^{
  489. if (code == 0) {
  490. [weakSelf uploadAllImageAndVideo];
  491. }
  492. });
  493. }];
  494. // [YBToolClass postNetworkWithUrl:@"Video.GetQiniuToken" andParameter:nil success:^(int code, id _Nonnull info, NSString * _Nonnull msg) {
  495. // if (code == 0) {
  496. // NSDictionary *dic = [info firstObject];
  497. // if (self.titleView.videoPath.length > 0) {
  498. // NSLog(@"有视频-------");
  499. // if([self.titleView.videoPath containsString:[common qiniu_domain]]){
  500. // videoCorverStr = self.commodityModel.video_thumb;
  501. // videoHerfStr = self.commodityModel.video_url;
  502. // [self uploadImage:minstr([dic valueForKey:@"token"])];
  503. // }else{
  504. // [self uploadVideoWithToken:minstr([dic valueForKey:@"token"])];
  505. // }
  506. // }else{
  507. // [self uploadImage:minstr([dic valueForKey:@"token"])];
  508. // }
  509. // }else{
  510. // [MBProgressHUD hideHUD];
  511. // [MBProgressHUD showError:msg];
  512. // }
  513. // } fail:^{
  514. // [MBProgressHUD hideHUD];
  515. // }];
  516. }
  517. //上传所有图片和视频
  518. -(void)uploadAllImageAndVideo{
  519. YBWeakSelf;
  520. dispatch_group_t group = dispatch_group_create();
  521. dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
  522. dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
  523. //********************上传商品标题内容开始*****************************//
  524. //如果有视频
  525. if (self.titleView.newvideoPath.length > 0 || self.titleView.videoPath.length > 0) {
  526. //如果有本地视频使用本地视频
  527. if (self.titleView.newvideoPath.length > 0) {
  528. dispatch_group_async(group, queue, ^{
  529. NSString *videoName = [PublicObj getNameBaseCurrentTime:@"_seller_action_video.mp4"];
  530. [[YBStorageObj storageManeger]yb_storageVideoOrVoice:self.titleView.videoPath andName:videoName progress:^(CGFloat percent) {
  531. } complete:^(int code, NSString *key) {
  532. if (code != 0) {
  533. dispatch_async(dispatch_get_main_queue(), ^{
  534. [MBProgressHUD hideHUD];
  535. [MBProgressHUD showPop:YZMsg(@"上传失败")];
  536. });
  537. return;
  538. }
  539. videoHerfStr = key;
  540. dispatch_semaphore_signal(semaphore);
  541. }];
  542. dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
  543. });
  544. }else{
  545. //这是是服务端返回的视频链接
  546. videoCorverStr = self.commodityModel.video_thumb;
  547. videoHerfStr = self.commodityModel.video_url;
  548. }
  549. }
  550. if (self.titleImgArr.count > 0) {
  551. _upTitleImgArr = [NSMutableArray array];
  552. thumbs = @"";
  553. for (int i = 0; i < self.titleImgArr.count ; i ++) {
  554. if ([self.titleImgArr[i] isKindOfClass:[UIImage class]]) {
  555. UIImage *image =self.titleImgArr[i];
  556. NSData *imageData = UIImagePNGRepresentation(image);
  557. if (!imageData) {
  558. [MBProgressHUD hideHUD];
  559. [MBProgressHUD showError:YZMsg(@"图片错误")];
  560. return;
  561. }
  562. dispatch_group_async(group, queue, ^{
  563. NSString *imageName = [PublicObj getNameBaseCurrentTime:[NSString stringWithFormat:@"_commodity_title_image%d_cover.png", i]];
  564. [[YBStorageObj storageManeger]yb_storageImg:image andName:imageName progress:^(CGFloat percent) {
  565. }complete:^(int code, NSString *key) {
  566. if (code != 0) {
  567. dispatch_async(dispatch_get_main_queue(), ^{
  568. [MBProgressHUD hideHUD];
  569. [MBProgressHUD showPop:YZMsg(@"上传失败")];
  570. });
  571. return;
  572. }
  573. [_upTitleImgArr addObject:key];
  574. dispatch_semaphore_signal(semaphore);
  575. }];
  576. dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
  577. });
  578. }else{
  579. NSString *imgthumb =self.titleImgArr[i];
  580. NSArray *imgArr = [imgthumb componentsSeparatedByString:@"/"];
  581. imgthumb = [imgArr lastObject];
  582. [_upTitleImgArr addObject:imgthumb];
  583. }
  584. }
  585. };
  586. //********************上传商品标题内容结束*****************************//
  587. //********************上传商品详情内容开始*****************************//
  588. if (self.detailImgArr.count > 0) {
  589. _upDetailImgArr = [NSMutableArray array];
  590. pictures = @"";
  591. for (int i = 0; i < self.detailImgArr.count ; i ++) {
  592. if ([self.detailImgArr[i] isKindOfClass:[UIImage class]]) {
  593. UIImage *image =self.detailImgArr[i];
  594. NSData *imageData = UIImagePNGRepresentation(image);
  595. if (!imageData) {
  596. [MBProgressHUD hideHUD];
  597. [MBProgressHUD showError:YZMsg(@"图片错误")];
  598. return;
  599. }
  600. dispatch_group_async(group, queue, ^{
  601. NSString *imageName = [PublicObj getNameBaseCurrentTime:[NSString stringWithFormat:@"_commodity_detail_image%d_cover.png", i]];
  602. [[YBStorageObj storageManeger]yb_storageImg:image andName:imageName progress:^(CGFloat percent) {
  603. }complete:^(int code, NSString *key) {
  604. if (code != 0) {
  605. dispatch_async(dispatch_get_main_queue(), ^{
  606. [MBProgressHUD hideHUD];
  607. [MBProgressHUD showPop:YZMsg(@"上传失败")];
  608. });
  609. return;
  610. }
  611. [_upDetailImgArr addObject:key];
  612. dispatch_semaphore_signal(semaphore);
  613. }];
  614. dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
  615. });
  616. }else{
  617. NSString *imgthumb =self.detailImgArr[i];
  618. NSArray *imgArr = [imgthumb componentsSeparatedByString:@"/"];
  619. imgthumb = [imgArr lastObject];
  620. [_upDetailImgArr addObject:imgthumb];
  621. }
  622. }
  623. }else{
  624. picturesBool = YES;
  625. pictures = @"";
  626. }
  627. //********************上传商品详情内容结束*****************************//
  628. dispatch_group_notify(group, queue, ^{
  629. dispatch_async(dispatch_get_main_queue(), ^{
  630. NSMutableArray * sortTitleArr = [self compareArrWithArray:_upTitleImgArr];
  631. for (NSString *str in sortTitleArr) {
  632. if (thumbs.length == 0) {
  633. thumbs = str;
  634. }else{
  635. thumbs = [NSString stringWithFormat:@"%@,%@",thumbs,str];
  636. }
  637. }
  638. NSLog(@"-------标题图片合并完成------:%@",thumbs);
  639. thumbsBool = YES;
  640. NSMutableArray * sortDetailArr = [self compareArrWithArray:_upDetailImgArr];
  641. for (NSString *str in sortDetailArr) {
  642. if (pictures.length == 0) {
  643. pictures = str;
  644. }else{
  645. pictures = [NSString stringWithFormat:@"%@,%@",pictures,str];
  646. }
  647. }
  648. picturesBool = YES;
  649. if (thumbsBool && picturesBool) {
  650. [weakSelf uploadStandImg];
  651. }
  652. });
  653. NSLog(@"任务完成执行");
  654. });
  655. }
  656. //上传商品规格图片开始
  657. -(void)uploadStandImg{
  658. YBWeakSelf;
  659. dispatch_group_t group = dispatch_group_create();
  660. dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
  661. dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
  662. for (int i = 0; i < standarsArr.count; i ++) {
  663. StandardsView *imgVVVV = standarsArr[i];
  664. if ([imgVVVV.imageArray[0] isKindOfClass:[UIImage class]]) {
  665. UIImage *image =imgVVVV.imageArray[0];
  666. NSData *imageData = UIImagePNGRepresentation(image);
  667. if (!imageData) {
  668. [MBProgressHUD hideHUD];
  669. [MBProgressHUD showError:YZMsg(@"图片错误")];
  670. return;
  671. }
  672. dispatch_group_async(group, queue, ^{
  673. NSString *imageName = [PublicObj getNameBaseCurrentTime:[NSString stringWithFormat:@"_commodity_standard_image%d_cover.png", i]];
  674. [[YBStorageObj storageManeger]yb_storageImg:image andName:imageName progress:^(CGFloat percent) {
  675. }complete:^(int code, NSString *key) {
  676. if (code != 0) {
  677. dispatch_async(dispatch_get_main_queue(), ^{
  678. [MBProgressHUD hideHUD];
  679. [MBProgressHUD showPop:YZMsg(@"上传失败")];
  680. });
  681. return;
  682. }
  683. [self.standardsImgArr addObject:key];
  684. if (self.standardsImgArr.count == standarsArr.count) {
  685. standardsBool = YES;
  686. }
  687. dispatch_semaphore_signal(semaphore);
  688. }];
  689. dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
  690. });
  691. }else{
  692. NSString *imgthumb = [imgVVVV.imageArray[0] stringByReplacingOccurrencesOfString:[common qiniu_domain] withString:@""];
  693. [self.standardsImgArr addObject:imgthumb];
  694. if (self.standardsImgArr.count == standarsArr.count) {
  695. standardsBool = YES;
  696. }
  697. }
  698. }
  699. dispatch_group_notify(group, queue, ^{
  700. dispatch_async(dispatch_get_main_queue(), ^{
  701. if (standardsBool == YES) {
  702. [weakSelf submitService];
  703. }
  704. });
  705. NSLog(@"任务完成执行");
  706. });
  707. }
  708. -(NSMutableArray *)compareArrWithArray:(NSArray *)arr{
  709. //图片排序
  710. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  711. //这块取出数组中的数字, 请根据自己数组而定
  712. for (int i = 0; i < arr.count; i++) {
  713. NSArray *array = [arr[i] componentsSeparatedByString:@"_image"];
  714. NSString *str_t = [array lastObject];
  715. NSArray *array_t =[str_t componentsSeparatedByString:@"_cover"];
  716. NSString *str = [array_t firstObject];
  717. [dict setValue:arr[i] forKey:str];
  718. }
  719. NSArray *arrKey = [dict allKeys];
  720. //将key排序
  721. NSArray *sortedArray = [arrKey sortedArrayUsingComparator:^NSComparisonResult(id obj1,id obj2) {
  722. return[obj1 compare:obj2 options:NSNumericSearch];//正序
  723. }];
  724. NSMutableArray *orderValueArray=[NSMutableArray array];
  725. //根据key的顺序提取相应value
  726. for (NSString *key in sortedArray) {
  727. [orderValueArray addObject:[dict objectForKey:key]];
  728. }
  729. return orderValueArray;
  730. }
  731. -(void)submitService{
  732. NSString *postage;
  733. if (!postageSwitch.on) {
  734. postage = postageField.text;
  735. if (postage.length < 1) {
  736. [MBProgressHUD hideHUD];
  737. [MBProgressHUD showError:YZMsg(@"请输入运费")];
  738. return;
  739. }
  740. }else{
  741. postage = @"0";
  742. }
  743. NSString *share_income;
  744. if (commissionField.text.length < 1) {
  745. share_income = @"0";
  746. }else{
  747. share_income = commissionField.text;
  748. }
  749. NSMutableArray *specsArr = [NSMutableArray array];
  750. for (int i = 0; i < standarsArr.count; i ++) {
  751. StandardsView *imgVVVV = standarsArr[i];
  752. NSString *standard_image = [NSString stringWithFormat:@"_standard_image%d",i];
  753. NSString *selImageStr;
  754. for (NSString *picStr in self.standardsImgArr) {
  755. if ([picStr containsString:standard_image]) {
  756. selImageStr = picStr;
  757. }
  758. }
  759. NSString *spec_id = [NSString stringWithFormat:@"%d",i+1];
  760. NSString *spec_name = imgVVVV.nameField.text;
  761. NSString *spec_num = imgVVVV.countField.text;
  762. NSString *price = imgVVVV.priceField.text;
  763. NSString *thumb = selImageStr;
  764. NSMutableDictionary *specDic = [NSMutableDictionary dictionary];
  765. [specDic setValue:spec_id forKey:@"spec_id"];
  766. [specDic setValue:spec_name forKey:@"spec_name"];
  767. [specDic setValue:spec_num forKey:@"spec_num"];
  768. [specDic setValue:price forKey:@"price"];
  769. [specDic setValue:thumb forKey:@"thumb"];
  770. [specsArr addObject:specDic];
  771. }
  772. NSString *specsStr = [self gs_jsonStringCompactFormatForNSArray:specsArr];
  773. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  774. [dic setValue:[Config getOwnID] forKey:@"uid"];
  775. [dic setValue:[Config getOwnToken] forKey:@"token"];
  776. [dic setValue:one_classidStr forKey:@"one_classid"];
  777. [dic setValue:two_classidStr forKey:@"two_classid"];
  778. [dic setValue:three_classidStr forKey:@"three_classid"];
  779. [dic setValue:self.titleView.titleText.text forKey:@"name"];
  780. [dic setValue:videoHerfStr forKey:@"video_url"];
  781. [dic setValue:videoCorverStr forKey:@"video_thumb"];
  782. [dic setValue:thumbs forKey:@"thumbs"];
  783. [dic setValue:self.contentView.contentText.text forKey:@"content"];
  784. [dic setValue:pictures forKey:@"pictures"];
  785. [dic setValue:specsStr forKey:@"specs"];
  786. [dic setValue:postage forKey:@"postage"];
  787. [dic setValue:share_income forKey:@"share_income"];
  788. NSString *url;
  789. if ([self.fromWhere isEqual:@"seller"]) {
  790. // url = [purl stringByAppendingFormat:@"?service=Seller.upgoods"];
  791. url = @"Seller.upgoods";
  792. [dic setValue:self.commodityModel.goodsid forKey:@"goodsid"];
  793. }else{
  794. url = @"Seller.setGoods";
  795. }
  796. [YBNetworking postWithUrl:url Dic:dic Suc:^(int code, id info, NSString *msg) {
  797. [MBProgressHUD hideHUD];
  798. if (code ==0) {
  799. [MBProgressHUD showError: msg];
  800. [[YBBaseAppDelegate sharedAppDelegate]popViewController:YES];
  801. }else{
  802. [MBProgressHUD showError:msg];
  803. }
  804. } Fail:^(id fail) {
  805. [MBProgressHUD hideHUD];
  806. }];
  807. }
  808. - (NSString *)gs_jsonStringCompactFormatForNSArray:(NSArray *)arrJson {
  809. if (![arrJson isKindOfClass:[NSArray class]] || ![NSJSONSerialization isValidJSONObject:arrJson]) {
  810. return nil;
  811. }
  812. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:arrJson options:0 error:nil];
  813. NSString *strJson = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  814. return strJson;
  815. }
  816. #pragma mark-------商家编辑商品赋值-----------------
  817. -(void)reloadUIData{
  818. _classLb.text = self.commodityModel.three_class_name;
  819. one_classidStr =self.commodityModel.one_classid;
  820. two_classidStr = self.commodityModel.two_classid;
  821. three_classidStr =self.commodityModel.three_classid;
  822. self.titleView.titleText.text =self.commodityModel.name;
  823. [self.titleView setDetaiModelData:self.commodityModel fromWhere:@"seller"];
  824. commissionField.text = minstr([self.commodityModel.goods_info valueForKey:@"share_income"]);
  825. self.contentView.contentText.text = self.commodityModel.content;
  826. [self.contentView setDetaiModelData:self.commodityModel fromWhere:@"seller"];
  827. if (self.commodityModel.specs_format.count > 0) {
  828. for (int i = 1; i < self.commodityModel.specs_format.count; i++) {
  829. [self addStdClick];
  830. }
  831. for (int i = 0; i < standarsArr.count; i ++) {
  832. StandardsView *imgVVVV = standarsArr[i];
  833. imgVVVV.nameField.text = minstr([self.commodityModel.specs_format[i] valueForKey:@"spec_name"]);
  834. imgVVVV.countField.text = minstr([self.commodityModel.specs_format[i] valueForKey:@"spec_num"]);
  835. imgVVVV.priceField.text = minstr([self.commodityModel.specs_format[i] valueForKey:@"price"]);
  836. NSString *imgurl =minstr([self.commodityModel.specs_format[i] valueForKey:@"thumb"]);
  837. [imgVVVV.imgeBtn sd_setBackgroundImageWithURL:[NSURL URLWithString:imgurl] forState:0];
  838. [imgVVVV.imgeBtn setImage:nil forState:0];
  839. [imgVVVV.imgeBtn setTitle:nil forState:0];
  840. imgVVVV.delBtn.hidden = NO;
  841. [imgVVVV.imageArray removeAllObjects];
  842. [imgVVVV.imageArray addObject:imgurl];
  843. }
  844. }
  845. if ([self.commodityModel.postage floatValue] > 0) {
  846. postageSwitch.on = YES;
  847. [self openPostage];
  848. postageField.text = self.commodityModel.postage;
  849. }else{
  850. postageSwitch.on = YES;
  851. }
  852. }
  853. -(void)scrollViewDidScroll:(UIScrollView *)scrollView
  854. {
  855. // NSLog(@"jjjjjjjj:%f",scrollView.contentOffset.y);
  856. currentScrollY =scrollView.contentOffset.y;
  857. }
  858. #pragma mark -- 获取键盘高度
  859. - (void)keyboardWillShow:(NSNotification *)aNotification
  860. {
  861. if (postageField.isFirstResponder||commissionField.isFirstResponder) {
  862. NSDictionary *userInfo = [aNotification userInfo];
  863. NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
  864. CGRect keyboardRect = [aValue CGRectValue];
  865. CGFloat height = keyboardRect.origin.y;
  866. CGFloat heightw = keyboardRect.size.height;
  867. int newHeight = _window_height - height -44;
  868. [UIView animateWithDuration:0.3 animations:^{
  869. [_backScroll setContentOffset:CGPointMake(0, currentScrollY+heightw)];
  870. }];
  871. }
  872. //获取键盘的高度
  873. }
  874. - (void)keyboardWillHide:(NSNotification *)aNotification
  875. {
  876. if (postageField.resignFirstResponder) {
  877. NSDictionary *userInfo = [aNotification userInfo];
  878. NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
  879. CGRect keyboardRect = [aValue CGRectValue];
  880. CGFloat height = keyboardRect.origin.y;
  881. CGFloat heightw = keyboardRect.size.height;
  882. [UIView animateWithDuration:0.1 animations:^{
  883. [UIView animateWithDuration:0.3 animations:^{
  884. [_backScroll setContentOffset:CGPointMake(0, currentScrollY-heightw)];
  885. }];
  886. }];
  887. // [UIView animateWithDuration:0.1 animations:^{
  888. // [UIView animateWithDuration:0.3 animations:^{
  889. // [_backScroll setContentOffset:CGPointMake(0, 520)];
  890. // }];
  891. // }];
  892. }
  893. // else{
  894. // [UIView animateWithDuration:0.1 animations:^{
  895. // [UIView animateWithDuration:0.3 animations:^{
  896. // [_backScroll setContentOffset:CGPointMake(0, 0)];
  897. // }];
  898. // }];
  899. //
  900. // }
  901. }
  902. @end