169 lines
5.6 KiB
Swift
169 lines
5.6 KiB
Swift
//
|
||
// SearchLocationResultVC.swift
|
||
// QuickLocation
|
||
//
|
||
|
||
import UIKit
|
||
import RxSwift
|
||
import RxCocoa
|
||
import ObjectMapper
|
||
import URLNavigator
|
||
|
||
class SearchLocationResultVC: BaseViewController {
|
||
|
||
fileprivate var rootView: SearchLocationResultView!
|
||
|
||
override func loadView() {
|
||
rootView = SearchLocationResultView(frame: UIScreen.main.bounds)
|
||
view = rootView
|
||
}
|
||
|
||
private let phone: String
|
||
private let code: Int
|
||
private let memberData: [String: Any]
|
||
private var groupModel: GroupModel?
|
||
|
||
override func viewDidLoad() {
|
||
super.viewDidLoad()
|
||
reactiveAction()
|
||
applyResultPresentation()
|
||
requestPhoneArea()
|
||
}
|
||
|
||
override func viewWillAppear(_ animated: Bool) {
|
||
super.viewWillAppear(animated)
|
||
rootView.startMarqueeAnimation()
|
||
applyResultPresentation()
|
||
}
|
||
|
||
private func isVipUnlocked() -> Bool {
|
||
AppContextManager.shared.vip > 1
|
||
}
|
||
|
||
private func applyResultPresentation() {
|
||
handleCode()
|
||
let isVip = isVipUnlocked()
|
||
rootView.areaBlurView.isHidden = isVip
|
||
if !isVip {
|
||
rootView.actionBtn.setTitle("开通会员", for: .normal)
|
||
rootView.actionBtn.isHidden = false
|
||
}
|
||
}
|
||
|
||
private func reactiveAction() {
|
||
rootView.actionBtn.rx.tap.subscribe(onNext: { _ in
|
||
guard self.isVipUnlocked() else {
|
||
AppRouter.push(Route.vipRecharge)
|
||
return
|
||
}
|
||
switch self.code {
|
||
case 0:
|
||
NotificationCenter.default.post(name: .ShowMemberLocationNotification,
|
||
object: nil,
|
||
userInfo: self.memberData)
|
||
self.navigationController?.popToRootViewController(animated: true)
|
||
if let tab = self.tabBarController as? MainTabBarController
|
||
?? UIViewController.topMost?.tabBarController as? MainTabBarController {
|
||
tab.selectTab(at: 0)
|
||
}
|
||
case 20004:
|
||
SharePopView.show()
|
||
case 20005:
|
||
self.showGroupPicker()
|
||
default:
|
||
break
|
||
}
|
||
}).disposed(by: disposeBag)
|
||
}
|
||
|
||
private func showGroupPicker() {
|
||
guard let model = groupModel else {
|
||
requestGroupInfo(showPicker: true)
|
||
return
|
||
}
|
||
presentGroupPicker(with: model)
|
||
}
|
||
|
||
private func presentGroupPicker(with model: GroupModel) {
|
||
GroupListPopView.show(groupModel: model) { groupKey in
|
||
guard let key = groupKey,
|
||
let groupInfo = model.groups.first(where: { $0.group_key == key })?.toJSON() else { return }
|
||
AppRouter.push(Route.inviteJoin, userInfo: ["groupInfo": groupInfo])
|
||
}
|
||
}
|
||
|
||
private func shareApp() {
|
||
let text = "快来极速定位,实时守护家人出行安全"
|
||
let activity = UIActivityViewController(activityItems: [text], applicationActivities: nil)
|
||
present(activity, animated: true)
|
||
}
|
||
|
||
private func handleCode() {
|
||
rootView.actionBtn.isHidden = true
|
||
rootView.inviteView.isHidden = true
|
||
|
||
switch code {
|
||
case 0:
|
||
rootView.configureResult(
|
||
status: "定位成功",
|
||
disclaimer: "点击去查看可获得具体位置",
|
||
showInviteRow: false
|
||
)
|
||
rootView.actionBtn.setTitle("去查看", for: .normal)
|
||
rootView.actionBtn.isHidden = false
|
||
case 20004:
|
||
rootView.configureResult(
|
||
status: "用户未注册",
|
||
disclaimer: "根据最新的相关法规,需用户双方均安装该APP才可实现定位,未安装APP的用户将不再提供具体定位功能。",
|
||
showInviteRow: false
|
||
)
|
||
rootView.actionBtn.setTitle("分享", for: .normal)
|
||
rootView.actionBtn.isHidden = false
|
||
case 20005:
|
||
rootView.configureResult(
|
||
status: "定位成功",
|
||
disclaimer: "根据最新的相关法规,您查询的用户与您不在同一个圈子时, 不再提供具体的位置定位,邀请ta加入你的圈子后可随时查看位置。",
|
||
showInviteRow: false
|
||
)
|
||
rootView.actionBtn.setTitle("邀请TA加入", for: .normal)
|
||
rootView.actionBtn.isHidden = false
|
||
if groupModel == nil {
|
||
requestGroupInfo()
|
||
}
|
||
default:
|
||
break
|
||
}
|
||
}
|
||
|
||
private func requestPhoneArea() {
|
||
SystemService.phoneArea(phone: phone).subscribe(onNext: { response in
|
||
guard let data = response.data else { return }
|
||
let province = data["Province"].safeString
|
||
let city = data["City"].safeString
|
||
self.rootView.phoneAreaLab.text = "\(province)·\(city)"
|
||
self.applyResultPresentation()
|
||
}).disposed(by: disposeBag)
|
||
}
|
||
|
||
private func requestGroupInfo(showPicker: Bool = false) {
|
||
GroupService.groupInfo().subscribe { [weak self] response in
|
||
guard let self = self, let model = response.model else { return }
|
||
self.groupModel = model
|
||
if showPicker {
|
||
self.presentGroupPicker(with: model)
|
||
}
|
||
}.disposed(by: disposeBag)
|
||
}
|
||
|
||
init(phone: String, code: Int, memberData: [String: Any] = [:]) {
|
||
self.phone = phone
|
||
self.code = code
|
||
self.memberData = memberData
|
||
super.init(nibName: nil, bundle: nil)
|
||
}
|
||
|
||
required init?(coder: NSCoder) {
|
||
fatalError("init(coder:) has not been implemented")
|
||
}
|
||
}
|