123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- //
- // TodoedTaskViewController.swift
- // O2Platform
- //
- // Created by 刘振兴 on 16/8/15.
- // Copyright © 2016年 zoneland. All rights reserved.
- //
- import UIKit
- import Alamofire
- import AlamofireImage
- import AlamofireObjectMapper
- import SwiftyJSON
- import ObjectMapper
- import CocoaLumberjack
- class TodoedTaskViewController: UITableViewController {
-
- var loadUrl:String?
-
- var todoedActions:[TodoedActionModel] = []
-
- var todoedStatus:[TodoedStatusModel] = []
-
- var todoTask:TodoTask? {
- didSet {
- let url = AppDelegate.o2Collect.generateURLWithAppContextKey(TaskedContext.taskedContextKey, query: TaskedContext.taskedDataByIdQuery, parameter: ["##id##":(todoTask?.id)! as AnyObject])
- self.loadUrl = url
- }
- }
-
- override func viewDidLoad() {
- super.viewDidLoad()
- var t = self.todoTask?.title
- if t == nil || t?.isEmpty == true {
- t = self.todoTask?.processName ?? ""
- }
- title = t
- self.loadTodoedData()
- }
-
- func loadTodoedData(){
- self.showLoading(title: "加载中...")
- AF.request(loadUrl!).responseJSON(completionHandler:{ response in
- debugPrint(response.result)
- switch response.result {
- case .success(let val):
- let data = JSON(val)["data"]
- let type = JSON(val)["type"]
- DDLogDebug(data.description)
- if type == "success" {
- self.setActionModel(data["taskCompleted"].array,completed: true)
- self.setActionModel(data["workCompletedList"].array, completed: true)
- self.setActionModel(data["workList"].array,completed: false)
- self.setStatusModel(Mapper<ActivityTask>().mapArray(JSONString:data["workLogList"].description))
- self.tableView.reloadData()
- self.showSuccess(title: "加载完成")
- }else{
- DDLogError(JSON(val)["message"].description)
- self.showError(title: "加载失败")
- }
- case .failure(let err):
- DDLogError(err.localizedDescription)
- self.showError(title: "加载失败")
- }
- })
- }
-
- func setActionModel(_ actionArray:[JSON]?,completed:Bool){
- if actionArray != nil {
- for action in actionArray! {
- if completed {
- let title = "\(action["title"].stringValue) 完成于\(action["completedTime"].stringValue)"
- let id = action["id"].stringValue
- let workType = "workCompletedList"
- let actionModel = TodoedActionModel(destText: title, workType: workType, workId: id)
- self.todoedActions.append(actionModel)
- }else{
- // %@于%@ 停留在%@",item[@"title"],item[@"updateTime"],item[@"activityName"]
- let title = "\(action["title"].stringValue) 当前在\(action["activityName"].stringValue)"
- let id = action["id"].stringValue
- let workType = "workList"
- let actionModel = TodoedActionModel(destText: title, workType: workType, workId: id)
- self.todoedActions.append(actionModel)
- }
-
- }
- }
- }
-
- func setStatusModel(_ statusArray:[ActivityTask]?){
- for task in statusArray! {
- if task.fromActivityType == "begin" {
- continue
- }
- let activity = task.arrivedActivityName == nil ? task.fromActivityName : "\(task.fromActivityName ?? "") -> \(task.arrivedActivityName ?? "")"
- var identity = ""
- if (task.taskCompletedList == nil || task.taskCompletedList!.count == 0) {
- if (task.taskList!.count > 0 ) {
- identity = task.taskList![0].identity!;
- }else{
- identity = "当前处理人";
- }
- }else{
- identity = (task.taskCompletedList![0] as! NSDictionary)["identity"]! as! String;
- }
- let status = task.routeName == nil ? "正在处理":"选择了【\(task.routeName ?? "")】"
- let time = task.arrivedTime == nil ? "到达于:\(task.fromTime ?? "")" : "提交于:\(task.arrivedTime ?? "")"
- identity = identity.components(separatedBy: "@").first ?? ""
- let statusModel = TodoedStatusModel(activity: activity, identity: identity, status: status, statusTime: time)
- self.todoedStatus.append(statusModel)
- }
-
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- }
- // MARK: - Table view data source
- override func numberOfSections(in tableView: UITableView) -> Int {
- return 2
- }
- override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- switch section {
- case 0:
- return self.todoedActions.count
- case 1:
- return self.todoedStatus.count
- default:
- return 0
- }
- }
-
- override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- switch (indexPath as NSIndexPath).section {
- case 0:
- let cell = tableView.dequeueReusableCell(withIdentifier: "todoedActionCell", for: indexPath) as! TodoedActionCell
- cell.delegate = self
- cell.actionModel = self.todoedActions[(indexPath as NSIndexPath).row]
- return cell
- case 1:
- let cell = tableView.dequeueReusableCell(withIdentifier: "todoedStatusCell", for: indexPath) as! TodoedStatusCell
- cell.statusModel = self.todoedStatus[(indexPath as NSIndexPath).row]
- return cell
- default:
- return UITableViewCell(style: .default, reuseIdentifier: "none")
- }
-
- }
-
- override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
- if (indexPath as NSIndexPath).section == 1{
- cell.separatorInset = UIEdgeInsets.zero
- cell.layoutMargins = UIEdgeInsets.zero
- cell.layer.transform = CATransform3DMakeScale(0.1, 0.1, 1)
-
- //设置动画时间为0.25秒,xy方向缩放的最终值为1
-
- UIView.animate(withDuration: 0.25 * (Double((indexPath as NSIndexPath).row) + 1.0), animations: { () -> Void in
-
- cell.layer.transform = CATransform3DMakeScale(1, 1, 1)
-
- })
- }
- }
-
- override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- switch (indexPath as NSIndexPath).section {
- case 0:
- return 60.0
- case 1:
- return 100.0
- default:
- return 44.0
- }
- }
-
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- if segue.identifier == "showTodoedWork" {
- let destVC = segue.destination as! TodoTaskDetailViewController
- if let model = sender as? TodoedActionModel {
- let id = model.workId ?? ""
- let title = model.destText ?? ""
- let json: String
- if model.workType == "workCompletedList" {
- json = """
- {"workCompleted":"\(id)", "title":"\(title)"}
- """
- }else {
- json = """
- {"work":"\(id)", "title":"\(title)"}
- """
- }
- let todo = TodoTask(JSONString: json)
- destVC.todoTask = todo
- }
- destVC.backFlag = 4 // 特殊来源
- }
- }
-
- }
- extension TodoedTaskViewController:TodoedActionCellDelegate{
- func open(_ actionModel: TodoedActionModel) {
- DDLogDebug(actionModel.workId!)
- self.performSegue(withIdentifier: "showTodoedWork", sender: actionModel)
-
- }
- }
|