IHNewRoomService.swift 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // IHNewRoomService.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2019/12/31.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. import PKHUD
  10. struct NewRoomInfo {
  11. var floorId :String?
  12. var floorName:String?
  13. var number:String?
  14. var sn:String?
  15. var image:String?
  16. var pickImage:UIImage?
  17. var deviceList:[EquipmentInfo]?
  18. }
  19. enum IHNewRoomViewEditError {
  20. case success
  21. case lackImage
  22. case lackRoomName
  23. case lackSN
  24. case lackEquipment
  25. }
  26. class IHNewRoomService: NSObject {
  27. static let share = IHNewRoomService()
  28. func editRoomInfo(buildId:String, roomInfo :NewRoomInfo,roomId: String?,requestSuccess:@escaping ()->Void) {
  29. log.debug("editRoomInfo = \(roomInfo) ")
  30. let username = AppShare.username
  31. let client_key = AppShare.client_key
  32. let os = AppShare.os
  33. let version = AppShare.version
  34. let token = AppShare.token
  35. let floor = roomInfo.floorId!
  36. let number = roomInfo.number!
  37. let sn = roomInfo.sn!
  38. let image = roomInfo.image!
  39. let equipments = roomInfo.deviceList
  40. var optionalDict :[[String:String]]? = nil
  41. if equipments != nil {
  42. var deviceList:[[String:String]] = [[String:String]] ()
  43. for equipmentArr in equipments!{
  44. let equipmentDict = ["name":equipmentArr.deviceName!,
  45. "deviceId":equipmentArr.deviceID!,
  46. "image":equipmentArr.imagePath ?? "",// 可以为空
  47. "devType":equipmentArr.deviceType!]
  48. deviceList.append(equipmentDict)
  49. }
  50. optionalDict = deviceList
  51. }
  52. //HUD.show(.progress)
  53. g_room_save_roomHttpRequest(username, client_key: client_key, os: os, version: version, token: token, buildId: buildId, floor: floor, number: number, sn: sn, image: image, roomId: roomId, optionalDict: optionalDict, success: { (json) -> (Void) in
  54. let opitonInfo = Operation_Info.fromJSON(json)
  55. log.debug("json - \(json)")
  56. let result = opitonInfo?.result
  57. let msg = result?.msg
  58. if result?.code == .Success{
  59. // HUD.flash(.labeledSuccess(title: nil, subtitle: "Added room successfully"), delay: 1)
  60. requestSuccess()
  61. }else{
  62. HUD.flash(.labeledError(title: nil, subtitle: msg), delay: 2)
  63. }
  64. }) { () -> (Void) in
  65. // HUD.flash(.labeledError(title: nil, subtitle: "Network Error"), delay: 2)
  66. }
  67. }
  68. }