123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385 |
- //
- // ShoppingCarDetailView.swift
- // ADHTuanCan
- //
- // Created by 敖德亨 on 2023/11/1.
- //
- import UIKit
- import RxSwift
- import RxCocoa
- class ShoppingCarDetailView: UIView {
-
-
- /// 购物车类型
- var shopType : String?{
- didSet{
- self.viewModel.HomeTimeGetModel.shopType = shopType
- }
- }
-
- /// 购物车ID
- var shopcartId : NSNumber?{
- didSet{
- self.viewModel.getShoppingCarMsgResultMeal.shopcartId = shopcartId
- self.viewModel.editShoppingCarRequestModel.shopcartId = shopcartId
- self.viewModel.cleanShopcarModel.id = shopcartId
-
- }
- }
-
- /// 购物车时间ID
- var shopcartTimeId : NSNumber?{
- didSet{
- self.viewModel.getShoppingCarMsgResultMeal.shopcartTimeId = shopcartTimeId
- self.viewModel.getTimeRequestModel.shopcartTimeId = shopcartTimeId
- }
- }
- @IBOutlet weak var blackView: UIView!
- let dateView = Bundle.main.loadNibNamed("HomeDateView", owner: nil, options: nil)?.last as? HomeDateView
-
- let editorDeliveryTimeView = Bundle.main.loadNibNamed("EditorDeliveryView", owner: nil, options: nil)?.last as? EditorDeliveryView
-
- let editPersonNumView = Bundle.main.loadNibNamed("EditPersonNumView", owner: nil, options: nil)?.last as? EditPersonNumView
-
- let adhAV = Bundle.main.loadNibNamed("ADHAlertView", owner: nil, options: nil)?.last as? ADHAlertView
-
- @IBOutlet weak var priceLab: UILabel!
-
- @IBOutlet weak var tableView: UITableView!
-
- /// 优惠金额
- @IBOutlet weak var saleLab: UILabel!
-
- /// 优惠显示
- @IBOutlet weak var saleView: UIView!
-
- /// 底部LAB偏移量
- @IBOutlet weak var bottomY1: NSLayoutConstraint!
- /// 底部LAB偏移量
- @IBOutlet weak var bottomY2: NSLayoutConstraint!
-
- var editModel : ShopMealMsgDetailModel?
-
- /// 当前选择的时间
- var nowTimeModel : HomeTimeItem?
-
- let viewModel : ShoppingCarViewModel = ShoppingCarViewModel.init()
-
- let diposableBag = DisposeBag()
-
- var isRefresh = true
-
- lazy var hud : MCHud! = {
- return MCHud()
- }()
-
- var reFreshBlock : (()->Void)?
- var checkOrderBlock : (()->Void)?
-
- var reloadCallBackBlock : (()->Void)?
-
- override func awakeFromNib() {
- super.awakeFromNib()
- tableView.register(withType: MenuTableViewCell.self)
- tableView.separatorStyle = UITableViewCell.SeparatorStyle.none
-
- self.tableView.mj_header = MJRefreshNormalHeader.init(refreshingBlock: {[unowned self] in
- self.isRefresh = true
- self.getShopCarDetail()
- });
-
- self.tableView.ly_emptyView = LYEmptyView.emptyActionView(with: UIImage.init(named: "暂无数据"), titleStr: LanguagesUtil.createTextBy(Ctext: "暂无数据", Etext: "no data"), detailStr: "", btnTitleStr: LanguagesUtil.createTextBy(Ctext: "点击刷新", Etext: "Click to refresh"), btnClick: {[weak self] in
- self?.isRefresh = true
- self?.getShopCarDetail()
- })
-
- self.dateView?.deletBtn.isHidden = false
- self.dateView?.timeBtn.isHidden = true
- self.dateView?.titleLab.text = LanguagesUtil.createTextBy(Ctext: "已选菜品", Etext: "selected foods")
- self.addSubview(self.dateView!)
- self.dateView!.mas_remakeConstraints { make in
- make?.left.right().mas_equalTo()(self)
- make?.top.mas_equalTo()(self)?.offset()(200)
- make?.height.offset()(180)
- }
-
- self.dateView?.selectBlock = {[weak self] model in
- self?.nowTimeModel = model
- self?.viewModel.getShoppingCarMsgResultMeal.shopcartTimeId = self?.nowTimeModel!.shopcartTimeId
- self?.viewModel.getShoppingCarMsgResultMeal.shopcartTimeId = model.shopcartTimeId
- self?.getShopCarDetail()
- self?.reloadDateView()
- }
- self.dateView?.deletActionBlock = {[weak self] in
- self?.adhAV?.show()
- }
-
- self.adhAV?.sureActionBlock = {[weak self] in
- //清空购物车
- self?.viewModel.signalCleanShopCar()?.on(success: { dd in
- // NotificationCenter.default.post(name: NSNotification.Name("刷新首页"), object: self, userInfo:nil)
- if self?.reloadCallBackBlock != nil{
- self?.reloadCallBackBlock!()
- }
- self?.hidden()
- }, error: { error in
- self?.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "网络错误", Etext: "network error"))
- })
- }
-
- self.editorDeliveryTimeView?.selectTimeBlock = {[weak self] model in
- self?.viewModel.editShoppingCarRequestModel.shopMealId = self?.editModel?.shopMealId
- self?.viewModel.editShoppingCarRequestModel.mealType = self?.editModel?.mealType
- self?.viewModel.editShoppingCarRequestModel.shopcartTimeId = self?.viewModel.getShoppingCarMsgResultMeal.shopcartTimeId
-
- self?.viewModel.editShoppingCarRequestModel.deliveryId = model.id
- self?.viewModel.signalEditShopCar()?.on(success: { dd in
- self?.getShopCarDetail()
- self?.getShopCarPrice()
- }, error: { error in
- self?.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "网络错误", Etext: "network error"))
- })
- }
-
- self.editPersonNumView?.inputBlock = {[weak self] num in
-
- if num < Int(self?.editModel?.lowestNum ?? "1"){
- self?.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "就餐人数不能低于\(self?.editModel?.lowestNum ?? "1")人", Etext: "The number of diners should not be lower \(self?.editModel?.lowestNum ?? "1")"))
- return
- }
-
- self?.viewModel.editShoppingCarRequestModel.shopMealId = self?.editModel?.shopMealId
- self?.viewModel.editShoppingCarRequestModel.mealType = self?.editModel?.mealType
- self?.viewModel.editShoppingCarRequestModel.shopcartTimeId = self?.viewModel.getShoppingCarMsgResultMeal.shopcartTimeId
- self?.viewModel.editShoppingCarRequestModel.numPeople = num
-
- self?.viewModel.signalEditShopCar()?.on(success: { dd in
- self?.getShopCarDetail()
- self?.getShopCarPrice()
- }, error: { error in
- self?.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "网络错误", Etext: "network error"))
- })
- }
- }
- //MARK: 获取时间范围
- func getTimeRangDetail(){
- self.hud.showLoading()
- self.viewModel.signalGetHomeTime()?.on(success: { dd in
- for item in self.viewModel.TimeRangDetail!.timeVoList! {
- let model : HomeTimeItem = item
- if model.day == self.nowTimeModel?.day{
- model.isSelect = true
- }
- }
- self.getShopCarPrice()
- self.reloadDateView()
- self.hud.hidden()
- }, error: { error in
- self.hud.showFailure("获取时间范围失败")
- })
- }
-
- //MARK: 获取日期下购物车详情
- func getShopCarDetail(){
-
- if isRefresh{
- self.hud.showLoading()
- NSLog("刷新")
- }else{
- NSLog("计算")
- }
- self.viewModel.signalgetShoppingCarMsg()?.on(success: { dd in
- self.tableView.reloadData()
- self.hud.hidden()
- self.tableView.mj_header.endRefreshing()
- }, error: { error in
- self.hud.showFailure("获取失败")
- self.tableView.mj_header.endRefreshing()
- })
- }
-
- //MARK: 获取购物车价格详情
- func getShopCarPrice(){
-
- self.viewModel.getShopCarPriceRModel.id = self.viewModel.TimeRangDetail?.shopcartId
- self.viewModel.signalGetShopCarPrice()?.on(success: { dd in
- self.priceLab.text = "\(self.viewModel.shopCarPriceDetail?.price ?? "")"
- self.saleLab.text = LanguagesUtil.createTextBy(Ctext: "已优惠:", Etext: "Sale:") + "\(self.viewModel.shopCarPriceDetail?.discountAmount ?? "")"
-
- if self.viewModel.shopCarPriceDetail?.discountAmount > 0{
- self.saleView.isHidden = false
- self.bottomY1.constant = -10
- self.bottomY2.constant = -10
- }else{
- self.saleView.isHidden = true
- self.bottomY1.constant = 0
- self.bottomY2.constant = 0
- }
-
- }, error: { error in
- self.hud.showFailure(error.msg ?? LanguagesUtil.createTextBy(Ctext: "网络错误", Etext: "network error"))
- })
- }
-
- @IBAction func checkSaleDetail(_ sender: UIButton) {
- let saleView = Bundle.main.loadNibNamed("SaleDetailView", owner: nil, options: nil)?.last as? SaleDetailView
- saleView?.showWith(model: self.viewModel.shopCarPriceDetail)
- }
-
-
- //MARK: 获取配送时段
- func getDeliveryTime(){
- self.viewModel.signalGetDeliveryTime()?.on(success: { dd in
- self.editorDeliveryTimeView?.configModel(dataSource: self.viewModel.deliveryTimeList)
- }, error: { error in
- self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "网络错误", Etext: "network error"))
- })
- }
-
- func reloadDateView(){
- self.dateView!.configModel(dateModel: self.viewModel.TimeRangDetail!)
- }
-
- @IBAction func gotoJIesuan(_ sender: UIButton) {
- if self.checkOrderBlock != nil{
- self.checkOrderBlock!()
- }
- self.hidden()
- }
-
- public func show(){
-
- self.getTimeRangDetail()
- self.getShopCarDetail()
-
-
- kAppDelegateWindow.addSubview(self)
- self.blackView.alpha = 0
- self.frame = CGRect.init(x: 0, y: kSCREEN_HEIGHT, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
- UIView.animate(withDuration: 0.5) {
- self.frame = CGRect.init(x: 0, y: 0, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
- self.layoutIfNeeded()
- }
- DELAY(0.5) {
- self.blackView.alpha = 0.3
- }
- }
-
- public func hidden(){
- self.blackView.alpha = 0
- UIView.animate(withDuration: 0.5) {
- self.frame = CGRect.init(x: 0, y: kSCREEN_HEIGHT, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
- self.layoutIfNeeded()
- }
- DELAY(0.5) {
- self.removeFromSuperview()
- }
-
- }
-
- @IBAction func backTouchAction(_ sender: UIButton) {
- if self.reFreshBlock != nil{
- self.reFreshBlock!()
- }
- self.hidden()
- }
-
- func add(){
-
- if (self.editModel?.numPeople ?? "0") < Int(self.editModel?.lowestNum ?? "1"){
- self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "就餐人数不能低于\(self.editModel?.lowestNum ?? "1")人", Etext: "The number of diners should not be lower \(self.editModel?.lowestNum ?? "1")") ,delay: 1.5)
- self.getShopCarDetail()
- self.getShopCarPrice()
- }else{
- self.viewModel.editShoppingCarRequestModel.shopMealId = self.editModel?.shopMealId
- self.viewModel.editShoppingCarRequestModel.mealType = self.editModel?.mealType
- self.viewModel.editShoppingCarRequestModel.shopcartTimeId = self.viewModel.getShoppingCarMsgResultMeal.shopcartTimeId
- self.viewModel.editShoppingCarRequestModel.numPeople = self.editModel?.numPeople
-
- self.viewModel.signalEditShopCar()?.on(success: { dd in
- self.getShopCarDetail()
- self.getShopCarPrice()
- }, error: { error in
- self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "网络错误", Etext: "network error"))
- })
- }
- }
-
- func deleteMeal(){
- self.viewModel.editShoppingCarRequestModel.shopMealId = self.editModel?.shopMealId
- self.viewModel.editShoppingCarRequestModel.mealType = self.editModel?.mealType
- self.viewModel.editShoppingCarRequestModel.shopcartTimeId = self.viewModel.getShoppingCarMsgResultMeal.shopcartTimeId
- self.viewModel.editShoppingCarRequestModel.del = "1"
-
- self.viewModel.signalEditShopCar()?.on(success: { dd in
- self.getTimeRangDetail()
- self.getShopCarDetail()
- self.getShopCarPrice()
- }, error: { error in
- self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "网络错误", Etext: "network error"))
- })
- }
- }
- extension ShoppingCarDetailView : UITableViewDelegate,UITableViewDataSource{
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return self.viewModel.ShopCarAllModelList?[section].shopMealMsgVos?.count ?? 0
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "MenuTableViewCell") as! MenuTableViewCell;
-
- let batchModel = self.viewModel.ShopCarAllModelList?[indexPath.section]
- let model = (batchModel?.shopMealMsgVos?[indexPath.row])!
-
- var isfirst = indexPath.row == 0 ? true : false
- cell.configModel(model: model, isfirstLine: isfirst)
- //加上左滑事件
- cell.addLeftSlideAction()
- cell.addOrSubtractionBlock = {[weak self] isAdd in
- self?.editModel = model
- self?.isRefresh = false
- self?.add()
- }
- cell.selectTimeActionBlock = {[weak self] in
-
- // self?.viewModel.getTimeRequestModel.mealId = model.shopMealId
- self?.viewModel.getTimeRequestModel.mealId = model.mealId
- self?.getDeliveryTime()
-
-
- self?.editModel = model
- }
- cell.inPutNumBlock = {[weak self] in
- self?.editModel = model
- self?.editPersonNumView?.showWithNum(model.numPeople!)
- }
- cell.deleteBlock = {[weak self] in
- self?.editModel = model
- self?.deleteMeal()
- }
- return cell
- }
-
- func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
- return 0.01
- }
-
- func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
- return 0.01
- }
- //
-
- func numberOfSections(in tableView: UITableView) -> Int {
- return self.viewModel.ShopCarAllModelList?.count ?? 0
- }
-
- }
|