// // HuolalaCancelViewController.swift // GeliBusinessPlatform // // Created by 刘俊宏 on 2020/8/11. // Copyright © 2020 junye lu. All rights reserved. // import UIKit import LGButton class HuolalaCancelViewController: BaseViewController ,UITableViewDelegate,UITableViewDataSource,OtherInfoTextViewTableViewCellDelegate{ @IBOutlet weak var bottomLbl: UILabel! var lwbno = "" var isShowIndex = 0 var selectID = 81338860 var reason_id = 0 var reason = "" var reasonStr = "" @IBOutlet weak var listView: UITableView! override func viewDidLoad() { super.viewDidLoad() navbar.title = "取消订单" self.view.addSubview(navbar) SetTopFrameView(view: listView, btmView: self.view) listView.separatorStyle = .none listView.register(UINib(nibName: "FirstCell", bundle: nil), forCellReuseIdentifier: "FirstCell") listView.register(UINib(nibName: "SecondCell", bundle: nil), forCellReuseIdentifier: "SecondCell") listView.register(UINib(nibName: "OtherInfoTextViewTableViewCell", bundle: nil), forCellReuseIdentifier: "OtherInfoTextViewTableViewCell") loadData() } @IBAction func cancelAction(_ sender: LGButton) { if selectID == 81338860 { HUD.flash(.label("请选择取消原因"),delay: 1.2) return } if reason == "其他" { if reasonStr.count == 0 { HUD.flash(.label("填写选择取消原因"),delay: 1.2) return } } orderCancelOrder() } //请求取消原因 var reasonArr:Array = [] func loadData(){ let UserToken = UserDefaults.standard.value(forKey: "user_token") orderCancelReason(["user_token":UserToken as Any,"lwb_no":lwbno as Any,"nonce_str":String.randomStr(len:30) as Any], success: { (data) in let model = data as! orderCancelReasonModel model.data?.forEach({ (dataModel) in self.reasonArr.append(dataModel) }) self.listView.reloadData() }) { (error) in } } func numberOfSections(in tableView: UITableView) -> Int { return reasonArr.count } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { let sectionModel = reasonArr[section] if reasonArr.count == 1 { return sectionModel.sub_cat!.count } if sectionModel.isShow { return sectionModel.sub_cat!.count }else{ return 0 } } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { let sectionModel = reasonArr[indexPath.section] let rowModel = sectionModel.sub_cat![indexPath.row] if rowModel.sub_name == "其他" || sectionModel.category == "其他"{ if rowModel.sub_name != "其他" { return 50 } if selectID == rowModel.sub_id { return 175 }else{ return 50 } } return 50 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let sectionModel = reasonArr[indexPath.section] let rowModel = sectionModel.sub_cat![indexPath.row] if rowModel.sub_name == "其他" || sectionModel.category == "其他"{ if rowModel.sub_name != "其他" { let cellS = tableView.dequeueReusableCell(withIdentifier: "SecondCell") as! SecondCell cellS.nameLbl.text = rowModel.sub_name if rowModel.sub_id == selectID { cellS.imgView.image = UIImage.init(named: "yuxuan") cellS.nameLbl.textColor = UIColor.init(named: "蓝色字体颜色") }else{ cellS.imgView.image = UIImage.init(named: "daixuan") cellS.nameLbl.textColor = UIColor.init(named: "标题字颜色") } cellS.contentView.backgroundColor = UIColor.white cellS.line.backgroundColor = UIColor.init(named: "灰色分界线") return cellS } let cell = tableView.dequeueReusableCell(withIdentifier: "OtherInfoTextViewTableViewCell") as! OtherInfoTextViewTableViewCell if rowModel.sub_id == selectID { cell.iconImV.image = UIImage.init(named: "yuxuan") cell.nameLbl.textColor = UIColor.init(named: "蓝色字体颜色") cell.textCountLbl.textColor = UIColor.init(named: "蓝色字体颜色") cell.textViewBgV.isHidden = false }else{ cell.iconImV.image = UIImage.init(named: "daixuan") cell.nameLbl.textColor = UIColor.init(named: "标题字颜色") cell.textCountLbl.textColor = UIColor.init(named: "标题字颜色") cell.textViewBgV.isHidden = true } if rowModel.sub_name == "其他" && sectionModel.category == "其他" { cell.titleLeft.constant = 40 cell.bgLeft.constant = 40 }else{ cell.titleLeft.constant = 15 cell.bgLeft.constant = 15 } cell.delegate = self return cell } let cell = tableView.dequeueReusableCell(withIdentifier: "FirstCell") as! FirstCell cell.nameLbl.text = rowModel.sub_name if reasonArr.count == 1 { if rowModel.sub_id == selectID { cell.imgView.image = UIImage.init(named: "yuxuan") cell.nameLbl.textColor = UIColor.init(named: "蓝色字体颜色") }else{ cell.imgView.image = UIImage.init(named: "daixuan") cell.nameLbl.textColor = UIColor.init(named: "标题字颜色") } }else{ let cellS = tableView.dequeueReusableCell(withIdentifier: "SecondCell") as! SecondCell cellS.nameLbl.text = rowModel.sub_name if rowModel.sub_id == selectID { cellS.imgView.image = UIImage.init(named: "yuxuan") cellS.nameLbl.textColor = UIColor.init(named: "蓝色字体颜色") }else{ cellS.imgView.image = UIImage.init(named: "daixuan") cellS.nameLbl.textColor = UIColor.init(named: "标题字颜色") } cellS.contentView.backgroundColor = UIColor.white cellS.line.backgroundColor = UIColor.init(named: "灰色分界线") return cellS } return cell } func OtherInfoTextViewTableViewCellGetTextContent(sender: String) { reasonStr = sender } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let sectionModel = reasonArr[indexPath.section] let rowModel = sectionModel.sub_cat![indexPath.row] selectID = rowModel.sub_id! reason_id = selectID reason = rowModel.sub_name! listView.reloadData() bottomLbl.text = "确定" } func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { if reasonArr.count == 1 { return nil } let model = reasonArr[section] let view = UIView(frame: CGRect(x: 0, y: 0, width: fullScreenWidth, height: 50)) view.backgroundColor = UIColor.white let nameLbl = UILabel() nameLbl.textColor = UIColor.init(named: "标题字颜色") nameLbl.font = UIFont.systemFont(ofSize: 13) view.addSubview(nameLbl) nameLbl.snp.makeConstraints { (make) in make.centerY.equalToSuperview() make.left.equalTo(15) } var img = UIImage.init(named: "3") if model.isShow { img = UIImage.init(named: "1") } let imgV = UIImageView.init(image: img) view.addSubview(imgV) imgV.snp.makeConstraints { (make) in make.centerY.equalToSuperview() make.right.equalTo(-15) } let line = UIView() line.backgroundColor = UIColor.init(named: "灰色分界线") view.addSubview(line) line.snp.makeConstraints { (make) in make.left.equalTo(15) make.right.equalToSuperview() make.bottom.equalToSuperview() make.height.equalTo(1) } let showBtn = UIButton() showBtn.tag = section view.addSubview(showBtn) showBtn.snp.makeConstraints { (make) in make.left.right.top.bottom.equalToSuperview() } showBtn.addTarget(self, action: #selector(headerShowBtnAction(sender:)), for: .touchUpInside) nameLbl.text = model.category return view } @objc func headerShowBtnAction(sender:UIButton) { reasonArr[sender.tag].isShow = !reasonArr[sender.tag].isShow listView.reloadData() } func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { if reasonArr.count == 1 { return 0.01 } return 50 } //MARK:--取消货拉拉运单 func orderCancelOrder (){ let UserToken = UserDefaults.standard.value(forKey: "user_token") var lastReason = reason if reason == "其他" { lastReason = reasonStr } let dict = ["user_token":UserToken as Any,"lwb_no":lwbno as Any,"reason_id":reason_id as Any,"reason":lastReason as Any,"nonce_str":String.randomStr(len:30) as Any] orderLalamoveCancel(dict, success: { (data) in NotificationCenter.default.post(name: NSNotification.Name(rawValue: "HuolalaOrderChange"), object: "isCancel") HUD.flash(.labeledSubSuccess(subtitle: "取消成功"),delay: 1.2) self.navigationController?.popViewController(animated: true) }) { (error) in } } }