ICCheckAppealViewController.swift 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. //
  2. // ICCheckAppealViewController.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 2016/10/25.
  6. // Copyright © 2016年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import Alamofire
  10. import AlamofireImage
  11. import AlamofireObjectMapper
  12. import ObjectMapper
  13. import SwiftyJSON
  14. import BWSwipeRevealCell
  15. import CocoaLumberjack
  16. import O2OA_Auth_SDK
  17. class ICCheckAppealViewController: UIViewController {
  18. @IBOutlet weak var tableView: ZLBaseTableView!
  19. var currentTime:ICTimeComponent?
  20. var checkEntrys:[AttendanceCheckEntry] = []
  21. override func viewDidLoad() {
  22. super.viewDidLoad()
  23. self.tableView.emptyTitle = "没有待审批申诉"
  24. self.tableView.dataSource = self
  25. self.tableView.delegate = self
  26. //self.tableView.setEditing(true, animated: true)
  27. self.tableView.mj_header = MJRefreshNormalHeader(refreshingBlock: {
  28. self.loadAppealCheckData()
  29. })
  30. self.loadAppealCheckData()
  31. }
  32. func loadAppealCheckData(){
  33. let url = AppDelegate.o2Collect.generateURLWithAppContextKey(icContext.icContextKey, query: icContext.attendanceCheckListQuery, parameter: ["##id##":"(0)" as AnyObject,"##count##":"2000" as AnyObject])
  34. let filter = AttendanceAppealApprovalWrapInFilter()
  35. filter.status = "0"
  36. filter.yearString = currentTime?.year
  37. filter.processPerson1 = O2AuthSDK.shared.myInfo()?.name
  38. self.checkEntrys.removeAll()
  39. Alamofire.request(url!, method: .put, parameters: filter.toJSON(), encoding: JSONEncoding.default, headers: nil).responseJSON { (response) in
  40. //debugPrint(response)
  41. switch response.result {
  42. case .success(let val):
  43. let type = JSON(val)["type"]
  44. if type == "success" {
  45. let checkDatas = Mapper<AttendanceAppealInfoData>().mapArray(JSONString: JSON(val)["data"].description)
  46. let entrys:[AttendanceCheckEntry] = (checkDatas?.map({ (e) -> AttendanceCheckEntry in
  47. return AttendanceCheckEntry.genernateEntry(infoData: e)
  48. }))!
  49. self.checkEntrys.append(contentsOf: entrys)
  50. self.tableView.reloadData()
  51. }else{
  52. DDLogError(JSON(val).description)
  53. }
  54. case .failure(let err):
  55. DDLogError(err.localizedDescription)
  56. }
  57. if self.tableView.mj_header.isRefreshing() {
  58. self.tableView.mj_header.endRefreshing()
  59. }
  60. }
  61. }
  62. override func didReceiveMemoryWarning() {
  63. super.didReceiveMemoryWarning()
  64. // Dispose of any resources that can be recreated.
  65. }
  66. }
  67. extension ICCheckAppealViewController:UITableViewDataSource,UITableViewDelegate{
  68. func numberOfSections(in tableView: UITableView) -> Int {
  69. return 1
  70. }
  71. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  72. return self.checkEntrys.count
  73. }
  74. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  75. let cell:CheckAppealCell = tableView.dequeueReusableCell(withIdentifier: "checkAppealCell", for: indexPath) as! CheckAppealCell
  76. let entry = self.checkEntrys[indexPath.row]
  77. cell.entry = entry
  78. let bsCell:BWSwipeRevealCell = cell as BWSwipeRevealCell
  79. bsCell.bgViewLeftImage = UIImage(named:"Done")!.withRenderingMode(.alwaysTemplate)
  80. bsCell.bgViewLeftColor = UIColor.green
  81. bsCell.bgViewRightImage = UIImage(named:"Delete")!.withRenderingMode(.alwaysTemplate)
  82. bsCell.bgViewRightColor = UIColor.red
  83. bsCell.type = .slidingDoor
  84. bsCell.delegate = self
  85. return cell
  86. }
  87. func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
  88. return true
  89. }
  90. }
  91. extension ICCheckAppealViewController:BWSwipeRevealCellDelegate{
  92. func swipeCellActivatedAction(_ cell: BWSwipeCell, isActionLeft: Bool) {
  93. let indexPath = tableView.indexPath(for: cell)!
  94. let entry = self.checkEntrys[indexPath.row]
  95. if isActionLeft == true {
  96. self.acceptAppealCheck((entry.appealObj!), indexPath: indexPath)
  97. }else{
  98. self.rejectAppealCheck((entry.appealObj!), indexPath: indexPath)
  99. }
  100. }
  101. func acceptAppealCheck(_ appealData:AttendanceAppealInfoData,indexPath:IndexPath){
  102. DDLogDebug("acceptAppealCheck")
  103. appealData.status = 1 //同意
  104. let url = AppDelegate.o2Collect.generateURLWithAppContextKey(icContext.icContextKey, query: icContext.attendanceCheckSubmitQuery, parameter: ["##id##":appealData.id! as AnyObject])
  105. Alamofire.request(url!, method: .put, parameters: appealData.toJSON(), encoding: JSONEncoding.default, headers: nil).responseJSON { (response) in
  106. switch response.result {
  107. case .success(let val):
  108. let type = JSON(val)["type"]
  109. if type == "success" {
  110. self.tableViewCellUpdate(indexPath)
  111. }else{
  112. DDLogError(JSON(val).description)
  113. ProgressHUD.showError("提交失败")
  114. }
  115. case .failure(let err):
  116. DDLogError(err.localizedDescription)
  117. ProgressHUD.showError("提交失败")
  118. }
  119. }
  120. }
  121. func rejectAppealCheck(_ appealData:AttendanceAppealInfoData,indexPath:IndexPath){
  122. DDLogDebug("rejectAppealCheck")
  123. appealData.status = -1 //不同意
  124. let url = AppDelegate.o2Collect.generateURLWithAppContextKey(icContext.icContextKey, query: icContext.attendanceCheckSubmitQuery, parameter: ["##id##":appealData.id! as AnyObject])
  125. Alamofire.request(url!, method: .put, parameters: appealData.toJSON(), encoding: JSONEncoding.default, headers: nil).responseJSON { (response) in
  126. switch response.result {
  127. case .success(let val):
  128. let type = JSON(val)["type"]
  129. if type == "success" {
  130. self.tableViewCellUpdate(indexPath)
  131. }else{
  132. DDLogError(JSON(val).description)
  133. ProgressHUD.showError("提交失败")
  134. }
  135. case .failure(let err):
  136. DDLogError(err.localizedDescription)
  137. ProgressHUD.showError("提交失败")
  138. }
  139. }
  140. }
  141. func tableViewCellUpdate(_ indexPath:IndexPath){
  142. //let meeting = self.meetings[indexPath.row]
  143. self.checkEntrys.remove(at:indexPath.row)
  144. tableView.beginUpdates()
  145. tableView.deleteRows(at: [indexPath], with: .left)
  146. tableView.endUpdates()
  147. }
  148. }