MainTaskSecondViewController.swift 25 KB

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