//
|
// MineContactCustomerServiceVC.swift
|
// OKProject
|
//
|
// Created by alvin_y on 2020/6/17.
|
// Copyright © 2020 yangwang. All rights reserved.
|
//
|
|
import UIKit
|
|
/// 联系客服
|
class MineContactCustomerServiceVC: YYTableViewController {
|
|
/// 数据源
|
private let dataSource = ["平台客服","本地客服"]
|
|
let viewModel = MineContactCustomerServiceViewModel()
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
|
// Do any additional setup after loading the view.
|
viewModel.queryCustomerPhone()
|
}
|
|
//MARK: - UI
|
override func setupViews() {
|
super.setupViews()
|
navigationItem.title = "联系客服"
|
tableView.delegate = self
|
tableView.dataSource = self
|
tableView.tableFooterView = UIView()
|
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "item")
|
tableView.separatorColor = UIColor.color(light: UIColor.color(hexString: "#F6F6F6"), dark: UIColor.color(hexString: "#F6F6F6"))
|
}
|
|
//MARK: - Rx
|
override func bindRx() {
|
super.bindRx()
|
/// 获取客服电话
|
viewModel.requestSubject
|
.subscribe(onNext: {[unowned self] (status) in
|
switch status{
|
case .loading:
|
self.show()
|
break
|
case .success(_):
|
self.hide()
|
self.tableView.reloadData()
|
break
|
case .error(let error):
|
self.hide()
|
alert(text: error.localizedDescription)
|
break
|
}
|
}).disposed(by: rx.disposeBag)
|
}
|
|
}
|
// MARK: - UITableViewDelegate
|
extension MineContactCustomerServiceVC:UITableViewDelegate{
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
return 50
|
}
|
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
tableView.deselectRow(at: indexPath, animated: true)
|
switch dataSource[indexPath.row] {
|
case "平台客服":
|
guard self.viewModel.platform.value != "" else{return}
|
call(number: self.viewModel.platform.value)
|
break
|
case "本地客服":
|
guard self.viewModel.company.value != "" else{return}
|
call(number: self.viewModel.company.value)
|
break
|
default:
|
break
|
}
|
}
|
}
|
|
// MARK: - UITableViewDelegate
|
extension MineContactCustomerServiceVC:UITableViewDataSource{
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
return dataSource.count
|
}
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
let cell = tableView.dequeueReusableCell(withIdentifier: "item", for: indexPath)
|
cell.textLabel?.text = dataSource[indexPath.row]
|
cell.textLabel?.font = Medium(font: 14)
|
cell.textLabel?.textColor = UIColor.color(light: UIColor.color(hexString: "#333333"), dark: UIColor.color(hexString: "#333333"))
|
cell.separatorInset = UIEdgeInsets(top: 0, left: 14, bottom: 0, right: 14)
|
let label_phone = UILabel()
|
label_phone.textColor = UIColor.color(light: UIColor.color(hexString: "#333333"), dark: UIColor.color(hexString: "#333333"))
|
label_phone.font = Medium(font: 14)
|
cell.contentView.addSubview(label_phone)
|
label_phone.snp.makeConstraints { (make) in
|
make.right.equalToSuperview().offset(-14)
|
make.centerY.equalToSuperview()
|
}
|
label_phone.attributedText = dataSource[indexPath.row] == "平台客服" ? AttributedStringbuilder.build().add(string: self.viewModel.platform.value, withFont: Medium(font: 14), withColor: UIColor.color(light: UIColor.color(hexString: "#333333"), dark: UIColor.color(hexString: "#333333"))).mutableAttributedString : AttributedStringbuilder.build().add(string: "\(self.viewModel.company.value) ", withFont: Medium(font: 14), withColor: UIColor.color(light: UIColor.color(hexString: "#333333"), dark: UIColor.color(hexString: "#333333"))).attach(image: UIImage.init(named: "icon_phone_green")!).mutableAttributedString
|
return cell
|
}
|
}
|