CustomerInfoViewController.swift 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. //
  2. // CustomerInfoViewController.swift
  3. // MTP2_iOS
  4. //
  5. // Created by Muchinfo on 2021/1/2.
  6. // Copyright © 2021 Muchinfo. All rights reserved.
  7. //
  8. import UIKit
  9. import JXSegmentedView
  10. import IBAnimatable
  11. import GTMRefresh
  12. import WHToast
  13. import ZLPhotoBrowser
  14. import NVActivityIndicatorView
  15. /// 客户资料视图容器控制类
  16. class CustomerInfoViewController: BaseViewController {
  17. // MARK: - 属性列表
  18. /// 新增合同按钮
  19. @IBOutlet weak var new: UIBarButtonItem!
  20. /// 类目
  21. @IBOutlet weak var segmentedView: JXSegmentedView! {
  22. didSet {
  23. segmentedView.dataSource = dataSource
  24. segmentedView.indicators = [indicator]
  25. segmentedView.delegate = self
  26. }
  27. }
  28. /// 列表
  29. @IBOutlet weak var tableView: UITableView! {
  30. didSet {
  31. tableView.reloadData()
  32. }
  33. }
  34. /// CellIdentifier
  35. let CellIdentifier = "CustomerInfo_Cell"
  36. /// 选中的位置
  37. var selectedIndex: (row: Int, isExpland: Bool)? {
  38. didSet {
  39. if let index = selectedIndex {
  40. /// 刷新某一行
  41. tableView.reloadRows(at: [IndexPath(row: index.row, section: 0)], with: .automatic)
  42. } else {
  43. if let cell = tableView.visibleCells.first(where: { (obj) -> Bool in
  44. return (obj as? CustomerInfoCell)?.isExpland ?? false
  45. }) as? CustomerInfoCell {
  46. cell.isExpland = false
  47. }
  48. }
  49. if let old = oldValue,
  50. let cell = (tableView.cellForRow(at: IndexPath(row: old.row, section: 0)) as? CustomerInfoCell) {
  51. cell.isExpland = false
  52. }
  53. }
  54. }
  55. /// 客户资料数据
  56. var userInfos: [MoUserInfo] = [] {
  57. didSet {
  58. /// 刷新数据
  59. tableView.reloadData()
  60. /// isHidden
  61. noDataButton.isHidden = userInfos.count != 0
  62. }
  63. }
  64. /// 权限功能
  65. var roleTitles: [String] {
  66. get {
  67. var titles: [String] = []
  68. /// 权限控制
  69. guard let commonManager = MTP2BusinessCore.shared.commonManager else {
  70. return titles
  71. }
  72. if commonManager.containMenu(key: "client_customer_unsubmit") {
  73. titles.append("未提交")
  74. }
  75. if commonManager.containMenu(key: "client_customer_unaduit") {
  76. titles.append("待审核")
  77. }
  78. if commonManager.containMenu(key: "client_customer_normal") {
  79. titles.append("正常")
  80. }
  81. if commonManager.containMenu(key: "client_customer_stop") {
  82. titles.append("停用")
  83. }
  84. return titles
  85. }
  86. }
  87. // MARK: - 生命周期
  88. override func viewDidLoad() {
  89. super.viewDidLoad()
  90. // Do any additional setup after loading the view.
  91. }
  92. override func loadView() {
  93. super.loadView()
  94. /// 判断其权限控制
  95. guard let commonManager = MTP2BusinessCore.shared.commonManager else { return }
  96. /// 没有新增客户资料权限
  97. if !commonManager.containMenu(key: "client_customer_add") {
  98. new.image = nil
  99. new.isEnabled = false
  100. } else {
  101. new.image = UIImage(named: "new_customer")
  102. new.isEnabled = true
  103. }
  104. /// titles
  105. dataSource.titles = roleTitles
  106. segmentedView.reloadData()
  107. /// addLoadingView
  108. addLoadingView()
  109. if roleTitles.count != 0 {
  110. /// 添加下拉刷新控件
  111. tableView.gtm_addRefreshHeaderView(refreshHeader: DefaultGTMRefreshHeader()) {
  112. switch self.roleTitles[self.segmentedView.selectedIndex] {
  113. case "未提交": /// 未提交
  114. self.queryCustomerInfo(1)
  115. case "待审核": /// 待审核
  116. self.queryCustomerInfo(2)
  117. case "正常": /// 正常
  118. self.queryCustomerInfo(3)
  119. default: /// 停用
  120. self.queryCustomerInfo(4)
  121. }
  122. self.selectedIndex = nil
  123. }
  124. /// 默认选中第一个
  125. segmentedView.defaultSelectedIndex = 0
  126. segmentedView.delegate?.segmentedView(segmentedView, didSelectedItemAt: 0)
  127. }
  128. }
  129. // MARK: - 接口请求
  130. /// queryUserInfo
  131. /// - Parameter querytype: 查询类型 1:未提交(网上开户表) 2:待审核(网上开户表) 3:正常 4:停用
  132. fileprivate func queryCustomerInfo(_ querytype: Int) {
  133. /// 异常
  134. guard let spotManager = MTP2BusinessCore.shared.spotManager else { return }
  135. /// startAnimating
  136. _anim?.startAnimating()
  137. /// 发送请求
  138. spotManager.queryCustomerInfo(querytype: querytype, userinfotype: nil, customername: nil, nickname: nil, includesub: nil) { isSuccess, er, objs in
  139. DispatchQueue.main.async {
  140. /// stopAnimating
  141. self._anim?.stopAnimating()
  142. /// endRefreshing
  143. self.tableView.endRefreshing()
  144. /// 查询失败
  145. if !isSuccess {
  146. self.userInfos = []
  147. WHToast.showMessage("数据查询失败,原因:\(er?.retMsg ?? "请求超时")", duration: ToastTimer, finishHandler: {})
  148. return
  149. }
  150. /// 数据赋值
  151. self.userInfos = objs ?? []
  152. }
  153. }
  154. }
  155. /// 更新用户状态
  156. /// - Parameter status: status
  157. /// - Parameter accountStatus: 账户状态 - 4:正常 6:注销(停用
  158. /// - Parameter userID: 用户ID
  159. fileprivate func requestUpdateUserAccountStatus(_ accountStatus: Int, _ userID: Int) {
  160. /// 异常
  161. guard let spotManager = MTP2BusinessCore.shared.spotManager else { return }
  162. /// startAnimating
  163. _anim?.startAnimating()
  164. /// 发送请求
  165. spotManager.requestUpdateUserAccountStatus(userID: userID, accountStatus: accountStatus) { (isSuccess, er) in
  166. DispatchQueue.main.async {
  167. /// stopAnimating
  168. self._anim?.stopAnimating()
  169. /// endRefreshing
  170. self.tableView.endRefreshing()
  171. /// 查询失败
  172. if !isSuccess {
  173. WHToast.showMessage("数据查询失败,原因:\(er?.retMsg ?? "请求超时")", duration: ToastTimer, finishHandler: {})
  174. return
  175. }
  176. /// 刷新数据
  177. self.tableView.triggerRefreshing()
  178. }
  179. }
  180. }
  181. /// 删除客户申请
  182. /// - Parameter userID: 用户ID
  183. fileprivate func deleteUserInfoApply(_ userID: Int) {
  184. /// 异常
  185. guard let spotManager = MTP2BusinessCore.shared.spotManager else { return }
  186. /// startAnimating
  187. NVActivityIndicatorPresenter.sharedInstance.startAnimating(animData("删除请求中..."))
  188. /// 删除
  189. spotManager.deleteUserInfoApply(userID: userID) { (isSuccess, er) in
  190. DispatchQueue.main.async {
  191. /// stopAnimating
  192. NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
  193. /// 查询失败
  194. if !isSuccess {
  195. WHToast.showMessage("数据查询失败,原因:\(er?.retMsg ?? "请求超时")", duration: ToastTimer, finishHandler: {})
  196. return
  197. }
  198. /// 刷新数据
  199. self.tableView.triggerRefreshing()
  200. }
  201. }
  202. }
  203. // MARK: - Navigation
  204. // In a storyboard-based application, you will often want to do a little preparation before navigation
  205. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  206. // Get the new view controller using segue.destination.
  207. // Pass the selected object to the new view controller.
  208. /// 客户详情信息
  209. if segue.identifier == "ShowCustomerInfoDetail", let d = segue.destination as? CustomerInfoDetailViewController, let row = selectedIndex?.row {
  210. d.takeInfo = userInfos[row]
  211. /// 执行回调
  212. d.popBlock = { (_ takeInfo: Any?) in
  213. /// 跳转到待审核
  214. self.segmentedView.selectItemAt(index: 1)
  215. /// didSelectedItemAt
  216. self.segmentedView.delegate?.segmentedView(self.segmentedView, didSelectedItemAt: 1)
  217. }
  218. d.navigationItem.title = (sender as? UIButton)?.currentTitle
  219. } else if segue.identifier == "ShowNewCustomerInfo", let n = segue.destination as? NewCustomerInfoViewController {
  220. /// 新增、修改、重新提交
  221. if let _ = sender as? UIBarButtonItem {
  222. n.operatorType = .add
  223. } else {
  224. n.operatorType = .update
  225. n.takeInfo = userInfos[selectedIndex?.row ?? 0]
  226. }
  227. /// 执行回调
  228. n.popBlock = { (_ takeInfo: Any?) in
  229. if let type = takeInfo as? OperatorType {
  230. /// 跳转到待审核
  231. self.segmentedView.selectItemAt(index: type == .saveDrafts ? 0 : 1)
  232. /// didSelectedItemAt
  233. self.segmentedView.delegate?.segmentedView(self.segmentedView, didSelectedItemAt: type == .saveDrafts ? 0 : 1)
  234. }
  235. }
  236. }
  237. }
  238. }
  239. // MARK: - JXSegmentedViewDelegate
  240. extension CustomerInfoViewController: JXSegmentedViewDelegate {
  241. /// didSelectedItemAt
  242. /// - Parameters:
  243. /// - segmentedView: segmentedView
  244. /// - index: index
  245. func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
  246. switch roleTitles[index]{
  247. case "未提交":
  248. queryCustomerInfo(1)
  249. case "待审核":
  250. queryCustomerInfo(2)
  251. case "正常":
  252. queryCustomerInfo(3)
  253. default:
  254. queryCustomerInfo(4)
  255. }
  256. selectedIndex = nil
  257. }
  258. }
  259. extension CustomerInfoViewController: UITableViewDelegate, UITableViewDataSource {
  260. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  261. return userInfos.count
  262. }
  263. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  264. let cell = tableView.dequeueReusableCell(withIdentifier: CellIdentifier, for: indexPath) as! CustomerInfoCell
  265. cell.model = userInfos[indexPath.row]
  266. /// 执行回调
  267. cell.block = { (_ model: MoUserInfo?, _ sender: Any?) in
  268. if let button = sender as? UIButton {
  269. switch button.currentTitle {
  270. case "恢复":
  271. if let obj = model { self.requestUpdateUserAccountStatus(4, Int(obj.userid)) }
  272. case "删除":
  273. if let obj = model { self.deleteUserInfoApply(Int(obj.userid)) }
  274. default: break
  275. }
  276. }
  277. }
  278. return cell
  279. }
  280. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  281. if indexPath.row == (selectedIndex?.row ?? 0) {
  282. selectedIndex = (row: indexPath.row, !(selectedIndex?.isExpland ?? false))
  283. } else {
  284. selectedIndex = (row: indexPath.row, true)
  285. }
  286. (tableView.cellForRow(at: indexPath) as! CustomerInfoCell).isExpland = selectedIndex?.isExpland ?? false
  287. }
  288. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  289. return (selectedIndex?.row == indexPath.row && selectedIndex?.isExpland == true) ? 90.0 : 55.0
  290. }
  291. }
  292. class CustomerInfoCell: BaseTableViewCell<MoUserInfo> {
  293. /// 客户类型
  294. @IBOutlet weak var customerType: UILabel!
  295. /// 箭头
  296. @IBOutlet weak var arrow: AnimatableImageView!
  297. /// 企业名称
  298. @IBOutlet weak var enterpriseName: UILabel!
  299. /// 联系人手机
  300. @IBOutlet weak var mobilePhone: UILabel!
  301. /// 状态
  302. @IBOutlet weak var status: UILabel!
  303. /// 审核
  304. @IBOutlet weak var aduit: UIButton! {
  305. didSet {
  306. aduit.isHidden = true
  307. }
  308. }
  309. /// 修改
  310. @IBOutlet weak var update: UIButton! {
  311. didSet {
  312. update.isHidden = true
  313. }
  314. }
  315. /// 撤销
  316. @IBOutlet weak var cancel: UIButton! {
  317. didSet {
  318. cancel.isHidden = true
  319. }
  320. }
  321. /// 详情
  322. @IBOutlet weak var detail: UIButton!
  323. /// 重新提交
  324. @IBOutlet weak var reSubmit: UIButton! {
  325. didSet {
  326. reSubmit.isHidden = true
  327. }
  328. }
  329. /// 停用
  330. @IBOutlet weak var stop: UIButton! {
  331. didSet {
  332. stop.isHidden = true
  333. }
  334. }
  335. /// 恢复
  336. @IBOutlet weak var restore: UIButton! {
  337. didSet {
  338. restore.isHidden = true
  339. }
  340. }
  341. /// 删除
  342. @IBOutlet weak var delete: UIButton! {
  343. didSet {
  344. delete.isHidden = true
  345. }
  346. }
  347. /// 是否拓展
  348. override var isExpland: Bool {
  349. didSet {
  350. arrow.image = UIImage(named: isExpland ? "arrow_up" : "arrow_down")
  351. }
  352. }
  353. /// 数据
  354. override var model: MoUserInfo? {
  355. didSet {
  356. /// 异常
  357. guard let commonManager = MTP2BusinessCore.shared.commonManager,
  358. let obj = model else { return }
  359. /// 客户类型
  360. customerType.text = obj.userinfotype == .enterprise ? "企业" : "个人"
  361. /// 企业简称
  362. enterpriseName.text = obj.userinfotype == .personal ? obj.username.isBlank() : obj.nickname.isBlank()
  363. /// 联系人手机
  364. mobilePhone.text = obj.mobile.isBlank()
  365. /// 状态
  366. status.text = obj.status.description
  367. /// 判断其权限控制
  368. switch model?.status {
  369. case .ACCOUNTSTATUS_INACTIVE:
  370. /// 未提交
  371. cancel.isHidden = true
  372. aduit.isHidden = true
  373. restore.isHidden = true
  374. update.isHidden = !commonManager.containMenu(key: "client_customer_update")
  375. stop.isHidden = true
  376. reSubmit.isHidden = true
  377. delete.isHidden = false
  378. case .ACCOUNTSTATUS_PENDINGAUDIT:
  379. /// 待审核
  380. cancel.isHidden = !commonManager.containMenu(key: "client_customer_cancel")
  381. aduit.isHidden = !commonManager.containMenu(key: "client_customer_check")
  382. restore.isHidden = true
  383. update.isHidden = true
  384. stop.isHidden = true
  385. reSubmit.isHidden = true
  386. delete.isHidden = true
  387. case .ACCOUNTSTATUS_REJECT:
  388. /// 审核拒绝
  389. cancel.isHidden = true
  390. aduit.isHidden = true
  391. restore.isHidden = true
  392. update.isHidden = true
  393. stop.isHidden = true
  394. reSubmit.isHidden = !commonManager.containMenu(key: "client_customer_recommit")
  395. delete.isHidden = true
  396. case .ACCOUNTSTATUS_NORMAL:
  397. /// 正常
  398. cancel.isHidden = true
  399. aduit.isHidden = true
  400. restore.isHidden = true
  401. update.isHidden = true
  402. stop.isHidden = !commonManager.containMenu(key: "client_customer_disable")
  403. reSubmit.isHidden = true
  404. delete.isHidden = true
  405. default:
  406. /// 停用
  407. cancel.isHidden = true
  408. aduit.isHidden = true
  409. restore.isHidden = !commonManager.containMenu(key: "client_customer_restore")
  410. update.isHidden = true
  411. stop.isHidden = true
  412. reSubmit.isHidden = true
  413. delete.isHidden = true
  414. }
  415. }
  416. }
  417. // MARK: - 交互相关
  418. /// onButtonPressed
  419. /// - Parameter sender: sender
  420. @IBAction fileprivate func onButtonPressed(_ sender: UIControl) {
  421. /// 执行回调
  422. if let bk = block {
  423. bk(model, sender as? UIButton)
  424. }
  425. }
  426. }