HomeViewController.swift 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. //
  2. // HomeViewController.swift
  3. // MTP2_iOS
  4. //
  5. // Created by Muchinfo on 2020/12/30.
  6. // Copyright © 2020 Muchinfo. All rights reserved.
  7. //
  8. import UIKit
  9. import SDCycleScrollView
  10. import JXSegmentedView
  11. import WHToast
  12. import GTMRefresh
  13. import SwiftyAttributes
  14. import SwiftDate
  15. import DeviceKit
  16. import IBAnimatable
  17. import SafariServices
  18. import NVActivityIndicatorView
  19. import SDWebImage
  20. /// 首页视图容器控制类
  21. class HomeViewController: BaseViewController {
  22. // MARK: - 属性列表
  23. /// 标题
  24. @IBOutlet weak var titleButton: UIButton!
  25. /// 标题
  26. @IBOutlet weak var account: UIButton!
  27. /// 主滚动视图
  28. @IBOutlet weak var scrollView: UIScrollView!
  29. /// 轮播图
  30. @IBOutlet weak var sdCycle: SDCycleScrollView! {
  31. didSet {
  32. sdCycle.bannerImageViewContentMode = .scaleAspectFill
  33. sdCycle.autoScrollTimeInterval = 5.0
  34. sdCycle.autoScroll = true
  35. sdCycle.showPageControl = true
  36. sdCycle.infiniteLoop = true
  37. sdCycle.scrollDirection = .horizontal
  38. sdCycle.delegate = self
  39. self.sdCycle.localizationImageNamesGroup = banners
  40. }
  41. }
  42. /// 菜单项约束视图
  43. @IBOutlet weak var menuStackView: UIStackView!
  44. /// 菜单项高度约束
  45. @IBOutlet weak var menuLayoutConstraint: NSLayoutConstraint!
  46. /// 分页高度约束
  47. @IBOutlet weak var pageLayoutConstraint: NSLayoutConstraint!
  48. /// 菜单项集合视图
  49. @IBOutlet weak var menuCollectionView: UICollectionView! {
  50. didSet {
  51. /// 设置约束
  52. menuCollectionView.setCollectionViewLayout(layout, animated: true)
  53. }
  54. }
  55. /// 类目
  56. @IBOutlet weak var segmentedView: JXSegmentedView! {
  57. didSet {
  58. segmentedView.dataSource = dataSource
  59. segmentedView.indicators = [indicator]
  60. segmentedView.delegate = self
  61. }
  62. }
  63. /// 公告列表
  64. @IBOutlet weak var tableView: UITableView!
  65. /// 列表高度约束
  66. @IBOutlet weak var heightLayoutConstraint: NSLayoutConstraint!
  67. /// 页签
  68. @IBOutlet weak var pageControl: UIPageControl!
  69. /// 菜单项约束
  70. lazy var layout: HorizontalPageFlowlayout = {
  71. $0.setParams(columnSpacing: 10.0, rowSpacing: 0.0, edgeInsets: UIEdgeInsets(top: 10.0, left: 10.0, bottom: 0.0, right: 10.0))
  72. $0.minimumInteritemSpacing = 0
  73. $0.minimumLineSpacing = 0
  74. $0.scrollDirection = .horizontal
  75. return $0
  76. } (HorizontalPageFlowlayout(rowCount: 2, itemCountPerRow: Device.current.isPad ? 5 : 4))
  77. /// 通用layout
  78. lazy var noLayout: UICollectionViewFlowLayout = {
  79. $0.minimumInteritemSpacing = 0
  80. $0.minimumLineSpacing = 0
  81. $0.scrollDirection = .horizontal
  82. return $0
  83. } (UICollectionViewFlowLayout())
  84. /// MSG_CELl
  85. let cellIdentifier = "MSG_CELl"
  86. /// 集合视图
  87. let collectionCellIdentifier = "MENU_CELL"
  88. /// 公告数据
  89. var notices: [MoNotice] = [] {
  90. didSet {
  91. heightLayoutConstraint.constant = CGFloat(notices.count > 5 ? notices.count : 5)*65.0
  92. /// 刷新列表数据
  93. tableView.reloadData()
  94. }
  95. }
  96. /// 新闻资讯数据信息
  97. var news: [MoSiteColumnDetail] = [] {
  98. didSet {
  99. heightLayoutConstraint.constant = CGFloat(news.count > 5 ? news.count : 5)*65.0
  100. /// 刷新列表数据
  101. tableView.reloadData()
  102. }
  103. }
  104. /// 菜单项
  105. var menus: [(image: String, title: String, type: MenuType, badge: Int)] = [] {
  106. didSet {
  107. /// 显示菜单项
  108. menuCollectionView.reloadData()
  109. }
  110. }
  111. /// 本地轮播图
  112. var banners: [Any] {
  113. get {
  114. switch MTP2BusinessCore.shared.address?.oem {
  115. case "qhj":
  116. return [UIImage(named: "qhj_banner_01") as Any]
  117. default:
  118. return [UIImage(named: "banner01") as Any]
  119. }
  120. }
  121. }
  122. /// 广告配置信息
  123. var configs: [MoImageConfigs] = [] {
  124. didSet {
  125. /// 数据
  126. let paths = configs.map({ (model) -> String in
  127. return model.imagepath.getUrlString()
  128. })
  129. sdCycle.imageURLStringsGroup = paths
  130. }
  131. }
  132. // MARK: - 生命周期
  133. override func viewDidLoad() {
  134. super.viewDidLoad()
  135. // Do any additional setup after loading the view.
  136. /// 不需要返回按钮
  137. addBackBarButtonItem(true)
  138. /// 异常
  139. let oem = MTP2BusinessCore.shared.address?.oem
  140. /// titles
  141. dataSource.titles = oem?.lowercased() == "qyfg" ? ["公告", "研报", "资讯"] : ["资讯", "公告", "消息"]
  142. segmentedView.defaultSelectedIndex = 0
  143. segmentedView.reloadData()
  144. segmentedView.delegate?.segmentedView(segmentedView, didSelectedItemAt: 0)
  145. /// gtm_addRefreshHeaderView
  146. scrollView.gtm_addRefreshHeaderView(refreshHeader: DefaultGTMRefreshHeader()) { [weak self] in
  147. /// 请求数据
  148. self?.requestHomePageDatas()
  149. }
  150. /// 请求数据
  151. DispatchQueue.main.asyncAfter(deadline: .now()+1.0) {
  152. /// 请求数据
  153. self.requestHomePageDatas()
  154. }
  155. /// 异常
  156. guard let accountManager = MTP2BusinessCore.shared.accountManager,
  157. let commonManager = MTP2BusinessCore.shared.commonManager,
  158. let loginQuery = accountManager.loginQuery,
  159. let userInfo = loginQuery.userInfo else {
  160. return
  161. }
  162. /// 标题按钮
  163. if let root = accountManager.rootUserAccountInfo {
  164. titleButton.setAttributedTitle(root.accountname.withFont(.font_15).withTextColor(.white), for: .normal)
  165. } else {
  166. titleButton.setAttributedTitle(app_Name.withFont(.font_15).withTextColor(.white), for: .normal)
  167. }
  168. if let login = loginQuery.loginAccount {
  169. /// 账户信息
  170. account.setAttributedTitle("\(login.accountname)".withFont(.font_10).withTextColor(.white), for: .normal)
  171. } else {
  172. /// 账户信息
  173. account.setAttributedTitle("\(userInfo.customername)".withFont(.font_10).withTextColor(.white), for: .normal)
  174. }
  175. /// 判断其权限控制
  176. var datas: [(image: String, title: String, type: MenuType, badge: Int)] = []
  177. /// 判断其是否有客户资料权限
  178. if commonManager.containMenu(key: "client_customer") || commonManager.containMenu(key: "client_qhjkhzl") {
  179. datas.append((image: "home_menu_khzl", title: "客户资料", .khzl, 0))
  180. }
  181. /// 判断其是否有账户管理权限
  182. if commonManager.containMenu(key: "client_accountmanage") {
  183. datas.append((image: "home_menu_zhgl", title: "账户管理", .zhgl, 0))
  184. }
  185. /// 判断其是否有商品信息权限
  186. if commonManager.containMenu(key: "client_deliverygoods") {
  187. datas.append((image: "home_menu_spxx", title: "商品信息", .spxx, 0))
  188. }
  189. /// 判断其是否有仓库信息权限
  190. if commonManager.containMenu(key: "client_warehouse") {
  191. datas.append((image: "home_menu_ckxx", title: "仓库信息", .ckxx, 0))
  192. }
  193. /// 判断其是否有现货审核权限
  194. if commonManager.containMenu(key: "client_spotsaduit") {
  195. datas.append((image: "home_menu_xhht", title: "现货审核", .xhsh, 0))
  196. }
  197. /// 判断其是否有财务审核权限
  198. if commonManager.containMenu(key: "client_finance") {
  199. datas.append((image: "home_menu_cwgl", title: "财务审核", .cwgl, 0))
  200. }
  201. /// 判断其是否有库存审核权限
  202. if commonManager.containMenu(key: "client_stock") {
  203. datas.append((image: "home_menu_kcsh", title: "库存审核", .kcsh, 0))
  204. }
  205. /// 判断其是否有库存管理权限
  206. if commonManager.containMenu(key: "client_stock_manage") {
  207. datas.append((image: "home_menu_kcgl", title: "库存管理", .kcgl, 0))
  208. }
  209. /// 判断其是否有交易查询权限
  210. if commonManager.containMenu(key: "client_traderflow") {
  211. datas.append((image: "home_menu_jycx", title: "交易查询", .jycx, 0))
  212. }
  213. /// 判断其是否有现货市价权限
  214. if commonManager.containMenu(key: "client_spotmarketprice") {
  215. datas.append((image: "home_menu_xhsj", title: "现货市价", .xhsj, 0))
  216. }
  217. /// 判断其是否有交易主体权限
  218. if commonManager.containMenu(key: "client_trademain") {
  219. datas.append((image: "home_menu_jyzt", title: "交易主体", .jyzt, 0))
  220. }
  221. /// 判断其是否有审核设置权限
  222. if commonManager.containMenu(key: "client_aduitsetting") {
  223. datas.append((image: "home_menu_shsz", title: "审核设置", .shsz, 0))
  224. }
  225. /// 判断其是否有审核设置权限
  226. if commonManager.containMenu(key: "client_mobile_varietiesparameteraduit") {
  227. datas.append((image: "home_menu_fgsh", title: "风管审核", .fgsh, 0))
  228. }
  229. /// 判断其是否有千海金-交易查询权限
  230. if commonManager.containMenu(key: "client_qhjjycx") {
  231. datas.append((image: "home_menu_jycx", title: "交易查询", .qhjjycx, 0))
  232. }
  233. /// 判断其是否有千海金-定投管理权限
  234. if commonManager.containMenu(key: "client_qhjdtgl") {
  235. datas.append((image: "home_menu_dtgl", title: "定投管理", .dtgl, 0))
  236. }
  237. /// 判断其是否有千海金-资金信息权限
  238. if commonManager.containMenu(key: "client_qhjzjxx") {
  239. datas.append((image: "home_menu_zjxx", title: "资产信息", .zjxx, 0))
  240. }
  241. /// 判断其是否有千海金-充值提现权限
  242. if commonManager.containMenu(key: "client_qhjcztx") {
  243. datas.append((image: "home_menu_cztx", title: "充值提现", .cztx, 0))
  244. }
  245. menus = datas
  246. /// 显示页签个数
  247. pageControl.numberOfPages = Int(menus.count/8)+1
  248. pageLayoutConstraint.constant = menus.count <= 8 ? 0.0 : 25.0
  249. pageControl.isHidden = menus.count <= 8
  250. /// 隐藏菜单视图
  251. menuStackView.isHidden = menus.count == 0
  252. /// 重置高度约束
  253. menuLayoutConstraint.constant = menus.count == 0 ? 0.0 : 175.0
  254. /// 小于4个菜单项
  255. if menus.count <= 4 {
  256. menuLayoutConstraint.constant = 90.0
  257. menuCollectionView.setCollectionViewLayout(noLayout, animated: true)
  258. }
  259. }
  260. override func viewWillAppear(_ animated: Bool) {
  261. super.viewWillAppear(animated)
  262. /// 解决bug
  263. if UIDevice.current.orientation != .portrait {
  264. /// 强制设置成竖屏
  265. UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
  266. /// 重新设置一下
  267. (UIApplication.shared.keyWindow?.rootViewController as? MainTabBarController)?.selectedIndex = 0
  268. }
  269. }
  270. override func viewDidAppear(_ animated: Bool) {
  271. super.viewDidAppear(animated)
  272. /// 查询待办事项
  273. queryPendingAuditInfo()
  274. }
  275. // MARK: - 交互相关
  276. /// onBarButtonItemPressed
  277. /// - Parameter sender: sender
  278. @IBAction func onBarButtonItemPressed(_ sender: UIBarButtonItem) {
  279. push("Settings", "Settings")
  280. }
  281. /// onValueChanged
  282. /// - Parameter sender: sender
  283. @IBAction func onValueChanged(_ sender: UIPageControl) {
  284. /// 设定滚动位置
  285. menuCollectionView.setContentOffset(CGPoint(x: CGFloat(sender.currentPage)*menuCollectionView.width, y: menuCollectionView.contentOffset.y), animated: true)
  286. }
  287. // MARK: - 数据查询
  288. /// 查询首页数据信息
  289. fileprivate func requestHomePageDatas() {
  290. /// 异常
  291. guard let commonManager = MTP2BusinessCore.shared.commonManager else {
  292. return
  293. }
  294. let group = DispatchGroup()
  295. /// startAnimating
  296. _anim?.startAnimating()
  297. /// 发送请求
  298. group.enter()
  299. /// 查询轮播图
  300. commonManager.queryImageConfigs { (isSuccess, error, imageConfigs) in
  301. DispatchQueue.main.async {
  302. if isSuccess, imageConfigs?.count != 0 {
  303. /// 数据赋值
  304. self.configs = imageConfigs ?? []
  305. } else {
  306. self.configs = []
  307. self.sdCycle.localizationImageNamesGroup = self.banners
  308. }
  309. }
  310. group.leave()
  311. }
  312. group.notify(queue: .main) {
  313. /// stopAnimating
  314. self._anim?.stopAnimating()
  315. /// endRefreshing
  316. self.scrollView.endRefreshing()
  317. }
  318. }
  319. /// 查询公告数据信息
  320. fileprivate func requestNotices() {
  321. /// 异常
  322. guard let commonManager = MTP2BusinessCore.shared.commonManager else {
  323. return
  324. }
  325. /// 清空数据 防止崩溃
  326. news = []
  327. /// 消息类型
  328. let msgType = dataSource.titles[segmentedView.selectedIndex] == "公告" ? 1 : 2
  329. /// 查询公告
  330. commonManager.queryNotice(page: nil, pageSize: nil, msgType: msgType) { (isSuccess, er, objs) in
  331. DispatchQueue.main.async {
  332. if !isSuccess {
  333. /// 清空数据
  334. self.notices = []
  335. WHToast.showMessage("公告数据查询错误,原因:\(ErrorUtils.desc(er?.retCode))", duration: ToastTimer, finishHandler: {})
  336. return
  337. }
  338. /// 公告和消息
  339. self.notices = objs ?? []
  340. }
  341. }
  342. }
  343. /// 查询新闻资讯数据信息
  344. fileprivate func querySiteColumnDetail() {
  345. /// 异常
  346. guard let commonManager = MTP2BusinessCore.shared.commonManager else {
  347. return
  348. }
  349. /// 清空数据 防止崩溃
  350. notices = []
  351. /// 查询新闻资讯数据信息
  352. commonManager.querySiteColumnDetail { isSuccess, er, objs in
  353. DispatchQueue.main.async {
  354. if !isSuccess {
  355. /// 清空数据
  356. self.news = []
  357. WHToast.showMessage("新闻资讯数据查询错误,原因:\(ErrorUtils.desc(er?.retCode))", duration: ToastTimer, finishHandler: {})
  358. return
  359. }
  360. /// 数据赋值
  361. self.news = objs ?? []
  362. }
  363. }
  364. }
  365. /// 查询待办事项
  366. fileprivate func queryPendingAuditInfo() {
  367. /// 异常
  368. guard let commonManager = MTP2BusinessCore.shared.commonManager else { return }
  369. /// 查询待办事项
  370. commonManager.queryPendingAuditInfo { (isSuccess, error) in
  371. DispatchQueue.main.async {
  372. if isSuccess,
  373. let info = commonManager.auditInfo {
  374. var datas = self.menus
  375. /// 客户资料
  376. if var menu = datas.first(where: {$0.type == .khzl}), let index = datas.firstIndex(where: {$0.type == .khzl}) {
  377. menu.badge = info.userqty
  378. datas.replaceSubrange(index...index, with: [menu])
  379. }
  380. /// 现货审核
  381. if var menu = datas.first(where: {$0.type == .xhsh}), let index = datas.firstIndex(where: {$0.type == .xhsh}) {
  382. menu.badge = (info.hedgeplanqty+info.businessdjqty+info.businessjsqty+info.spotcontractqty)
  383. datas.replaceSubrange(index...index, with: [menu])
  384. }
  385. /// 财务审核
  386. if var menu = datas.first(where: {$0.type == .cwgl}), let index = datas.firstIndex(where: {$0.type == .cwgl}) {
  387. menu.badge = info.businessfpqty+info.businesskxqty
  388. datas.replaceSubrange(index...index, with: [menu])
  389. }
  390. /// 库存审核
  391. if var menu = datas.first(where: {$0.type == .kcsh}), let index = datas.firstIndex(where: {$0.type == .kcsh}) {
  392. menu.badge = info.areastockqty
  393. datas.replaceSubrange(index...index, with: [menu])
  394. }
  395. self.menus = datas
  396. }
  397. }
  398. }
  399. }
  400. // MARK: - Navigation
  401. // In a storyboard-based application, you will often want to do a little preparation before navigation
  402. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  403. // Get the new view controller using segue.destination.
  404. // Pass the selected object to the new view controller.
  405. if segue.identifier == "ShowMsgDetail", let d = segue.destination as? MessageDetailViewController, let notice = sender as? MoNotice { /// 公告详情
  406. d.takeInfo = notice
  407. } else if segue.identifier == "ShowNewsDetail", let n = segue.destination as? NewsDetailViewController, let site = sender as? MoSiteColumnDetail { /// 新闻资讯详情
  408. n.takeInfo = site
  409. }
  410. }
  411. }
  412. // MARK: - JXSegmentedViewDelegate
  413. extension HomeViewController: JXSegmentedViewDelegate {
  414. /// didSelectedItemAt
  415. /// - Parameters:
  416. /// - segmentedView: segmentedView
  417. /// - index: index
  418. func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
  419. if dataSource.titles.count != 0 {
  420. switch dataSource.titles[index] {
  421. case "资讯":
  422. /// 查询新闻资讯数据信息
  423. querySiteColumnDetail()
  424. case "公告", "消息":
  425. /// 查询消息数据
  426. requestNotices()
  427. default:
  428. /// 目前没有研报
  429. notices = []
  430. }
  431. }
  432. }
  433. }
  434. // MARK: - UITableViewDelegate、UITableViewDataSource
  435. extension HomeViewController: UITableViewDelegate, UITableViewDataSource {
  436. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  437. return dataSource.titles[segmentedView.selectedIndex] == "资讯" ? news.count : notices.count
  438. }
  439. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  440. let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! MSGCell
  441. cell.model = dataSource.titles[segmentedView.selectedIndex] == "资讯" ? news[indexPath.row] : notices[indexPath.row]
  442. return cell
  443. }
  444. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  445. return 65.0
  446. }
  447. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  448. /// 新闻资讯
  449. if dataSource.titles[segmentedView.selectedIndex] == "资讯" {
  450. self.performSegue(withIdentifier: "ShowNewsDetail", sender: news[indexPath.row])
  451. } else {
  452. self.performSegue(withIdentifier: "ShowMsgDetail", sender: notices[indexPath.row])
  453. }
  454. }
  455. }
  456. // MARK: - UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout
  457. extension HomeViewController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
  458. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  459. return menus.count
  460. }
  461. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  462. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: collectionCellIdentifier, for: indexPath) as! MenuCollectionCell
  463. cell.model = menus[indexPath.item]
  464. return cell
  465. }
  466. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  467. switch menus[indexPath.item].type {
  468. case .khzl: /// 客户资料
  469. push("Customer", "CustomerInfo")
  470. case .xhsh: /// 现货审核
  471. push("SpotsAduit", "SpotsAduit")
  472. case .cwgl: /// 财务管理
  473. push("SpotsAduit", "Financial")
  474. case .spxx: /// 商品信息
  475. push("Varieties", "GoodsVarieties")
  476. case .jycx: /// 交易查询
  477. push("Futures", "TradeFlow")
  478. case .ckxx: /// 仓库信息
  479. push("Stock", "WareHouse")
  480. case .kcgl: /// 库存管理
  481. push("Stock", "StockManager")
  482. case .kcsh: /// 库存审核
  483. push("Stock", "InOutStockAduit")
  484. case .zhgl: /// 账户管理
  485. push("Account", "AccountManager")
  486. case .xhsj: /// 现货市价
  487. push("Spots", "SpotMarketPrice")
  488. case .shsz: /// 审核设置
  489. push("SpotsAduit", "AduitSetting")
  490. case .jyzt: /// 交易主体
  491. push("Account", "TradeMain")
  492. case .fgsh: /// 风管审核
  493. push("Varieties", "VarietiesParameterAduit")
  494. case .ckhq: /// 参考行情
  495. let quote = viewController("QHJQuote", "BJBQuote") as! BJBQuoteViewController
  496. quote.title = "参考行情"
  497. quote.isQhj = false
  498. self.navigationController?.pushViewController(quote, animated: true)
  499. case .wymh: /// 云融大宗 我要买货
  500. if let main = (UIApplication.shared.delegate as? AppDelegate)?.window?.rootViewController as? MainTabBarController {
  501. main.selectedIndex = 1
  502. }
  503. case .wyys: /// 云融大宗 我要预售
  504. if let main = (UIApplication.shared.delegate as? AppDelegate)?.window?.rootViewController as? MainTabBarController {
  505. main.selectedIndex = 4
  506. if let mine = (main.selectedViewController as? BaseNavigationController)?.viewControllers[0] as? YrdzMineViewController {
  507. /// 跳转到预售仓单
  508. DispatchQueue.main.asyncAfter(deadline: .now()+0.3) {
  509. mine.collectionView.delegate?.collectionView?(mine.collectionView, didSelectItemAt: IndexPath(item: 1, section: 0))
  510. }
  511. }
  512. }
  513. case .qhjjycx, .zjxx: /// 交易查询 资金信息
  514. if let tr = viewController("QHJOrder", "QhjOrderMain") as? QhjOrderMainViewController {
  515. let trn = BaseNavigationController(rootViewController: tr)
  516. trn.modalTransitionStyle = .crossDissolve
  517. trn.modalPresentationStyle = .overFullScreen
  518. let index = menus[indexPath.item].type == .qhjjycx ? 4 : 5
  519. /// 默认显示卖出
  520. DispatchQueue.main.asyncAfter(deadline: .now()+0.3) {
  521. tr.segmentedView.defaultSelectedIndex = index
  522. tr.segmentedView.reloadData()
  523. tr.segmentedView.delegate?.segmentedView(tr.segmentedView, didSelectedItemAt: index)
  524. }
  525. self.present(trn, animated: true, completion: {})
  526. }
  527. case .dtgl: /// 定投管理
  528. push("QHJOrder", "AutoInvestment")
  529. case .cztx: /// 充值提现
  530. push("QHJBank", "InOutCharge")
  531. case .lygl: /// 履约管理
  532. if let main = (UIApplication.shared.delegate as? AppDelegate)?.window?.rootViewController as? MainTabBarController {
  533. main.selectedIndex = 4
  534. if let mine = (main.selectedViewController as? BaseNavigationController)?.viewControllers[0] as? YrdzMineViewController {
  535. /// 跳转到履约管理
  536. DispatchQueue.main.asyncAfter(deadline: .now()+0.3) {
  537. mine.collectionView.delegate?.collectionView?(mine.collectionView, didSelectItemAt: IndexPath(item: 3, section: 0))
  538. }
  539. }
  540. }
  541. default: break
  542. }
  543. }
  544. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  545. let width = collectionView.width/(Device.current.isPad ? 5 : 4)
  546. return CGSize(width: width, height: 70.0)
  547. }
  548. func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
  549. /// FIXME: 暂时性处理代码
  550. pageControl.currentPage = scrollView.contentOffset.x > 0 ? 1 : 0
  551. }
  552. }
  553. // MARK: - SFSafariViewControllerDelegate
  554. extension HomeViewController: SFSafariViewControllerDelegate {
  555. func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
  556. controller.dismiss(animated: true, completion: {})
  557. }
  558. }
  559. // MARK: - SDCycleScrollViewDelegate
  560. extension HomeViewController: SDCycleScrollViewDelegate {
  561. func cycleScrollView(_ cycleScrollView: SDCycleScrollView!, didSelectItemAt index: Int) {
  562. /// 广告跳转
  563. if configs.count != 0, configs[index].urltype == 1, configs[index].url != "" {
  564. let urlString = !configs[index].url.lowercased().hasPrefix("http://") ? ("http://"+configs[index].url) : configs[index].url
  565. guard let url = URL(string: urlString) else { return }
  566. let safriViewController = SFSafariViewController(url: url)
  567. safriViewController.delegate = self
  568. self.present(safriViewController, animated: true, completion: {})
  569. }
  570. }
  571. }
  572. // MARK: - MSGCell
  573. class MSGCell: BaseTableViewCell<Any> {
  574. /// 公告类型
  575. @IBOutlet weak var msgType: UIImageView!
  576. /// 公告标题
  577. @IBOutlet weak var title: UITextView!
  578. /// 公告详情
  579. @IBOutlet weak var detail: UILabel!
  580. /// 发布时间
  581. @IBOutlet weak var date: UILabel!
  582. /// model
  583. override var model: Any? {
  584. didSet {
  585. /// 时间
  586. var stime: Date = Date()
  587. switch model {
  588. case is MoNotice:
  589. /// 公告消息
  590. let obj = model as! MoNotice
  591. /// 公告标题
  592. title.text = obj.title
  593. /// 公告详情
  594. detail.text = obj.content
  595. /// 类型
  596. msgType.image = UIImage(named: obj.msgtype != 1 ? "msg_notice" : "msg_bulletin")
  597. /// 发布时间
  598. stime = obj.scheduletime.getTDateString().toDate(formatter: "yyyy-MM-dd HH:mm:ss") ?? Date()
  599. default:
  600. /// 新闻资讯
  601. let obj = model as! MoSiteColumnDetail
  602. /// 新闻标题
  603. title.text = obj.title
  604. /// 公告详情
  605. detail.text = obj.brief
  606. /// 发布时间
  607. stime = obj.creaedate.toDate(formatter: "yyyy-MM-dd HH:mm:ss") ?? Date()
  608. }
  609. if stime.isToday {
  610. date.text = stime.getString(formatter: "HH:mm")
  611. } else if stime.isYesterday {
  612. date.text = "昨天 \(stime.getString(formatter: "HH:mm"))"
  613. } else {
  614. date.text = stime.getString(formatter: "MM-dd")
  615. }
  616. }
  617. }
  618. }
  619. // MARK: - UI元素: UICollectionViewCell
  620. /// MenuCollectionCell 主页功能cell
  621. class MenuCollectionCell: AnimatableCollectionViewCell {
  622. /// 图标
  623. @IBOutlet weak var imageView: UIImageView!
  624. /// 标题
  625. @IBOutlet weak var title: UILabel!
  626. /// badgeView
  627. @IBOutlet weak var badge: UILabel! {
  628. didSet {
  629. badge.layer.cornerRadius = badge.width*0.5
  630. badge.layer.masksToBounds = true
  631. }
  632. }
  633. /// 数据Mo类
  634. var model: (image: String, title: String, type: MenuType, badge: Int)? {
  635. didSet {
  636. /// 数据异常
  637. guard let obj = model else { return }
  638. /// 图片信息
  639. if obj.image.hasPrefix("./uploadFile"), let url = URL(string: obj.image.getUrlString()) {
  640. imageView.sd_setImage(with: url, completed: nil)
  641. } else {
  642. imageView.image = UIImage(named: obj.image)
  643. }
  644. /// 标题
  645. title.text = obj.title
  646. /// 是否隐藏
  647. badge.isHidden = obj.badge == 0
  648. /// 显示数字
  649. badge.text = obj.badge > 99 ? "99+" : "\(obj.badge)"
  650. }
  651. }
  652. }