SalesmanFirstShowView.swift 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. //
  2. // SalesmanFirstShowView.swift
  3. // ADHTuanCan
  4. //
  5. // Created by 敖德亨 on 2023/11/14.
  6. //
  7. import UIKit
  8. import RxSwift
  9. import RxCocoa
  10. class SalesmanFirstShowView: UIView {
  11. @IBOutlet weak var topContent: NSLayoutConstraint!
  12. @IBOutlet weak var nameTF: UITextField!
  13. @IBOutlet weak var phoneTF: UITextField!
  14. @IBOutlet weak var postCodeTF: UITextField!
  15. @IBOutlet weak var addressDetailTF: UITextView!
  16. @IBOutlet weak var streeTF: UITextField!
  17. @IBOutlet weak var startTimeLab: UILabel!
  18. @IBOutlet weak var endTimeLab: UILabel!
  19. var name : String?
  20. var phone : String?
  21. var postCode : String?
  22. var address : String?
  23. var street : String?
  24. var startTime : String?
  25. var endTime : String?
  26. var shopcartId : NSNumber?
  27. ///
  28. var shopType : String?{
  29. didSet{
  30. self.viewModel.salesmanCompleteModel.shopType = self.shopType
  31. }
  32. }
  33. var vc : ADHBaseVC?
  34. @IBOutlet weak var saveBtn: UIButton!
  35. /// hud 提示
  36. lazy var hud : MCHud! = {
  37. return MCHud()
  38. }()
  39. let viewModel : HomeViewModel = HomeViewModel.init()
  40. let diposableBag = DisposeBag()
  41. override func awakeFromNib() {
  42. super.awakeFromNib()
  43. self.nameTF.inputText(maxLength: 19) {
  44. self.name = self.nameTF.text
  45. }
  46. self.phoneTF.inputNumber(maxLength: 20) {
  47. self.phone = self.phoneTF.text
  48. }
  49. self.postCodeTF.inputNumber(maxLength: 20) {
  50. self.postCode = self.postCodeTF.text
  51. }
  52. self.addressDetailTF.inputText(maxLength: 300) {
  53. self.address = self.addressDetailTF.text
  54. }
  55. self.streeTF.inputText(maxLength: 40) {
  56. self.street = self.streeTF.text
  57. }
  58. }
  59. func saveSalesmanDetail(){
  60. if name.isEmptyStr{
  61. self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "请输入姓名", Etext: "Please input your name"))
  62. return
  63. }
  64. if phone.isEmptyStr{
  65. self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "请输入手机号", Etext: "Please input your phone number"))
  66. return
  67. }
  68. if phone?.count ?? 0 < 8{
  69. self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "请输入正确的手机号", Etext: "Please input the correct phone number"))
  70. return
  71. }
  72. if postCode.isEmptyStr{
  73. self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "请输入邮编", Etext: "Please input postal coder"))
  74. return
  75. }
  76. if street.isEmptyStr{
  77. self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "请输入街道", Etext: "Please input street"))
  78. return
  79. }
  80. if address.isEmptyStr{
  81. self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "请输入详细地址", Etext: "Please input the full address"))
  82. return
  83. }
  84. if startTime.isEmptyStr{
  85. self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "请选择开始时间", Etext: "Please select a start time"))
  86. return
  87. }
  88. if endTime.isEmptyStr{
  89. self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "请选择结束时间", Etext: "Please select an end time"))
  90. return
  91. }
  92. self.hud.showLoading()
  93. self.viewModel.salesmanCompleteModel.receiving = name
  94. self.viewModel.salesmanCompleteModel.phoneNum = phone
  95. self.viewModel.salesmanCompleteModel.postcode = postCode
  96. self.viewModel.salesmanCompleteModel.detailAddress = address
  97. self.viewModel.salesmanCompleteModel.street = street
  98. self.viewModel.salesmanCompleteModel.startDate = "2023-11-14"
  99. self.viewModel.salesmanCompleteModel.endDate = "2023-11-20"
  100. self.viewModel.salesmanCompleteModel.addressId = self.viewModel.HomeSalesmanInputModel?.addressId
  101. self.viewModel.salesmanCompleteModel.shopcartId = self.viewModel.HomeSalesmanInputModel?.shopcartId
  102. self.viewModel.signalSalesmanComplete()?.on(success: { dd in
  103. self.hud.showSuccess()
  104. self.hidden()
  105. }, error: { error in
  106. self.hud.showFailure(error.msg ?? LanguagesUtil.createTextBy(Ctext: "网络错误", Etext: "network error"))
  107. })
  108. }
  109. //根据购物车ID获取业务员填入信息并回显
  110. func getData(){
  111. self.viewModel.homeGetSalesmanInputModel.id = self.shopcartId
  112. self.viewModel.signalGetSalesmanInputDto()?.on(success: { dd in
  113. self.hud.hidden()
  114. self.setShowDefualData()
  115. }, error: { error in
  116. self.hud.showFailure(error.msg ?? LanguagesUtil.createTextBy(Ctext: "网络错误", Etext: "network error"))
  117. })
  118. }
  119. func setShowDefualData(){
  120. self.nameTF.text = self.viewModel.HomeSalesmanInputModel?.receiving
  121. self.name = self.nameTF.text
  122. self.phoneTF.text = self.viewModel.HomeSalesmanInputModel?.phoneNum
  123. self.phone = self.phoneTF.text
  124. self.postCodeTF.text = self.viewModel.HomeSalesmanInputModel?.postcode
  125. self.postCode = self.postCodeTF.text
  126. self.addressDetailTF.text = self.viewModel.HomeSalesmanInputModel?.detailAddress
  127. self.address = self.addressDetailTF.text
  128. self.streeTF.text = self.viewModel.HomeSalesmanInputModel?.street
  129. self.street = self.streeTF.text
  130. self.startTimeLab.text = self.viewModel.HomeSalesmanInputModel?.startDate
  131. self.startTime = self.startTimeLab.text
  132. if self.startTime.isNotEmptyStr{
  133. self.startTimeLab.textColor = kThemeBlackColor
  134. }
  135. self.endTimeLab.text = self.viewModel.HomeSalesmanInputModel?.endDate
  136. self.endTime = self.endTimeLab.text
  137. if self.endTime.isNotEmptyStr{
  138. self.endTimeLab.textColor = kThemeBlackColor
  139. }
  140. }
  141. @IBAction func sharTimeAction(_ sender: UIButton) {
  142. MCDatePikerView.init(defaultDateStr: nil, minDateStr: nil, maxDateStr: nil) { selectValue in
  143. self.startTime = selectValue
  144. self.startTimeLab.text = selectValue
  145. self.startTimeLab.textColor = kThemeBlackColor
  146. }.show()
  147. }
  148. @IBAction func endTimeAction(_ sender: UIButton) {
  149. MCDatePikerView.init(defaultDateStr: nil, minDateStr: nil, maxDateStr: nil) { selectValue in
  150. self.endTime = selectValue
  151. self.endTimeLab.text = selectValue
  152. self.endTimeLab.textColor = kThemeBlackColor
  153. }.show()
  154. }
  155. /// 展示
  156. public func showWithShopcartId(shopcartId : NSNumber , vc : ADHBaseVC){
  157. self.shopcartId = shopcartId
  158. self.vc = vc
  159. vc.view.addSubview(self)
  160. self.frame = CGRect(x: 0, y: self.frame.size.height, width: kSCREEN_WIDTH, height: vc.view.frame.size.height)
  161. UIView.animate(withDuration: 0.5, delay: 0.3, options: .curveEaseOut, animations: {
  162. self.frame = CGRect(x: 0, y: 0, width: kSCREEN_WIDTH, height: vc.view.frame.size.height)
  163. self.layoutIfNeeded()
  164. }, completion: nil)
  165. self.getData()
  166. }
  167. @IBAction func saveAction(_ sender: UIButton) {
  168. self.saveSalesmanDetail()
  169. }
  170. /// 隐藏
  171. public func hidden(){
  172. UIView.animate(withDuration: 0.5) {
  173. self.frame = CGRect(x: 0, y: self.frame.size.height, width: kSCREEN_WIDTH, height: self.vc?.view.frame.size.height ?? 0)
  174. self.layoutIfNeeded()
  175. }
  176. DELAY(0.5) {
  177. self.removeFromSuperview()
  178. }
  179. }
  180. @IBAction func backAction(_ sender: UIButton) {
  181. self.hidden()
  182. }
  183. }