| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456 |
- //
- // CustomerInfoViewController.swift
- // MTP2_iOS
- //
- // Created by Muchinfo on 2021/1/2.
- // Copyright © 2021 Muchinfo. All rights reserved.
- //
- import UIKit
- import JXSegmentedView
- import IBAnimatable
- import GTMRefresh
- import WHToast
- import ZLPhotoBrowser
- import NVActivityIndicatorView
- /// 客户资料视图容器控制类
- class CustomerInfoViewController: BaseViewController {
- // MARK: - 属性列表
- /// 新增合同按钮
- @IBOutlet weak var new: UIBarButtonItem!
- /// 类目
- @IBOutlet weak var segmentedView: JXSegmentedView! {
- didSet {
- segmentedView.dataSource = dataSource
- segmentedView.indicators = [indicator]
- segmentedView.delegate = self
- }
- }
- /// 列表
- @IBOutlet weak var tableView: UITableView! {
- didSet {
- tableView.reloadData()
- }
- }
-
- /// CellIdentifier
- let CellIdentifier = "CustomerInfo_Cell"
-
- /// 选中的位置
- var selectedIndex: (row: Int, isExpland: Bool)? {
- didSet {
- if let index = selectedIndex {
- /// 刷新某一行
- tableView.reloadRows(at: [IndexPath(row: index.row, section: 0)], with: .automatic)
- } else {
- if let cell = tableView.visibleCells.first(where: { (obj) -> Bool in
- return (obj as? CustomerInfoCell)?.isExpland ?? false
- }) as? CustomerInfoCell {
- cell.isExpland = false
- }
- }
- if let old = oldValue,
- let cell = (tableView.cellForRow(at: IndexPath(row: old.row, section: 0)) as? CustomerInfoCell) {
- cell.isExpland = false
- }
- }
- }
- /// 客户资料数据
- var userInfos: [MoUserInfo] = [] {
- didSet {
- /// 刷新数据
- tableView.reloadData()
- /// isHidden
- noDataButton.isHidden = userInfos.count != 0
- }
- }
-
- /// 权限功能
- var roleTitles: [String] {
- get {
- var titles: [String] = []
- /// 权限控制
- guard let commonManager = MTP2BusinessCore.shared.commonManager else {
- return titles
- }
- if commonManager.containMenu(key: "client_customer_unsubmit") {
- titles.append("未提交")
- }
- if commonManager.containMenu(key: "client_customer_unaduit") {
- titles.append("待审核")
- }
- if commonManager.containMenu(key: "client_customer_normal") {
- titles.append("正常")
- }
- if commonManager.containMenu(key: "client_customer_stop") {
- titles.append("停用")
- }
- return titles
- }
- }
-
- // MARK: - 生命周期
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view.
- }
-
- override func loadView() {
- super.loadView()
-
- /// 判断其权限控制
- guard let commonManager = MTP2BusinessCore.shared.commonManager else { return }
-
- /// 没有新增客户资料权限
- if !commonManager.containMenu(key: "client_customer_add") {
- new.image = nil
- new.isEnabled = false
- } else {
- new.image = UIImage(named: "new_customer")
- new.isEnabled = true
- }
-
- /// titles
- dataSource.titles = roleTitles
- segmentedView.reloadData()
-
- /// addLoadingView
- addLoadingView()
-
- if roleTitles.count != 0 {
- /// 添加下拉刷新控件
- tableView.gtm_addRefreshHeaderView(refreshHeader: DefaultGTMRefreshHeader()) {
- switch self.roleTitles[self.segmentedView.selectedIndex] {
- case "未提交": /// 未提交
- self.queryCustomerInfo(1)
- case "待审核": /// 待审核
- self.queryCustomerInfo(2)
- case "正常": /// 正常
- self.queryCustomerInfo(3)
- default: /// 停用
- self.queryCustomerInfo(4)
- }
- self.selectedIndex = nil
- }
- /// 默认选中第一个
- segmentedView.defaultSelectedIndex = 0
- segmentedView.delegate?.segmentedView(segmentedView, didSelectedItemAt: 0)
- }
- }
-
- // MARK: - 接口请求
- /// queryUserInfo
- /// - Parameter querytype: 查询类型 1:未提交(网上开户表) 2:待审核(网上开户表) 3:正常 4:停用
- fileprivate func queryCustomerInfo(_ querytype: Int) {
- /// 异常
- guard let spotManager = MTP2BusinessCore.shared.spotManager else { return }
- /// startAnimating
- _anim?.startAnimating()
- /// 发送请求
- spotManager.queryCustomerInfo(querytype: querytype, userinfotype: nil, customername: nil, nickname: nil, includesub: nil) { isSuccess, er, objs in
- DispatchQueue.main.async {
- /// stopAnimating
- self._anim?.stopAnimating()
- /// endRefreshing
- self.tableView.endRefreshing()
- /// 查询失败
- if !isSuccess {
- self.userInfos = []
- WHToast.showMessage("数据查询失败,原因:\(er?.retMsg ?? "请求超时")", duration: ToastTimer, finishHandler: {})
- return
- }
- /// 数据赋值
- self.userInfos = objs ?? []
- }
- }
- }
-
- /// 更新用户状态
- /// - Parameter status: status
- /// - Parameter accountStatus: 账户状态 - 4:正常 6:注销(停用
- /// - Parameter userID: 用户ID
- fileprivate func requestUpdateUserAccountStatus(_ accountStatus: Int, _ userID: Int) {
- /// 异常
- guard let spotManager = MTP2BusinessCore.shared.spotManager else { return }
- /// startAnimating
- _anim?.startAnimating()
- /// 发送请求
- spotManager.requestUpdateUserAccountStatus(userID: userID, accountStatus: accountStatus) { (isSuccess, er) in
- DispatchQueue.main.async {
- /// stopAnimating
- self._anim?.stopAnimating()
- /// endRefreshing
- self.tableView.endRefreshing()
- /// 查询失败
- if !isSuccess {
- WHToast.showMessage("数据查询失败,原因:\(er?.retMsg ?? "请求超时")", duration: ToastTimer, finishHandler: {})
- return
- }
- /// 刷新数据
- self.tableView.triggerRefreshing()
- }
- }
- }
-
- /// 删除客户申请
- /// - Parameter userID: 用户ID
- fileprivate func deleteUserInfoApply(_ userID: Int) {
- /// 异常
- guard let spotManager = MTP2BusinessCore.shared.spotManager else { return }
- /// startAnimating
- NVActivityIndicatorPresenter.sharedInstance.startAnimating(animData("删除请求中..."))
- /// 删除
- spotManager.deleteUserInfoApply(userID: userID) { (isSuccess, er) in
- DispatchQueue.main.async {
- /// stopAnimating
- NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
- /// 查询失败
- if !isSuccess {
- WHToast.showMessage("数据查询失败,原因:\(er?.retMsg ?? "请求超时")", duration: ToastTimer, finishHandler: {})
- return
- }
- /// 刷新数据
- self.tableView.triggerRefreshing()
- }
- }
- }
-
- // MARK: - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- // Get the new view controller using segue.destination.
- // Pass the selected object to the new view controller.
- /// 客户详情信息
- if segue.identifier == "ShowCustomerInfoDetail", let d = segue.destination as? CustomerInfoDetailViewController, let row = selectedIndex?.row {
- d.takeInfo = userInfos[row]
- /// 执行回调
- d.popBlock = { (_ takeInfo: Any?) in
- /// 跳转到待审核
- self.segmentedView.selectItemAt(index: 1)
- /// didSelectedItemAt
- self.segmentedView.delegate?.segmentedView(self.segmentedView, didSelectedItemAt: 1)
- }
- d.navigationItem.title = (sender as? UIButton)?.currentTitle
- } else if segue.identifier == "ShowNewCustomerInfo", let n = segue.destination as? NewCustomerInfoViewController {
- /// 新增、修改、重新提交
- if let _ = sender as? UIBarButtonItem {
- n.operatorType = .add
- } else {
- n.operatorType = .update
- n.takeInfo = userInfos[selectedIndex?.row ?? 0]
- }
- /// 执行回调
- n.popBlock = { (_ takeInfo: Any?) in
- if let type = takeInfo as? OperatorType {
- /// 跳转到待审核
- self.segmentedView.selectItemAt(index: type == .saveDrafts ? 0 : 1)
- /// didSelectedItemAt
- self.segmentedView.delegate?.segmentedView(self.segmentedView, didSelectedItemAt: type == .saveDrafts ? 0 : 1)
- }
- }
- }
- }
- }
- // MARK: - JXSegmentedViewDelegate
- extension CustomerInfoViewController: JXSegmentedViewDelegate {
- /// didSelectedItemAt
- /// - Parameters:
- /// - segmentedView: segmentedView
- /// - index: index
- func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
- switch roleTitles[index]{
- case "未提交":
- queryCustomerInfo(1)
- case "待审核":
- queryCustomerInfo(2)
- case "正常":
- queryCustomerInfo(3)
- default:
- queryCustomerInfo(4)
- }
- selectedIndex = nil
- }
- }
- extension CustomerInfoViewController: UITableViewDelegate, UITableViewDataSource {
-
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return userInfos.count
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: CellIdentifier, for: indexPath) as! CustomerInfoCell
- cell.model = userInfos[indexPath.row]
- /// 执行回调
- cell.block = { (_ model: MoUserInfo?, _ sender: Any?) in
- if let button = sender as? UIButton {
- switch button.currentTitle {
- case "恢复":
- if let obj = model { self.requestUpdateUserAccountStatus(4, Int(obj.userid)) }
- case "删除":
- if let obj = model { self.deleteUserInfoApply(Int(obj.userid)) }
- default: break
- }
- }
- }
- return cell
- }
-
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- if indexPath.row == (selectedIndex?.row ?? 0) {
- selectedIndex = (row: indexPath.row, !(selectedIndex?.isExpland ?? false))
- } else {
- selectedIndex = (row: indexPath.row, true)
- }
- (tableView.cellForRow(at: indexPath) as! CustomerInfoCell).isExpland = selectedIndex?.isExpland ?? false
- }
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return (selectedIndex?.row == indexPath.row && selectedIndex?.isExpland == true) ? 90.0 : 55.0
- }
- }
- class CustomerInfoCell: BaseTableViewCell<MoUserInfo> {
-
- /// 客户类型
- @IBOutlet weak var customerType: UILabel!
- /// 箭头
- @IBOutlet weak var arrow: AnimatableImageView!
- /// 企业名称
- @IBOutlet weak var enterpriseName: UILabel!
- /// 联系人手机
- @IBOutlet weak var mobilePhone: UILabel!
- /// 状态
- @IBOutlet weak var status: UILabel!
- /// 审核
- @IBOutlet weak var aduit: UIButton! {
- didSet {
- aduit.isHidden = true
- }
- }
- /// 修改
- @IBOutlet weak var update: UIButton! {
- didSet {
- update.isHidden = true
- }
- }
- /// 撤销
- @IBOutlet weak var cancel: UIButton! {
- didSet {
- cancel.isHidden = true
- }
- }
- /// 详情
- @IBOutlet weak var detail: UIButton!
- /// 重新提交
- @IBOutlet weak var reSubmit: UIButton! {
- didSet {
- reSubmit.isHidden = true
- }
- }
- /// 停用
- @IBOutlet weak var stop: UIButton! {
- didSet {
- stop.isHidden = true
- }
- }
- /// 恢复
- @IBOutlet weak var restore: UIButton! {
- didSet {
- restore.isHidden = true
- }
- }
- /// 删除
- @IBOutlet weak var delete: UIButton! {
- didSet {
- delete.isHidden = true
- }
- }
-
- /// 是否拓展
- override var isExpland: Bool {
- didSet {
- arrow.image = UIImage(named: isExpland ? "arrow_up" : "arrow_down")
- }
- }
- /// 数据
- override var model: MoUserInfo? {
- didSet {
- /// 异常
- guard let commonManager = MTP2BusinessCore.shared.commonManager,
- let obj = model else { return }
- /// 客户类型
- customerType.text = obj.userinfotype == .enterprise ? "企业" : "个人"
- /// 企业简称
- enterpriseName.text = obj.userinfotype == .personal ? obj.username.isBlank() : obj.nickname.isBlank()
- /// 联系人手机
- mobilePhone.text = obj.mobile.isBlank()
- /// 状态
- status.text = obj.status.description
-
- /// 判断其权限控制
- switch model?.status {
- case .ACCOUNTSTATUS_INACTIVE:
- /// 未提交
- cancel.isHidden = true
- aduit.isHidden = true
- restore.isHidden = true
- update.isHidden = !commonManager.containMenu(key: "client_customer_update")
- stop.isHidden = true
- reSubmit.isHidden = true
- delete.isHidden = false
- case .ACCOUNTSTATUS_PENDINGAUDIT:
- /// 待审核
- cancel.isHidden = !commonManager.containMenu(key: "client_customer_cancel")
- aduit.isHidden = !commonManager.containMenu(key: "client_customer_check")
- restore.isHidden = true
- update.isHidden = true
- stop.isHidden = true
- reSubmit.isHidden = true
- delete.isHidden = true
- case .ACCOUNTSTATUS_REJECT:
- /// 审核拒绝
- cancel.isHidden = true
- aduit.isHidden = true
- restore.isHidden = true
- update.isHidden = true
- stop.isHidden = true
- reSubmit.isHidden = !commonManager.containMenu(key: "client_customer_recommit")
- delete.isHidden = true
- case .ACCOUNTSTATUS_NORMAL:
- /// 正常
- cancel.isHidden = true
- aduit.isHidden = true
- restore.isHidden = true
- update.isHidden = true
- stop.isHidden = !commonManager.containMenu(key: "client_customer_disable")
- reSubmit.isHidden = true
- delete.isHidden = true
- default:
- /// 停用
- cancel.isHidden = true
- aduit.isHidden = true
- restore.isHidden = !commonManager.containMenu(key: "client_customer_restore")
- update.isHidden = true
- stop.isHidden = true
- reSubmit.isHidden = true
- delete.isHidden = true
- }
- }
- }
-
- // MARK: - 交互相关
- /// onButtonPressed
- /// - Parameter sender: sender
- @IBAction fileprivate func onButtonPressed(_ sender: UIControl) {
- /// 执行回调
- if let bk = block {
- bk(model, sender as? UIButton)
- }
- }
- }
|