123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- //
- // SalesmanFirstShowView.swift
- // ADHTuanCan
- //
- // Created by 敖德亨 on 2023/11/14.
- //
- import UIKit
- import RxSwift
- import RxCocoa
- class SalesmanFirstShowView: UIView {
-
- @IBOutlet weak var topContent: NSLayoutConstraint!
-
- @IBOutlet weak var nameTF: UITextField!
-
- @IBOutlet weak var phoneTF: UITextField!
-
- @IBOutlet weak var postCodeTF: UITextField!
-
- @IBOutlet weak var addressDetailTF: UITextView!
-
- @IBOutlet weak var streeTF: UITextField!
-
- @IBOutlet weak var startTimeLab: UILabel!
-
- @IBOutlet weak var endTimeLab: UILabel!
-
- var name : String?
-
- var phone : String?
-
- var postCode : String?
-
- var address : String?
-
- var street : String?
-
- var startTime : String?
-
- var endTime : String?
- var shopcartId : NSNumber?
-
- ///
- var shopType : String?{
- didSet{
- self.viewModel.salesmanCompleteModel.shopType = self.shopType
- }
- }
-
- var vc : ADHBaseVC?
-
- @IBOutlet weak var saveBtn: UIButton!
-
- /// hud 提示
- lazy var hud : MCHud! = {
- return MCHud()
- }()
-
- let viewModel : HomeViewModel = HomeViewModel.init()
- let diposableBag = DisposeBag()
-
- override func awakeFromNib() {
- super.awakeFromNib()
-
- self.nameTF.inputText(maxLength: 19) {
- self.name = self.nameTF.text
- }
-
- self.phoneTF.inputNumber(maxLength: 20) {
- self.phone = self.phoneTF.text
- }
-
- self.postCodeTF.inputNumber(maxLength: 20) {
- self.postCode = self.postCodeTF.text
- }
-
- self.addressDetailTF.inputText(maxLength: 300) {
- self.address = self.addressDetailTF.text
- }
-
- self.streeTF.inputText(maxLength: 40) {
- self.street = self.streeTF.text
- }
- }
-
- func saveSalesmanDetail(){
-
- if name.isEmptyStr{
- self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "请输入姓名", Etext: "Please input your name"))
- return
- }
-
- if phone.isEmptyStr{
- self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "请输入手机号", Etext: "Please input your phone number"))
- return
- }
-
- if phone?.count ?? 0 < 8{
- self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "请输入正确的手机号", Etext: "Please input the correct phone number"))
- return
- }
-
- if postCode.isEmptyStr{
- self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "请输入邮编", Etext: "Please input postal coder"))
- return
- }
-
- if street.isEmptyStr{
- self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "请输入街道", Etext: "Please input street"))
- return
- }
-
- if address.isEmptyStr{
- self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "请输入详细地址", Etext: "Please input the full address"))
- return
- }
-
-
- if startTime.isEmptyStr{
- self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "请选择开始时间", Etext: "Please select a start time"))
- return
- }
- if endTime.isEmptyStr{
- self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "请选择结束时间", Etext: "Please select an end time"))
- return
- }
-
- self.hud.showLoading()
-
- self.viewModel.salesmanCompleteModel.receiving = name
- self.viewModel.salesmanCompleteModel.phoneNum = phone
- self.viewModel.salesmanCompleteModel.postcode = postCode
- self.viewModel.salesmanCompleteModel.detailAddress = address
- self.viewModel.salesmanCompleteModel.street = street
- self.viewModel.salesmanCompleteModel.startDate = "2023-11-14"
- self.viewModel.salesmanCompleteModel.endDate = "2023-11-20"
- self.viewModel.salesmanCompleteModel.addressId = self.viewModel.HomeSalesmanInputModel?.addressId
- self.viewModel.salesmanCompleteModel.shopcartId = self.viewModel.HomeSalesmanInputModel?.shopcartId
-
- self.viewModel.signalSalesmanComplete()?.on(success: { dd in
- self.hud.showSuccess()
- self.hidden()
- }, error: { error in
-
- self.hud.showFailure(error.msg ?? LanguagesUtil.createTextBy(Ctext: "网络错误", Etext: "network error"))
- })
- }
-
- //根据购物车ID获取业务员填入信息并回显
- func getData(){
- self.viewModel.homeGetSalesmanInputModel.id = self.shopcartId
- self.viewModel.signalGetSalesmanInputDto()?.on(success: { dd in
- self.hud.hidden()
- self.setShowDefualData()
- }, error: { error in
-
- self.hud.showFailure(error.msg ?? LanguagesUtil.createTextBy(Ctext: "网络错误", Etext: "network error"))
- })
- }
-
-
- func setShowDefualData(){
- self.nameTF.text = self.viewModel.HomeSalesmanInputModel?.receiving
- self.name = self.nameTF.text
-
- self.phoneTF.text = self.viewModel.HomeSalesmanInputModel?.phoneNum
- self.phone = self.phoneTF.text
-
- self.postCodeTF.text = self.viewModel.HomeSalesmanInputModel?.postcode
- self.postCode = self.postCodeTF.text
-
- self.addressDetailTF.text = self.viewModel.HomeSalesmanInputModel?.detailAddress
- self.address = self.addressDetailTF.text
-
- self.streeTF.text = self.viewModel.HomeSalesmanInputModel?.street
- self.street = self.streeTF.text
-
- self.startTimeLab.text = self.viewModel.HomeSalesmanInputModel?.startDate
- self.startTime = self.startTimeLab.text
- if self.startTime.isNotEmptyStr{
- self.startTimeLab.textColor = kThemeBlackColor
- }
-
- self.endTimeLab.text = self.viewModel.HomeSalesmanInputModel?.endDate
- self.endTime = self.endTimeLab.text
- if self.endTime.isNotEmptyStr{
- self.endTimeLab.textColor = kThemeBlackColor
- }
- }
-
- @IBAction func sharTimeAction(_ sender: UIButton) {
- MCDatePikerView.init(defaultDateStr: nil, minDateStr: nil, maxDateStr: nil) { selectValue in
- self.startTime = selectValue
- self.startTimeLab.text = selectValue
- self.startTimeLab.textColor = kThemeBlackColor
- }.show()
- }
-
- @IBAction func endTimeAction(_ sender: UIButton) {
-
- MCDatePikerView.init(defaultDateStr: nil, minDateStr: nil, maxDateStr: nil) { selectValue in
- self.endTime = selectValue
- self.endTimeLab.text = selectValue
- self.endTimeLab.textColor = kThemeBlackColor
- }.show()
- }
-
- /// 展示
- public func showWithShopcartId(shopcartId : NSNumber , vc : ADHBaseVC){
-
- self.shopcartId = shopcartId
-
- self.vc = vc
- vc.view.addSubview(self)
-
- self.frame = CGRect(x: 0, y: self.frame.size.height, width: kSCREEN_WIDTH, height: vc.view.frame.size.height)
- UIView.animate(withDuration: 0.5, delay: 0.3, options: .curveEaseOut, animations: {
- self.frame = CGRect(x: 0, y: 0, width: kSCREEN_WIDTH, height: vc.view.frame.size.height)
- self.layoutIfNeeded()
- }, completion: nil)
-
- self.getData()
- }
-
- @IBAction func saveAction(_ sender: UIButton) {
-
- self.saveSalesmanDetail()
- }
-
- /// 隐藏
- public func hidden(){
- UIView.animate(withDuration: 0.5) {
- self.frame = CGRect(x: 0, y: self.frame.size.height, width: kSCREEN_WIDTH, height: self.vc?.view.frame.size.height ?? 0)
- self.layoutIfNeeded()
- }
- DELAY(0.5) {
- self.removeFromSuperview()
- }
- }
-
- @IBAction func backAction(_ sender: UIButton) {
-
- self.hidden()
- }
- }
|