123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- //
- // 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..<viewList!.count{
- let itme : UIView = viewList![i] as! UIView
- itme.mas_remakeConstraints { make in
- make?.left.right().mas_equalTo()(self.scrollView)
- if i == 0{
- make?.top.mas_equalTo()(self.scrollView)
- make?.width.offset()(kSCREEN_WIDTH)
- }
- if i == 1{
- make?.top.mas_equalTo()(self.mealHeadView?.mas_bottom)?.offset()(-34)
- make?.width.offset()(kSCREEN_WIDTH)
- }
- if i == 2{
- make?.top.mas_equalTo()(self.mealDescribeView?.mas_bottom)
- make?.width.offset()(kSCREEN_WIDTH)
-
- //self.viewModel.deliveryTimeList?.count date数量 2两列 取整数取余数
- let lin1 = (self.viewModel.deliveryTimeList?.count ?? 0)/3
- var lin2 = (self.viewModel.deliveryTimeList?.count ?? 0)%3
- if lin2 > 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 ?? "")")
- })
- }
-
- }
|