1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- //
- // IHNewRoomService.swift
- // Inhealth
- //
- // Created by weclouds on 2019/12/31.
- // Copyright © 2019 weclouds. All rights reserved.
- //
- import UIKit
- import PKHUD
- struct NewRoomInfo {
- var floorId :String?
- var floorName:String?
- var number:String?
- var sn:String?
- var image:String?
- var pickImage:UIImage?
- var deviceList:[EquipmentInfo]?
- }
- enum IHNewRoomViewEditError {
- case success
- case lackImage
- case lackRoomName
- case lackSN
- case lackEquipment
-
- }
- class IHNewRoomService: NSObject {
- static let share = IHNewRoomService()
-
- func editRoomInfo(buildId:String, roomInfo :NewRoomInfo,roomId: String?,requestSuccess:@escaping ()->Void) {
- log.debug("editRoomInfo = \(roomInfo) ")
- let username = AppShare.username
- let client_key = AppShare.client_key
- let os = AppShare.os
- let version = AppShare.version
- let token = AppShare.token
- let floor = roomInfo.floorId!
- let number = roomInfo.number!
- let sn = roomInfo.sn!
- let image = roomInfo.image!
- let equipments = roomInfo.deviceList
-
- var optionalDict :[[String:String]]? = nil
- if equipments != nil {
- var deviceList:[[String:String]] = [[String:String]] ()
- for equipmentArr in equipments!{
- let equipmentDict = ["name":equipmentArr.deviceName!,
- "deviceId":equipmentArr.deviceID!,
- "image":equipmentArr.imagePath ?? "",// 可以为空
- "devType":equipmentArr.deviceType!]
- deviceList.append(equipmentDict)
- }
- optionalDict = deviceList
- }
- //HUD.show(.progress)
- 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
-
- let opitonInfo = Operation_Info.fromJSON(json)
- log.debug("json - \(json)")
- let result = opitonInfo?.result
- let msg = result?.msg
- if result?.code == .Success{
-
- // HUD.flash(.labeledSuccess(title: nil, subtitle: "Added room successfully"), delay: 1)
- requestSuccess()
- }else{
- HUD.flash(.labeledError(title: nil, subtitle: msg), delay: 2)
- }
- }) { () -> (Void) in
- // HUD.flash(.labeledError(title: nil, subtitle: "Network Error"), delay: 2)
- }
- }
-
- }
|