123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- //
- // ShopAddressViewController.swift
- // xingchuangke
- //
- // Created by Virgil on 2019/3/29.
- // Copyright © 2019 Virgil. All rights reserved.
- //
- import UIKit
- class ShopAddressViewController: BaseViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
- var shopOpen: ShopOpenEntity!
- @IBOutlet weak var txt2: UITextField!
- @IBOutlet weak var txt1: UITextField!
- @IBOutlet weak var btnFinish: UIButton!
- @IBOutlet weak var txtNo: UITextField!
- @IBOutlet weak var view1: UIView!
- @IBOutlet weak var view2: UIView!
- @IBOutlet weak var view3: UIView!
- @IBOutlet weak var imgYYZZ: UIImageView!
- override func viewDidLoad() {
- super.viewDidLoad()
- initNavLeftBackButton()
- self.title = "店铺信息"
- loadDefaultData()
- if shopOpen.shopType == 0 {
- view1.isHidden = true
- view2.isHidden = true
- view3.marginTop(top: 25)
- btnFinish.marginTop(top: 20, view: view3)
- }
- // Do any additional setup after loading the view.
- }
- @IBAction func btnUploadClick(_ sender: Any) {
- 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 = false
- 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: "图片选择失败,请重试")
- }
- }
- }
- var strImgYYZZ = ""
- func UploadFile(img: UIImage) {
- SVProgressHUD.show()
- let uploadFile = QiNiuUploadFile()
- uploadFile.uploadFile(img: img) {[weak self] (type, str) in
- SVProgressHUD.dismiss()
- if type == 1 {
- let userLoginUrl = RequestURL.qiNiuImageUrl + str
- self!.strImgYYZZ = userLoginUrl
- self!.imgYYZZ.loadImage(imgUrl: userLoginUrl, defaultImage: "")
- } else {
- SVProgressHUD.showError(withStatus: "上传失败")
- }
- }
- }
- func loadDefaultData() {
- txt2.text = shopOpen.addressDetail
- txt1.text = "\(shopOpen.addressName1) \(shopOpen.addressName2) \(shopOpen.addressName3)"
- if shopOpen.shopType == 1 {
- if shopOpen.licenseImage != "" {
- imgYYZZ.loadImage(imgUrl: shopOpen.licenseImage, defaultImage: "")
- txtNo.text = shopOpen.licenseNum
- }
- }
- }
- override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) {
- txt1.resignFirstResponder()
- txt2.resignFirstResponder()
- txtNo.resignFirstResponder()
- }
- var viewSelectCity: Virgil_SelectCity!
- @IBAction func btnSelectAddressClick(_ sender: Any) {
- //var viewSelectCity:Virgil_SelectCity!
- let addressList = CommonUntils.getPlistArrayForName(fileName: "AddressNew")
- if viewSelectCity == nil {
- viewSelectCity = Virgil_SelectCity(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: view.height()))
- viewSelectCity.modelType = 2
- viewSelectCity.initView(arrAddress: addressList) {[weak self] (dic) in
- self!.shopOpen.addressId1 = self!.getString(key: "addressId1", dic: dic)
- self!.shopOpen.addressId2 = self!.getString(key: "addressId2", dic: dic)
- self!.shopOpen.addressId3 = self!.getString(key: "addressId3", dic: dic)
- self!.shopOpen.addressName1 = self!.getString(key: "addressName1", dic: dic)
- self!.shopOpen.addressName2 = self!.getString(key: "addressName2", dic: dic)
- self!.shopOpen.addressName3 = self!.getString(key: "addressName3", dic: dic)
- //self!.shopOpen.address = self!.getString(key: "address", dic: dic);
- self!.txt1.text = self!.getString(key: "address", dic: dic)
- }
- self.view.addSubview(viewSelectCity)
- }
- viewSelectCity.showPickerView()
- }
- @IBAction func btnFinishClick(_ sender: Any) {
- if shopOpen.shopType == 1 {
- if strImgYYZZ == "" {
- SVProgressHUD.showError(withStatus: "请上传营业执照")
- return
- }
- if txtNo.text! == "" {
- SVProgressHUD.showError(withStatus: "请输入营业执照号")
- return
- }
- }
- if txt1.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请选择商户所在省市区")
- return
- }
- if txt2.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请填写店铺经营位置")
- return
- }
- shopOpen.licenseImage = strImgYYZZ
- shopOpen.licenseNum = txtNo.text!
- shopOpen.addressDetail = txt2.text!
- handleBack()
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- }
- override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
- super.init(nibName: "ShopAddressViewController", bundle: nil)
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
|