ShopAddressViewController.swift 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. //
  2. // ShopAddressViewController.swift
  3. // xingchuangke
  4. //
  5. // Created by Virgil on 2019/3/29.
  6. // Copyright © 2019 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. class ShopAddressViewController: BaseViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
  10. var shopOpen: ShopOpenEntity!
  11. @IBOutlet weak var txt2: UITextField!
  12. @IBOutlet weak var txt1: UITextField!
  13. @IBOutlet weak var btnFinish: UIButton!
  14. @IBOutlet weak var txtNo: UITextField!
  15. @IBOutlet weak var view1: UIView!
  16. @IBOutlet weak var view2: UIView!
  17. @IBOutlet weak var view3: UIView!
  18. @IBOutlet weak var imgYYZZ: UIImageView!
  19. override func viewDidLoad() {
  20. super.viewDidLoad()
  21. initNavLeftBackButton()
  22. self.title = "店铺信息"
  23. loadDefaultData()
  24. if shopOpen.shopType == 0 {
  25. view1.isHidden = true
  26. view2.isHidden = true
  27. view3.marginTop(top: 25)
  28. btnFinish.marginTop(top: 20, view: view3)
  29. }
  30. // Do any additional setup after loading the view.
  31. }
  32. @IBAction func btnUploadClick(_ sender: Any) {
  33. CommonUntils.AlertView(controller: self, title: nil, message: nil, buttons: ["拍照上传", "从相册上传"], style: .actionSheet) {[weak self] (index, _) in
  34. let ipc = UIImagePickerController()
  35. if index == 0 {
  36. ipc.sourceType = .camera
  37. } else {
  38. ipc.sourceType = .photoLibrary
  39. }
  40. ipc.delegate = self!
  41. ipc.allowsEditing = false
  42. self!.present(ipc, animated: true, completion: nil)
  43. }
  44. }
  45. var imgTemp: UIImage!
  46. func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
  47. self.dismiss(animated: true) {[weak self] in
  48. var imgTemp: UIImage? = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
  49. if picker.allowsEditing {
  50. imgTemp = info[UIImagePickerController.InfoKey.editedImage] as? UIImage
  51. }
  52. if imgTemp != nil {
  53. self!.UploadFile(img: imgTemp!)
  54. } else {
  55. SVProgressHUD.showError(withStatus: "图片选择失败,请重试")
  56. }
  57. }
  58. }
  59. var strImgYYZZ = ""
  60. func UploadFile(img: UIImage) {
  61. SVProgressHUD.show()
  62. let uploadFile = QiNiuUploadFile()
  63. uploadFile.uploadFile(img: img) {[weak self] (type, str) in
  64. SVProgressHUD.dismiss()
  65. if type == 1 {
  66. let userLoginUrl = RequestURL.qiNiuImageUrl + str
  67. self!.strImgYYZZ = userLoginUrl
  68. self!.imgYYZZ.loadImage(imgUrl: userLoginUrl, defaultImage: "")
  69. } else {
  70. SVProgressHUD.showError(withStatus: "上传失败")
  71. }
  72. }
  73. }
  74. func loadDefaultData() {
  75. txt2.text = shopOpen.addressDetail
  76. txt1.text = "\(shopOpen.addressName1) \(shopOpen.addressName2) \(shopOpen.addressName3)"
  77. if shopOpen.shopType == 1 {
  78. if shopOpen.licenseImage != "" {
  79. imgYYZZ.loadImage(imgUrl: shopOpen.licenseImage, defaultImage: "")
  80. txtNo.text = shopOpen.licenseNum
  81. }
  82. }
  83. }
  84. override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) {
  85. txt1.resignFirstResponder()
  86. txt2.resignFirstResponder()
  87. txtNo.resignFirstResponder()
  88. }
  89. var viewSelectCity: Virgil_SelectCity!
  90. @IBAction func btnSelectAddressClick(_ sender: Any) {
  91. //var viewSelectCity:Virgil_SelectCity!
  92. let addressList = CommonUntils.getPlistArrayForName(fileName: "AddressNew")
  93. if viewSelectCity == nil {
  94. viewSelectCity = Virgil_SelectCity(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: view.height()))
  95. viewSelectCity.modelType = 2
  96. viewSelectCity.initView(arrAddress: addressList) {[weak self] (dic) in
  97. self!.shopOpen.addressId1 = self!.getString(key: "addressId1", dic: dic)
  98. self!.shopOpen.addressId2 = self!.getString(key: "addressId2", dic: dic)
  99. self!.shopOpen.addressId3 = self!.getString(key: "addressId3", dic: dic)
  100. self!.shopOpen.addressName1 = self!.getString(key: "addressName1", dic: dic)
  101. self!.shopOpen.addressName2 = self!.getString(key: "addressName2", dic: dic)
  102. self!.shopOpen.addressName3 = self!.getString(key: "addressName3", dic: dic)
  103. //self!.shopOpen.address = self!.getString(key: "address", dic: dic);
  104. self!.txt1.text = self!.getString(key: "address", dic: dic)
  105. }
  106. self.view.addSubview(viewSelectCity)
  107. }
  108. viewSelectCity.showPickerView()
  109. }
  110. @IBAction func btnFinishClick(_ sender: Any) {
  111. if shopOpen.shopType == 1 {
  112. if strImgYYZZ == "" {
  113. SVProgressHUD.showError(withStatus: "请上传营业执照")
  114. return
  115. }
  116. if txtNo.text! == "" {
  117. SVProgressHUD.showError(withStatus: "请输入营业执照号")
  118. return
  119. }
  120. }
  121. if txt1.text!.length() < 1 {
  122. SVProgressHUD.showError(withStatus: "请选择商户所在省市区")
  123. return
  124. }
  125. if txt2.text!.length() < 1 {
  126. SVProgressHUD.showError(withStatus: "请填写店铺经营位置")
  127. return
  128. }
  129. shopOpen.licenseImage = strImgYYZZ
  130. shopOpen.licenseNum = txtNo.text!
  131. shopOpen.addressDetail = txt2.text!
  132. handleBack()
  133. }
  134. override func viewWillAppear(_ animated: Bool) {
  135. super.viewWillAppear(animated)
  136. }
  137. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  138. super.init(nibName: "ShopAddressViewController", bundle: nil)
  139. }
  140. required init?(coder aDecoder: NSCoder) {
  141. fatalError("init(coder:) has not been implemented")
  142. }
  143. }