// // MyViewController.swift // xingchuangke // // Created by Virgil on 2019/3/22. // Copyright © 2019 Virgil. All rights reserved. // import UIKit class MyViewController: BaseViewController, UITableViewDataSource, UITableViewDelegate { // @IBOutlet weak var btnOnLine: UIButton! @IBOutlet weak var imgTitle: UIImageView! @IBOutlet weak var tableView: UITableView! @IBOutlet weak var viewMenu3: UIView! @IBOutlet weak var viewMenu2: UIView! @IBOutlet weak var viewMenu1: UIView! @IBOutlet weak var btnCopyCode: UIButton! @IBOutlet weak var imgUserIcon: UIImageView! @IBOutlet weak var lblName: UILabel! @IBOutlet weak var lblCode: UILabel! @IBOutlet weak var viewTop: UIView! @IBOutlet var imgName: UILabel! // @IBOutlet weak var btnCall: UIButton! @IBOutlet weak var lblAmount1: UILabel! @IBOutlet weak var lblAmount2: UILabel! @IBOutlet weak var lblAmount3: UILabel! let arrTitle = [["我的钱包","我的政策", "我的订单", "实名认证", "提现签约认证", "修改结算卡"], ["展业守则", "帮助中心", "安全设置"], ["退出登录"]] let arrImage = [["qianbao","ion_personal_policy", "ion_personal_08", "ion_personal_02", "qianzheng", "ion_personal_03"], ["ion_personal_04", "ion_personal_05", "ion_personal_06"], ["ion_personal_07"]] override func viewDidLoad() { super.viewDidLoad() CommonViewUntils.setViewCenter(arrView: [viewMenu1, viewMenu2, viewMenu3], marginLeft: 30, marginRight: 30) if CommonUntils.isIphonex() { viewTop.setSizeHeight(height: 46 + 166) tableView.marginTop(top: 0, view: viewTop) tableView.setSizeHeight(height: ScreenHeight - viewTop.bottom() - 80) } else { viewTop.setSizeHeight(height: 22 + 166) tableView.marginTop(top: 0, view: viewTop) tableView.setSizeHeight(height: ScreenHeight - viewTop.bottom() - 50) } tableView.register(UINib(nibName: "CommonMyMenuTableViewCell", bundle: nil), forCellReuseIdentifier: "CommonMyMenuTableViewCell") tableView.delegate = self tableView.dataSource = self // tableView.separatorStyle = .none tableView.showsVerticalScrollIndicator = false tableView.estimatedRowHeight = 100 if tableView.responds(to: #selector(setter: UITableViewCell.separatorInset)) { tableView.separatorInset = UIEdgeInsets.init(top: 0, left: 51, bottom: 0, right: 0) } if tableView.responds(to: #selector(setter: UITableViewCell.layoutMargins)) { tableView.layoutMargins = UIEdgeInsets.init(top: 0, left: 51, bottom: 0, right: 0) } // if !CommonUntils.isIphonex() { // btnCall.marginTop(top: btnCall.topm() + 20) // btnOnLine.marginBottom(bottom: 20, view: btnCall) // } } @IBAction func btnMenuClick(_ sender: AnyObject) { switch (sender as! UIButton).tag { case 1001: // 修改个人信息 appDelegate.navController.pushViewController(PersonalInfoViewController(), animated: true) break case 1002: // 荣誉认证 appDelegate.navController.pushViewController(QualificationsViewController(), animated: true) break case 1003: // 私信 appDelegate.navController.pushViewController(NewsListViewController(), animated: true) break case 1004: // 电话 if CommonUntils.getIsSimulator() { SVProgressHUD.showError(withStatus: "模拟器环境下不能拨打电话") } else { if CommonValue.getDefaultValueForKey(key: "customer_phone") != "" { CommonUntils.callPhone(phone: CommonValue.getDefaultValueForKey(key: "customer_phone")) } } break case 1005: //复制我的推荐码 CommonUntils.copyString(str: CommonValue.getUserRecCode()) SVProgressHUD.showSuccess(withStatus: "复制成功!") break case 1006: // let qySource = QYSource() qySource.title = "客服" qySource.urlString = "" let sessionQY = QYSDK.shared().sessionViewController() if sessionQY != nil { sessionQY!.sessionTitle = "在线客服"// CommonValue.getNikeName() sessionQY!.source = qySource sessionQY!.hidesBottomBarWhenPushed = true appDelegate.navController.pushViewController(sessionQY!, animated: true) initCusServiceBackButton(viewController: sessionQY!) } break default: break } } // MARK: TABLEVLEW 实现 func numberOfSections(in tableView: UITableView) -> Int { return arrTitle.count } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return arrTitle[section].count } func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return 10 } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return 58 } func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { let view = UIView.init() view.backgroundColor = UIColor.init(white: 242/255.0, alpha: 1.0) return view } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "CommonMyMenuTableViewCell", for: indexPath as IndexPath) as! CommonMyMenuTableViewCell cell.lblTitle.text = arrTitle[indexPath.section][indexPath.row] cell.btnLeftImage.setImage(UIImage(named: arrImage[indexPath.section][indexPath.row]), for: .normal) cell.lblRight.isHidden = true cell.imgRightContent.isHidden = true cell.viewLine.isHidden = true if arrTitle[indexPath.section][indexPath.row] == "实名认证" { ///未实名或审核未通过 if(CommonValue.getUserIsAuthentication() == -1) //未登录 { cell.lblRight.isHidden = true cell.imgRightContent.isHidden = true } else if CommonValue.getUserIsAuthentication() == 0 || CommonValue.getUserIsAuthentication() == 3 { cell.lblRight.isHidden = true cell.imgRightContent.isHidden = true } else if(CommonValue.getUserIsAuthentication() == 1) //审核中 { cell.lblRight.isHidden = false cell.imgRightContent.isHidden = true cell.lblRight.text = "审核中" } else //审核已通过 { cell.lblRight.isHidden = false cell.imgRightContent.isHidden = false cell.lblRight.text = CommonValue.getUserRealName() } } return cell } func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { if cell.responds(to: #selector(setter: UITableViewCell.separatorInset)) { cell.separatorInset = UIEdgeInsets.init(top: 0, left: 51, bottom: 0, right: 0) } if cell.responds(to: #selector(setter: UITableViewCell.layoutMargins)) { cell.layoutMargins = UIEdgeInsets.init(top: 0, left: 51, bottom: 0, right: 0) } } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let titleStr: String = arrTitle[indexPath.section][indexPath.row] if titleStr == "我的订单" { let viewWeb = MyOrderViewController() toViewController(viewController: viewWeb) } else if titleStr == "实名认证" { ///未实名或审核未通过 if CommonValue.getUserIsAuthentication() == 0 || CommonValue.getUserIsAuthentication() == 3 { let viewWeb = RealNameAuthViewController() toViewController(viewController: viewWeb) } else if(CommonValue.getUserIsAuthentication() == 1) //审核中 { SVProgressHUD.showError(withStatus: "实名认证信息正在审核中") appDelegate.reloadUserInfo() } else //审核已通过 { let viewWeb = RealNameDetailViewController() toViewController(viewController: viewWeb) } } else if titleStr == "我的钱包" { let viewWeb = WalletHomeVC() GB_Nav.pushViewController(viewWeb, animated: true) // toViewController(viewController: viewWeb) }else if titleStr == "修改结算卡" { let viewWeb = ModBankCardViewController() toViewController(viewController: viewWeb) }else if titleStr == "提现签约认证" { self.loadData() } else if titleStr == "邀请好友" { let viewWeb = InviteViewController() toViewController(viewController: viewWeb) } else if titleStr == "安全设置" { let viewWeb = SafeSettingViewController() toViewController(viewController: viewWeb) } else if titleStr == "帮助中心" { let viewWeb = HelpListViewController() toViewController(viewController: viewWeb) } else if titleStr == "展业守则" { let viewWeb = CommonWebViewViewController() viewWeb.strTitle = "展业守则" viewWeb.url = "\(RequestURL.sysConfigWeb)?type=exhibition_rules" viewWeb.sourceType = 0 appDelegate.navController.pushViewController(viewWeb, animated: true) } else if titleStr == "我的政策" { let vc = BrandListViewController() vc.strTitle = "我的政策" toViewController(viewController: vc) } else if titleStr == "我的学习" { let vc = StudyViewController() toViewController(viewController: vc) } else if titleStr == "退出登录" { CommonValue.setDefaultUserInfoForString(value: "0", key: "common_default_is_ss_password") CommonValue.clearLoginUser() GlobalMethod.logoutSuccess() if !GlobalMethod.isLoginSuccess(){ let vcvc = LoginViewController() GB_Nav.pushViewController(vcvc, animated: true) } } } // MARK: request func loadData() { let url = RequestURL.rz let params = NSMutableDictionary() params.setValue(CommonValue.getUserId(), forKey: "userId") params.setValue("0000", forKey: "code") params.setValue("", forKey: "returnUrl") loadDataInfoPostRZ(url: url, params: params, tag: 1001) } override func returnData(tag: Int) { if tag == 1001 { let htmlPath = "\(self.dicData["message"]as!String)" let viewWeb = SigningCertificationVC() viewWeb.htmlPath = htmlPath toViewController(viewController: viewWeb) } } override func notiReloadUser(noti: NSNotification) { tableView.reloadData() } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) appDelegate.setNavigationBarHidden(isHidden: true) reloadUserInfo() } func resetView(){ lblCode.text = CommonValue.getUserRecCode() // if CommonValue.getUserLogo() == "" { // lblName.marginLeft(left: imgUserIcon.frame.origin.x) // imgUserIcon.isHidden = true // } else { lblName.marginLeft(left: 57) imgUserIcon.loadImage(imgUrl: CommonValue.getUserLogo(), defaultImage: "common_user") imgUserIcon.setCornerRadius() imgUserIcon.isHidden = false // } lblName.text = CommonValue.getUserNickName() lblName.setSizeWidth(width: 200) lblName.sizeToFitWidth() lblCode.sizeToFitWidth() btnCopyCode.marginLeft(left: 4, view: lblCode) imgTitle.marginLeft(left: 2, view: lblName) imgName.marginLeft(left: 4, view: lblName) lblAmount1.text = "\(CommonValue.getUserAgentNum())" lblAmount2.text = "\(CommonValue.getUserMerchantNum())" lblAmount3.text = "\(CommonValue.getUserProfitTotal())" imgTitle.loadImage(imgUrl: CommonValue.getULevelPic(), defaultImage: "") imgName.text = "\(CommonValue.getUserLevelName())" // imgTitle.image = UIImage(named: "member\(CommonValue.getUserLevel())") tableView.reloadData() if CommonValue.checkIsAS() { imgTitle.isHidden = true } if CommonValue.getULevelPic() == ""{ imgTitle.isHidden = true imgName.isHidden = false }else{ imgTitle.isHidden = false imgName.isHidden = true } } ///更新用户信息 func reloadUserInfo() { if CommonValue.getUserId() == "" { return } let params = NSMutableDictionary() // let http = AFHTTPSessionManager() // http.requestSerializer.setValue(CommonValue.getUserId(), forHTTPHeaderField: "userId") // http.requestSerializer.setValue("1", forHTTPHeaderField: "phoneType") // http.requestSerializer.setValue(CommonUntils.getSystemVersion(), forHTTPHeaderField: "apkVersion") let http = CommonValue.getHttp() params.setValue(CommonValue.getUserId(), forKey: "userId") let url = RequestURL.findUserById http.get(url, parameters: params, progress: nil, success: {[weak self] (_, json1) -> Void in let json = json1 as! NSDictionary let succeed = json.object(forKey: "succeed") as! String if succeed == "000" { let dataInfo = json["dataInfo"] as? NSDictionary if dataInfo != nil { CommonValue.setLoginUserInfo(loginUser: NSMutableDictionary(dictionary: dataInfo!)) self!.initCusServiceUserInfo() } } }, failure: { (_, _) -> Void in }) } func initCusServiceUserInfo() { let userInfo = QYUserInfo() userInfo.userId = CommonValue.getUserId() let dicName = ["key": "real_name", "value": CommonValue.getUserNickName()] let dicPhone = ["key": "mobile_phone", "value": CommonValue.getUserPhone()] let dicCode = ["key": "bankcard", "value": CommonValue.getUserRecCode(), "index": "0", "label": "推荐码"] let array = NSMutableArray(array: [dicName, dicPhone, dicCode]) userInfo.data = CommonJSON.arrayToJson(arr: array) QYSDK.shared()?.setUserInfo(userInfo, authTokenVerificationResultBlock: { (succ) in print("====\(succ)===") }) resetView() } override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName: "MyViewController", bundle: nil) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } }