YOUPAILCBigCastSetVC.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. //
  2. // YOUPAILCBigCastSetVC.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/8/30.
  6. // Copyright © 2018年 caicai. All rights reserved.
  7. //
  8. #import "YOUPAILCBigCastSetVC.h"
  9. #import "YOUPAILCSkillView.h"
  10. #import "YOUPAILZBigCastAudioSetVC.h"
  11. #import "FSAudioStream.h"
  12. #import "YOUPAIZYNobleSaleWindow.h"
  13. #import "UIViewController+TFPresent.h"
  14. #import "YOUPAIZYNobleDetailModel.h"
  15. @interface YOUPAILCBigCastSetVC ()
  16. @property(nonatomic,strong)UIView* youpaiptopView; /// 设置价格背景View
  17. @property(nonatomic,strong)YOUPAILCSkillModel* youpaipcurrentModel;
  18. @property (nonatomic, weak)UIView *youpaipaudioBgV;/// 音频背景View
  19. @property (nonatomic, weak)UIButton *youpaipaudioPlayBtn; // 播放音频按钮
  20. @property (nonatomic, weak)UILabel *youpaiptimerL;
  21. @property (nonatomic, weak)UIImageView *youpaipanimationImgV;
  22. @property (nonatomic, weak)UIView *youpaiphiddenCallCountBgV; // 是否隐藏通话次数背景View
  23. @property (nonatomic, weak)UIView *youpaiptfBgV; /// 输入价格背景View
  24. @property (nonatomic, weak)UITextField *youpaippriceTF;
  25. // 语音播放器
  26. @property (nonatomic, strong)FSAudioStream *youpaipaudioStream;
  27. @property (nonatomic, strong)NSTimer *youpaiptimer;
  28. @end
  29. @implementation YOUPAILCBigCastSetVC
  30. - (void)dealloc{
  31. [[NSNotificationCenter defaultCenter] removeObserver:self];
  32. }
  33. - (void)viewWillAppear:(BOOL)animated{
  34. [super viewWillAppear:animated];
  35. [self youpaifrefreshData];
  36. }
  37. - (void)viewDidDisappear:(BOOL)animated{
  38. [super viewDidDisappear:animated];
  39. [self stopPlay];
  40. }
  41. - (void)viewDidLoad {
  42. [super viewDidLoad];
  43. self.title = @"女神设置";
  44. [self youpaifinitData];
  45. [self _setupPriceView];
  46. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifkeyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  47. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifkeyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  48. }
  49. - (void)youpaifinitData{
  50. [LCHttpHelper requestWithURLString:AnchorSet parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  51. NSDictionary* dict = (NSDictionary*)responseObject;
  52. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  53. if (code==0) {
  54. NSMutableArray* skillArray = [YOUPAILCSkillModel mj_objectArrayWithKeyValuesArray:[dict objectForKey:@"data"]];
  55. if (skillArray.count>0) {
  56. self.youpaipcurrentModel = skillArray[0];
  57. [self youpaifsetupView];
  58. }
  59. }
  60. } failure:^(NSError *error) {
  61. }];
  62. }
  63. - (void)youpaifrefreshData{
  64. [LCHttpHelper requestWithURLString:UserCenter parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  65. NSDictionary* dict = (NSDictionary*)responseObject;
  66. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  67. if (code==0) {//成功
  68. NSDictionary *anchor = [[dict objectForKey:@"data"]objectForKey:@"anchor"];
  69. NSDictionary *info = [[dict objectForKey:@"data"]objectForKey:@"userinfo"];
  70. if ([[anchor allKeys] containsObject:@"open_video_status"]) {
  71. if ([[anchor objectForKey:@"open_video_status"] integerValue] == 0) {//0 未开启 1 已开启
  72. [LCSaveData saveVideoOpenStatu:NO];
  73. }else{
  74. [LCSaveData saveVideoOpenStatu:YES];
  75. }
  76. }
  77. if ([[anchor allKeys] containsObject:@"order_switch"]) {
  78. if ([[anchor objectForKey:@"order_switch"] integerValue] == 1) {//1隐藏 2不隐藏
  79. [LCSaveData saveOrderOpenStatu:YES];
  80. }else{
  81. [LCSaveData saveOrderOpenStatu:NO];
  82. }
  83. }
  84. if ([[info allKeys] containsObject:@"is_msg_refuse"]) {
  85. if ([[info objectForKey:@"is_msg_refuse"] integerValue] == 1) {//1开启 0关闭
  86. [LCSaveData saveProfileWuraoStatus:YES];
  87. }else{
  88. [LCSaveData saveProfileWuraoStatus:NO];
  89. }
  90. }
  91. YOUPAILCBaseInfo* userinfo = [YOUPAILCBaseInfo mj_objectWithKeyValues:[[dict objectForKey:@"data"]objectForKey:@"userinfo"]];
  92. YOUPAILCUserModel* userModel = [LCSaveModel getUserModel];
  93. userModel.youpaipuserinfo = userinfo;
  94. [LCSaveModel saveUserModel:userModel];
  95. [self youpaifsetupView];
  96. }
  97. } failure:^(NSError *error) {
  98. }];
  99. }
  100. - (void)_setupPriceView{
  101. UIView *tfBgV = [[UIView alloc] initWithFrame:CGRectMake(0.0f, KScreenHeight, KScreenWidth, 48.0f)];
  102. tfBgV.backgroundColor = HexColorFromRGB(0xCFD3DB);
  103. [self.view addSubview:tfBgV];
  104. self.youpaiptfBgV = tfBgV;
  105. [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:tfBgV size:CGSizeMake(KScreenWidth, 48)];
  106. UITextField *priceTF = [[UITextField alloc] init];
  107. priceTF.placeholder = @"请输入价格";
  108. priceTF.font = LCFont15;
  109. priceTF.textColor = HexColorFromRGB(0x333333);
  110. priceTF.tintColor = ZYPinkColor;
  111. priceTF.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10.0f, 0.0f)];
  112. priceTF.leftViewMode = UITextFieldViewModeAlways;
  113. priceTF.rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10.0f, 0.0f)];
  114. priceTF.rightViewMode = UITextFieldViewModeAlways;
  115. priceTF.backgroundColor = [UIColor whiteColor];
  116. priceTF.keyboardType = UIKeyboardTypeNumberPad;
  117. priceTF.layer.cornerRadius = 17.0f;
  118. priceTF.clipsToBounds = YES;
  119. [tfBgV addSubview:priceTF];
  120. self.youpaippriceTF = priceTF;
  121. UIButton *confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  122. UIImage *bgImage = [LCTools ColorImage:CGSizeMake(62.0f, 33.0f) FromColors:@[HexColorFromRGB(0xFF0084),HexColorFromRGB(0xFF3A00)] ByGradientType:GradientLeftToRight];
  123. [confirmBtn setBackgroundImage:bgImage forState:UIControlStateNormal];
  124. [confirmBtn setBackgroundImage:bgImage forState:UIControlStateHighlighted];
  125. confirmBtn.layer.cornerRadius = 16.5f;
  126. confirmBtn.clipsToBounds = YES;
  127. confirmBtn.titleLabel.font = LCFont14;
  128. [confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  129. [confirmBtn setTitle:@"确定" forState:UIControlStateNormal];
  130. [confirmBtn addTarget:self action:@selector(youpaifconfirmBtnClick) forControlEvents:UIControlEventTouchUpInside];
  131. [tfBgV addSubview:confirmBtn];
  132. [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  133. make.right.offset(-14.0f);
  134. make.centerY.equalTo(tfBgV.mas_centerY);
  135. make.size.mas_offset(CGSizeMake(62.0f, 33.0f));
  136. }];
  137. [priceTF mas_makeConstraints:^(MASConstraintMaker *make) {
  138. make.top.offset(7.0f);
  139. make.bottom.offset(-7.0f);
  140. make.left.offset(14.0f);
  141. make.right.equalTo(confirmBtn.mas_left).offset(-8.0f);
  142. }];
  143. }
  144. - (void)youpaifsetupView{
  145. [self.youpaiptopView removeFromSuperview];
  146. self.youpaiptopView = nil;
  147. UIView* topView = [[UIView alloc]initWithFrame:CGRectMake(14, NavBarHeight + 34, KScreenWidth-28,119.0f)];
  148. [self.view addSubview:topView];
  149. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0.0f, topView.mj_w, 17)];
  150. label.text = @"视频通话价格";
  151. label.font = LCFont15;
  152. label.textColor = HexColorFromRGB(0x9F9DA5);
  153. [topView addSubview:label];
  154. YOUPAILCSkillView* skill = [[YOUPAILCSkillView alloc]initWithFrame:CGRectMake(0.0f,label.mj_h + 14.0f, topView.mj_w,88.0f) skillModel:self.youpaipcurrentModel];
  155. [skill.youpaippriceBtn addTarget:self action:@selector(setSkillPriceClick) forControlEvents:(UIControlEventTouchUpInside)];
  156. [skill.youpaipnobleSaleBtn addTarget:self action:@selector(nobleSaleBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  157. [topView addSubview:skill];
  158. self.youpaiptopView = topView;
  159. /// 音频View
  160. [self.youpaipaudioBgV removeFromSuperview];
  161. self.youpaipaudioBgV = nil;
  162. UIView *audioBgV = [[UIView alloc] init];
  163. audioBgV.backgroundColor = HexColorFromRGB(0x2A2935);
  164. audioBgV.layer.cornerRadius = 5.0f;
  165. audioBgV.clipsToBounds = YES;
  166. [self.view addSubview:audioBgV];
  167. self.youpaipaudioBgV = audioBgV;
  168. [audioBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  169. make.left.offset(14.0f);
  170. make.right.offset(-14.0f);
  171. make.top.equalTo(topView.mas_bottom).offset(10.0f);
  172. make.height.offset(49.0f);
  173. }];
  174. UILabel *audioDescL = [[UILabel alloc] init];
  175. // audioDescL.text = @"声音展示";
  176. audioDescL.font = LCFont14;
  177. audioDescL.textColor = [UIColor whiteColor];
  178. [audioBgV addSubview:audioDescL];
  179. [audioDescL mas_makeConstraints:^(MASConstraintMaker *make) {
  180. make.left.offset(12.0f);
  181. make.centerY.equalTo(audioBgV.mas_centerY);
  182. }];
  183. YOUPAILCBaseInfo *userinfo = [LCSaveModel getUserModel].youpaipuserinfo;
  184. //审核状态:0=未审核,1=审核通过,2=审核未通过,4=初始状态
  185. BOOL showArrow = NO;
  186. NSString *redText = @"";
  187. if (userinfo.youpaipvoice_status == 0) {
  188. redText = @"(审核中)";
  189. }else if (userinfo.youpaipvoice_status == 1){
  190. }else if (userinfo.youpaipvoice_status == 2){
  191. showArrow = YES;
  192. }else{
  193. showArrow = YES;
  194. }
  195. NSString *text = [NSString stringWithFormat:@"声音展示%@",redText];
  196. NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:text];
  197. [str addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xF4003F) range:[text rangeOfString:redText]];
  198. [str addAttribute:NSFontAttributeName value:LCFont12 range:[text rangeOfString:redText]];
  199. audioDescL.attributedText = str;
  200. if (showArrow) {
  201. UIImageView *audioArrowImgV = [[UIImageView alloc] init];
  202. audioArrowImgV.image = [UIImage imageNamed:@"vqu_images_D_profile_item_arrow"];
  203. [audioBgV addSubview:audioArrowImgV];
  204. [audioArrowImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  205. make.right.offset(-12.0f);
  206. make.width.height.offset(16.0f);
  207. make.centerY.equalTo(audioBgV.mas_centerY);
  208. }];
  209. UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addAudioEvent:)];
  210. [audioBgV addGestureRecognizer:tapGesture];
  211. }else{
  212. UIButton *removeAudioBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  213. [removeAudioBtn setImage:[UIImage imageNamed:@"vqu_images_big_cast_remove_audio"] forState:UIControlStateNormal];
  214. [removeAudioBtn addTarget:self action:@selector(removeAudioBtnClick) forControlEvents:UIControlEventTouchUpInside];
  215. [audioBgV addSubview:removeAudioBtn];
  216. [removeAudioBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  217. make.right.offset(0.0f);
  218. make.top.bottom.offset(0.0f);
  219. make.width.offset(37.0f);
  220. }];
  221. UIView *aBgV = [[UIView alloc] init];
  222. aBgV.layer.cornerRadius = 13.5f;
  223. aBgV.clipsToBounds = YES;
  224. aBgV.layer.borderWidth = 0.5f;
  225. aBgV.layer.borderColor = [UIColor whiteColor].CGColor;
  226. [audioBgV addSubview:aBgV];
  227. [aBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  228. make.right.equalTo(removeAudioBtn.mas_left).offset(0.0f);
  229. make.centerY.equalTo(audioBgV.mas_centerY);
  230. make.size.mas_offset(CGSizeMake(73.0f, 27.0f));
  231. }];
  232. UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(youpaifplayAudioEvent:)];
  233. [aBgV addGestureRecognizer:tapGesture];
  234. UIButton *audioPlayBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  235. [audioPlayBtn setImage:[UIImage imageNamed:@"vqu_images_big_cast_audio_play"] forState:UIControlStateSelected];
  236. [audioPlayBtn setImage:[UIImage imageNamed:@"vqu_images_big_cast_audio_none-1"] forState:UIControlStateNormal];
  237. audioPlayBtn.userInteractionEnabled = NO;
  238. [aBgV addSubview:audioPlayBtn];
  239. self.youpaipaudioPlayBtn = audioPlayBtn;
  240. [audioPlayBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  241. make.left.offset(5.0f);
  242. make.centerY.equalTo(aBgV.mas_centerY);
  243. make.size.mas_offset(CGSizeMake(19.0f, 19.0f));
  244. }];
  245. UILabel *timerL = [[UILabel alloc] init];
  246. timerL.font = LCFont(12);
  247. timerL.textColor = [UIColor whiteColor];
  248. timerL.text = [NSString stringWithFormat:@"%@\"",@(userinfo.youpaipvoice_time)];
  249. [aBgV addSubview:timerL];
  250. self.youpaiptimerL = timerL;
  251. [timerL mas_makeConstraints:^(MASConstraintMaker *make) {
  252. make.left.equalTo(audioPlayBtn.mas_right).offset(5.0f);
  253. make.centerY.equalTo(aBgV);
  254. }];
  255. UIImageView *animationImgV = [[UIImageView alloc] init];
  256. animationImgV.image = [UIImage imageNamed:@"vqu_images_IM_im_left_3"];
  257. NSMutableArray * animationArray = [NSMutableArray array];
  258. for (NSInteger i = 0; i < 3; i ++) {
  259. [animationArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"vqu_images_IM_im_left_%@",@(i + 1)]]];
  260. }
  261. //设置动画数组
  262. [animationImgV setAnimationImages:animationArray];
  263. //设置动画播放次数
  264. [animationImgV setAnimationRepeatCount:INT32_MAX];
  265. //设置动画播放时间
  266. [animationImgV setAnimationDuration:3*0.35];
  267. [aBgV addSubview:animationImgV];
  268. self.youpaipanimationImgV = animationImgV;
  269. [animationImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  270. make.left.equalTo(timerL.mas_right).offset(5.0f);
  271. make.centerY.equalTo(aBgV);
  272. make.size.mas_offset(CGSizeMake(19.0f, 19.0f));
  273. }];
  274. }
  275. // 是否隐藏通话次数View
  276. [self.youpaiphiddenCallCountBgV removeFromSuperview];
  277. self.youpaiphiddenCallCountBgV = nil;
  278. UIView *hiddenCallCountBgV = [[UIView alloc] init];
  279. hiddenCallCountBgV.backgroundColor = HexColorFromRGB(0x2A2935);
  280. hiddenCallCountBgV.layer.cornerRadius = 5.0f;
  281. hiddenCallCountBgV.clipsToBounds = YES;
  282. [self.view addSubview:hiddenCallCountBgV];
  283. self.youpaiphiddenCallCountBgV = hiddenCallCountBgV;
  284. [hiddenCallCountBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  285. make.left.offset(14.0f);
  286. make.right.offset(-14.0f);
  287. make.top.equalTo(audioBgV.mas_bottom).offset(10.0f);
  288. make.height.offset(49.0f);
  289. }];
  290. UILabel *hiddenCallCountDescL = [[UILabel alloc] init];
  291. hiddenCallCountDescL.text = @"是否隐藏通话次数";
  292. hiddenCallCountDescL.font = LCFont14;
  293. hiddenCallCountDescL.textColor = [UIColor whiteColor];
  294. [hiddenCallCountBgV addSubview:hiddenCallCountDescL];
  295. [hiddenCallCountDescL mas_makeConstraints:^(MASConstraintMaker *make) {
  296. make.left.offset(12.0f);
  297. make.centerY.equalTo(hiddenCallCountBgV.mas_centerY);
  298. }];
  299. UIButton *hiddenCallCountSwitch = [UIButton buttonWithType:UIButtonTypeCustom];
  300. [hiddenCallCountSwitch setImage:[UIImage imageNamed:@"vqu_images_ic_profile_siwch_on"] forState:UIControlStateSelected];
  301. [hiddenCallCountSwitch setImage:[UIImage imageNamed:@"vqu_images_ic_profile_siwch_off"] forState:UIControlStateNormal];
  302. [hiddenCallCountSwitch addTarget:self action:@selector(hiddenCallCountSwitchBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  303. [hiddenCallCountBgV addSubview:hiddenCallCountSwitch];
  304. [hiddenCallCountSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
  305. make.right.offset(-12.0f);
  306. make.centerY.equalTo(hiddenCallCountBgV.mas_centerY);
  307. make.size.mas_offset(CGSizeMake(27.5f, 44.0f));
  308. }];
  309. if ([LCSaveData getOrderOpenStatu]) {
  310. hiddenCallCountSwitch.selected = YES;
  311. }else{
  312. hiddenCallCountSwitch.selected = NO;
  313. }
  314. }
  315. - (void)setSkillPriceClick{
  316. [self.youpaippriceTF becomeFirstResponder];
  317. }
  318. -(void)nobleSaleBtnClick//贵族优惠查看
  319. {
  320. [LCHttpHelper requestWithURLString:NobleDetail parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  321. NSDictionary* dict = (NSDictionary*)responseObject;
  322. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  323. if (code==0) {//成功
  324. NSMutableArray* dataArray = [YOUPAIZYNobleDetailModel mj_objectArrayWithKeyValuesArray:[dict objectForKey:@"data"]];
  325. YOUPAIZYNobleSaleWindow *vc= [[YOUPAIZYNobleSaleWindow alloc]init];
  326. vc.vWidth = 313.0f;
  327. vc.vHeight = 95.0f + dataArray.count * 35 + 103.5f;
  328. vc.youpaipdataArray = dataArray;
  329. // vc.delegate = self;
  330. vc.isTouchDismiss = YES;
  331. [self TFPresentVC:vc completion:^{}];
  332. }
  333. } failure:^(NSError *error) {
  334. }];
  335. }
  336. - (void)youpaifconfirmBtnClick{
  337. [LCHttpHelper requestWithURLString:SetSkillPrice parameters:@{@"price":@([self.youpaippriceTF.text floatValue]),@"skill_id":@(self.youpaipcurrentModel.youpaipskill_id)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  338. NSDictionary* dict = (NSDictionary*)responseObject;
  339. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  340. if (code==0) {//成功
  341. [ZCHUDHelper showTitle:@"价格设置成功"];
  342. [self youpaifinitData];
  343. dispatch_async(dispatch_get_main_queue(), ^{
  344. [self.view endEditing:YES];
  345. self.youpaippriceTF.text = @"";
  346. });
  347. }
  348. } failure:^(NSError *error) {
  349. }];
  350. }
  351. - (void)removeAudioBtnClick{
  352. [LCHttpHelper requestWithURLString:VoiceDelete parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  353. NSDictionary* dict = (NSDictionary*)responseObject;
  354. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  355. if (code==0) {//成功
  356. [self youpaifrefreshData];
  357. }
  358. } failure:^(NSError *error) {
  359. }];
  360. }
  361. - (void)addAudioEvent:(UITapGestureRecognizer *)gesture{
  362. YOUPAILZBigCastAudioSetVC *vc = [[YOUPAILZBigCastAudioSetVC alloc] init];
  363. [self.navigationController pushViewController:vc animated:YES];
  364. }
  365. - (void)youpaifplayAudioEvent:(UITapGestureRecognizer *)gesture{
  366. self.youpaipaudioPlayBtn.selected = !self.youpaipaudioPlayBtn.selected;
  367. if (self.youpaipaudioPlayBtn.selected) {
  368. [self startPlay];
  369. [self startTimer];
  370. }else{
  371. [self stopPlay];
  372. }
  373. }
  374. - (void)hiddenCallCountSwitchBtnClick:(UIButton *)sender{
  375. NSInteger status = 1;
  376. if (sender.selected != YES) {//将状态置为1 隐藏
  377. status = 1;
  378. }else{
  379. status = 0;
  380. }
  381. [LCHttpHelper requestWithURLString:BigCastSetOrderStatus parameters:@{@"status":@(status)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  382. NSDictionary* dict = (NSDictionary*)responseObject;
  383. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  384. if (code==0) {
  385. if (status==1) {
  386. [LCSaveData saveOrderOpenStatu:YES];
  387. sender.selected = YES;
  388. }else{
  389. [LCSaveData saveOrderOpenStatu:NO];
  390. sender.selected = NO;
  391. }
  392. }
  393. } failure:^(NSError *error) {
  394. }];
  395. }
  396. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  397. [self.view endEditing:YES];
  398. }
  399. //键盘即将隐藏
  400. - (void)youpaifkeyboardWillHide:(NSNotification *)note{
  401. [UIView animateWithDuration:0.25f animations:^{
  402. self.youpaiptfBgV.mj_y = KScreenHeight;
  403. }];
  404. }
  405. //键盘即将弹出
  406. - (void)youpaifkeyboardWillShow:(NSNotification *)note{
  407. CGRect keyboardF = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  408. CGFloat keyboardH = keyboardF.size.height;
  409. [UIView animateWithDuration:0.25f animations:^{
  410. self.youpaiptfBgV.mj_y = KScreenHeight - keyboardH - self.youpaiptfBgV.mj_h;
  411. }];
  412. }
  413. /// 开始播放语音
  414. - (void)startPlay{
  415. NSURL *url = [LCTools getImageUrlWithAddress:[LCSaveModel getUserModel].youpaipuserinfo.youpaipvoice];
  416. self.youpaipaudioStream.url = url;
  417. [self.youpaipaudioStream play];
  418. [self.youpaipanimationImgV startAnimating];
  419. }
  420. /// 停止播放语音
  421. - (void)stopPlay{
  422. self.youpaipaudioPlayBtn.selected = NO;
  423. self.youpaiptimerL.text = [NSString stringWithFormat:@"%@\"",@([LCSaveModel getUserModel].youpaipuserinfo.youpaipvoice_time)];
  424. // 停止播放
  425. if ([self.youpaipaudioStream isPlaying]) {
  426. [self.youpaipaudioStream stop];
  427. }
  428. [self youpaifstopTimer];
  429. [self.youpaipanimationImgV stopAnimating];
  430. }
  431. - (FSAudioStream *)youpaipaudioStream{
  432. if (_youpaipaudioStream == nil) {
  433. _youpaipaudioStream = [[FSAudioStream alloc] init];
  434. WeakSelf;
  435. _youpaipaudioStream.onFailure = ^(FSAudioStreamError error,NSString *description){
  436. [weakSelf stopPlay];
  437. };
  438. _youpaipaudioStream.onCompletion = ^(){
  439. [weakSelf stopPlay];
  440. };
  441. [_youpaipaudioStream setVolume:0.7];//设置声音
  442. _youpaipaudioStream.strictContentTypeChecking = NO;
  443. _youpaipaudioStream.defaultContentType = @"audio/mpeg";
  444. }
  445. return _youpaipaudioStream;
  446. }
  447. // 开始计时
  448. - (void)startTimer{
  449. self.youpaiptimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
  450. [[NSRunLoop currentRunLoop] addTimer:self.youpaiptimer forMode:NSRunLoopCommonModes];
  451. }
  452. // 结束计时
  453. - (void)youpaifstopTimer{
  454. [self.youpaiptimer invalidate];
  455. self.youpaiptimer = nil;
  456. }
  457. - (void)timerAction{
  458. NSInteger timer = [LCSaveModel getUserModel].youpaipuserinfo.youpaipvoice_time - self.youpaipaudioStream.currentTimePlayed.playbackTimeInSeconds;
  459. self.youpaiptimerL.text = [NSString stringWithFormat:@"%@\"",@(timer)];
  460. }
  461. @end