123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- //
- // IHGuestInfoManager.swift
- // Inhealth
- //
- // Created by weclouds on 2020/2/13.
- // Copyright © 2020 weclouds. All rights reserved.
- //
- import UIKit
- import Photos
- import AVFoundation
- import PKHUD
- let kNotifactionRegisterSuccess = "kNotifactionRegisterSuccess"
- class IHGuestInfoManager: NSObject {
- // private var vc = UIViewController()
- private weak var vc : UIViewController?
- let imagePicker = UIImagePickerController()
- lazy var mainView: IHGuestInfoView = {
- let mainView = Bundle.main.loadNibNamed("IHGuestInfoView", owner: nil, options: nil)?.last as! IHGuestInfoView
- mainView.delegate = self
- return mainView
- }()
-
- /// 懒加载
- lazy var addressPicker: IHRoomPicker = {
- // let nib = UINib(nibName: "IHRoomPicker", bundle: nil)
- // let picker = nib.instantiate(withOwner: nil, options: nil).first as! IHRoomPicker
- let picker = IHRoomPicker()
- picker.modalSize = (width: .full, height: .custom(size: 300))
- picker.modalPosition = .bottomCenter
- // picker.cornerRadius = 10
- /// 该回调方法可以在本类任意地方写
- picker.selectedRoomCompleted = { [weak self] (build, floor, room,roomId) in
- self?.mainView.roomNumber = build + "-" + floor + "-" + room
- AppShare.register_roomId = roomId
- }
- return picker
- }()
-
- func bindController(_ vc: UIViewController) {
- self.vc = vc
- createUI()
- requestdata()
- }
- deinit {
- NotificationCenter.default.removeObserver(self)
- }
-
- func createUI() {
-
- let scrollView = UIScrollView(frame: CGRect(x: 0, y: 0, width: KSCREENWIDTH, height: KSCREENHEIGHT - KNavBarHeight))
-
- self.vc?.view.addSubview(scrollView)
- scrollView.contentSize = CGSize(width: 0, height: 812)
- scrollView.addSubview(mainView)
-
- setNavigationBar()
- imagePicker.delegate = self
-
- self.imagePicker.modalPresentationStyle = .fullScreen
-
- }
-
- func setNavigationBar() {
-
- }
-
-
- func requestdata() {
- //请求酒店数据
- IHLoginService.share.getHotelList(requstSuccess: { (hotellist) in
- self.mainView.hotellist = hotellist
- }) {
-
- }
- }
-
-
- }
- extension IHGuestInfoManager:IHGuestInfoViewDelegate{
- //选择照片
- func goToPickerAvatar() {
- let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
-
- alert.addAction(UIAlertAction(title: "相册", style: .default, handler: { (button) in
- if self.checkAlbum() == true{
- self.presentToImagePickerController(.photoLibrary)
- }else{
- self.showAlart(title: "提示", message: "相册权限未启用,请进入系统[设置]>[隐私]>[照片]打开开关启用相册功能")
- }
- }))
-
- alert.addAction(UIAlertAction(title: "相机", style: .default, handler: { (button) in
- //判断是否支持使用相册
- if UIImagePickerController.isSourceTypeAvailable(.camera){
- if self.checkCamera() == true {
- self.presentToImagePickerController(.camera)
- }else{
- self.showAlart(title: "提示", message: "相机权限未开启,请进入系统[设置]>[隐私]>[相机]打开开关,开启相机功能")
- return
- }
- }else{
- g_showHUD("该设备不支持拍照功能")
- }
- }))
-
- alert.addAction(UIAlertAction(title: "取消", style: .cancel, handler: nil))
-
- self.vc?.present(alert, animated: true, completion: nil)
- }
-
- func presentToImagePickerController(_ type : UIImagePickerController.SourceType) {
- self.imagePicker.sourceType = type
- self.vc?.present(self.imagePicker, animated: true, completion: nil)
- }
-
- func showAlart(title:String,message:String) {
- let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
- let action = UIAlertAction(title: "I know", style: .default) { (action) in
-
- }
- alert.addAction(action)
- self.vc?.present(alert, animated: true, completion: nil)
-
- }
- func checkAlbum() -> Bool {
- let status = PHPhotoLibrary.authorizationStatus()
- if status == .denied || status == .restricted {
- return false
- }
- return true
- }
- func checkCamera() -> Bool {
- let status = AVCaptureDevice.authorizationStatus(for: .video)
- if status == .restricted || status == .denied {
-
- return false
- }
- return true
- }
-
- func guestInfoConfirm(_ name: String, age: String) {
- if AppShare.register_roomId == "" {
- g_showHUD("请选择您的房间")
- return
- }
-
- if AppShare.register_avatar == "" {
- g_showHUD("请选择您的头像")
- return
- }
- let username = AppShare.register_username
- let password = AppShare.register_password
- let name = AppShare.register_name
- let age = AppShare.register_age
- let roomId = AppShare.register_roomId
- let avatar = AppShare.register_avatar
- IHLoginService.share.registerUser(username, password: password, name: name, age: age, roomId: roomId, avatar: avatar) {
- log.debug("guestInfoConfirm")
- let success = IHSignupSuccess()
- success.show(above: self.vc, completion: nil)
- NotificationCenter.default.post(name: NSNotification.Name(kNotifactionRegisterSuccess), object: username)
- }
- }
-
- func guestInfoConfirm() {
- }
-
-
- func selectedHotel(hotelId: String) {
- addressPicker.hotelId = hotelId
- // picker.hotelId = hotelId
- }
- //选择题房间信息
- func goToselectedRoomNumber(_ hotelId :String?) {
- addressPicker.hotelId = hotelId
- self.vc?.present(addressPicker, animated: true, completion: nil)
- // self.vc.present(picker, animated: true, completion: nil)
- }
-
-
- }
- //MARK : UIImagePickerControllerDelegate
- extension IHGuestInfoManager : UIImagePickerControllerDelegate, UINavigationControllerDelegate {
- func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
- guard let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage else { return }
- //imageView.image = pickedImage
- log.debug("pickedImage - \(pickedImage)")
- NotificationCenter.default.post(name: NSNotification.Name(kIHwGuestInfoNotificationGetDeviceImage), object: pickedImage)
- self.vc?.dismiss(animated: true, completion: nil)
- //上传图片
- //let imageData = pickedImage.pngData()
- HUD.show(.progress)
- IHNewEquipmentService.share.uploadImage(file: pickedImage, requestSuccess: { (path) in
- log.debug("图片地址 - \(path)")
- AppShare.register_avatar = path
- NotificationCenter.default.post(name: NSNotification.Name(kNotifactionIHGuestInfoUploadImageFinished), object: path)
- HUD.flash(.success, delay: 1)
- }) {
- log.debug("上传失败")
- HUD.flash(.error, delay: 1)
- }
-
- }
-
- }
|