123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- //
- // ArticleManagerViewController.swift
- // xingchuangke
- //
- // Created by Virgil on 2019/4/25.
- // Copyright © 2019 Virgil. All rights reserved.
- //
- import UIKit
- class KnowledgeBaseViewController: BaseViewController, UITableViewDataSource, UITableViewDelegate, SDPhotoBrowserDelegate {
- @IBOutlet weak var viewMenu: UIView!
- @IBOutlet weak var tableView: UITableView!
- var typeId = ""
- override func viewDidLoad() {
- super.viewDidLoad()
- self.title = "知识库"
- initNavLeftBackButton()
- tableView.register(UINib(nibName: "KnowledgeBaseTableViewCell", bundle: nil), forCellReuseIdentifier: "KnowledgeBaseTableViewCell")
- tableView.delegate = self
- tableView.dataSource = self
- tableView.separatorStyle = .none
- tableView.showsVerticalScrollIndicator = false
- tableView.estimatedRowHeight = 100
- tableView.mj_header = MJRefreshNormalHeader(refreshingBlock: {[weak self] in
- self!.currentPage = 1
- self!.loadData()
- })
- tableView.mj_header?.lastUpdatedTimeKey = "ShowTableViewCell"
- tableView.mj_footer = MJRefreshBackNormalFooter(refreshingBlock: {[weak self] in
- self!.currentPage += 1
- self!.loadData()
- })
- loadType()
- }
- ///加载头部的菜单
- func loadMenu() {
- var arrTitle = [String]()
- arrTitle.append("全部")
- for i in 0 ..< arrType.count {
- arrTitle.append(arrType.getString(index: i, key: "name"))
- }
- 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
- self!.currentPage = 1
- if index == 0 {
- self!.typeId = "FFFFFF"
- } else {
- self!.typeId = self!.arrType.getString(index: index - 1, key: "id")
- }
- self!.tableView.mj_header?.beginRefreshing()
- }
- self.viewMenu.addSubview(segment)
- typeId = arrType.getString(index: 0, key: "id")
- tableView.mj_header?.beginRefreshing()
- }
- let arrType = NSMutableArray()
- // MARK: =============加载数据===============
- func loadType() {
- let url = RequestURL.studyTypeList
- let params = NSMutableDictionary()
- params.setValue(2, forKey: "type")
- loadDataList(url: url, params: params, tag: 1001, array: arrType)
- }
- func loadData() {
- let url = RequestURL.knowledgeList
- let params = NSMutableDictionary()
- params.setValue(typeId, forKey: "typeId")
- loadDataList(url: url, params: params, tableView: self.tableView, tag: 1002)
- }
- override func returnData(tag: Int) {
- if tag == 1001 {
- if arrType.count > 0 {
- loadMenu()
- } else {
- SVProgressHUD.showError(withStatus: "知识库类型加载失败,请重试")
- loadData()
- }
- } else if tag == 1002 {
- tableView.reloadData()
- }
- }
- override func returnError(tag: Int, type: String) {
- }
- // MARK: TABLEVLEW 实现
- func numberOfSections(in tableView: UITableView) -> Int {
- return 1
- }
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return self.arrData.count
- }
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return 62
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "KnowledgeBaseTableViewCell", for: indexPath as IndexPath) as! KnowledgeBaseTableViewCell
- cell.lblTitle.text = getString(current: indexPath.row, key: "title")
- //cell.lblTitle.text = getString(indexPath.row, key: "Name")
- return cell
- }
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- if indexPath.row >= arrData.count {
- return
- }
- let vc = CommonWebViewViewController()
- vc.strTitle = "详情"
- vc.url = getString(current: indexPath.row, key: "webUrl")
- toViewController(viewController: vc)
- }
- @IBAction func centerBtnAction(sender: UIButton) {
- if self.arrData.count <= sender.superview!.tag {
- return
- }
- let sd = SDPhotoBrowser()
- sd.tag = sender.tag
- viewTopImage = sender.superview!
- // if(sender.tag == 0)
- // {
- // viewTopImage = sender.superview!.subviews[sender.tag]!
- // }
- // else if(sender.tag == 1)
- // {
- // viewTopImage = sender.superview!
- // }
- // else if(sender.tag == 2)
- // {
- // viewTopImage = sender.superview!
- // }
- arrImagePaths.removeAll()
- let dic = self.arrData[sender.superview!.tag] as! NSDictionary
- if dic.getString(key: "imageone") != "" {
- arrImagePaths.append(dic.getString(key: "imageone"))
- }
- if dic.getString(key: "imagetwo") != "" {
- arrImagePaths.append(dic.getString(key: "imagetwo"))
- }
- if dic.getString(key: "imagethree") != "" {
- arrImagePaths.append(dic.getString(key: "imagethree"))
- }
- sd.sourceImagesContainerView = viewTopImage
- sd.imageCount = arrImagePaths.count
- sd.currentImageIndex = Int32(sender.tag)
- sd.delegate = self
- sd.show()
- }
- var viewTopImage = UIView()
- var arrImagePaths = [String]()
- // MARK: 图片
- func photoBrowser(_ browser: SDPhotoBrowser!, placeholderImageFor index: Int) -> UIImage! {
- return (viewTopImage.subviews[index] as! UIImageView).image!
- }
- func photoBrowser(_ browser: SDPhotoBrowser!, highQualityImageURLFor index: Int) -> URL! {
- return URL(string: arrImagePaths[index])
- }
- func photoBrowser(_ browser: SDPhotoBrowser!, select index: Int) {
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- }
- override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
- super.init(nibName: "KnowledgeBaseViewController", bundle: nil)
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
|