MainTaskSecondViewController.swift 25 KB

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