ICAppealFormViewController.swift 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. //
  2. // ICAppealFormViewController.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 Eureka
  13. import SwiftyJSON
  14. import CocoaLumberjack
  15. import O2OA_Auth_SDK
  16. class ICAppealFormViewController: FormViewController {
  17. var detailData:AttendanceDetailData?
  18. var entry:AttendanceAppealInfoEntry?
  19. override func viewDidLoad() {
  20. super.viewDidLoad()
  21. //读取直接主管
  22. self.loadProcessPerson()
  23. self.initFormStyle()
  24. self.initFormValue()
  25. }
  26. func initFormValue(){
  27. form +++ Section()
  28. <<< LabelRow("empName"){
  29. row in
  30. row.title = "姓名"
  31. row.value = self.detailData?.empName
  32. }
  33. <<< LabelRow("appealDate"){
  34. row in
  35. row.title = "考勤日期"
  36. row.value = self.detailData?.recordDateString
  37. }
  38. <<< LabelRow("onDutyTime"){
  39. row in
  40. row.title = "上班打卡时间"
  41. row.value = self.detailData?.onDutyTime
  42. }
  43. <<< LabelRow("offDutyTime"){
  44. row in
  45. row.title = "下班打卡时间"
  46. row.value = self.detailData?.offDutyTime
  47. }
  48. <<< LabelRow("statusType"){
  49. row in
  50. row.title = "考勤状态"
  51. let t = calcAttendanceStatus(attendance: self.detailData!)
  52. row.value = t.statusType.rawValue
  53. }
  54. <<< LabelRow("appealStatus"){
  55. row in
  56. row.title = "审批状态"
  57. row.value = "发起"
  58. }
  59. <<< SegmentedRow<String>("appealType") {
  60. $0.title = "申诉类型"
  61. $0.options = ["临时请假", "出差", "因公外出","其他"]
  62. $0.value = ""
  63. }
  64. +++ Section(header:"临时请假",footer:"") {
  65. $0.tag = "a1"
  66. $0.hidden = "$appealType!='临时请假'"
  67. }
  68. <<< SegmentedRow<String>("selfHolidayType"){
  69. $0.title = "请假类型"
  70. $0.add(rule: RuleRequired())
  71. $0.validationOptions = .validatesOnChangeAfterBlurred
  72. $0.options = ["带薪年休假","带薪病假","带薪福利假","扣薪事假","其他"]
  73. $0.value = ""
  74. }.cellUpdate { cell, row in
  75. if !row.isValid {
  76. cell.titleLabel?.textColor = .red
  77. }
  78. }
  79. <<< DateRow("startTime"){
  80. $0.title = "开始日期"
  81. $0.add(rule: RuleRequired())
  82. $0.validationOptions = .validatesAlways
  83. }.cellUpdate { cell, row in
  84. if !row.isValid {
  85. cell.textLabel?.textColor = .red
  86. }
  87. }
  88. <<< DateRow("endTime"){
  89. $0.title = "结束日期"
  90. $0.add(rule: RuleRequired())
  91. $0.validationOptions = .validatesAlways
  92. }.cellUpdate { cell, row in
  93. if !row.isValid {
  94. cell.textLabel?.textColor = .red
  95. }
  96. }
  97. +++ Section(header:"出差",footer:"") {
  98. $0.tag = "a2"
  99. $0.hidden = "$appealType!='出差'"
  100. }
  101. <<< TextRow("address1"){
  102. $0.title = "地点"
  103. $0.add(rule: RuleRequired())
  104. $0.validationOptions = .validatesAlways
  105. }.cellUpdate { cell, row in
  106. if !row.isValid {
  107. cell.titleLabel?.textColor = .red
  108. }
  109. }
  110. <<< DateRow("startTime1"){
  111. $0.title = "开始日期"
  112. $0.add(rule: RuleRequired())
  113. $0.validationOptions = .validatesAlways
  114. }.cellUpdate { cell, row in
  115. if !row.isValid {
  116. cell.textLabel?.textColor = .red
  117. }
  118. }
  119. <<< DateRow("endTime1"){
  120. $0.title = "结束日期"
  121. $0.add(rule: RuleRequired())
  122. $0.validationOptions = .validatesAlways
  123. }.cellUpdate { cell, row in
  124. if !row.isValid {
  125. cell.textLabel?.textColor = .red
  126. }
  127. }
  128. +++ Section(header:"因公外出",footer:"") {
  129. $0.tag = "a3"
  130. $0.hidden = "$appealType!='因公外出'"
  131. }
  132. <<< TextRow("address2"){
  133. $0.title = "地点"
  134. $0.add(rule: RuleRequired())
  135. $0.validationOptions = .validatesAlways
  136. }.cellUpdate { cell, row in
  137. if !row.isValid {
  138. cell.titleLabel?.textColor = .red
  139. }
  140. }
  141. <<< DateRow("startTime2"){
  142. $0.title = "开始日期"
  143. }.cellUpdate { cell, row in
  144. if !row.isValid {
  145. cell.textLabel?.textColor = .red
  146. }
  147. }
  148. <<< DateRow("endTime2"){
  149. $0.title = "结束日期"
  150. }.cellUpdate { cell, row in
  151. if !row.isValid {
  152. cell.textLabel?.textColor = .red
  153. }
  154. }
  155. <<< TextRow("appealReson2"){
  156. $0.title = "事由"
  157. $0.add(rule: RuleRequired())
  158. $0.validationOptions = .validatesAlways
  159. }.cellUpdate { cell, row in
  160. if !row.isValid {
  161. cell.titleLabel?.textColor = .red
  162. }
  163. }
  164. +++ Section(header:"其他",footer:"") {
  165. $0.tag = "a4"
  166. $0.hidden = "$appealType!='其他'"
  167. }
  168. <<< TextRow("appealReson3"){
  169. $0.title = "事由"
  170. $0.add(rule: RuleRequired())
  171. $0.validationOptions = .validatesAlways
  172. }.cellUpdate { cell, row in
  173. if !row.isValid {
  174. cell.titleLabel?.textColor = .red
  175. }
  176. }
  177. }
  178. func initFormStyle(){
  179. LabelRow.defaultCellUpdate = {
  180. cell,row in
  181. cell.textLabel?.font = setting_content_textFont
  182. cell.textLabel?.textColor = setting_content_textColor
  183. //cell.accessoryType = .disclosureIndicator
  184. }
  185. EmailRow.defaultCellUpdate = {
  186. cell,row in
  187. cell.textLabel?.font = setting_content_textFont
  188. cell.textLabel?.textColor = setting_content_textColor
  189. //cell.accessoryType = .disclosureIndicator
  190. }
  191. PhoneRow.defaultCellUpdate = {
  192. cell,row in
  193. cell.textLabel?.font = setting_content_textFont
  194. cell.textLabel?.textColor = setting_content_textColor
  195. //cell.accessoryType = .disclosureIndicator
  196. }
  197. TextRow.defaultCellUpdate = {
  198. cell,row in
  199. cell.textLabel?.font = setting_content_textFont
  200. cell.textLabel?.textColor = setting_content_textColor
  201. }
  202. DateRow.defaultCellUpdate = {
  203. cell,row in
  204. cell.textLabel?.font = setting_content_textFont
  205. cell.textLabel?.textColor = setting_content_textColor
  206. }
  207. ButtonRow.defaultCellUpdate = {
  208. cell,row in
  209. cell.textLabel?.font = setting_item_textFont
  210. cell.textLabel?.textColor = RGB(251, g: 71, b: 71)
  211. }
  212. ActionSheetRow<String>.defaultCellUpdate = {
  213. cell,row in
  214. cell.textLabel?.font = setting_content_textFont
  215. cell.textLabel?.textColor = setting_content_textColor
  216. }
  217. SegmentedRow<String>.defaultCellUpdate = {
  218. cell,row in
  219. cell.textLabel?.font = setting_content_textFont
  220. cell.textLabel?.textColor = setting_content_textColor
  221. cell.segmentedControl.backgroundColor = RGB(251, g: 71, b: 71)
  222. cell.segmentedControl.tintColor = UIColor.white
  223. }
  224. }
  225. override func didReceiveMemoryWarning() {
  226. super.didReceiveMemoryWarning()
  227. // Dispose of any resources that can be recreated.
  228. }
  229. func loadProcessPerson(){
  230. let account = O2AuthSDK.shared.myInfo()
  231. self.entry = AttendanceAppealInfoEntry()
  232. let url = AppDelegate.o2Collect.generateURLWithAppContextKey(ContactContext.contactsContextKey, query: ContactContext.personDirectManageQuery, parameter: ["##attribute##":"直接主管" as AnyObject,"##name##":account?.name as AnyObject])
  233. Alamofire.request(url!, method: .get, parameters: nil, encoding: JSONEncoding.default, headers: nil).responseJSON { (response) in
  234. switch response.result {
  235. case .success(let val):
  236. let type = JSON(val)["type"]
  237. if type == "success" {
  238. let data = JSON(val)["data"]
  239. let name = data["attributeList"]
  240. self.entry?.processPerson1 = name.array![0].stringValue
  241. }else{
  242. DDLogError(JSON(val).description)
  243. ProgressHUD.showError("初始化主管审批人错误")
  244. }
  245. case .failure(let err):
  246. DDLogError(err.localizedDescription)
  247. ProgressHUD.showError("初始化主管审批人错误")
  248. }
  249. }
  250. }
  251. //返回是否已经获取正常的参数
  252. func getSubmitEntry() -> Bool {
  253. let sRow:SegmentedRow<String> = form.rowBy(tag: "appealType")!
  254. var result = false
  255. result = sRow.isValid
  256. if sRow.isValid {
  257. self.entry?.appealReason = sRow.value
  258. if sRow.value == "临时请假" {
  259. let a1Row1:SegmentedRow<String> = form.rowBy(tag:"selfHolidayType")!
  260. let a1Row2:DateRow = form.rowBy(tag: "startTime")!
  261. let a1Row3:DateRow = form.rowBy(tag: "endTime")!
  262. result = a1Row1.isValid && a1Row2.isValid && a1Row3.isValid && a1Row1.value != nil && a1Row2.value != nil && a1Row3.value != nil
  263. if result {
  264. entry?.appealDescription = a1Row1.value
  265. entry?.startTime = a1Row2.value?.toString(format: "yyyy-MM-dd")
  266. entry?.endTime = a1Row3.value?.toString(format: "yyyy-MM-dd")
  267. }
  268. }else if sRow.value == "出差" {
  269. let a2Row1:TextRow = form.rowBy(tag: "address1")!
  270. let a2Row2:DateRow = form.rowBy(tag: "startTime1")!
  271. let a2Row3:DateRow = form.rowBy(tag: "endTime1")!
  272. result = a2Row1.isValid && a2Row2.isValid && a2Row3.isValid && a2Row1.value != nil && a2Row2.value != nil && a2Row3.value != nil
  273. if result {
  274. entry?.address = a2Row1.value
  275. entry?.startTime = a2Row2.value?.toString(format: "yyyy-MM-dd")
  276. entry?.endTime = a2Row3.value?.toString(format: "yyyy-MM-dd")
  277. }
  278. }else if sRow.value == "因公外出" {
  279. let a3Row4:TextRow = form.rowBy(tag: "appealReson2")!
  280. let a3Row1:TextRow = form.rowBy(tag: "address2")!
  281. let a3Row2:DateRow = form.rowBy(tag: "startTime2")!
  282. let a4Row3:DateRow = form.rowBy(tag: "endTime2")!
  283. result = a3Row1.isValid && a3Row2.isValid && a4Row3.isValid && a3Row4.isValid && a3Row1.value != nil && a3Row2.value != nil && a4Row3.value != nil && a3Row4.value != nil
  284. if result {
  285. entry?.appealDescription = a3Row4.value
  286. entry?.address = a3Row1.value
  287. entry?.startTime = a3Row2.value?.toString(format: "yyyy-MM-dd")
  288. entry?.endTime = a4Row3.value?.toString(format: "yyyy-MM-dd")
  289. }
  290. }else if sRow.value == "其他" {
  291. let a4Row1:TextRow = form.rowBy(tag: "appealReson3")!
  292. result = a4Row1.isValid && a4Row1.value != nil
  293. if result {
  294. entry?.appealDescription = a4Row1.value
  295. }
  296. }
  297. }else{
  298. }
  299. return result
  300. }
  301. @IBAction func submitAppealAction(_ sender: UIBarButtonItem) {
  302. if getSubmitEntry() == true {
  303. //设置参数
  304. let url = AppDelegate.o2Collect.generateURLWithAppContextKey(icContext.icContextKey, query: icContext.attendanceInfoQuery, parameter: ["##id##":detailData?.id as AnyObject])
  305. Alamofire.request(url!, method: .put, parameters: self.entry?.toJSON(), encoding: JSONEncoding.default, headers: nil).responseJSON { (response) in
  306. switch response.result {
  307. case .success(let val):
  308. let type = JSON(val)["type"]
  309. if type == "success" {
  310. ProgressHUD.showSuccess("提交成功")
  311. self.backDetail()
  312. }else{
  313. DDLogError(JSON(val).description)
  314. ProgressHUD.showError("申诉提交错误")
  315. }
  316. case .failure(let err):
  317. DDLogError(err.localizedDescription)
  318. ProgressHUD.showError("申诉提交错误")
  319. }
  320. }
  321. }else{
  322. ProgressHUD.showError("请设置相应的参数")
  323. }
  324. }
  325. func backDetail(){
  326. self.performSegue(withIdentifier: "unBackDetailSegue", sender: nil)
  327. }
  328. }