MainTaskSecondViewController.swift 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. //
  2. // MainTaskSecondViewController.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 2017/3/12.
  6. // Copyright © 2017年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import Alamofire
  10. import AlamofireImage
  11. import AlamofireObjectMapper
  12. import SwiftyJSON
  13. import ObjectMapper
  14. import CocoaLumberjack
  15. import MBProgressHUD
  16. import WebKit
  17. class MainTaskSecondViewController: UIViewController {
  18. fileprivate static let PAGE_SIZE = 20
  19. @IBOutlet weak var tableViewTopConstraint: NSLayoutConstraint!
  20. @IBOutlet weak var tableView: UITableView!
  21. //相关变量
  22. //1段分类
  23. fileprivate var seguementControl:SegmentedControl!
  24. //存储热点图片新闻数组
  25. private var taskImageshowEntitys:[TaskImageshowEntity] = [] {
  26. didSet {
  27. if taskImageshowEntitys.count > 0 {
  28. self.tableView.tableHeaderView = self.initTableHeaderView()
  29. let imageShowView = self.tableView.tableHeaderView as! ImageSlidesShowView
  30. imageShowView.imageshowEntitys = taskImageshowEntitys
  31. // self.tableView.reloadData()
  32. }else {
  33. self.tableView.tableHeaderView = self.initTableHeaderImageView()
  34. }
  35. }
  36. }
  37. fileprivate var newPublishPageModel = CommonPageModel(MainTaskSecondViewController.PAGE_SIZE)
  38. fileprivate var newTaskPageModel = CommonPageModel(MainTaskSecondViewController.PAGE_SIZE)
  39. //所有首页应用
  40. private var homeApps:[O2App] = []
  41. //所有待办数据
  42. fileprivate var todoTasks:[TodoTask] = []
  43. //所有最新公告数据
  44. fileprivate var newPublishInfos:[CMS_PublishInfo] = []
  45. //顶部导航
  46. private lazy var navView: MyView = {
  47. let nav = MyView(frame: CGRect.init(x: 0, y: 0, width: SCREEN_WIDTH, height: safeAreaTopHeight))
  48. nav.backgroundColor = UIColor.clear
  49. return nav
  50. }()
  51. //分段视图
  52. lazy var segmentView: UIView = {
  53. let view = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 40))
  54. view.backgroundColor = UIColor.white
  55. view.addSubview(self.seguementControl)
  56. return view
  57. }()
  58. override func viewWillAppear(_ animated: Bool) {
  59. super.viewWillAppear(animated)
  60. self.navigationController?.navigationBar.isHidden = true
  61. self.tableView.delegate = self
  62. loadHomeApps()
  63. loadPlayerList()
  64. loadNewPublish(newPublishPageModel)
  65. //self.initBarManager()
  66. }
  67. override func viewWillDisappear(_ animated: Bool) {
  68. super.viewWillDisappear(animated)
  69. self.tableView.delegate = nil
  70. self.navigationController?.navigationBar.isHidden = false
  71. }
  72. override func viewDidLoad() {
  73. super.viewDidLoad()
  74. //self.title = "首页"
  75. self.automaticallyAdjustsScrollViewInsets = false
  76. self.navView.tableViews.append(self.tableView)
  77. //添加扫描按钮事件
  78. self.navView.scanBtn?.addTarget(self, action: #selector(startScanAction(_:)), for: .touchUpInside)
  79. //添加发起按钮事件
  80. self.navView.addBtn?.addTarget(self, action: #selector(startFlowAction(_:)), for: .touchUpInside)
  81. self.view.addSubview(self.navView)
  82. self.seguementControl = initSegumentControl()
  83. self.tableView.dataSource = self
  84. self.tableView.tableHeaderView = self.initTableHeaderImageView()
  85. if #available(iOS 11.0, *) {
  86. let topConstant = CGFloat(0 - IOS11_TOP_STATUSBAR_HEIGHT)
  87. self.tableViewTopConstraint.constant = topConstant
  88. }
  89. }
  90. //初始化热点新闻显示
  91. private func initTableHeaderView() -> UIView {
  92. let height = SCREEN_WIDTH / 2
  93. let frame = CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: height)
  94. let imageShowView = ImageSlidesShowView(frame: frame)
  95. imageShowView.delegate = self
  96. return imageShowView
  97. }
  98. //默认新闻热点使用图片 如果服务器有数据 就用ImageSlidesShowView
  99. private func initTableHeaderImageView() -> UIView {
  100. let height = SCREEN_WIDTH / 2
  101. let frame = CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: height)
  102. let imageShowView = UIImageView(image: UIImage(named: "pic_lunbo_1"))
  103. imageShowView.frame = frame
  104. imageShowView.contentMode = .scaleAspectFill
  105. return imageShowView
  106. }
  107. //初始化
  108. private func initBarManager(){
  109. ZoneNavigationBarManager.managerWithController(self)
  110. ZoneNavigationBarManager.setBarColor(UIColor.clear)
  111. ZoneNavigationBarManager.setTintColor(UIColor.white)
  112. // ZoneNavigationBarManager.setBarColor(UIColor(colorLiteralRed: 1, green: 1, blue: 1, alpha: 0))
  113. // ZoneNavigationBarManager.setTintColor(UIColor.white)
  114. // ZoneNavigationBarManager.setStatusBarStyle(.lightContent)
  115. // ZoneNavigationBarManager.setZeroAlphaOffset(-64)
  116. // ZoneNavigationBarManager.setFullAlphaOffset(200)
  117. // ZoneNavigationBarManager.setFullAlphaTintColor(UIColor.red)
  118. //ZoneNavigationBarManager.setContinus(false)
  119. }
  120. //初始化分类显示
  121. private func initSegumentControl() -> SegmentedControl{
  122. //返回一个分类头部
  123. let titleStrings = ["信息中心", "办公中心"]
  124. let titles: [NSAttributedString] = {
  125. let attributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16), NSAttributedString.Key.foregroundColor: UIColor.black]
  126. var titles = [NSAttributedString]()
  127. for titleString in titleStrings {
  128. let title = NSAttributedString(string: titleString, attributes: attributes)
  129. titles.append(title)
  130. }
  131. return titles
  132. }()
  133. let selectedTitles: [NSAttributedString] = {
  134. let attributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16), NSAttributedString.Key.foregroundColor: base_color]
  135. var selectedTitles = [NSAttributedString]()
  136. for titleString in titleStrings {
  137. let selectedTitle = NSAttributedString(string: titleString, attributes: attributes)
  138. selectedTitles.append(selectedTitle)
  139. }
  140. return selectedTitles
  141. }()
  142. let segmentedControl = SegmentedControl.initWithTitles(titles, selectedTitles: selectedTitles)
  143. segmentedControl.delegate = self
  144. segmentedControl.backgroundColor = UIColor.white
  145. segmentedControl.autoresizingMask = [.flexibleRightMargin, .flexibleWidth]
  146. segmentedControl.selectionIndicatorStyle = .bottom
  147. segmentedControl.selectionIndicatorColor = base_color
  148. segmentedControl.selectionIndicatorHeight = 0.5
  149. segmentedControl.segmentWidth = (UIScreen.main.bounds.width - 100) / 2
  150. //segmentedControl.frame.origin.y = 64
  151. segmentedControl.frame = CGRect(x:50,y:0,width: UIScreen.main.bounds.width, height: 40)
  152. //segmentedControl.frame.size = CGSize(width: UIScreen.main.bounds.width, height: 40)
  153. return segmentedControl
  154. }
  155. //开始扫描
  156. @objc private func startScanAction(_ sender:AnyObject?) {
  157. ScanHelper.openScan(vc: self)
  158. }
  159. //开始显示新建页面
  160. @objc private func startFlowAction(_ sender:AnyObject?){
  161. self.performSegue(withIdentifier: "showAppCategorySegue", sender: nil)
  162. }
  163. //读取数据待办数据
  164. fileprivate func loadMainTodo(_ pageModel:CommonPageModel,_ isFirst:Bool = true){
  165. DDLogDebug("loadMainTodo ...........................")
  166. self.showLoading(title: "加载中...")
  167. //ZoneHUD.showNormalHUD((self.navigationController?.view!)!)
  168. let url = AppDelegate.o2Collect.generateURLWithAppContextKey(TaskContext.taskContextKey, query: TaskContext.todoTaskListQuery, parameter: pageModel.toDictionary() as [String : AnyObject]?)
  169. if isFirst {
  170. self.todoTasks.removeAll(keepingCapacity: true)
  171. }
  172. Alamofire.request(url!).responseArray(queue: nil, keyPath: "data", context: nil, completionHandler: { (response:DataResponse<[TodoTask]>) in
  173. DDLogDebug(response.debugDescription)
  174. switch response.result {
  175. case .success(let tTasks):
  176. DispatchQueue.main.async {
  177. self.todoTasks.append(contentsOf: tTasks)
  178. //let count:Int = JSON(val)["count"].int ?? 0
  179. self.newTaskPageModel.setPageTotal(tTasks.count)
  180. self.hideLoading()
  181. self.tableView.beginUpdates()
  182. self.tableView.reloadSections(IndexSet.init(integer: 1), with: .automatic)
  183. self.tableView.endUpdates()
  184. }
  185. case .failure(let err):
  186. DispatchQueue.main.async {
  187. self.showSuccess(title: "加载待办失败")
  188. DDLogError(err.localizedDescription)
  189. }
  190. }
  191. })
  192. }
  193. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  194. if segue.identifier == "showMailSegue" {
  195. if let mail = segue.destination as? MailViewController {
  196. mail.app = sender as? O2App
  197. }
  198. }
  199. }
  200. //读取首页应用
  201. private func loadHomeApps() {
  202. DDLogDebug("loadHomeApps ...........................")
  203. let apps = DBManager.shared.queryMainData()
  204. homeApps.removeAll()
  205. if apps.isEmpty {
  206. homeApps.append(contentsOf: O2AppUtil.defaultMainApps)
  207. }else {
  208. homeApps.append(contentsOf: apps)
  209. }
  210. tableView.beginUpdates()
  211. tableView.reloadSections(IndexSet.init(integer: 0), with: .automatic)
  212. tableView.endUpdates()
  213. }
  214. //读取最新公告
  215. fileprivate func loadNewPublish(_ pageModel:CommonPageModel,_ isFirst:Bool = true){
  216. DDLogDebug("loadNewPublish ...........................")
  217. self.showLoading(title: "加载中...")
  218. let npURL = AppDelegate.o2Collect.generateURLWithAppContextKey(CMSContext.cmsContextKey, query: CMSContext.cmsCategoryDetailQuery, parameter: pageModel.toDictionary() as[String:AnyObject]?)
  219. if isFirst {
  220. self.newPublishInfos.removeAll()
  221. }
  222. Alamofire.request(npURL!, method: .put, parameters:[String:Any](), encoding: JSONEncoding.default, headers: nil).responseJSON { (response) in
  223. DDLogDebug(response.debugDescription)
  224. switch response.result {
  225. case .success(let val):
  226. let json = JSON(val)["data"]
  227. let type = JSON(val)["type"]
  228. if type == "success" {
  229. let pInfos = Mapper<CMS_PublishInfo>().mapArray(JSONString: json.description)
  230. if let uPInfos = pInfos {
  231. self.newPublishInfos.append(contentsOf: uPInfos)
  232. let count:Int = JSON(val)["count"].int ?? 0
  233. self.newPublishPageModel.setPageTotal(count)
  234. }
  235. DispatchQueue.main.async {
  236. //ZoneHUD.dismissNormalHUD()
  237. self.hideLoading()
  238. self.tableView.beginUpdates()
  239. self.tableView.reloadSections(IndexSet.init(integer: 1), with: .automatic)
  240. self.tableView.endUpdates()
  241. }
  242. }else{
  243. DispatchQueue.main.async {
  244. self.showError(title: "新闻列表出错")
  245. DDLogError(json.description)
  246. }
  247. }
  248. //print(json)
  249. case .failure(let err):
  250. DispatchQueue.main.async {
  251. self.showError(title: "新闻列表出错")
  252. //ZoneHUD.showErrorHUD(errorText: "新闻列表出错", 0.5)
  253. DDLogError(err.localizedDescription)
  254. }
  255. }
  256. }
  257. }
  258. //热点图片新闻
  259. private func loadPlayerList(){
  260. DDLogDebug("loadPlayerList ...........................")
  261. // self.taskImageshowEntitys.removeAll(keepingCapacity: true)
  262. let url = AppDelegate.o2Collect.generateURLWithAppContextKey(HotpicContext.hotpicContextKey, query: HotpicContext.hotpicAllListQuery, parameter: ["##page##":"0" as AnyObject,"##count##":"8" as AnyObject])
  263. Alamofire.request(url!, method: .put, parameters: nil, encoding: JSONEncoding.default, headers: nil).responseJSON { (response) in
  264. switch response.result {
  265. case .success(let val):
  266. let type = JSON(val)["type"]
  267. if type == "success" {
  268. let data = JSON(val)["data"]
  269. let entrys = Mapper<TaskImageshowEntity>().mapArray(JSONString: data.description)
  270. DispatchQueue.main.async {
  271. self.taskImageshowEntitys = entrys ?? []
  272. }
  273. }else{
  274. }
  275. case .failure(let err):
  276. DDLogError(err.localizedDescription)
  277. }
  278. }
  279. }
  280. // MARK: - 回调刷新
  281. @IBAction func unWindRefreshSegueForMainTask(_ segue:UIStoryboardSegue){
  282. DDLogDebug("backRefreshMainTask")
  283. // newTaskPageModel = CommonPageModel(MainTaskSecondViewController.PAGE_SIZE)
  284. // self.loadMainTodo(newTaskPageModel)
  285. }
  286. @IBAction func unBackAppsForMain(_ segue:UIStoryboardSegue){
  287. DDLogDebug("返回应用列表")
  288. if segue.source.isKind(of: TaskCreateViewController.self) {
  289. newTaskPageModel = CommonPageModel(MainTaskSecondViewController.PAGE_SIZE)
  290. self.loadMainTodo(newTaskPageModel)
  291. // let sourceVC = segue.source as! TaskCreateViewController
  292. // if let task = sourceVC.task {
  293. // self.forwardTodoTaskDetail(task)
  294. // }
  295. }
  296. }
  297. override func didReceiveMemoryWarning() {
  298. super.didReceiveMemoryWarning()
  299. // Dispose of any resources that can be recreated.
  300. }
  301. }
  302. extension MainTaskSecondViewController:UITableViewDataSource,UITableViewDelegate{
  303. //分两个Section
  304. func numberOfSections(in tableView: UITableView) -> Int {
  305. return 2
  306. }
  307. //Section 0 返回1,Section 1返回读了的数据列表
  308. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  309. switch section {
  310. case 0:
  311. return 1
  312. case 1:
  313. if self.seguementControl.selectedIndex == 0 {
  314. return self.newPublishInfos.count
  315. }else if self.seguementControl.selectedIndex == 1 {
  316. return self.todoTasks.count
  317. }else{
  318. return 0
  319. }
  320. default:
  321. return 0
  322. }
  323. }
  324. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  325. if indexPath.section == 0 {
  326. //第0段返回应用列表
  327. let cell = tableView.dequeueReusableCell(withIdentifier: "NewMainAppTableViewCell", for: indexPath) as! (NewMainAppTableViewCell & Configurable)
  328. cell.apps.removeAll()
  329. cell.apps.append(contentsOf: homeApps)
  330. //设置代理
  331. cell.delegate = self
  332. return cell
  333. }else if indexPath.section == 1{
  334. //第1段返回数据列表
  335. let cell = tableView.dequeueReusableCell(withIdentifier: "NewMainItemTableViewCell", for: indexPath) as! NewMainItemTableViewCell
  336. if self.seguementControl.selectedIndex == 0 {
  337. if !self.newPublishInfos.isEmpty {
  338. let obj = self.newPublishInfos[indexPath.row]
  339. cell.model = obj
  340. }
  341. }else if self.seguementControl.selectedIndex == 1 {
  342. if !self.todoTasks.isEmpty {
  343. let obj = self.todoTasks[indexPath.row]
  344. cell.model = obj
  345. }
  346. }
  347. return cell
  348. }else{
  349. return UITableViewCell()
  350. }
  351. }
  352. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  353. if section == 1 {
  354. return 40.0
  355. }else{
  356. return 0
  357. }
  358. }
  359. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  360. if section == 0 {
  361. return 10.0
  362. }else{
  363. return 0.0
  364. }
  365. }
  366. func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
  367. if section == 0 {
  368. let view = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 10.0))
  369. view.backgroundColor = UIColor(red: 246.0/255.0, green: 246.0/255.0, blue: 246.0/255.0, alpha: 1.0)
  370. return view
  371. }else{
  372. return nil
  373. }
  374. }
  375. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  376. if section == 1{
  377. return segmentView
  378. }else{
  379. return nil
  380. }
  381. }
  382. //行高
  383. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  384. switch indexPath.section {
  385. case 0:
  386. return 100
  387. case 1:
  388. return 60
  389. default:
  390. return 50
  391. }
  392. }
  393. //信息点击和新闻点击执行
  394. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  395. if (indexPath as NSIndexPath).section == 1 {
  396. //self.navigationController?.navigationBar.isHidden = false
  397. if seguementControl.selectedIndex == 0 {
  398. let publishInfo = self.newPublishInfos[indexPath.row]
  399. let taskInfo = TaskImageshowEntity(JSON: (publishInfo.toJSON()))
  400. taskInfo?.infoId = publishInfo.id
  401. self.processApplicationForCMS(entity: taskInfo!)
  402. }else if seguementControl.selectedIndex == 1{
  403. let todoTask = self.todoTasks[(indexPath as NSIndexPath).row]
  404. //DDLogDebug("\(todoTask.title!)")
  405. self.forwardTodoTaskDetail(todoTask)
  406. }
  407. }
  408. }
  409. private func forwardTodoTaskDetail(_ todoTask:TodoTask){
  410. DDLogError("反反复复。。。。。。")
  411. let taskStoryboard = UIStoryboard(name: "task", bundle: Bundle.main)
  412. let todoTaskDetailVC = taskStoryboard.instantiateViewController(withIdentifier: "todoTaskDetailVC") as! TodoTaskDetailViewController
  413. todoTaskDetailVC.todoTask = todoTask
  414. todoTaskDetailVC.backFlag = 3
  415. todoTaskDetailVC.modalPresentationStyle = .fullScreen
  416. // self.show(todoTaskDetailVC, sender: nil)
  417. // self.presentVC(todoTaskDetailVC)
  418. self.navigationController?.pushViewController(todoTaskDetailVC, animated: false)
  419. }
  420. }
  421. //分类显示点击代理
  422. extension MainTaskSecondViewController: SegmentedControlDelegate {
  423. func segmentedControl(_ segmentedControl: SegmentedControl, didSelectIndex selectedIndex: Int) {
  424. print("Did select index \(selectedIndex)")
  425. switch segmentedControl.style {
  426. case .text:
  427. print("The title is “\(segmentedControl.titles[selectedIndex].string)”\n")
  428. case .image:
  429. print("The image is “\(segmentedControl.images[selectedIndex])”\n")
  430. }
  431. switch selectedIndex {
  432. case 0:
  433. newPublishPageModel = CommonPageModel(MainTaskSecondViewController.PAGE_SIZE)
  434. loadNewPublish(newPublishPageModel)
  435. break
  436. case 1:
  437. newTaskPageModel = CommonPageModel(MainTaskSecondViewController.PAGE_SIZE)
  438. loadMainTodo(newTaskPageModel)
  439. break
  440. default:
  441. break
  442. }
  443. }
  444. }
  445. //应用点击代理
  446. extension MainTaskSecondViewController:NewMainAppTableViewCellDelegate{
  447. func emptyTapClick() {
  448. // TODO
  449. // tabBarController?.cyl_tabBarController.cyl_popSelectTabBarChildViewController(at: 3)
  450. //tabBarController?.selectedIndex = 3
  451. }
  452. func NewMainAppTableViewCellWithApp(_ app: O2App) {
  453. AppConfigSettings.shared.appBackType = 1
  454. if let segueIdentifier = app.segueIdentifier,segueIdentifier != "" {
  455. if app.storyBoard! == "webview" {
  456. DDLogDebug("open webview for : "+app.title!+" url: "+app.vcName!)
  457. self.performSegue(withIdentifier: segueIdentifier, sender: app)
  458. }else {
  459. self.performSegue(withIdentifier: segueIdentifier, sender: nil)
  460. }
  461. } else {
  462. if app.storyBoard! == "webview" {
  463. DDLogError("open webview for : "+app.title!+" url: "+app.vcName!)
  464. } else {
  465. // 语音助手还没做
  466. if app.appId == "o2ai" {
  467. app.storyBoard = "ai"
  468. }
  469. let story = O2AppUtil.apps.first { (appInfo) -> Bool in
  470. return app.appId == appInfo.appId
  471. }
  472. var storyBoardName = app.storyBoard
  473. if story != nil {
  474. storyBoardName = story?.storyBoard
  475. }
  476. DDLogDebug("storyboard: \(storyBoardName!) , app:\(app.appId!)")
  477. let storyBoard = UIStoryboard(name: storyBoardName!, bundle: nil)
  478. //let storyBoard = UIStoryboard(name: app.storyBoard!, bundle: nil)
  479. var destVC:UIViewController!
  480. if let vcname = app.vcName,vcname.isEmpty == false {
  481. destVC = storyBoard.instantiateViewController(withIdentifier: app.vcName!)
  482. }else{
  483. destVC = storyBoard.instantiateInitialViewController()
  484. }
  485. if app.vcName == "todoTask" {
  486. if "taskcompleted" == app.appId {
  487. AppConfigSettings.shared.taskIndex = 2
  488. }else if "read" == app.appId {
  489. AppConfigSettings.shared.taskIndex = 1
  490. }else if "readcompleted" == app.appId {
  491. AppConfigSettings.shared.taskIndex = 3
  492. }else {
  493. AppConfigSettings.shared.taskIndex = 0
  494. }
  495. }
  496. if destVC.isKind(of: ZLNavigationController.self) {
  497. self.show(destVC, sender: nil)
  498. }else{
  499. self.navigationController?.pushViewController(destVC, animated: false)
  500. }
  501. }
  502. }
  503. }
  504. }
  505. //热点新闻代理实现
  506. extension MainTaskSecondViewController:ImageSlidesShowViewDelegate{
  507. func ImageSlidesShowClick(taskImageshowEntity: TaskImageshowEntity) {
  508. if taskImageshowEntity.application == "BBS" {
  509. processApplicationForBBS(entity: taskImageshowEntity)
  510. }else if taskImageshowEntity.application == "CMS" {
  511. processApplicationForCMS(entity: taskImageshowEntity)
  512. }
  513. }
  514. func processApplicationForBBS(entity:TaskImageshowEntity){
  515. let subjectURL = AppDelegate.o2Collect.generateURLWithAppContextKey(BBSContext.bbsContextKey, query: BBSContext.subjectByIdQuery, parameter: ["##id##":entity.infoId! as AnyObject])
  516. Alamofire.request(subjectURL!, method: .get, parameters: nil, encoding: JSONEncoding.default, headers: nil).responseJSON { (response) in
  517. switch response.result {
  518. case .success(let val):
  519. let type = JSON(val)["type"]
  520. if type == "success" {
  521. DDLogDebug(JSON(val).description)
  522. let currentSubject = JSON(val)["data"]["currentSubject"]
  523. let subjectData = Mapper<BBSSubjectData>().map(JSONString: currentSubject.description)
  524. DispatchQueue.main.async {
  525. let bbsStoryboard = UIStoryboard(name: "bbs", bundle: Bundle.main)
  526. let destVC = bbsStoryboard.instantiateViewController(withIdentifier: "BBSSubjectDetailVC") as! BBSSubjectDetailViewController
  527. destVC.subject = subjectData
  528. destVC.title = entity.title
  529. //self.navigationController?.navigationBar.isHidden = false
  530. self.pushVC(destVC)
  531. }
  532. }else{
  533. DDLogError(JSON(val).description)
  534. }
  535. case .failure(let err):
  536. DDLogError(err.localizedDescription)
  537. }
  538. }
  539. }
  540. func processApplicationForCMS(entity:TaskImageshowEntity){
  541. let bbsStoryboard = UIStoryboard(name: "information", bundle: Bundle.main)
  542. let destVC = bbsStoryboard.instantiateViewController(withIdentifier: "CMSSubjectDetailVC") as! CMSItemDetailViewController
  543. destVC.documentId = entity.infoId
  544. destVC.title = entity.title
  545. destVC.modalPresentationStyle = .fullScreen
  546. self.navigationController?.pushViewController(destVC, animated: false)
  547. }
  548. }