123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- //
- // PersonalnfoViewController.swift
- // CommonFrame
- //
- // Created by Virgil on 2019/1/28.
- // Copyright © 2019 Virgil. All rights reserved.
- //
- import UIKit
- class PersonalInfoViewController: BaseViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
- @IBOutlet weak var lblAccount: UILabel!
- @IBOutlet weak var btnExit: UIButton!
- @IBOutlet weak var lblName: UILabel!
- @IBOutlet weak var imgIcon: UIImageView!
- @IBOutlet weak var lblNo: UILabel!
- var imgIconUrl = ""
- override func viewDidLoad() {
- super.viewDidLoad()
- self.title = "个人资料"
- initNavLeftBackButton()
- // Do any additional setup after loading the view.
- //btnExit.setCornerRadius(size: btnExit.height() / 2);
- imgIconUrl = CommonValue.getUserLogo()
- }
- //btnAddTarget(view: self.view, selector: #selector(self.btnMenuClick))
- @IBAction func btnMenuClick(_ sender: AnyObject) {
- switch (sender as! UIButton).tag {
- case 1001: // 头像
- btnLogoClick()
- break
- case 1002: // 性别
- break
- case 1003: // 昵称
- let vc = ModUserInfoViewController()
- vc.type = 0
- toViewController(viewController: vc)
- break
- case 1004: // 保存
- saveData()
- break
- case 1005: // 签名
- let vc = ModUserInfoViewController()
- vc.type = 1
- toViewController(viewController: vc)
- break
- case 1006: // 出生日期
- break
- default:
- break
- }
- }
- // MARK: =============加载数据===============
- func saveData() {
- let url = RequestURL.editUser
- let params = NSMutableDictionary()
- params.setValue(CommonValue.getUserId(), forKey: "userId")
- params.setValue(imgIconUrl, forKey: "headPortrait")
- submitData(url: url, params: params, tag: 1001)
- }
- override func returnData(tag: Int) {
- if tag == 1001 {
- appDelegate.reloadUserInfo()
- SVProgressHUD.showSuccess(withStatus: "修改成功")
- }
- }
- override func returnError(tag: Int, type: String) {
- if tag == 1001 {
- }
- }
- // MARK: ============选择头像============
- func btnLogoClick() {
- CommonUntils.AlertView(controller: self, title: nil, message: nil, buttons: ["拍照上传", "从相册上传"], style: .actionSheet) {[weak self] (index, _) in
- let ipc = UIImagePickerController()
- if index == 0 {
- ipc.sourceType = .camera
- } else {
- ipc.sourceType = .photoLibrary
- }
- ipc.delegate = self!
- ipc.allowsEditing = true
- self!.present(ipc, animated: true, completion: nil)
- }
- }
- var imgTemp: UIImage!
- func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
- self.dismiss(animated: true) {[weak self] in
- var imgTemp: UIImage? = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
- if picker.allowsEditing {
- imgTemp = info[UIImagePickerController.InfoKey.editedImage] as? UIImage
- }
- if imgTemp != nil {
- self!.UploadFile(img: imgTemp!)
- } else {
- SVProgressHUD.showError(withStatus: "图片选择失败,请重试")
- }
- }
- }
- func UploadFile(img: UIImage) {
- let qiNiuUpload = QiNiuUploadFile()
- qiNiuUpload.uploadFile(img: img) {[weak self] (type, str) in
- if type == 1 {
- self!.imgIconUrl = RequestURL.qiNiuImageUrl + str
- self!.imgIcon.loadImage(imgUrl: self!.imgIconUrl, defaultImage: "common_user")
- self!.imgIcon.setCornerRadius()
- } else {
- SVProgressHUD.showError(withStatus: "图片上传失败,请重新选择!")
- }
- }
- }
- override func notiReloadUser(noti: NSNotification) {
- lblName.text = CommonValue.getUserNickName()
- lblAccount.text = CommonValue.getUserPhone()
- lblNo.text = CommonValue.getUserRecCode()
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- imgIcon.loadImage(imgUrl: CommonValue.getUserLogo(), defaultImage: "common_user")
- imgIcon.setCornerRadius()
- lblName.text = CommonValue.getUserNickName()
- lblAccount.text = CommonValue.getUserPhone()
- lblNo.text = CommonValue.getUserRecCode()
- }
- override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
- super.init(nibName: "PersonalInfoViewController", bundle: nil)
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- /*
- // MARK: - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- // Get the new view controller using segue.destination.
- // Pass the selected object to the new view controller.
- }
- */
- }
|