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