// // SingleMealDetailController.swift // ADHTuanCan // // Created by 敖德亨 on 2023/10/29. // import UIKit //import MJRefresh import RxSwift import RxCocoa import RxAlamofire import Alamofire import HandyJSON class SingleMealDetailController: ADHBaseVC { /// 展示更多 var showMore = false /// 菜品/套餐id var mealId : NSNumber?{ didSet{ self.viewModel.getSMDetailRequestModel.mealId = mealId } } /// /// 菜品类型,1为单品,2为套餐 var mealType : String?{ didSet{ self.viewModel.getSMDetailRequestModel.mealType = mealType } } /// 供餐类型(早餐、中餐、晚餐) var supplyTypeId : String?{ didSet{ self.viewModel.getSMDetailRequestModel.supplyTypeId = supplyTypeId self.viewModel.addShoppingRequestModel.supplyTypeId = supplyTypeId } } /// 菜品分类 var runTypeId : String?{ didSet{ self.viewModel.getSMDetailRequestModel.runTypeId = runTypeId self.viewModel.addShoppingRequestModel.runTypeId = runTypeId } } /// 时间 var shopcartTime : String?{ didSet{ self.viewModel.addShoppingRequestModel.shopcartTime = shopcartTime } } /// 时间id var shopcartTimeId : NSNumber?{ didSet{ self.viewModel.addShoppingRequestModel.shopcartTimeId = shopcartTimeId self.viewModel.getTimeRequestModel.id = shopcartTimeId } } /// 购物车id var shopcartId : NSNumber?{ didSet{ self.viewModel.addShoppingRequestModel.shopcartId = shopcartId } } @IBOutlet weak var bottonView: UIView! @IBOutlet weak var priceLab: UILabel! @IBOutlet weak var attentionLab: UILabel! @IBOutlet weak var addShopBtn: UIButton! //HeadView let mealHeadView = Bundle.main.loadNibNamed("MealHeadView", owner: nil, options: nil)?.last as? MealHeadView //评价 let mealDescribeView = Bundle.main.loadNibNamed("MealDescribeView", owner: nil, options: nil)?.last as? MealDescribeView //配送时间选择 let deliveryTimeSetView = Bundle.main.loadNibNamed("DeliveryTimeSetView", owner: nil, options: nil)?.last as? DeliveryTimeSetView //需知 let needKonwView = Bundle.main.loadNibNamed("NeedKonwView", owner: nil, options: nil)?.last as? NeedKonwView let viewModel : SetMealViewModel = SetMealViewModel.init() let diposableBag = DisposeBag() //子视图列表 var viewList : [Any]? override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) } override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = UIColor.white // Do any additional setup after loading the view. self.navBar = MCNavBarView.init(title:"", subTitle: nil,style: nil) self.navBar?.insertNavRightBtn(nil, image: "分享图标", tap: {[unowned self] in }, semantic: nil, at: 0) self.addShopBtn.setBackColor(kThemeColorAlpha, forState: .normal) self.addShopBtn.isUserInteractionEnabled = false self.attentionLab.text = LanguagesUtil.createTextBy(Ctext: "请选择送餐时间", Etext: "Please select a delivery time") //MARK: 获取详情 self.hud.showLoading() self.viewModel.signalGetSetMealDetail()?.on(success: { dd in self.mealHeadView?.configModel(model: self.viewModel.SMDetailModel!) self.mealDescribeView!.configDescribLab(text: (self.viewModel.SMDetailModel!.introduce ?? "")) self.resetConstraint() self.viewModel.addShoppingRequestModel.activityId = self.viewModel.SMDetailModel?.activityId self.viewModel.addShoppingRequestModel.discountId = self.viewModel.SMDetailModel?.discountId self.viewModel.addShoppingRequestModel.isGeneral = self.viewModel.SMDetailModel?.isGeneral self.viewModel.addShoppingRequestModel.mealType = self.viewModel.SMDetailModel?.mealType self.viewModel.addShoppingRequestModel.isFixed = self.viewModel.SMDetailModel?.isFixed self.viewModel.addShoppingRequestModel.mealId = self.viewModel.SMDetailModel?.mealId // self.viewModel.addShoppingRequestModel.runTypeId = self.viewModel.SMDetailModel?.runTypeId // self.viewModel.addShoppingRequestModel.supplyTypeId = self.viewModel.SMDetailModel?.supplyTypeId self.viewModel.addShoppingRequestModel.mealType = self.viewModel.SMDetailModel?.mealType self.priceLab.text = "\(self.viewModel.SMDetailModel?.price ?? "")" self.hud.hidden() }, error: { error in self.hud.showFailure("\(error.msg ?? "")") }) //MARK: 获取配送时段 self.viewModel.signalGetDeliveryTime()?.on(success: { dd in self.deliveryTimeSetView?.configModel(dataSource: self.viewModel.deliveryTimeList!) self.resetConstraint() }, error: { error in self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "网络错误", Etext: "network error")) }) self.createUI() } //MARK: createUI func createUI(){ self.view.addSubview(self.scrollView) self.scrollView.backgroundColor = UIColor.clear self.scrollView.mas_remakeConstraints { make in make?.left.right().mas_equalTo()(self.view) make?.top.mas_equalTo()(self.view)?.offset()(kNavAndStatuHeight) make?.bottom.mas_equalTo()(self.bottonView.mas_top) make?.height.offset()(kSCREEN_HEIGHT - kTabBarHeight - 76 - kNavAndStatuHeight) make?.width.offset()(kSCREEN_WIDTH) } self.viewList = [self.mealHeadView!,self.mealDescribeView!,self.deliveryTimeSetView!] self.scrollView.addSubview(self.mealHeadView!) self.scrollView.addSubview(self.mealDescribeView!) self.scrollView.addSubview(self.deliveryTimeSetView!) self.resetConstraint() //查看评论 self.mealHeadView?.evaluateActionBlock = {[weak self] in let vc = MealEvaluateListVC() vc.mealId = self?.mealId self?.navigationController?.pushViewController(vc, animated: true) } self.deliveryTimeSetView?.selectTimeBlock = {[weak self] model in self?.viewModel.addShoppingRequestModel.deliveryStart = model.startTime self?.viewModel.addShoppingRequestModel.deliveryEnd = model.endTime self?.viewModel.addShoppingRequestModel.deliveryId = model.id if (self?.chenkSaveData() ?? false){ } } self.deliveryTimeSetView?.inputNumBlock = {[weak self] numStr in self?.viewModel.addShoppingRequestModel.numPeople = numStr let price : String = numStr ** "\(self?.viewModel.SMDetailModel?.price ?? "")" self?.priceLab.text = "\(price ?? "")" if (self?.chenkSaveData() ?? false){ } } } //MARK: 重设约束 func resetConstraint(){ var contentSizeH : CGFloat = 0 for i in 0.. 0 { lin2 = 1 } make?.height.offset()(154 + 44 * CGFloat(lin1 + lin2) - 12) make?.bottom.mas_equalTo()(self.scrollView) } } contentSizeH = contentSizeH + itme.frame.size.height } scrollView.contentSize = CGSize.init(width: 0, height: contentSizeH) } //MARK: scrollView private var scrollView : UIScrollView = { let scrollView = UIScrollView.init(frame: CGRect.zero) scrollView.alwaysBounceVertical = true scrollView.isScrollEnabled = true scrollView.showsVerticalScrollIndicator = false scrollView.backgroundColor = kTBackgroundColor scrollView.contentInsetAdjustmentBehavior = .never return scrollView }() func chenkSaveData() ->(Bool){ if self.viewModel.addShoppingRequestModel.numPeople.isEmptyStr{ self.attentionLab.text = LanguagesUtil.createTextBy(Ctext: "请先设置用餐人数", Etext: "Please set the number of diners first") self.addShopBtn.setBackColor(kThemeColorAlpha, forState: .normal) self.addShopBtn.isUserInteractionEnabled = false return false } if self.viewModel.addShoppingRequestModel.numPeople < Int(self.viewModel.SMDetailModel?.lowestNum ?? "1"){ self.attentionLab.text = LanguagesUtil.createTextBy(Ctext: "就餐人数不能低于\(self.viewModel.SMDetailModel?.lowestNum ?? "1")人", Etext: "The number of diners should not be lower \(self.viewModel.SMDetailModel?.lowestNum ?? "1")") self.addShopBtn.setBackColor(kThemeColorAlpha, forState: .normal) self.addShopBtn.isUserInteractionEnabled = false return false } if (self.viewModel.addShoppingRequestModel.numPeople > Int(self.viewModel.SMDetailModel?.lowestNum ?? "1") || self.viewModel.addShoppingRequestModel.numPeople === Int(self.viewModel.SMDetailModel?.lowestNum ?? "1")) && self.viewModel.addShoppingRequestModel.numPeople.isNotEmptyStr{ self.attentionLab.text = LanguagesUtil.createTextBy(Ctext: "", Etext: "") } if self.viewModel.addShoppingRequestModel.deliveryId.isNil{ self.attentionLab.text = LanguagesUtil.createTextBy(Ctext: "请选择配送时间", Etext: "Please select a delivery time") self.addShopBtn.setBackColor(kThemeColorAlpha, forState: .normal) self.addShopBtn.isUserInteractionEnabled = false return false } self.addShopBtn.setBackColor(kThemeColor, forState: .normal) self.addShopBtn.isUserInteractionEnabled = true return true } @IBAction func addToShoppingcart(_ sender: UIButton) { if self.viewModel.addShoppingRequestModel.deliveryEnd.isEmptyStr{ self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "请选择送餐时间", Etext: "Please select a delivery time")) return } if self.viewModel.addShoppingRequestModel.numPeople.isEmptyStr{ self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "请输入就餐人数", Etext: "Please enter the number of diners")) return } if self.viewModel.addShoppingRequestModel.numPeople < Int(self.viewModel.SMDetailModel?.lowestNum ?? "1"){ self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "就餐人数不能低于\(self.viewModel.SMDetailModel?.lowestNum ?? "1")人", Etext: "The number of diners should not be lower \(self.viewModel.SMDetailModel?.lowestNum ?? "1")")) return } //MARK: 加入购物车 self.viewModel.signalAddShopping()?.on(success: { dd in self.hud.showSuccess() NotificationCenter.default.post(name: NSNotification.Name("刷新首页"), object: self, userInfo:nil) self.navigationController?.popViewController(animated: true) }, error: { error in self.hud.showFailure("\(error.msg ?? "")") }) } }