// // CustomerInfoDetailViewController.swift // MTP2_iOS // // Created by Muchinfo on 2021/1/2. // Copyright © 2021 Muchinfo. All rights reserved. // import UIKit import WHToast import SDWebImage import JXPhotoBrowser import NVActivityIndicatorView /// 客户资料详情视图容器控制类 class CustomerInfoDetailViewController: BaseViewController { // MARK: - 属性列表 /// 状态 @IBOutlet weak var status: UILabel! /// 状态 @IBOutlet weak var statusImage: UIImageView! /// 状态 @IBOutlet weak var statusView: UIView! /// 客户类型 @IBOutlet weak var customerType: UILabel! /// 企业名称 @IBOutlet weak var enterpriseName: UILabel! /// 企业简称 @IBOutlet weak var nickName: UILabel! /// 纳税人识别号 @IBOutlet weak var taxpayerNo: UILabel! /// 法定代表人 @IBOutlet weak var legalName: UILabel! /// 联系人 @IBOutlet weak var contractName: UILabel! /// 证件类型 @IBOutlet weak var certificateType: UILabel! /// 证件类型 @IBOutlet weak var certificateTitle: UILabel! /// 证件类型 @IBOutlet weak var certificateView: UIView! /// 证件号码 @IBOutlet weak var certificateNo: UILabel! /// 查看附件 @IBOutlet weak var checkFile: UIButton! /// 背面照查看附件 @IBOutlet weak var bgCheckFile: UIButton! /// 手机号码 @IBOutlet weak var mobilePhone: UILabel! /// 联系电话 @IBOutlet weak var telphone: UILabel! /// 通讯地址 @IBOutlet weak var address: UILabel! /// 备注 @IBOutlet weak var remark: UILabel! /// 审核拒绝 @IBOutlet weak var refused: UIButton! /// 审核通过 @IBOutlet weak var approved: UIButton! /// 恢复 @IBOutlet weak var restore: UIButton! /// 停用 @IBOutlet weak var stop: UIButton! /// 撤销 @IBOutlet weak var cancel: UIButton! /// 邮箱 @IBOutlet weak var email: UILabel! /// 营业执照标题 @IBOutlet weak var licenseTitle: UILabel! /// 企业名称视图 @IBOutlet weak var enterpriseView: UIView! /// 企业简称视图 @IBOutlet weak var nickNameView: UIView! /// 法定代表人视图 @IBOutlet weak var legalView: UIView! /// 纳税人识别号视图 @IBOutlet weak var taxpayerView: UIView! /// 联系人视图 @IBOutlet weak var contractView: UIView! /// 手机号码视图 @IBOutlet weak var mobilePhoneTitle: UILabel! /// 联系电话视图 @IBOutlet weak var telphoneView: UIView! /// 姓名视图 @IBOutlet weak var personalView: UIView! /// 姓名视图 @IBOutlet weak var personalName: UILabel! /// 邮箱视图 @IBOutlet weak var emailView: UIView! /// 身份证证件照背面正面视图 @IBOutlet weak var identifyBackgroundView: UIView! /// 地址标签 @IBOutlet weak var addressTitle: UILabel! /// 所属机构 @IBOutlet weak var areaname: UILabel! /// 登录账号 @IBOutlet weak var loginno: UILabel! /// 所属机构视图 @IBOutlet weak var areaView: UIView! { didSet { areaView.isHidden = !(MTP2BusinessCore.shared.address?.oem.lowercased() == "qhj") } } /// 登录账号视图 @IBOutlet weak var loginnoView: UIView! { didSet { loginnoView.isHidden = !(MTP2BusinessCore.shared.address?.oem.lowercased() == "qhj") } } // MARK: - 生命周期 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. /// 显示客户资料数据信息 showUserInfoDetail() } /// 显示客户资料数据信息 fileprivate func showUserInfoDetail() { /// 异常 guard let commonManager = MTP2BusinessCore.shared.commonManager, let obj = takeInfo as? MoUserInfo else { return } /// 状态 视图颜色 status.text = obj.status.description status.textColor = .fromHex(rgbValue: obj.status.rawValue == 4 ? 0x4DBB33 : 0xFE9A68) statusView.backgroundColor = obj.status.rawValue == 4 ? .D3FFE1() : .FFEBDD() /// 标记 statusImage.image = UIImage(named: obj.status.rawValue == 4 ? "status_success" : "clock") /// 用户状态 customerType.text = obj.userinfotype == .personal ? "个人" : "企业" /// 企业名称 enterpriseName.text = (obj.userinfotype == .personal ? obj.username : obj.customername).isBlank() /// 证件类型 certificateType.text = obj.cardtype == -1 ? "--" : ECardTypeStringValue(CardType(rawValue: Int(obj.cardtype))) /// 证件号码 certificateNo.text = obj.cardnum.isBlank() /// 手机号码 mobilePhone.text = obj.mobile.isBlank() /// 联系电话 telphone.text = obj.telphone.isBlank() /// 通讯地址 address.text = obj.address.isBlank() /// 备注 remark.text = obj.remark.isBlank() /// 企业简称 nickName.text = obj.nickname.isBlank() /// 法定代表人 legalName.text = obj.legalpersonname.isBlank() /// 纳税人识别号 taxpayerNo.text = obj.taxpayernum.isBlank() /// 联系人 contractName.text = obj.contactname.isBlank() /// 个人邮箱 email.text = obj.email.isBlank() /// 姓名 personalName.text = (obj.userinfotype == .personal ? obj.username : obj.customername).isBlank() /// addressTitle addressTitle.text = obj.userinfotype == .personal ? "常住地址" : "通讯地址" /// licenseTitle licenseTitle.text = obj.userinfotype == .personal ? "身份证正面照" : "营业执照" /// mobilePhoneTitle mobilePhoneTitle.text = obj.userinfotype == .personal ? "手机号码" : "联系人手机号" /// certificateTitle certificateTitle.text = obj.userinfotype == .personal ? "身份证号码" : "证件号码" /// 企业名称视图 enterpriseView.isHidden = obj.userinfotype == .personal /// 企业简称视图 nickNameView.isHidden = obj.userinfotype == .personal /// 法定代表人视图 legalView.isHidden = obj.userinfotype == .personal /// 纳税人识别号视图 taxpayerView.isHidden = obj.userinfotype == .personal /// 联系人视图 contractView.isHidden = obj.userinfotype == .personal /// 姓名视图 personalView.isHidden = obj.userinfotype != .personal /// 邮箱视图 emailView.isHidden = obj.userinfotype != .personal /// 身份证证件照背面正面视图 identifyBackgroundView.isHidden = obj.userinfotype != .personal /// 证件类型视图 certificateView.isHidden = obj.userinfotype == .personal /// 联系电话 telphoneView.isHidden = obj.userinfotype == .personal /// 登录代码 loginno.text = obj.logincode.isBlank() /// 所属机构 areaname.text = obj.parentusername.isBlank() /// 查询客户省市县 queryProvincesAndCitys() /// 判断其权限控制 switch obj.status { case .ACCOUNTSTATUS_PENDINGAUDIT: /// 待审核 approved.isHidden = !commonManager.containMenu(key: "client_customer_check") refused.isHidden = !commonManager.containMenu(key: "client_customer_check") stop.isHidden = true restore.isHidden = true cancel.isHidden = !commonManager.containMenu(key: "client_customer_cancel") case.ACCOUNTSTATUS_CANCELLED: /// 注销 approved.isHidden = true refused.isHidden = true stop.isHidden = true restore.isHidden = !commonManager.containMenu(key: "client_customer_restore") cancel.isHidden = true case .ACCOUNTSTATUS_NORMAL: /// 正常 approved.isHidden = true refused.isHidden = true stop.isHidden = !commonManager.containMenu(key: "client_customer_disable") restore.isHidden = true cancel.isHidden = true default: approved.isHidden = true refused.isHidden = true stop.isHidden = true restore.isHidden = true cancel.isHidden = true } } // MARK: - 交互相关 /// onButtonPressed /// - Parameter sender: sender @IBAction fileprivate func onButtonPressed(_ sender: UIControl) { switch sender { case approved: /// 审核通过 doUserInfoCheckOperate(4) case refused: /// 审核拒绝 doUserInfoCheckOperate(5) case restore: /// 恢复 requestUpdateUserAccountStatus(4) case stop: /// 停用 requestUpdateUserAccountStatus(6) case cancel: /// 撤销 doModifyUserInfoApply() case checkFile, bgCheckFile: /// 文件查看 /// 异常 guard let file = sender == checkFile ? (takeInfo as? MoUserInfo)?.cardfrontphotourl : (takeInfo as? MoUserInfo)?.cardbackphotourl, file != "", let dnUrl = URL(string: file.getUrlString()) else { WHToast.showMessage("未上传附件内容", duration: ToastTimer, finishHandler: {}) return } /// 实例化 let browser = JXPhotoBrowser() /// 浏览过程中实时获取数据总量 browser.numberOfItems = { return 1 } /// 刷新Cell数据。本闭包将在Cell完成位置布局后调用。 browser.reloadCellAtIndex = { context in let cell = context.cell as? JXPhotoBrowserImageCell SDWebImageDownloader.shared.downloadImage(with: dnUrl) { (image, data, error, finished) in cell?.imageView.image = image cell?.layoutSubviews() } } /// 可指定打开时定位到哪一页 browser.pageIndex = 1 /// 展示 browser.show() default: break } } // MARK: - 接口请求 /// 查询对应的省市区 func queryProvincesAndCitys() { /// 异常 guard let obj = takeInfo as? MoUserInfo else { return } /// 对应的省 let province = (try? DatabaseHelper.getAllDivisions())?.first(where: {$0.autoid == obj.provinceid}) /// 对应的市 let city = (try? DatabaseHelper.getAllDivisions())?.first(where: {$0.autoid == obj.cityid}) /// 对应的区 let district = (try? DatabaseHelper.getAllDivisions())?.first(where: {$0.autoid == obj.districtid}) /// 地址信息 address.text = "\(province?.divisionname ?? "") \(city?.divisionname ?? "") \(district?.divisionname ?? "") \(obj.address)" } /// 客户资料申请操作 /// - Parameter auditflag: 4审核通过 5审核拒绝 fileprivate func doUserInfoCheckOperate(_ auditflag: Int) { /// 异常 guard let spotManager = MTP2BusinessCore.shared.spotManager, let obj = takeInfo as? MoUserInfo else { return } /// startAnimating NVActivityIndicatorPresenter.sharedInstance.startAnimating(animData("操作请求中...")) /// 客户ID let userid = obj.userid /// 备注信息 let rk = self.remark.text /// 发送请求 spotManager.requestAuditWskhUserInfo(userState: auditflag, userid: userid, remark: rk) { isSuccess, rsp, er in DispatchQueue.main.async { /// stopAnimating NVActivityIndicatorPresenter.sharedInstance.stopAnimating() /// 请求失败 if !isSuccess { WHToast.showMessage("请求失败,原因:\(rsp?.retDesc ?? "请求超时")", duration: ToastTimer, finishHandler: {}) return } WHToast.showSuccess(withMessage: "请求成功", duration: ToastTimer, finishHandler: { /// 执行回调 if let bk = self.popBlock { bk(nil) } /// 返回上层视图 self.navigationController?.popViewController(animated: true) }) } } } /// 更新用户状态 /// - Parameter status: status /// - Parameter accountStatus: 账户状态 - 4:正常 6:注销(停用 fileprivate func requestUpdateUserAccountStatus(_ accountStatus: Int) { /// 异常 guard let spotManager = MTP2BusinessCore.shared.spotManager, let userid = (takeInfo as? MoUserInfo)?.userid else { return } /// startAnimating NVActivityIndicatorPresenter.sharedInstance.startAnimating(animData("操作请求中...")) /// 发送请求 spotManager.requestUpdateUserAccountStatus(userID: Int(userid), accountStatus: accountStatus) { (isSuccess, er) in DispatchQueue.main.async { /// stopAnimating NVActivityIndicatorPresenter.sharedInstance.stopAnimating() /// 请求失败 if !isSuccess { WHToast.showMessage("请求失败,原因:\(er?.retMsg ?? "请求超时")", duration: ToastTimer, finishHandler: {}) return } WHToast.showSuccess(withMessage: "请求成功", duration: ToastTimer, finishHandler: { /// 执行回调 if let bk = self.popBlock { bk(nil) } /// 返回上层视图 self.navigationController?.popViewController(animated: true) }) } } } /// 撤销操作申请 fileprivate func doModifyUserInfoApply() { /// 异常 guard let spotManager = MTP2BusinessCore.shared.spotManager, let obj = takeInfo as? MoUserInfo else { return } /// startAnimating NVActivityIndicatorPresenter.sharedInstance.startAnimating(animData("撤销请求中...")) /// 发送请求 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 DispatchQueue.main.async { /// stopAnimating NVActivityIndicatorPresenter.sharedInstance.stopAnimating() /// 请求失败 if !isSuccess { WHToast.showMessage("撤销请求失败,原因:\(er?.retMsg ?? "请求超时")", duration: ToastTimer, finishHandler: {}) return } /// 请求成功 WHToast.showSuccess(withMessage: "撤销请求成功", duration: ToastTimer, finishHandler: { /// 执行回调 if let bk = self.popBlock { bk(OperatorType.saveDrafts) } /// 返回上层视图 self.navigationController?.popViewController(animated: true) }) } }) } }