KnowledgeBaseViewController.swift 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //
  2. // ArticleManagerViewController.swift
  3. // xingchuangke
  4. //
  5. // Created by Virgil on 2019/4/25.
  6. // Copyright © 2019 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. class KnowledgeBaseViewController: BaseViewController, UITableViewDataSource, UITableViewDelegate, SDPhotoBrowserDelegate {
  10. @IBOutlet weak var viewMenu: UIView!
  11. @IBOutlet weak var tableView: UITableView!
  12. var typeId = ""
  13. override func viewDidLoad() {
  14. super.viewDidLoad()
  15. self.title = "知识库"
  16. initNavLeftBackButton()
  17. tableView.register(UINib(nibName: "KnowledgeBaseTableViewCell", bundle: nil), forCellReuseIdentifier: "KnowledgeBaseTableViewCell")
  18. tableView.delegate = self
  19. tableView.dataSource = self
  20. tableView.separatorStyle = .none
  21. tableView.showsVerticalScrollIndicator = false
  22. tableView.estimatedRowHeight = 100
  23. tableView.mj_header = MJRefreshNormalHeader(refreshingBlock: {[weak self] in
  24. self!.currentPage = 1
  25. self!.loadData()
  26. })
  27. tableView.mj_header?.lastUpdatedTimeKey = "ShowTableViewCell"
  28. tableView.mj_footer = MJRefreshBackNormalFooter(refreshingBlock: {[weak self] in
  29. self!.currentPage += 1
  30. self!.loadData()
  31. })
  32. loadType()
  33. }
  34. ///加载头部的菜单
  35. func loadMenu() {
  36. var arrTitle = [String]()
  37. arrTitle.append("全部")
  38. for i in 0 ..< arrType.count {
  39. arrTitle.append(arrType.getString(index: i, key: "name"))
  40. }
  41. let segment = Virgil_SegmentView(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: 47), titles: arrTitle, defaultColor: CommonUntils.getUIColorFromRGB(rgbValue: 0x333333, alpha: 1.0), currentColor: CommonUntils.getUIColorFromRGB(rgbValue: 0x2094F5, alpha: 1.0), lineHeight: 2, lineIsBottom: true) {[weak self] (index) in
  42. self!.currentPage = 1
  43. if index == 0 {
  44. self!.typeId = "FFFFFF"
  45. } else {
  46. self!.typeId = self!.arrType.getString(index: index - 1, key: "id")
  47. }
  48. self!.tableView.mj_header?.beginRefreshing()
  49. }
  50. self.viewMenu.addSubview(segment)
  51. typeId = arrType.getString(index: 0, key: "id")
  52. tableView.mj_header?.beginRefreshing()
  53. }
  54. let arrType = NSMutableArray()
  55. // MARK: =============加载数据===============
  56. func loadType() {
  57. let url = RequestURL.studyTypeList
  58. let params = NSMutableDictionary()
  59. params.setValue(2, forKey: "type")
  60. loadDataList(url: url, params: params, tag: 1001, array: arrType)
  61. }
  62. func loadData() {
  63. let url = RequestURL.knowledgeList
  64. let params = NSMutableDictionary()
  65. params.setValue(typeId, forKey: "typeId")
  66. loadDataList(url: url, params: params, tableView: self.tableView, tag: 1002)
  67. }
  68. override func returnData(tag: Int) {
  69. if tag == 1001 {
  70. if arrType.count > 0 {
  71. loadMenu()
  72. } else {
  73. SVProgressHUD.showError(withStatus: "知识库类型加载失败,请重试")
  74. loadData()
  75. }
  76. } else if tag == 1002 {
  77. tableView.reloadData()
  78. }
  79. }
  80. override func returnError(tag: Int, type: String) {
  81. }
  82. // MARK: TABLEVLEW 实现
  83. func numberOfSections(in tableView: UITableView) -> Int {
  84. return 1
  85. }
  86. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  87. return self.arrData.count
  88. }
  89. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  90. return 62
  91. }
  92. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  93. let cell = tableView.dequeueReusableCell(withIdentifier: "KnowledgeBaseTableViewCell", for: indexPath as IndexPath) as! KnowledgeBaseTableViewCell
  94. cell.lblTitle.text = getString(current: indexPath.row, key: "title")
  95. //cell.lblTitle.text = getString(indexPath.row, key: "Name")
  96. return cell
  97. }
  98. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  99. if indexPath.row >= arrData.count {
  100. return
  101. }
  102. let vc = CommonWebViewViewController()
  103. vc.strTitle = "详情"
  104. vc.url = getString(current: indexPath.row, key: "webUrl")
  105. toViewController(viewController: vc)
  106. }
  107. @IBAction func centerBtnAction(sender: UIButton) {
  108. if self.arrData.count <= sender.superview!.tag {
  109. return
  110. }
  111. let sd = SDPhotoBrowser()
  112. sd.tag = sender.tag
  113. viewTopImage = sender.superview!
  114. // if(sender.tag == 0)
  115. // {
  116. // viewTopImage = sender.superview!.subviews[sender.tag]!
  117. // }
  118. // else if(sender.tag == 1)
  119. // {
  120. // viewTopImage = sender.superview!
  121. // }
  122. // else if(sender.tag == 2)
  123. // {
  124. // viewTopImage = sender.superview!
  125. // }
  126. arrImagePaths.removeAll()
  127. let dic = self.arrData[sender.superview!.tag] as! NSDictionary
  128. if dic.getString(key: "imageone") != "" {
  129. arrImagePaths.append(dic.getString(key: "imageone"))
  130. }
  131. if dic.getString(key: "imagetwo") != "" {
  132. arrImagePaths.append(dic.getString(key: "imagetwo"))
  133. }
  134. if dic.getString(key: "imagethree") != "" {
  135. arrImagePaths.append(dic.getString(key: "imagethree"))
  136. }
  137. sd.sourceImagesContainerView = viewTopImage
  138. sd.imageCount = arrImagePaths.count
  139. sd.currentImageIndex = Int32(sender.tag)
  140. sd.delegate = self
  141. sd.show()
  142. }
  143. var viewTopImage = UIView()
  144. var arrImagePaths = [String]()
  145. // MARK: 图片
  146. func photoBrowser(_ browser: SDPhotoBrowser!, placeholderImageFor index: Int) -> UIImage! {
  147. return (viewTopImage.subviews[index] as! UIImageView).image!
  148. }
  149. func photoBrowser(_ browser: SDPhotoBrowser!, highQualityImageURLFor index: Int) -> URL! {
  150. return URL(string: arrImagePaths[index])
  151. }
  152. func photoBrowser(_ browser: SDPhotoBrowser!, select index: Int) {
  153. }
  154. override func viewWillAppear(_ animated: Bool) {
  155. super.viewWillAppear(animated)
  156. }
  157. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  158. super.init(nibName: "KnowledgeBaseViewController", bundle: nil)
  159. }
  160. required init?(coder aDecoder: NSCoder) {
  161. fatalError("init(coder:) has not been implemented")
  162. }
  163. }