MainTaskSecondViewController.swift 25 KB

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