SelfMentionContactsListViewController.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // SelfMentionContactsListViewController.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/4/25.
  6. // Copyright © 2019 南鑫林. All rights reserved.
  7. //
  8. import UIKit
  9. class SelfMentionContactsListViewController: BaseViewController {
  10. var selfMentionContactsModels : Array<SelfMentionContactsModel>?
  11. // 是否由支付订单页面进入
  12. var isFromOrderPay: Bool = false
  13. override func viewDidLoad() {
  14. super.viewDidLoad()
  15. setupViews()
  16. setupLayouts()
  17. setupData()
  18. }
  19. override func setupViews() {
  20. navigationBar.title = "我的自提收货信息"
  21. navigationBar.wr_setRightButton(title: "添加新收货人", titleColor: k333333Color)
  22. navigationBar.rightButton.titleLabel!.font = kRegularFont14
  23. navigationBar.onClickRightButton = {
  24. [weak self] in
  25. self?.pushEditSelfMention()
  26. }
  27. view.addSubview(selfMentionContactsListView)
  28. }
  29. override func setupLayouts() {
  30. selfMentionContactsListView.snp.makeConstraints { (make) in
  31. make.top.equalTo(kNavBarTotalHeight)
  32. make.left.right.bottom.equalToSuperview()
  33. }
  34. }
  35. override func setupData() {
  36. self.selfMentionContactsListView
  37. .tableView
  38. .addHeaderWithHeader(withBeginRefresh: true, animation: false) {
  39. [weak self] (data) in
  40. self?.userExpreesContactsListApi()
  41. }
  42. }
  43. private lazy var selfMentionContactsListView: SelfMentionContactsListView = {
  44. let selfMentionContactsListView = SelfMentionContactsListView()
  45. selfMentionContactsListView.editClosure = { //编辑,新增
  46. [weak self] selfMentionContactsModel in
  47. self?.pushEditSelfMention(selfMentionContactsModel: selfMentionContactsModel)
  48. }
  49. selfMentionContactsListView.didSelectRowClosure = {
  50. [weak self] indexPath in
  51. let selfMentionContactsModel = self?.selfMentionContactsModels?[indexPath.row]
  52. self?.userSetExpreesContactsDefaultApi(id: selfMentionContactsModel?.id ?? 0)
  53. }
  54. return selfMentionContactsListView
  55. }()
  56. /// 修改/新建
  57. ///
  58. /// - Parameter selfMentionContactsModel: 修改个人信息
  59. func pushEditSelfMention(selfMentionContactsModel:SelfMentionContactsModel? = nil) -> Void {
  60. let vc = EditSelfMentionContactsViewController()
  61. vc.saveClosure = {
  62. [weak self] in
  63. self?.userExpreesContactsListApi()
  64. }
  65. if let selfMentionContactsModel = selfMentionContactsModel {
  66. vc.selfMentionContactsModel = selfMentionContactsModel
  67. }
  68. self.navigationController?.pushViewController(vc, animated: true)
  69. }
  70. /// 自提收货人信息
  71. func userExpreesContactsListApi() {
  72. SwiftMoyaNetWorkServiceUser.shared().userExpreesContactsListApi {
  73. [weak self] (contactListModel) -> (Void) in
  74. let originMdl = contactListModel as? ContactListModel
  75. self?.selfMentionContactsModels = originMdl?.list
  76. self?.selfMentionContactsListView.selfMentionContactsModels = self?.selfMentionContactsModels
  77. }
  78. }
  79. /// 自提点收货人信息,设置默认
  80. func userSetExpreesContactsDefaultApi(id:Int = 0) {
  81. SwiftMoyaNetWorkServiceUser.shared().userSetExpreesContactsDefaultApi(id: id, completion: {
  82. [weak self] (data) -> (Void) in
  83. if self!.isFromOrderPay {
  84. self?.navigationController?.popViewController(animated: true)
  85. } else {
  86. self?.userExpreesContactsListApi()
  87. }
  88. })
  89. }
  90. }