NewCustomerInfoViewController.swift 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. //
  2. // NewCustomerInfoViewController.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 IBAnimatable
  11. import ActionSheetPicker_3_0
  12. import ZLPhotoBrowser
  13. import JXPhotoBrowser
  14. import SDWebImage
  15. import NVActivityIndicatorView
  16. /// 新增客户资料视图容器控制类
  17. class NewCustomerInfoViewController: BaseViewController {
  18. // MARK: - 属性列表
  19. /// 客户类型
  20. @IBOutlet weak var customerType: UIButton! {
  21. didSet {
  22. customerType.setTitle("企业", for: .normal)
  23. customerType.setTitleColor(.hex333(), for: .normal)
  24. }
  25. }
  26. /// 企业名称视图
  27. @IBOutlet weak var enterpriseView: UIView!
  28. /// 企业名称
  29. @IBOutlet weak var enterpriseName: AnimatableTextField!
  30. /// 企业简称视图
  31. @IBOutlet weak var nickNameView: UIView!
  32. /// 企业简称
  33. @IBOutlet weak var nickName: UITextField!
  34. /// 证件类型视图
  35. @IBOutlet weak var certificateView: UIView!
  36. /// 证件类型
  37. @IBOutlet weak var certificateType: UIButton!
  38. /// 证件号码视图
  39. @IBOutlet weak var certificateNoView: UIView!
  40. /// 证件号码
  41. @IBOutlet weak var certificateNo: AnimatableTextField!
  42. /// 法定代表人视图
  43. @IBOutlet weak var legalView: UIView!
  44. /// 法定代表人
  45. @IBOutlet weak var legalName: UITextField!
  46. /// 纳税人识别号视图
  47. @IBOutlet weak var taxpayerView: UIView!
  48. /// 纳税人识别号
  49. @IBOutlet weak var taxpayerNo: UITextField!
  50. /// 联系人视图
  51. @IBOutlet weak var contractView: UIView!
  52. /// 联系人
  53. @IBOutlet weak var contractName: UITextField!
  54. /// 营业执照视图
  55. @IBOutlet weak var licenseView: UIView!
  56. /// 上传
  57. @IBOutlet weak var upload: AnimatableButton!
  58. /// 查看附件
  59. @IBOutlet weak var checkFile: UIButton!
  60. /// 手机号码视图
  61. @IBOutlet weak var mobilePhoneView: UIView!
  62. /// 手机号码
  63. @IBOutlet weak var mobilePhone: AnimatableTextField!
  64. /// 联系电话视图
  65. @IBOutlet weak var telphoneView: UIView!
  66. /// 联系电话
  67. @IBOutlet weak var telphone: AnimatableTextField!
  68. /// 通讯地址
  69. @IBOutlet weak var address: UIButton!
  70. /// 详细地址
  71. @IBOutlet weak var detailAddress: AnimatableTextView!
  72. /// 备注
  73. @IBOutlet weak var remark: AnimatableTextField!
  74. /// 保存草稿
  75. @IBOutlet weak var saveDrafts: UIButton!
  76. /// 提交审核
  77. @IBOutlet weak var audit: UIButton!
  78. /// 姓名视图
  79. @IBOutlet weak var personalView: UIView!
  80. /// 姓名
  81. @IBOutlet weak var personalName: UITextField!
  82. /// 邮箱视图
  83. @IBOutlet weak var emailView: UIView!
  84. /// 邮箱
  85. @IBOutlet weak var email: UITextField!
  86. /// 个人手机号码视图
  87. @IBOutlet weak var personalPhoneView: UIView!
  88. /// 个人手机号码
  89. @IBOutlet weak var personalPhone: UITextField!
  90. /// 身份证号码视图
  91. @IBOutlet weak var identifyView: UIView!
  92. /// 身份证号码
  93. @IBOutlet weak var identifyNo: UITextField!
  94. /// 身份证证件照正面视图
  95. @IBOutlet weak var identifyFrontView: UIView!
  96. /// 上传
  97. @IBOutlet weak var frontUpload: AnimatableButton!
  98. /// 查看附件
  99. @IBOutlet weak var frontFile: UIButton!
  100. /// 身份证证件照背面正面视图
  101. @IBOutlet weak var identifyBackgroundView: UIView!
  102. /// 上传
  103. @IBOutlet weak var backgroundUpload: AnimatableButton!
  104. /// 查看附件
  105. @IBOutlet weak var backgroundFile: UIButton!
  106. /// 地址标签
  107. @IBOutlet weak var addressTitle: UILabel!
  108. /// 所属机构
  109. @IBOutlet weak var area: UIButton!
  110. /// 所属机构视图
  111. @IBOutlet weak var areaView: UIView! {
  112. didSet {
  113. areaView.isHidden = !(MTP2BusinessCore.shared.address?.oem.lowercased() == "qhj")
  114. }
  115. }
  116. /// 登录账号
  117. @IBOutlet weak var loginno: UITextField!
  118. /// 登录账号视图
  119. @IBOutlet weak var loginnoView: UIView! {
  120. didSet {
  121. loginnoView.isHidden = !(MTP2BusinessCore.shared.address?.oem.lowercased() == "qhj")
  122. }
  123. }
  124. /// 登录密码
  125. @IBOutlet weak var password: UITextField!
  126. /// 登录密码视图
  127. @IBOutlet weak var passwordView: UIView! {
  128. didSet {
  129. passwordView.isHidden = !(MTP2BusinessCore.shared.address?.oem.lowercased() == "qhj")
  130. }
  131. }
  132. /// 证件类型
  133. var cardType: Int? {
  134. didSet {
  135. /// 异常
  136. guard let type = cardType else { return }
  137. certificateType.setTitle(CardType(rawValue: type)?.description, for: .normal)
  138. certificateType.setTitleColor(.hex333(), for: .normal)
  139. }
  140. }
  141. /// 客户类型
  142. var accountType: AccountType = .enterprise {
  143. didSet {
  144. customerType.setTitle(accountType == .enterprise ? "企业" : "个人", for: .normal)
  145. customerType.setTitleColor(.hex333(), for: .normal)
  146. /// 地址标签
  147. addressTitle.text = accountType == .enterprise ? "通讯地址" : "常住地址"
  148. /// 企业名称视图
  149. enterpriseView.isHidden = accountType != .enterprise
  150. /// 企业简称视图
  151. nickNameView.isHidden = accountType != .enterprise
  152. /// 证件类型视图
  153. certificateView.isHidden = accountType != .enterprise
  154. /// 证件号码视图
  155. certificateNoView.isHidden = accountType != .enterprise
  156. /// 证件号码
  157. certificateNo.isHidden = accountType != .enterprise
  158. /// 法定代表人视图
  159. legalView.isHidden = accountType != .enterprise
  160. /// 纳税人识别号视图
  161. taxpayerView.isHidden = accountType != .enterprise
  162. /// 联系人视图
  163. contractView.isHidden = accountType != .enterprise
  164. /// 营业执照视图
  165. licenseView.isHidden = accountType != .enterprise
  166. /// 手机号码视图
  167. mobilePhoneView.isHidden = accountType != .enterprise
  168. /// 联系电话视图
  169. telphoneView.isHidden = accountType != .enterprise
  170. /// 姓名视图
  171. personalView.isHidden = accountType == .enterprise
  172. /// 邮箱视图
  173. emailView.isHidden = accountType == .enterprise
  174. /// 个人手机号码视图
  175. personalPhoneView.isHidden = accountType == .enterprise
  176. /// 身份证号码视图
  177. identifyView.isHidden = accountType == .enterprise
  178. /// 身份证证件照正面视图
  179. identifyFrontView.isHidden = accountType == .enterprise
  180. /// 身份证证件照背面正面视图
  181. identifyBackgroundView.isHidden = accountType == .enterprise
  182. }
  183. }
  184. /// 证件类型
  185. var cards: [MoEnum] {
  186. /// 目前只显示机构类型执照
  187. return (try! DatabaseHelper.getEnumInfo(enumdiccode: "certificatetype"))?.filter({ (obj) -> Bool in
  188. return obj.enumitemname == 2 || obj.enumitemname == 4 || obj.enumitemname == 18 || obj.enumitemname == 21
  189. }) ?? []
  190. }
  191. /// 证件执照
  192. var file: UIImage? {
  193. didSet {
  194. /// 异常
  195. guard let image = file else {
  196. return
  197. }
  198. /// 文件上传
  199. self.uploadFile(image)
  200. }
  201. }
  202. /// 身份证正反面照路径
  203. var bgfile: UIImage? {
  204. didSet {
  205. /// 异常
  206. guard let image = file else {
  207. return
  208. }
  209. /// 文件上传
  210. self.uploadFile(image, false)
  211. }
  212. }
  213. /// 文件上传路径
  214. var filePath: String?
  215. /// 身份证正反面照路径
  216. var bgfilePath: String?
  217. /// 国家
  218. var country: MoDivisions?
  219. /// 省
  220. var province: MoDivisions?
  221. /// 市
  222. var city: MoDivisions?
  223. /// 区
  224. var district: MoDivisions?
  225. /// 操作
  226. var operatorType: OperatorType? {
  227. didSet {
  228. self.navigationItem.title = (operatorType?.description ?? "")+"客户资料"
  229. }
  230. }
  231. /// 地址
  232. var addressStr: String? {
  233. didSet {
  234. self.address.setTitle(addressStr, for: .normal)
  235. self.address.setTitleColor(.hex333(), for: .normal)
  236. }
  237. }
  238. /// 所属机构列表信息
  239. var arealists: [MoQhjAreaList] = []
  240. /// 选中的所属机构
  241. var moQhjArea: MoQhjAreaList? {
  242. didSet {
  243. /// 异常
  244. guard let obj = moQhjArea else {
  245. return
  246. }
  247. area.setTitle(obj.accountname, for: .normal)
  248. area.setTitleColor(.hex333(), for: .normal)
  249. }
  250. }
  251. // MARK: - 生命周期
  252. override func viewDidLoad() {
  253. super.viewDidLoad()
  254. // Do any additional setup after loading the view.
  255. /// loding.....
  256. addLoadingView()
  257. /// 千海金才需要查询
  258. if MTP2BusinessCore.shared.address?.oem.lowercased() == "qhj" {
  259. /// 查询所属机构信息
  260. queryQhjAreaLists()
  261. }
  262. }
  263. override func loadView() {
  264. super.loadView()
  265. /// 输入框
  266. moveView(views: [enterpriseName, nickName, certificateNo, legalName, taxpayerNo, contractName, mobilePhone, telphone, detailAddress, remark])
  267. /// 异常
  268. guard let obj = takeInfo as? MoUserInfo else { return }
  269. /// 企业名称
  270. self.enterpriseName.text = obj.customername
  271. /// 客户类型
  272. self.accountType = obj.userinfotype
  273. /// 手机号码
  274. self.mobilePhone.text = obj.mobile
  275. /// 联系电话
  276. self.telphone.text = obj.telphone
  277. /// 证件号码
  278. self.certificateNo.text = obj.cardnum
  279. /// 证件类型
  280. if obj.cardtype != -1 { self.cardType = Int(obj.cardtype) }
  281. /// 备注信息
  282. self.remark.text = obj.remark
  283. /// 地址信息
  284. self.detailAddress.text = obj.address
  285. /// 联系人
  286. self.contractName.text = obj.contactname
  287. /// 纳税人识别号
  288. self.taxpayerNo.text = obj.taxpayernum
  289. /// 法定代表人
  290. self.legalName.text = obj.legalpersonname
  291. /// 企业简称
  292. self.nickName.text = obj.nickname
  293. /// 个人姓名
  294. self.personalName.text = obj.customername
  295. /// 手机号码
  296. self.personalPhone.text = obj.mobile
  297. /// 身份证号码
  298. self.identifyNo.text = obj.cardnum
  299. /// 邮箱
  300. self.email.text = obj.email.isBlank()
  301. /// 查询省市信息
  302. queryProvincesAndCitys()
  303. /// 异常
  304. if let file = (takeInfo as? MoUserInfo)?.cardfrontphotourl, file != "",
  305. let dnUrl = URL(string: file.getUrlString()) {
  306. self.filePath = file
  307. /// 图片
  308. SDWebImageDownloader.shared.downloadImage(with: dnUrl, completed: { (image, imageData, error, _) in
  309. DispatchQueue.main.async { self.file = image }
  310. })
  311. }
  312. /// 异常
  313. if let file = (takeInfo as? MoUserInfo)?.cardbackphotourl, file != "",
  314. let dnUrl = URL(string: file.getUrlString()) {
  315. self.bgfilePath = file
  316. /// 图片
  317. SDWebImageDownloader.shared.downloadImage(with: dnUrl, completed: { (image, imageData, error, _) in
  318. DispatchQueue.main.async { self.bgfile = image }
  319. })
  320. }
  321. }
  322. // MARK: - 交互相关
  323. /// onButtonPressed
  324. /// - Parameter sender: sender
  325. @IBAction fileprivate func onButtonPressed(_ sender: UIControl) {
  326. switch sender {
  327. case area: /// 所属机构
  328. /// 异常
  329. guard arealists.count != 0 else {
  330. WHToast.showMessage("没有所属机构信息", duration: ToastTimer, finishHandler: {})
  331. return
  332. }
  333. ActionSheetStringPicker.show(withTitle: "请选择所属机构", rows: arealists.map({ obj in
  334. return obj.accountname
  335. }), initialSelection: 0, doneBlock: { picker, value, index in
  336. self.moQhjArea = self.arealists[value]
  337. },
  338. cancel: { picker in
  339. return
  340. },
  341. origin: sender)
  342. case customerType: /// 客户类型
  343. ActionSheetStringPicker.show(withTitle: "请选择客户类型", rows: ["个人", "企业"], initialSelection: 0, doneBlock: { picker, value, index in
  344. self.accountType = AccountType(rawValue: value+1)!
  345. },
  346. cancel: { picker in
  347. return
  348. },
  349. origin: sender)
  350. case certificateType: /// 证件类型
  351. ActionSheetStringPicker.show(withTitle: "请选择证件类型", rows: cards.map({ (obj) -> String in
  352. return obj.enumdicname
  353. }), initialSelection: 0, doneBlock: { picker, value, index in
  354. self.cardType = self.cards[value].enumitemname
  355. },
  356. cancel: { picker in
  357. return
  358. },
  359. origin: sender)
  360. case address: /// 地址选择
  361. self.view.endEditing(true)
  362. /// 弹出地址选择视图
  363. let selectAreaPopupView = Bundle.main.loadNibNamed("SelectArea", owner: nil, options: nil)?.first as! SelectAreaPopupView
  364. selectAreaPopupView.delegate = self
  365. selectAreaPopupView.show()
  366. case upload, frontUpload, backgroundUpload: /// 文件上传
  367. let ps = ZLPhotoPreviewSheet()
  368. ps.selectImageBlock = { [weak self] (images, assets, isOriginal) in
  369. if sender == self?.backgroundUpload {
  370. self?.bgfile = images.first
  371. } else {
  372. self?.file = images.first
  373. }
  374. }
  375. ps.showPhotoLibrary(sender: self)
  376. case checkFile, frontFile, backgroundFile: /// 查看文件
  377. /// 异常
  378. guard let image = (sender == backgroundFile ? bgfile : file) else {
  379. WHToast.showMessage("请选择上传文件", duration: ToastTimer, finishHandler: {})
  380. return
  381. }
  382. /// 实例化
  383. let bro = JXPhotoBrowser()
  384. /// 浏览过程中实时获取数据总量
  385. bro.numberOfItems = { return 1 }
  386. /// 刷新Cell数据。本闭包将在Cell完成位置布局后调用。
  387. bro.reloadCellAtIndex = { context in
  388. let cell = context.cell as? JXPhotoBrowserImageCell
  389. cell?.imageView.image = image
  390. }
  391. /// 可指定打开时定位到哪一页
  392. bro.pageIndex = 1
  393. /// 展示
  394. bro.show()
  395. case saveDrafts: /// 保存草稿
  396. ((takeInfo as? MoUserInfo) != nil) ? doAddUserInfoApply(operatetype: 2, userstate: 1) : doAddUserInfoApply(operatetype: 1, userstate: 1)
  397. case audit: /// 提交审核
  398. ((takeInfo as? MoUserInfo) != nil) ? doAddUserInfoApply(operatetype: 2, userstate: 2) : doAddUserInfoApply(operatetype: 1, userstate: 2)
  399. default:
  400. break
  401. }
  402. }
  403. // MARK: - 接口请求
  404. /// 查询对应的省市区
  405. func queryProvincesAndCitys() {
  406. /// 异常
  407. guard let obj = takeInfo as? MoUserInfo else { return }
  408. /// 对应的省
  409. province = (try? DatabaseHelper.getAllDivisions())?.first(where: {$0.autoid == obj.provinceid})
  410. /// 对应的市
  411. city = (try? DatabaseHelper.getAllDivisions())?.first(where: {$0.autoid == obj.cityid})
  412. /// 对应的区
  413. district = (try? DatabaseHelper.getAllDivisions())?.first(where: {$0.autoid == obj.districtid})
  414. /// 地址信息
  415. addressStr = "\(province?.divisionname ?? "") \(city?.divisionname ?? "") \(district?.divisionname ?? "")"
  416. }
  417. /// 查询千海金-所属机构信息
  418. fileprivate func queryQhjAreaLists() {
  419. /// 异常
  420. guard let qhjManager = MTP2BusinessCore.shared.qhjManager else {
  421. return
  422. }
  423. /// startAnimating
  424. _anim?.startAnimating()
  425. /// 发送查询请求
  426. qhjManager.queryParentAreaList { isSuccess, er, objs in
  427. DispatchQueue.main.async {
  428. ///stopAnimating
  429. self._anim?.stopAnimating()
  430. /// 查询失败
  431. if !isSuccess {
  432. WHToast.showMessage("所属机构数据获取失败,原因:\(ErrorUtils.desc(er?.retCode))", duration: ToastTimer, finishHandler: {})
  433. return
  434. }
  435. /// 数据赋值
  436. self.arealists = objs ?? []
  437. }
  438. }
  439. }
  440. /// 文件上传
  441. /// - Parameter image: image
  442. fileprivate func uploadFile(_ image: UIImage, _ isFront: Bool = true) {
  443. /// 异常
  444. guard let commonManager = MTP2BusinessCore.shared.commonManager else { return }
  445. /// 请选择上传文件
  446. guard let ig = file else {
  447. WHToast.showMessage("请选择上传文件", duration: ToastTimer, finishHandler: {})
  448. return
  449. }
  450. /// startAnimating
  451. NVActivityIndicatorPresenter.sharedInstance.startAnimating(animData("文件上传中..."))
  452. /// 发送请求
  453. commonManager.uploadImageData(image: ig) { (isSuccess, path, name, er) in
  454. DispatchQueue.main.async {
  455. /// stopAnimating
  456. NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
  457. /// 查询失败
  458. if !isSuccess {
  459. WHToast.showMessage("上传失败,原因:\(ErrorUtils.desc(er?.retCode))", duration: ToastTimer, finishHandler: {})
  460. return
  461. }
  462. /// 上传成功
  463. WHToast.showSuccess(withMessage: "上传成功", duration: ToastTimer, finishHandler: {
  464. if isFront {
  465. self.filePath = path
  466. } else {
  467. self.bgfilePath = path
  468. }
  469. })
  470. }
  471. }
  472. }
  473. /// 客户资料操作申请
  474. /// - Parameters:
  475. /// - operatetype: 操作类型-1:新增 2:修改
  476. /// - userstate: 开户状态 1:保存草稿 2:提交审核
  477. fileprivate func doAddUserInfoApply(operatetype: Int, userstate: Int) {
  478. /// 异常
  479. guard let spotManager = MTP2BusinessCore.shared.spotManager,
  480. let oem = MTP2BusinessCore.shared.address?.oem,
  481. check() else { return }
  482. /// 企业名称
  483. let name = accountType == .enterprise ? enterpriseName.text : personalName.text
  484. /// 证件类型
  485. let type = accountType == .enterprise ? cardType : 0
  486. /// 证件号码
  487. let num = accountType == .enterprise ? certificateNo.text : identifyNo.text
  488. /// 手机号码
  489. let mobile = accountType == .enterprise ? mobilePhone.text : personalPhone.text
  490. /// 法定代表人
  491. let ledge = accountType == .enterprise ? legalName.text : nil
  492. /// 纳税人识别号
  493. let taxpayer = accountType == .enterprise ? taxpayerNo.text : nil
  494. /// 联系人
  495. let contract = accountType == .enterprise ? contractName.text : nil
  496. /// 昵称
  497. let nick = accountType == .enterprise ? nickName.text : name
  498. /// 联系电话
  499. let tel = accountType == .enterprise ? telphone.text : nil
  500. /// 证件执照路径
  501. let url = filePath
  502. /// 地址信息
  503. let add = detailAddress.text
  504. /// 备注信息
  505. let rek = remark.text
  506. /// 市
  507. let cityid = city?.autoid
  508. /// 区
  509. let districtid = district?.autoid
  510. /// 省
  511. let provinceid = province?.autoid
  512. /// 邮箱
  513. let em = accountType == .personal ? email.text : nil
  514. /// 背面照
  515. let bgurl = accountType == .personal ? self.bgfilePath : nil
  516. /// 登录密码
  517. let loginpwd: String? = oem == "qhj" ? password.text : nil
  518. /// 登录账号
  519. let loginno: String? = oem == "qhj" ? loginno.text : nil
  520. /// 所属机构id
  521. let areaid: Int? = oem == "qhj" ? moQhjArea?.userid : Int(MTP2BusinessCore.getUserID())
  522. /// 用户ID(修改时必填)
  523. let userid: Int? = (takeInfo as? MoUserInfo) != nil ? Int((takeInfo as? MoUserInfo)!.userid) : nil
  524. /// startAnimating
  525. NVActivityIndicatorPresenter.sharedInstance.startAnimating(animData("请求中..."))
  526. /// 发送请求
  527. spotManager.requestCustomerInfoOperate(operatetype: operatetype, userid: userid, areaid: areaid, logincode: loginno, loginpwd: loginpwd, userinfotype: self.accountType.rawValue, username: name, nickname: nick, cardtype: type, cardnum: num, cardfrontphotourl: url, cardbackphotourl: bgurl, email: em, referral: nil, legalpersonname: ledge, taxpayernum: taxpayer, proxystatementurl: url, contactname: contract, mobilephone: mobile, telphone: tel, provinceid: provinceid, cityid: cityid, districtid: districtid, ipaddress: add, remark: rek, userstate: userstate) { isSuccess, rsp, er in
  528. DispatchQueue.main.async {
  529. /// stopAnimating
  530. NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
  531. /// 请求失败
  532. if !isSuccess {
  533. WHToast.showMessage("请求失败,原因:\(rsp?.retDesc ?? "未知错误")", duration: ToastTimer, finishHandler: {})
  534. return
  535. }
  536. /// 请求成功
  537. WHToast.showSuccess(withMessage: "请求成功", duration: ToastTimer, finishHandler: {
  538. /// 执行回调
  539. if let bk = self.popBlock { bk(userstate == 1 ? OperatorType.saveDrafts : OperatorType.add) }
  540. /// 返回上层视图
  541. self.navigationController?.popViewController(animated: true)
  542. })
  543. }
  544. }
  545. }
  546. // MARK: - 合规性校验
  547. /// 合规性校验
  548. /// - Returns: Bool
  549. fileprivate func check() -> Bool {
  550. /// 千海金需要这些功能
  551. if MTP2BusinessCore.shared.address?.oem.lowercased() == "qhj" {
  552. /// 请选择所属机构
  553. guard let _ = moQhjArea else {
  554. WHToast.showMessage("请选择所属机构", duration: ToastTimer, finishHandler: {})
  555. return false
  556. }
  557. /// 请输入登录账号
  558. guard let no = loginno.text, no.count != 0 else {
  559. WHToast.showMessage("请输入登录账号", duration: ToastTimer, finishHandler: {})
  560. return false
  561. }
  562. /// 请输入登录密码
  563. guard let pwd = password.text, pwd.count != 0 else {
  564. WHToast.showMessage("请输入登录密码", duration: ToastTimer, finishHandler: {})
  565. return false
  566. }
  567. }
  568. /// 企业
  569. if accountType == .enterprise {
  570. /// 请输入企业名称
  571. guard let name = enterpriseName.text, name.count != 0 else {
  572. WHToast.showMessage("请输入企业名称", duration: ToastTimer, finishHandler: {})
  573. return false
  574. }
  575. /// 请输入企业简称!
  576. guard let nick = nickName.text, nick.count != 0 else {
  577. WHToast.showMessage("请输入企业简称", duration: ToastTimer, finishHandler: {})
  578. return false
  579. }
  580. /// 请输入正确的手机号码
  581. guard let mo = mobilePhone.text, mo.count != 0 else {
  582. WHToast.showMessage("请输入手机号码", duration: ToastTimer, finishHandler: {})
  583. return false
  584. }
  585. /// 请输入正确的手机号码
  586. guard RegularUtils.checkPhoneNumber(with: mo) else {
  587. WHToast.showMessage("请输入正确的手机号码", duration: ToastTimer, finishHandler: {})
  588. return false
  589. }
  590. } else {
  591. /// 请输入姓名
  592. guard let name = personalName.text, name.count != 0 else {
  593. WHToast.showMessage("请输入姓名", duration: ToastTimer, finishHandler: {})
  594. return false
  595. }
  596. /// 请输入正确的身份证号码
  597. if let no = identifyNo.text, no != "", RegularUtils.isValidIDCard(no) {
  598. WHToast.showMessage("请输入正确的身份证号码", duration: ToastTimer, finishHandler: {})
  599. return false
  600. }
  601. /// 请输入手机号码
  602. guard let phone = personalPhone.text, phone.count != 0 else {
  603. WHToast.showMessage("请输入手机号码", duration: ToastTimer, finishHandler: {})
  604. return false
  605. }
  606. /// 请输入正确的手机号码
  607. guard RegularUtils.checkPhoneNumber(with: phone) else {
  608. WHToast.showMessage("请输入正确的手机号码", duration: ToastTimer, finishHandler: {})
  609. return false
  610. }
  611. }
  612. return true
  613. }
  614. }
  615. // MARK: - SelectAreaPopupViewDelegate
  616. extension NewCustomerInfoViewController: SelectAreaPopupViewDelegate {
  617. /// selectAreaPopupView
  618. /// - Parameters:
  619. /// - sender: sender
  620. /// - country: country
  621. /// - province: province
  622. /// - city: city
  623. /// - district: district
  624. func selectAreaPopupView(_ sender: SelectAreaPopupView, country: MoDivisions, province: MoDivisions, city: MoDivisions?, district: MoDivisions?) {
  625. /// 隐藏视图
  626. sender.hidePopupView()
  627. /// 地址拼接
  628. self.country = country
  629. self.province = province
  630. self.city = city
  631. self.district = district
  632. /// 地址拼接
  633. var areaAddress = province.divisionname
  634. /// 市
  635. if let cityname = city?.divisionname, cityname != "null" {
  636. areaAddress.append(" \(cityname)")
  637. }
  638. /// 区
  639. if let districtname = district?.divisionname, districtname != "null" {
  640. areaAddress.append(" \(districtname)")
  641. }
  642. self.addressStr = areaAddress
  643. }
  644. }