TodoedTaskViewController.swift 7.9 KB

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