123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411 |
- //
- // HomeViewController.swift
- // xingchuangke
- //
- // Created by Virgil on 2019/3/22.
- // Copyright © 2019 Virgil. All rights reserved.
- //
- import UIKit
- class HomeViewController: BaseViewController, UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate {
- @IBOutlet weak var imgUserType: UIImageView!
- @IBOutlet weak var lblRealName: UILabel!
- @IBOutlet weak var btnPersonal: UIButton!
- @IBOutlet weak var viewTop: UIView!
- var headerView: HomeHeaderView!
- @IBOutlet weak var tableView: UITableView!
- override func viewDidLoad() {
- super.viewDidLoad()
- tableView.register(UINib(nibName: "HomeTableViewCell", bundle: nil), forCellReuseIdentifier: "HomeTableViewCell")
- tableView.delegate = self
- tableView.dataSource = self
- tableView.separatorStyle = .none
- tableView.showsVerticalScrollIndicator = false
- tableView.estimatedRowHeight = 100
- tableView.keyboardDismissMode = .onDrag
- 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()
- })
- // tableView.mj_header.backgroundColor = CommonUntils.getUIColorFromRGB(rgbValue: 0x37A6FF, alpha: 1.0)
- headerView = (CommonViewUntils.getViewForXIB(xibName: "HomeHeaderView") as! HomeHeaderView)
- headerView.isHid = true
- headerView.initView()
- tableView.tableHeaderView = headerView
- tableView.reloadData()
- let imgUrl = ["https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1553911731&di=204e2bce757c3d97ec7a459bced6d226&imgtype=jpg&er=1&src=http%3A%2F%2Fpic31.nipic.com%2F20130804%2F7487939_090818211000_2.jpg", "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1553317230347&di=ded31b12c8a8d3ad31d4b88003e1dab7&imgtype=0&src=http%3A%2F%2Fpic2.ooopic.com%2F12%2F07%2F12%2F07bOOOPICbc_1024.jpg", "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1553317230345&di=a119f97664d26ba897e692a50554c35e&imgtype=0&src=http%3A%2F%2Fpic20.huitu.com%2Fres%2F20140728%2F239586_20140728224850215303_1.jpg"]
- //轮播图片
- let viewHeader = Virgil_PagedView(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: headerView.viewContent1.frame.height), imageURLStrings: imgUrl, placeholderImage: UIImage(named: "img_banner_01")!, timeInterval: 6) {
- (_) -> Void in
- }
- viewHeader.backgroundColor = UIColor.clear
- viewHeader.titles = ["1111", "2222", "3333", "4444"]
- headerView.viewContent1.addSubview(viewHeader)
- if CommonUntils.isIphonex() {
- viewTop.setSizeHeight(height: 88)
- } else {
- viewTop.setSizeHeight(height: 64)
- }
- headerView.btnStartJS.addTarget(self, action: #selector(btnMenuClick), for: .touchUpInside)
- loadadverData()
- }
- // MARK: =============加载数据===============
- func loadData() {
- let url = RequestURL.hotActivityPageList
- let params = NSMutableDictionary()
- loadDataList(url: url, params: params, tableView: self.tableView, tag: 1001)
- }
- let arrHeader = NSMutableArray()
- func loadHeaderData() {
- let url = RequestURL.findAdvertisingWheel
- let params = NSMutableDictionary()
- params.setValue(0, forKey: "position")
- arrHeader.removeAllObjects()
- loadDataList(url: url, params: params, tag: 1003, array: arrHeader)
- }
- let dicReRevenueCalculator = NSMutableDictionary()
- func revenueCalculator() {
- if headerView.txtCTPOSPersonal.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入传统POS(个人)月激活商户数")
- return
- }
- if headerView.txtCTPOS.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入传统POS(商户)月激活商户数")
- return
- }
- if headerView.txtMPOS.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入MPOS月激活商户数")
- return
- }
- if headerView.txtMonth.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入累计月数")
- return
- }
- headerView.txtMonth.resignFirstResponder()
- headerView.txtCTPOSPersonal.resignFirstResponder()
- headerView.txtCTPOS.resignFirstResponder()
- headerView.txtMPOS.resignFirstResponder()
- let url = RequestURL.revenueCalculator
- let params = NSMutableDictionary()
- params.setValue(headerView.txtCTPOSPersonal.text!, forKey: "ctPosGRNum")
- params.setValue(headerView.txtCTPOS.text!, forKey: "ctPosSHNum")
- params.setValue(headerView.txtMPOS.text!, forKey: "MPosNum")
- params.setValue(headerView.txtMonth.text!, forKey: "monthNum")
- loadDataInfo(url: url, params: params, tag: 1002, reDic: dicReRevenueCalculator)
- }
- override func returnData(tag: Int) {
- if tag == 1001 {
- tableView.reloadData()
- } else if tag == 1002 {
- let viewMoney = (CommonViewUntils.getViewForXIB(xibName: "CalcResultView") as! CalcResultView)
- viewMoney.initView(money: "\(dicReRevenueCalculator.getString(key: "total"))") {[weak self] (_, _) in
- self!.headerView.txtCTPOSPersonal.text = ""
- self!.headerView.txtCTPOS.text = ""
- self!.headerView.txtMPOS.text = ""
- self!.headerView.txtMonth.text = ""
- }
- appDelegate.navController.showBackgroudView(viewContent: viewMoney, isCenter: true, clickOtherIsClose: false)
- } else if tag == 1003 {
- if arrHeader.count > 0 {
- var imgUrl = [String]()
- if arrHeader.count == 3 {
- headerView.isHid = true
- headerView.initView()
- }else {
- headerView.isHid = false
- headerView.initView()
- }
- for i in 0 ..< arrHeader.count {
- imgUrl.append(getStringForArray(key: "img_path", arr: arrHeader, current: i))
- }
- let viewHeader = Virgil_PagedView(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: headerView.viewContent1.frame.height), imageURLStrings: imgUrl, placeholderImage: UIImage(named: "img_banner_01")!, timeInterval: 6) {[weak self]
- (item) -> Void in
- if CommonValue.getUserId() == "" {
- appDelegate.navController.pushViewController(LoginViewController(), animated: true)
- return
- }
- let type = (self!.arrHeader[item] as! NSDictionary).getInt(key: "type")
- ///0:内部web 1:外部web 111:邀请好友 222开通商户
- if type == 0 || type == 1 {
- let web = CommonWebViewViewController()
- web.strTitle = "详情"
- web.url = (self!.arrHeader[item] as! NSDictionary).getString(key: "web_url")
- appDelegate.navController.pushViewController(web, animated: true)
- } else if type == 111 {
- let vc = InviteViewController()
- appDelegate.navController.pushViewController(vc, animated: true)
- } else if type == 222 {
- let vc = SelectPayBrandViewController()
- appDelegate.navController.pushViewController(vc, animated: true)
- }
- }
- viewHeader.backgroundColor = UIColor.clear
- viewHeader.titles = ["1111", "2222", "3333", "4444"]
- headerView.viewContent1.removeAll()
- headerView.viewContent1.addSubview(viewHeader)
- }
- loadData()
- }
- }
- override func returnError(tag: Int, type: String) {
- if tag == 1003 {
- loadData()
- }
- }
- //btnAddTarget(view: self.view, selector: #selector(self.btnMenuClick))
- @IBAction func btnMenuClick(_ sender: AnyObject) {
- if CommonValue.getUserId() == "" && (sender as! UIButton).tag != 1013 {
- appDelegate.navController.pushViewController(LoginViewController(), animated: true)
- return
- }
- switch (sender as! UIButton).tag {
- case 1001: // 荣誉资质
- // let vc = TestCommon();
- // vc.uploadHaiKe();
- appDelegate.navController.pushViewController(QualificationsViewController(), animated: true)
- break
- case 1002: // 消息
- appDelegate.navController.pushViewController(NewsListViewController(), animated: true)
- break
- case 1003: // 个人信息
- appDelegate.navController.pushViewController(PersonalInfoViewController(), animated: true)
- break
- case 1004: //
- break
- case 1005: //
- break
- case 1006: //
- break
- case 1013: //
- revenueCalculator()
- break
- default:
- break
- }
- }
- // 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, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "HomeTableViewCell", for: indexPath as IndexPath) as! HomeTableViewCell
- cell.img.loadImage(imgUrl: getString(current: indexPath.row, key: "image"), defaultImage: "")
- cell.img.setCornerRadius(size: 8)
- return cell
- }
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- if indexPath.row >= arrData.count {
- return
- }
- let viewWeb = CommonWebViewViewController()
- viewWeb.strTitle = "详情"
- viewWeb.url = getString(current: indexPath.row, key: "webUrl")
- toViewController(viewController: viewWeb)
- }
- func scrollViewDidScroll(_ scrollView: UIScrollView) {
- if scrollView.contentOffset.y < 10 {
- viewTop.backgroundColor = CommonUntils.getUIColorFromRGB(rgbValue: 0x37A6FF, alpha: 0.15)
- } else {
- var alpha = 0.15 + 0.002 * scrollView.contentOffset.y
- if alpha > 1 {
- alpha = 1
- }
- viewTop.backgroundColor = CommonUntils.getUIColorFromRGB(rgbValue: 0x37A6FF, alpha: alpha)
- }
- }
- override func notiReloadUser(noti: NSNotification) {
- reloadUserInfo()
- headerView.reloadMoney()
- }
- func reloadUserInfo() {
- lblRealName.setSizeWidth(width: 120)
- lblRealName.text = CommonValue.getUserNickName()
- lblRealName.sizeToFitWidth()
- if CommonValue.getUserNickName() == "未实名" || CommonValue.getUserNickName() == "未登录" || CommonValue.getUserNickName() == "" {
- imgUserType.isHidden = true
- } else {
- if CommonValue.checkIsAS() {
- imgUserType.isHidden = true
- } else {
- imgUserType.isHidden = false
- }
- imgUserType.marginLeft(left: 2, view: lblRealName)
- imgUserType.image = UIImage(named: "member\(CommonValue.getUserLevel())")
- }
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- appDelegate.setNavigationBarHidden(isHidden: true)
- reloadUserInfo()
- headerView.reloadMoney()
- tableView.setSizeHeight(height: ScreenHeight - common_bottom_height - 48)
- loadHeaderData()
- tableView.reloadData()
- }
- override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
- super.init(nibName: "HomeViewController", bundle: nil)
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- let bgView = UIView.init(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight))
- let advertView = UIView.init(frame: CGRect(x: 0, y: 0, width: 300, height: 400))
- var advertArray = NSArray.init()
- func loadadverData(){
- let http = AFHTTPSessionManager()
- http.post("http://app.xingchuangke.net/app/screenList", parameters: nil, progress: { (_) in
- }, success: { (operation, json) in
- print(json as Any)
- let success = (json as! NSDictionary).object(forKey: "statusCode") as! Int
- if success == 200 {
- let datat = (json as! NSDictionary).object(forKey: "data") as! NSArray
- self.advertArray = datat
- let dic = datat[0]as!NSDictionary
- self.bgView.backgroundColor = .black
- self.bgView.alpha = 0.5
- self.view.addSubview(self.bgView)
- self.view.bringSubviewToFront(self.bgView)
- self.view.bringSubviewToFront(self.advertView)
- self.advertView.center = self.bgView.center
- self.advertView.backgroundColor = .white
- self.advertView.layer.cornerRadius = 20
- self.advertView.alpha = 1
- self.view.addSubview(self.advertView)
- var strHtml = self.getString(key: "content", dic: dic)
- let label:UITextView = UITextView()
- label.isEditable = false
- label.frame = CGRect(x:10,
- y:10,
- width:280,
- height:380);
- let width:CGFloat = ( 270);
- let str:NSString = "<html><meta name=\"viewport\" content=\"width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\"/><head><style type=\"text/css\">body{font-size:18px;}</style></head><body>%@<style>*{ width: %fpx; margin: 0; padding: 0 0; box-sizing: border-box;} img{ width: %fpx;}</style></body></html>" as NSString;
- strHtml = NSString(format: str,strHtml,width,width) as String
- let data:Data = strHtml.data(using: String.Encoding(rawValue: String.Encoding.unicode.rawValue))!
- do {
- let attrinbuteString: NSAttributedString = try! NSAttributedString.init(data: data, options: [ NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html ], documentAttributes: nil)
- DispatchQueue.main.async {
- label.attributedText = attrinbuteString
- }
- }
- label.isUserInteractionEnabled = true
- let tapGes = UITapGestureRecognizer(target: self,
- action: #selector(self.titleLabelClick(tapGes: )))
- label.addGestureRecognizer(tapGes)
- let closeBtn = UIButton.init(frame: CGRect(x: kScreenWidth/2-20, y: self.advertView.bottom()+20, width: 60, height: 60))
- closeBtn.addTarget(self, action: #selector(self.closeadvert), for: .touchUpInside)
- closeBtn.setImage(UIImage.init(named: "ion_delete"), for: .normal)
- self.bgView.addSubview(closeBtn)
- self.advertView.addSubview(label)
- let btnTap = UIButton.init(frame: CGRect(x: 250, y: 20, width: 40, height: 40))
- btnTap.setImage(UIImage.init(named: "ico_04"), for:.normal )
- btnTap.addTarget(self, action: #selector(self.btnTapTouch), for: .touchUpInside)
- self.advertView.addSubview(btnTap)
- }
- }) { (_, _) in
- }
- }
- @objc func btnTapTouch(){
- let dic = advertArray[0]as!NSDictionary
- if getString(key: "webUrl", dic: dic) == "" {
- }else{
- let web = CommonWebViewViewController()
- web.strTitle = dic.getString(key: "title")
- web.url = dic.getString(key: "webUrl")
- appDelegate.navController.pushViewController(web, animated: true)
- print("dianji")
- }
- }
- @objc func closeadvert(){
- self.bgView.removeFromSuperview()
- self.advertView.removeFromSuperview()
- }
- // 点击事件 需要添加 @objc
- @objc func titleLabelClick(tapGes:UITapGestureRecognizer){
- // 1、获取当前label
- let dic = advertArray[0]as!NSDictionary
- if getString(key: "webUrl", dic: dic) == "" {
- }else{
- let web = CommonWebViewViewController()
- web.strTitle = dic.getString(key: "title")
- web.url = dic.getString(key: "webUrl")
- appDelegate.navController.pushViewController(web, animated: true)
- print("dianji")
- }
- }
- }
|