123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- //
- // SelectedAddressViewController.swift
- // CommonFrame
- //
- // Created by Virgil on 2019/4/18.
- // Copyright © 2019 Virgil. All rights reserved.
- //
- import UIKit
- class SelectedAddressViewController: BaseViewController, UITextViewDelegate {
- @IBOutlet weak var txtAddress1: UITextField!
- @IBOutlet weak var txtPhone: UITextField!
- @IBOutlet weak var txtName: UITextField!
- @IBOutlet weak var btnConfrim: UIButton!
- @IBOutlet weak var txtContent: UITextView!
- @IBOutlet weak var view3: UIView!
- @IBOutlet weak var view2: UIView!
- @IBOutlet weak var view1: UIView!
- @IBOutlet weak var switchBtn: UISwitch!
- let dicAddress = NSMutableDictionary()
- var isDefault = 1
- override func viewDidLoad() {
- super.viewDidLoad()
- initNavLeftBackButton()
- self.title = "设置地址"
- view1.setLayer(borderWidth: 1.0, color: 0xf7f7f9)
- view2.setLayer(borderWidth: 1.0, color: 0xf7f7f9)
- view3.setLayer(borderWidth: 1.0, color: 0xf7f7f9)
- txtContent.setLayer(borderWidth: 1.0, color: 0xf7f7f9)
- view1.setCornerRadius(size: 6)
- view2.setCornerRadius(size: 6)
- view3.setCornerRadius(size: 6)
- txtContent.setCornerRadius(size: 8)
- lblAlert = UILabel(frame: CGRect(x: 15, y: 5, width: 180, height: 20))
- lblAlert.text = "输入详细地址"
- lblAlert.isEnabled = false
- lblAlert.backgroundColor = UIColor.clear
- lblAlert.font = UIFont.systemFont(ofSize: 12)
- txtContent.addSubview(lblAlert)
- txtContent.delegate = self
- txtName.setContentMarginLeft(leftWidth: 10)
- // txtContent.setmal
- btnConfrim.setCornerRadius(size: btnConfrim.height() / 2)
- }
- @IBAction func switchChanged(_ sender: Any) {
- if self.switchBtn.isOn == true {
- isDefault = 1
- } else {
- isDefault = 0
- }
- }
- override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) {
- txtContent.resignFirstResponder()
- txtName.resignFirstResponder()
- txtPhone.resignFirstResponder()
- txtAddress1.resignFirstResponder()
- }
- var lblAlert: UILabel!
- func textViewDidChange(_ textView: UITextView) {
- if textView.text.length() == 0 {
- lblAlert.text = "输入详细地址"
- } else {
- lblAlert.text = ""
- }
- }
- var address1 = ""
- var address2 = ""
- var address3 = ""
- var addressid1 = ""
- var addressid2 = ""
- var addressid3 = ""
- var viewSelectCity: Virgil_SelectCity!
- @IBAction func btnMenuClick(_ sender: AnyObject) {
- switch (sender as! UIButton).tag {
- case 1001: // 选择地址
- let addressList = CommonUntils.getPlistArrayForName(fileName: "AddressNew")
- if viewSelectCity == nil {
- viewSelectCity = Virgil_SelectCity(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: viewHeight))
- viewSelectCity.modelType = 2
- viewSelectCity.initView(arrAddress: addressList) {[weak self] (dic) in
- self!.txtAddress1.text = self!.getString(key: "address", dic: dic)
- self!.address1 = dic.getString(key: "addressName1")
- self!.address2 = dic.getString(key: "addressName2")
- self!.address3 = dic.getString(key: "addressName3")
- self!.addressid1 = dic.getString(key: "addressId1")
- self!.addressid2 = dic.getString(key: "addressId2")
- self!.addressid3 = dic.getString(key: "addressId3")
- }
- self.view.addSubview(viewSelectCity)
- }
- viewSelectCity.showPickerView()
- break
- case 1002: // 确定
- if txtName.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: txtName.placeholder!)
- return
- }
- if txtPhone.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: txtPhone.placeholder!)
- return
- }
- if txtAddress1.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: txtAddress1.placeholder!)
- return
- }
- if txtContent.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入详细地址")
- return
- }
- // mainViewControllerIsGo = false;
- // mainDicViewControllerIsGoValue.removeAllObjects();
- // mainDicViewControllerIsGoValue.setValue(txtName.text!, forKey: "name")
- // mainDicViewControllerIsGoValue.setValue(txtPhone.text!, forKey: "phone")
- // mainDicViewControllerIsGoValue.setValue(txtAddress1.text!, forKey: "address1")
- // mainDicViewControllerIsGoValue.setValue(txtContent.text!, forKey: "address2")
- submitData()
- break
- case 1003: //
- break
- case 1004: //
- break
- case 1005: //
- break
- case 1006: //
- break
- default:
- break
- }
- }
- // MARK: =============加载数据===============
- func submitData() {
- let params = NSMutableDictionary()
- if dicAddress.getString(key: "id") != "" {
- params.setValue(dicAddress.getString(key: "id"), forKey: "id")
- }
- params.setValue(CommonValue.getUserId(), forKey: "userId")
- params.setValue(address1, forKey: "provinceName")
- params.setValue(address2, forKey: "cityName")
- params.setValue(address3, forKey: "areaName")
- params.setValue(addressid1, forKey: "provinceId")
- params.setValue(addressid2, forKey: "cityId")
- params.setValue(addressid3, forKey: "areaId")
- params.setValue(txtName.text!, forKey: "linkName")
- params.setValue(txtContent.text!, forKey: "address")
- params.setValue(txtPhone.text!, forKey: "linkPhone")
- params.setValue(isDefault, forKey: "isDefault")
- let http = AFHTTPSessionManager()
- http.post(RequestURL.addUserAddress, parameters: params, progress: { (_) in
- }, success: { (operation, json) in
- print(json as Any)
- let success = (json as! NSDictionary).object(forKey: "statusCode") as! Int
- if success == 200 {
- // let dic = (json as! NSDictionary).object(forKey: "data") as! NSDictionary
- //
- SVProgressHUD.showSuccess(withStatus: "提交成功!")
- }
- }) { (_, _) in
- }
- // submitData(url: url, params: params, tag: 1001)
- }
- override func returnData(tag: Int) {
- if tag == 1001 {
- handleBack()
- }
- }
- override func returnError(tag: Int, type: String) {
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- if dicData.getString(key: "name") != "" {
- txtName.text = dicAddress.getString(key: "link_name")
- txtPhone.text = dicAddress.getString(key: "link_phone")
- txtAddress1.text = "\(dicAddress.getString(key: "province_name"))\(dicAddress.getString(key: "city_name"))\(dicAddress.getString(key: "area_name"))"
- txtContent.text = dicAddress.getString(key: "address")
- lblAlert.text = ""
- self.address1 = dicAddress.getString(key: "province_name")
- self.address2 = dicAddress.getString(key: "city_name")
- self.address3 = dicAddress.getString(key: "area_name")
- self.isDefault = dicAddress.getInt(key: "is_default")
- if dicAddress.getString(key: "is_default") == "1"{
- self.switchBtn.isOn = true
- } else {
- self.switchBtn.isOn = false
- }
- }
- }
- override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
- super.init(nibName: "SelectedAddressViewController", bundle: nil)
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
|