TodoedTaskViewController.swift 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //
  2. // TodoedTaskViewController.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 16/8/15.
  6. // Copyright © 2016年 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. class TodoedTaskViewController: UITableViewController {
  16. var loadUrl:String?
  17. var todoedActions:[TodoedActionModel] = []
  18. var todoedStatus:[TodoedStatusModel] = []
  19. var todoTask:TodoTask? {
  20. didSet {
  21. let url = AppDelegate.o2Collect.generateURLWithAppContextKey(TaskedContext.taskedContextKey, query: TaskedContext.taskedDataByIdQuery, parameter: ["##id##":(todoTask?.id)! as AnyObject])
  22. self.loadUrl = url
  23. }
  24. }
  25. override func viewDidLoad() {
  26. super.viewDidLoad()
  27. title = self.todoTask?.title
  28. self.loadTodoedData()
  29. }
  30. func loadTodoedData(){
  31. ProgressHUD.show("加载中...")
  32. Alamofire.request(loadUrl!).responseJSON(completionHandler:{ response in
  33. debugPrint(response.result)
  34. switch response.result {
  35. case .success(let val):
  36. let data = JSON(val)["data"]
  37. let type = JSON(val)["type"]
  38. DDLogDebug(data.description)
  39. if type == "success" {
  40. self.setActionModel(data["taskCompleted"].array,completed: true)
  41. self.setActionModel(data["workCompletedList"].array, completed: true)
  42. self.setActionModel(data["workList"].array,completed: false)
  43. self.setStatusModel(Mapper<ActivityTask>().mapArray(JSONString:data["workLogList"].description))
  44. self.tableView.reloadData()
  45. ProgressHUD.showSuccess("加载完成")
  46. }else{
  47. DDLogError(JSON(val)["message"].description)
  48. ProgressHUD.showError("加载失败")
  49. }
  50. case .failure(let err):
  51. DDLogError(err.localizedDescription)
  52. ProgressHUD.showError("加载失败")
  53. }
  54. })
  55. }
  56. func setActionModel(_ actionArray:[JSON]?,completed:Bool){
  57. if actionArray != nil {
  58. for action in actionArray! {
  59. if completed {
  60. let title = "\(action["title"].stringValue)于\(action["completedTime"].stringValue) 已完成"
  61. let id = action["id"].stringValue
  62. let workType = "workCompletedList"
  63. let actionModel = TodoedActionModel(destText: title, workType: workType, workId: id)
  64. self.todoedActions.append(actionModel)
  65. }else{
  66. // %@于%@ 停留在%@",item[@"title"],item[@"updateTime"],item[@"activityName"]
  67. let title = "\(action["title"].stringValue)于\(action["updateTime"].stringValue) 停留在\(action["activityName"].stringValue)"
  68. let id = action["id"].stringValue
  69. let workType = "workList"
  70. let actionModel = TodoedActionModel(destText: title, workType: workType, workId: id)
  71. self.todoedActions.append(actionModel)
  72. }
  73. }
  74. }
  75. }
  76. func setStatusModel(_ statusArray:[ActivityTask]?){
  77. for task in statusArray! {
  78. if task.fromActivityType == "begin" {
  79. continue
  80. }
  81. let activity = task.arrivedActivityName == nil ? task.fromActivityName:task.arrivedActivityName
  82. var identity = ""
  83. if (task.taskCompletedList == nil || task.taskCompletedList!.count == 0) {
  84. if (task.taskList!.count > 0 ) {
  85. identity = task.taskList![0].identity!;
  86. }else{
  87. identity = "当前处理人";
  88. }
  89. }else{
  90. identity = (task.taskCompletedList![0] as! NSDictionary)["identity"]! as! String;
  91. }
  92. let status = task.routeName == nil ? "当前节点":task.routeName
  93. // text22 = task.arrivedTime == nil ? task.fromTime : task.arrivedTime;
  94. let time = task.arrivedTime == nil ? task.fromTime : task.arrivedTime
  95. identity = identity.components(separatedBy: "@").first ?? ""
  96. let statusModel = TodoedStatusModel(activity: activity, identity: identity, status: status, statusTime: time)
  97. self.todoedStatus.append(statusModel)
  98. }
  99. }
  100. override func didReceiveMemoryWarning() {
  101. super.didReceiveMemoryWarning()
  102. }
  103. // MARK: - Table view data source
  104. override func numberOfSections(in tableView: UITableView) -> Int {
  105. return 2
  106. }
  107. override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  108. switch section {
  109. case 0:
  110. return self.todoedActions.count
  111. case 1:
  112. return self.todoedStatus.count
  113. default:
  114. return 0
  115. }
  116. }
  117. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  118. switch (indexPath as NSIndexPath).section {
  119. case 0:
  120. let cell = tableView.dequeueReusableCell(withIdentifier: "todoedActionCell", for: indexPath) as! TodoedActionCell
  121. cell.delegate = self
  122. cell.actionModel = self.todoedActions[(indexPath as NSIndexPath).row]
  123. return cell
  124. case 1:
  125. let cell = tableView.dequeueReusableCell(withIdentifier: "todoedStatusCell", for: indexPath) as! TodoedStatusCell
  126. cell.statusModel = self.todoedStatus[(indexPath as NSIndexPath).row]
  127. return cell
  128. default:
  129. return UITableViewCell(style: .default, reuseIdentifier: "none")
  130. }
  131. }
  132. override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
  133. if (indexPath as NSIndexPath).section == 1{
  134. cell.separatorInset = UIEdgeInsets.zero
  135. cell.layoutMargins = UIEdgeInsets.zero
  136. cell.layer.transform = CATransform3DMakeScale(0.1, 0.1, 1)
  137. //设置动画时间为0.25秒,xy方向缩放的最终值为1
  138. UIView.animate(withDuration: 0.25 * (Double((indexPath as NSIndexPath).row) + 1.0), animations: { () -> Void in
  139. cell.layer.transform = CATransform3DMakeScale(1, 1, 1)
  140. })
  141. }
  142. }
  143. override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  144. switch (indexPath as NSIndexPath).section {
  145. case 0:
  146. return 60.0
  147. case 1:
  148. return 100.0
  149. default:
  150. return 44.0
  151. }
  152. }
  153. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  154. if segue.identifier == "showTodoedWork" {
  155. let destVC = segue.destination as! TodoTaskDetailViewController
  156. if let model = sender as? TodoedActionModel {
  157. let id = model.workId ?? ""
  158. let title = model.destText ?? ""
  159. let json: String
  160. if model.workType == "workCompletedList" {
  161. json = """
  162. {"workCompleted":"\(id)", "title":"\(title)"}
  163. """
  164. }else {
  165. json = """
  166. {"work":"\(id)", "title":"\(title)"}
  167. """
  168. }
  169. let todo = TodoTask(JSONString: json)
  170. destVC.todoTask = todo
  171. }
  172. destVC.backFlag = 4 // 特殊来源
  173. }
  174. }
  175. }
  176. extension TodoedTaskViewController:TodoedActionCellDelegate{
  177. func open(_ actionModel: TodoedActionModel) {
  178. DDLogDebug(actionModel.workId!)
  179. self.performSegue(withIdentifier: "showTodoedWork", sender: actionModel)
  180. }
  181. }