CustomerInfoDetailViewController.swift 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. //
  2. // CustomerInfoDetailViewController.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 WHToast
  10. import SDWebImage
  11. import JXPhotoBrowser
  12. import NVActivityIndicatorView
  13. /// 客户资料详情视图容器控制类
  14. class CustomerInfoDetailViewController: BaseViewController {
  15. // MARK: - 属性列表
  16. /// 状态
  17. @IBOutlet weak var status: UILabel!
  18. /// 状态
  19. @IBOutlet weak var statusImage: UIImageView!
  20. /// 状态
  21. @IBOutlet weak var statusView: UIView!
  22. /// 客户类型
  23. @IBOutlet weak var customerType: UILabel!
  24. /// 企业名称
  25. @IBOutlet weak var enterpriseName: UILabel!
  26. /// 企业简称
  27. @IBOutlet weak var nickName: UILabel!
  28. /// 纳税人识别号
  29. @IBOutlet weak var taxpayerNo: UILabel!
  30. /// 法定代表人
  31. @IBOutlet weak var legalName: UILabel!
  32. /// 联系人
  33. @IBOutlet weak var contractName: UILabel!
  34. /// 证件类型
  35. @IBOutlet weak var certificateType: UILabel!
  36. /// 证件类型
  37. @IBOutlet weak var certificateTitle: UILabel!
  38. /// 证件类型
  39. @IBOutlet weak var certificateView: UIView!
  40. /// 证件号码
  41. @IBOutlet weak var certificateNo: UILabel!
  42. /// 查看附件
  43. @IBOutlet weak var checkFile: UIButton!
  44. /// 背面照查看附件
  45. @IBOutlet weak var bgCheckFile: UIButton!
  46. /// 手机号码
  47. @IBOutlet weak var mobilePhone: UILabel!
  48. /// 联系电话
  49. @IBOutlet weak var telphone: UILabel!
  50. /// 通讯地址
  51. @IBOutlet weak var address: UILabel!
  52. /// 备注
  53. @IBOutlet weak var remark: UILabel!
  54. /// 审核拒绝
  55. @IBOutlet weak var refused: UIButton!
  56. /// 审核通过
  57. @IBOutlet weak var approved: UIButton!
  58. /// 恢复
  59. @IBOutlet weak var restore: UIButton!
  60. /// 停用
  61. @IBOutlet weak var stop: UIButton!
  62. /// 撤销
  63. @IBOutlet weak var cancel: UIButton!
  64. /// 邮箱
  65. @IBOutlet weak var email: UILabel!
  66. /// 营业执照标题
  67. @IBOutlet weak var licenseTitle: UILabel!
  68. /// 企业名称视图
  69. @IBOutlet weak var enterpriseView: UIView!
  70. /// 企业简称视图
  71. @IBOutlet weak var nickNameView: UIView!
  72. /// 法定代表人视图
  73. @IBOutlet weak var legalView: UIView!
  74. /// 纳税人识别号视图
  75. @IBOutlet weak var taxpayerView: UIView!
  76. /// 联系人视图
  77. @IBOutlet weak var contractView: UIView!
  78. /// 手机号码视图
  79. @IBOutlet weak var mobilePhoneTitle: UILabel!
  80. /// 联系电话视图
  81. @IBOutlet weak var telphoneView: UIView!
  82. /// 姓名视图
  83. @IBOutlet weak var personalView: UIView!
  84. /// 姓名视图
  85. @IBOutlet weak var personalName: UILabel!
  86. /// 邮箱视图
  87. @IBOutlet weak var emailView: UIView!
  88. /// 身份证证件照背面正面视图
  89. @IBOutlet weak var identifyBackgroundView: UIView!
  90. /// 地址标签
  91. @IBOutlet weak var addressTitle: UILabel!
  92. /// 所属机构
  93. @IBOutlet weak var areaname: UILabel!
  94. /// 登录账号
  95. @IBOutlet weak var loginno: UILabel!
  96. /// 所属机构视图
  97. @IBOutlet weak var areaView: UIView! {
  98. didSet {
  99. areaView.isHidden = !(MTP2BusinessCore.shared.address?.oem.lowercased() == "qhj")
  100. }
  101. }
  102. /// 登录账号视图
  103. @IBOutlet weak var loginnoView: UIView! {
  104. didSet {
  105. loginnoView.isHidden = !(MTP2BusinessCore.shared.address?.oem.lowercased() == "qhj")
  106. }
  107. }
  108. // MARK: - 生命周期
  109. override func viewDidLoad() {
  110. super.viewDidLoad()
  111. // Do any additional setup after loading the view.
  112. /// 显示客户资料数据信息
  113. showUserInfoDetail()
  114. }
  115. /// 显示客户资料数据信息
  116. fileprivate func showUserInfoDetail() {
  117. /// 异常
  118. guard let commonManager = MTP2BusinessCore.shared.commonManager,
  119. let obj = takeInfo as? MoUserInfo else { return }
  120. /// 状态 视图颜色
  121. status.text = obj.status.description
  122. status.textColor = .fromHex(rgbValue: obj.status.rawValue == 4 ? 0x4DBB33 : 0xFE9A68)
  123. statusView.backgroundColor = obj.status.rawValue == 4 ? .D3FFE1() : .FFEBDD()
  124. /// 标记
  125. statusImage.image = UIImage(named: obj.status.rawValue == 4 ? "status_success" : "clock")
  126. /// 用户状态
  127. customerType.text = obj.userinfotype == .personal ? "个人" : "企业"
  128. /// 企业名称
  129. enterpriseName.text = (obj.userinfotype == .personal ? obj.username : obj.customername).isBlank()
  130. /// 证件类型
  131. certificateType.text = obj.cardtype == -1 ? "--" : ECardTypeStringValue(CardType(rawValue: Int(obj.cardtype)))
  132. /// 证件号码
  133. certificateNo.text = obj.cardnum.isBlank()
  134. /// 手机号码
  135. mobilePhone.text = obj.mobile.isBlank()
  136. /// 联系电话
  137. telphone.text = obj.telphone.isBlank()
  138. /// 通讯地址
  139. address.text = obj.address.isBlank()
  140. /// 备注
  141. remark.text = obj.remark.isBlank()
  142. /// 企业简称
  143. nickName.text = obj.nickname.isBlank()
  144. /// 法定代表人
  145. legalName.text = obj.legalpersonname.isBlank()
  146. /// 纳税人识别号
  147. taxpayerNo.text = obj.taxpayernum.isBlank()
  148. /// 联系人
  149. contractName.text = obj.contactname.isBlank()
  150. /// 个人邮箱
  151. email.text = obj.email.isBlank()
  152. /// 姓名
  153. personalName.text = (obj.userinfotype == .personal ? obj.username : obj.customername).isBlank()
  154. /// addressTitle
  155. addressTitle.text = obj.userinfotype == .personal ? "常住地址" : "通讯地址"
  156. /// licenseTitle
  157. licenseTitle.text = obj.userinfotype == .personal ? "身份证正面照" : "营业执照"
  158. /// mobilePhoneTitle
  159. mobilePhoneTitle.text = obj.userinfotype == .personal ? "手机号码" : "联系人手机号"
  160. /// certificateTitle
  161. certificateTitle.text = obj.userinfotype == .personal ? "身份证号码" : "证件号码"
  162. /// 企业名称视图
  163. enterpriseView.isHidden = obj.userinfotype == .personal
  164. /// 企业简称视图
  165. nickNameView.isHidden = obj.userinfotype == .personal
  166. /// 法定代表人视图
  167. legalView.isHidden = obj.userinfotype == .personal
  168. /// 纳税人识别号视图
  169. taxpayerView.isHidden = obj.userinfotype == .personal
  170. /// 联系人视图
  171. contractView.isHidden = obj.userinfotype == .personal
  172. /// 姓名视图
  173. personalView.isHidden = obj.userinfotype != .personal
  174. /// 邮箱视图
  175. emailView.isHidden = obj.userinfotype != .personal
  176. /// 身份证证件照背面正面视图
  177. identifyBackgroundView.isHidden = obj.userinfotype != .personal
  178. /// 证件类型视图
  179. certificateView.isHidden = obj.userinfotype == .personal
  180. /// 联系电话
  181. telphoneView.isHidden = obj.userinfotype == .personal
  182. /// 登录代码
  183. loginno.text = obj.logincode.isBlank()
  184. /// 所属机构
  185. areaname.text = obj.parentusername.isBlank()
  186. /// 查询客户省市县
  187. queryProvincesAndCitys()
  188. /// 判断其权限控制
  189. switch obj.status {
  190. case .ACCOUNTSTATUS_PENDINGAUDIT: /// 待审核
  191. approved.isHidden = !commonManager.containMenu(key: "client_customer_check")
  192. refused.isHidden = !commonManager.containMenu(key: "client_customer_check")
  193. stop.isHidden = true
  194. restore.isHidden = true
  195. cancel.isHidden = !commonManager.containMenu(key: "client_customer_cancel")
  196. case.ACCOUNTSTATUS_CANCELLED: /// 注销
  197. approved.isHidden = true
  198. refused.isHidden = true
  199. stop.isHidden = true
  200. restore.isHidden = !commonManager.containMenu(key: "client_customer_restore")
  201. cancel.isHidden = true
  202. case .ACCOUNTSTATUS_NORMAL: /// 正常
  203. approved.isHidden = true
  204. refused.isHidden = true
  205. stop.isHidden = !commonManager.containMenu(key: "client_customer_disable")
  206. restore.isHidden = true
  207. cancel.isHidden = true
  208. default:
  209. approved.isHidden = true
  210. refused.isHidden = true
  211. stop.isHidden = true
  212. restore.isHidden = true
  213. cancel.isHidden = true
  214. }
  215. }
  216. // MARK: - 交互相关
  217. /// onButtonPressed
  218. /// - Parameter sender: sender
  219. @IBAction fileprivate func onButtonPressed(_ sender: UIControl) {
  220. switch sender {
  221. case approved: /// 审核通过
  222. doUserInfoCheckOperate(4)
  223. case refused: /// 审核拒绝
  224. doUserInfoCheckOperate(5)
  225. case restore: /// 恢复
  226. requestUpdateUserAccountStatus(4)
  227. case stop: /// 停用
  228. requestUpdateUserAccountStatus(6)
  229. case cancel: /// 撤销
  230. doModifyUserInfoApply()
  231. case checkFile, bgCheckFile: /// 文件查看
  232. /// 异常
  233. guard let file = sender == checkFile ? (takeInfo as? MoUserInfo)?.cardfrontphotourl : (takeInfo as? MoUserInfo)?.cardbackphotourl,
  234. file != "",
  235. let dnUrl = URL(string: file.getUrlString()) else {
  236. WHToast.showMessage("未上传附件内容", duration: ToastTimer, finishHandler: {})
  237. return
  238. }
  239. /// 实例化
  240. let browser = JXPhotoBrowser()
  241. /// 浏览过程中实时获取数据总量
  242. browser.numberOfItems = { return 1 }
  243. /// 刷新Cell数据。本闭包将在Cell完成位置布局后调用。
  244. browser.reloadCellAtIndex = { context in
  245. let cell = context.cell as? JXPhotoBrowserImageCell
  246. SDWebImageDownloader.shared.downloadImage(with: dnUrl) { (image, data, error, finished) in
  247. cell?.imageView.image = image
  248. cell?.layoutSubviews()
  249. }
  250. }
  251. /// 可指定打开时定位到哪一页
  252. browser.pageIndex = 1
  253. /// 展示
  254. browser.show()
  255. default:
  256. break
  257. }
  258. }
  259. // MARK: - 接口请求
  260. /// 查询对应的省市区
  261. func queryProvincesAndCitys() {
  262. /// 异常
  263. guard let obj = takeInfo as? MoUserInfo else { return }
  264. /// 对应的省
  265. let province = (try? DatabaseHelper.getAllDivisions())?.first(where: {$0.autoid == obj.provinceid})
  266. /// 对应的市
  267. let city = (try? DatabaseHelper.getAllDivisions())?.first(where: {$0.autoid == obj.cityid})
  268. /// 对应的区
  269. let district = (try? DatabaseHelper.getAllDivisions())?.first(where: {$0.autoid == obj.districtid})
  270. /// 地址信息
  271. address.text = "\(province?.divisionname ?? "") \(city?.divisionname ?? "") \(district?.divisionname ?? "") \(obj.address)"
  272. }
  273. /// 客户资料申请操作
  274. /// - Parameter auditflag: 4审核通过 5审核拒绝
  275. fileprivate func doUserInfoCheckOperate(_ auditflag: Int) {
  276. /// 异常
  277. guard let spotManager = MTP2BusinessCore.shared.spotManager,
  278. let obj = takeInfo as? MoUserInfo else { return }
  279. /// startAnimating
  280. NVActivityIndicatorPresenter.sharedInstance.startAnimating(animData("操作请求中..."))
  281. /// 客户ID
  282. let userid = obj.userid
  283. /// 备注信息
  284. let rk = self.remark.text
  285. /// 发送请求
  286. spotManager.requestAuditWskhUserInfo(userState: auditflag, userid: userid, remark: rk) { isSuccess, rsp, er in
  287. DispatchQueue.main.async {
  288. /// stopAnimating
  289. NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
  290. /// 请求失败
  291. if !isSuccess {
  292. WHToast.showMessage("请求失败,原因:\(rsp?.retDesc ?? "请求超时")", duration: ToastTimer, finishHandler: {})
  293. return
  294. }
  295. WHToast.showSuccess(withMessage: "请求成功", duration: ToastTimer, finishHandler: {
  296. /// 执行回调
  297. if let bk = self.popBlock { bk(nil) }
  298. /// 返回上层视图
  299. self.navigationController?.popViewController(animated: true)
  300. })
  301. }
  302. }
  303. }
  304. /// 更新用户状态
  305. /// - Parameter status: status
  306. /// - Parameter accountStatus: 账户状态 - 4:正常 6:注销(停用
  307. fileprivate func requestUpdateUserAccountStatus(_ accountStatus: Int) {
  308. /// 异常
  309. guard let spotManager = MTP2BusinessCore.shared.spotManager,
  310. let userid = (takeInfo as? MoUserInfo)?.userid else {
  311. return
  312. }
  313. /// startAnimating
  314. NVActivityIndicatorPresenter.sharedInstance.startAnimating(animData("操作请求中..."))
  315. /// 发送请求
  316. spotManager.requestUpdateUserAccountStatus(userID: Int(userid), accountStatus: accountStatus) { (isSuccess, er) in
  317. DispatchQueue.main.async {
  318. /// stopAnimating
  319. NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
  320. /// 请求失败
  321. if !isSuccess {
  322. WHToast.showMessage("请求失败,原因:\(er?.retMsg ?? "请求超时")", duration: ToastTimer, finishHandler: {})
  323. return
  324. }
  325. WHToast.showSuccess(withMessage: "请求成功", duration: ToastTimer, finishHandler: {
  326. /// 执行回调
  327. if let bk = self.popBlock { bk(nil) }
  328. /// 返回上层视图
  329. self.navigationController?.popViewController(animated: true)
  330. })
  331. }
  332. }
  333. }
  334. /// 撤销操作申请
  335. fileprivate func doModifyUserInfoApply() {
  336. /// 异常
  337. guard let spotManager = MTP2BusinessCore.shared.spotManager,
  338. let obj = takeInfo as? MoUserInfo else {
  339. return
  340. }
  341. /// startAnimating
  342. NVActivityIndicatorPresenter.sharedInstance.startAnimating(animData("撤销请求中..."))
  343. /// 发送请求
  344. spotManager.requestEditUserInfoApply(userid: Int(obj.userid), userstate: 1, nickName: obj.nickname, taxpayernum: obj.taxpayernum, contactname: obj.contactname, legalpersonname: obj.legalpersonname, userinfotype: obj.userinfotype.rawValue, customername: obj.customername, cardtype: nil, cardnum: nil, mobilephone: nil, telphone: nil, cardfrontphotourl: nil, address: nil, remark: nil, cityid: nil, districtid: nil, countryid: nil, provinceid: nil, email: obj.email, cardbackphotourl: obj.cardbackphotourl, callback: { (isSuccess, er) in
  345. DispatchQueue.main.async {
  346. /// stopAnimating
  347. NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
  348. /// 请求失败
  349. if !isSuccess {
  350. WHToast.showMessage("撤销请求失败,原因:\(er?.retMsg ?? "请求超时")", duration: ToastTimer, finishHandler: {})
  351. return
  352. }
  353. /// 请求成功
  354. WHToast.showSuccess(withMessage: "撤销请求成功", duration: ToastTimer, finishHandler: {
  355. /// 执行回调
  356. if let bk = self.popBlock { bk(OperatorType.saveDrafts) }
  357. /// 返回上层视图
  358. self.navigationController?.popViewController(animated: true)
  359. })
  360. }
  361. })
  362. }
  363. }