TiXianFaPiaoViewController.swift 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 TiXianFaPiaoViewController: BaseViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
  10. var shopOpen: ShopOpenEntity!
  11. @IBOutlet weak var txt1: UITextField!
  12. @IBOutlet weak var btnFinish: UIButton!
  13. @IBOutlet weak var txtNo: UITextField!
  14. @IBOutlet weak var view1: UIView!
  15. @IBOutlet weak var view2: UIView!
  16. @IBOutlet weak var view3: UIView!
  17. ///发票类型 : 0:普通 1专用3% 2专用6% 3不开发票
  18. var fbType = 0
  19. var machineTypeId: String = ""
  20. // 选择品牌设置的金额
  21. var brandEarnArr: NSArray?
  22. var money = ""
  23. ///是否开发票 0:否 1:是
  24. var isFaPiao = 0
  25. @IBOutlet weak var imgYYZZ: UIImageView!
  26. override func viewDidLoad() {
  27. super.viewDidLoad()
  28. initNavLeftBackButton()
  29. self.title = "提示"
  30. //发票类型: 增值税专用发票 增值税普通发票
  31. //税率: 3% 6%
  32. //不开票扣8% 普通发票扣6%
  33. }
  34. @IBAction func btnUploadClick(_ sender: Any) {
  35. CommonUntils.AlertView(controller: self, title: nil, message: nil, buttons: ["拍照上传", "从相册上传"], style: .actionSheet) {[weak self] (index, _) in
  36. let ipc = UIImagePickerController()
  37. if index == 0 {
  38. ipc.sourceType = .camera
  39. } else {
  40. ipc.sourceType = .photoLibrary
  41. }
  42. ipc.delegate = self!
  43. ipc.allowsEditing = false
  44. self!.present(ipc, animated: true, completion: nil)
  45. }
  46. }
  47. var imgTemp: UIImage!
  48. func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
  49. self.dismiss(animated: true) {[weak self] in
  50. var imgTemp: UIImage? = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
  51. if picker.allowsEditing {
  52. imgTemp = info[UIImagePickerController.InfoKey.editedImage] as? UIImage
  53. }
  54. if imgTemp != nil {
  55. self!.UploadFile(img: imgTemp!)
  56. } else {
  57. SVProgressHUD.showError(withStatus: "图片选择失败,请重试")
  58. }
  59. }
  60. }
  61. var strImgYYZZ = ""
  62. func UploadFile(img: UIImage) {
  63. SVProgressHUD.show()
  64. let uploadFile = QiNiuUploadFile()
  65. uploadFile.uploadFile(img: img) {[weak self] (type, str) in
  66. SVProgressHUD.dismiss()
  67. if type == 1 {
  68. let userLoginUrl = RequestURL.qiNiuImageUrl + str
  69. self!.strImgYYZZ = userLoginUrl
  70. self!.imgYYZZ.loadImage(imgUrl: userLoginUrl, defaultImage: "")
  71. } else {
  72. SVProgressHUD.showError(withStatus: "上传失败")
  73. }
  74. }
  75. }
  76. override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) {
  77. txt1.resignFirstResponder()
  78. txtNo.resignFirstResponder()
  79. }
  80. var viewSelectCity: Virgil_SelectCity!
  81. @IBAction func btnSelectAddressClick(_ sender: Any) {
  82. //var viewSelectCity:Virgil_SelectCity!
  83. let addressList = CommonUntils.getPlistArrayForName(fileName: "AddressNew")
  84. if viewSelectCity == nil {
  85. viewSelectCity = Virgil_SelectCity(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: view.height()))
  86. viewSelectCity.modelType = 2
  87. viewSelectCity.initView(arrAddress: addressList) {[weak self] (dic) in
  88. self!.shopOpen.addressId1 = self!.getString(key: "addressId1", dic: dic)
  89. self!.shopOpen.addressId2 = self!.getString(key: "addressId2", dic: dic)
  90. self!.shopOpen.addressId3 = self!.getString(key: "addressId3", dic: dic)
  91. //self!.shopOpen.address = self!.getString(key: "address", dic: dic);
  92. self!.txt1.text = self!.getString(key: "address", dic: dic)
  93. }
  94. self.view.addSubview(viewSelectCity)
  95. }
  96. viewSelectCity.showPickerView()
  97. }
  98. @IBAction func btnFinishClick(_ sender: Any) {
  99. if strImgYYZZ == "" {
  100. SVProgressHUD.showError(withStatus: "请上传发票照片")
  101. return
  102. }
  103. if txtNo.text!.length() < 1 {
  104. SVProgressHUD.showError(withStatus: "请填写快递公司")
  105. return
  106. }
  107. if txt1.text!.length() < 1 {
  108. SVProgressHUD.showError(withStatus: "请填写快递号")
  109. return
  110. }
  111. submitData()
  112. }
  113. // MARK: =============加载数据===============
  114. func submitData() {
  115. var url = RequestURL.cashApplicationWithMachineTypeId
  116. let params = NSMutableDictionary()
  117. if machineTypeId == "" {
  118. url = RequestURL.cashApplicationWithMachineTypeIdAll
  119. let data = (try? JSONSerialization.data(withJSONObject: brandEarnArr!, options: .prettyPrinted))!
  120. let strJson = NSString(data: data, encoding: String.Encoding.utf8.rawValue)
  121. params.setValue(strJson, forKey: "machineTypeAndAtm")
  122. }
  123. params.setValue(machineTypeId, forKey: "machineTypeId")
  124. params.setValue(money, forKey: "amountMoney")
  125. params.setValue(isFaPiao, forKey: "type")
  126. params.setValue(strImgYYZZ, forKey: "invoicePhoto")
  127. params.setValue(txtNo.text!, forKey: "expressName")
  128. params.setValue(txt1.text!, forKey: "expressNumber")
  129. if fbType == 0 {
  130. params.setValue("0", forKey: "invoiceType")
  131. params.setValue("", forKey: "reteType")
  132. } else {
  133. params.setValue("1", forKey: "invoiceType")
  134. if fbType == 1 {
  135. params.setValue("0", forKey: "reteType")
  136. } else if fbType == 2 {
  137. params.setValue("1", forKey: "reteType")
  138. }
  139. }
  140. params.setValue("1", forKey: "phoneType")
  141. submitData(url: url, params: params, tag: 1001)
  142. }
  143. override func returnData(tag: Int) {
  144. if tag == 1001 {
  145. appDelegate.reloadUserInfo()
  146. toViewController(viewController: TiXianAlertViewController())
  147. }
  148. }
  149. override func returnError(tag: Int, type: String) {
  150. }
  151. override func viewWillAppear(_ animated: Bool) {
  152. super.viewWillAppear(animated)
  153. }
  154. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  155. super.init(nibName: "TiXianFaPiaoViewController", bundle: nil)
  156. }
  157. required init?(coder aDecoder: NSCoder) {
  158. fatalError("init(coder:) has not been implemented")
  159. }
  160. }