// // XinZengAndBianJiKeHuViewController.swift // GeliBusinessPlatform // // Created by junye lu on 2020/4/29. // Copyright © 2020 junye lu. All rights reserved. // import UIKit import LGButton protocol XinZengAndBianJiKeHuViewControllerDelegate { func XinZengAndBianJiKeHuViewControllerFinish() } class XinZengAndBianJiKeHuViewController: BaseViewController,UITableViewDataSource,UITableViewDelegate,BingDingKeHuViewControllerDelegate,GLAlertSelectViewDelegate,UITextFieldDelegate,GeliAlertViewDelegate, DZGLViewControllerDelegate{ var count = 0 func DZGLViewController_back(count: Int) { print("count =",count) self.count = count listView.reloadData() } func DZGLViewControllerSelect(data: GetAddrsInfoDataModel) { //此处无用 } func DZGLViewController_adr(adr_id: String,count:Int) { address_id = adr_id } var delegate:XinZengAndBianJiKeHuViewControllerDelegate? var cus_id:Int? var user_id:Int? var address_id = "" func rightBtnClick() { let alertView = GeliAlertView(frame: self.view.window!.bounds) alertView.delegate = self; alertView.tishiLbl.text = "" alertView.titileLbl.text = "是否删除客户?" alertView.rightBtn.tag = 100 alertView.rightBtn.setAttributedTitle(NSAttributedString(string: "确定"), for: .normal) self.view.window?.addSubview(alertView) } func sureGeliAlertViewAction(sender: UIButton) { HUD.flash(.progress) if sender.tag == 100 { let dic = [ "user_token":UserToken as Any, "function_id":22 as Any, "prval":cus_id as Any, "value":1 as Any, ] editField(dic, success: { (data) in HUD.hide() self.delegate?.XinZengAndBianJiKeHuViewControllerFinish() self.navigationController?.popViewController(animated: true) }) { (err) in } return } var dict = [ "user_token":UserToken as Any, "cus_name":kehuName as Any, "company":companyName as Any, "cus_type":typeSelect + 1 as Any, "phone":phoneNum as Any, "user_id":user_id as Any, "discounts_rate":discount as Any ] if cus_id == nil { dict["address_id"] = address_id cusAdd(dict, success: { (data) in HUD.hide() HUD.flash(.labeledSubSuccess(subtitle: "提交成功"), delay: 1.2) self.delegate?.XinZengAndBianJiKeHuViewControllerFinish() self.navigationController?.popViewController(animated: true) }) { (err) in } }else{ dict["cus_id"] = cus_id cusEdit(dict, success: { (data) in HUD.hide() HUD.flash(.labeledSubSuccess(subtitle: "编辑成功"), delay: 1.2) self.delegate?.XinZengAndBianJiKeHuViewControllerFinish() self.navigationController?.popViewController(animated: true) }) { (err) in } } } func GLASClose(view: GLAlertSelectView, selectnum: Int, selectArr: Array) { typeSelect = selectnum glSelectView?.removeFromSuperview() glSelectView = nil } var glSelectView:GLAlertSelectView? var kehuName:String = "" var phoneNum:String = "" var companyName:String = "" var bindKehu:String = "" var discount:String = "" var typeArr = ["个人","企业"] var typeSelect = 0 @IBAction func submitAction(_ sender: Any) { if kehuName.count == 0 { HUD.flash(.label("请填写客户名称"), delay: 1.2) return } if phoneNum.count == 0 { HUD.flash(.label("请填写手机号码"), delay: 1.2) return } if isTelNumber(num: phoneNum as NSString) == false{ HUD.flash(.label("请填写正确的手机号码"), delay: 1.2) return } if companyName.count == 0 { HUD.flash(.label("请填写客户公司名称"), delay: 1.2) return } // if bindKehu.count == 0 { // HUD.flash(.label("请选择绑定用户"), delay: 1.2) // return // } // if discount.count == 0 { // HUD.flash(.label("请填写折扣数,没有折扣请输入0"), delay: 1.2) // return // } let alertView = GeliAlertView(frame: self.view.window!.bounds) alertView.delegate = self; alertView.tishiLbl.text = "" if (titleStr?.contains("编辑"))!{ alertView.titileLbl.text = "是否完成编辑?" }else{ alertView.titileLbl.text = "是否新增客户?" } alertView.rightBtn.setAttributedTitle(NSAttributedString(string: "确定"), for: .normal) self.view.window?.addSubview(alertView) } var titleStr:String? let UserToken = UserDefaults.standard.value(forKey: "user_token") let titleArr = ["客户名称","客户手机号码 ","客户公司名称","绑定用户","客户类型","客户折扣","客户地址管理"] var holderArr = ["请输入客户名","请输入手机号码","请输入公司名称","搜索绑定","个人","敬请期待",""] @IBOutlet weak var bottomBtn: LGButton! @IBOutlet weak var tbv_h: NSLayoutConstraint! @IBOutlet weak var listView: UITableView! @IBOutlet weak var top_margin: NSLayoutConstraint! override func viewDidLoad() { super.viewDidLoad() navbar.title = titleStr if (titleStr?.contains("编辑"))! { navbar.rightTitle = "删除" navbar.rightBtnColor = UIColor(named: "#F57575") } self.view.addSubview(navbar) listView.separatorStyle = .none listView.isScrollEnabled = false top_margin.constant = NavCGRect.height-49 tbv_h.constant = CGFloat(49*titleArr.count) listView.register(UINib(nibName: "TitleAndBtnCell", bundle: nil), forCellReuseIdentifier: "TitleAndBtnCell") listView.register(UINib(nibName: "TitleAndTFCell", bundle: nil), forCellReuseIdentifier: "TitleAndTFCell") listView.register(UINib(nibName: "Title_Btn_Cell", bundle: nil), forCellReuseIdentifier: "Title_Btn_Cell") getAddrsInfo(["user_token":UserToken as Any,"cus_id":cus_id as Any]) { data in let model = data as! GetAddrsInfoModel self.count = model.data!.count self.listView.reloadData() } failture: { err in } } //MARK: - CELL DELEGATE func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return 49 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return titleArr.count } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if indexPath.row == 6 { let vc = DZGLViewController() vc.is_keHu_list = true vc.cus_id = cus_id print("vc.cus = ",vc.cus_id) vc.delegate = self self.navigationController?.pushViewController(vc, animated: true ) } if indexPath.row == 3 { let vc = BingDingKeHuViewController() vc.delegate = self self.navigationController?.pushViewController(vc, animated: true) } if indexPath.row == 4 { if glSelectView == nil { let view = GLAlertSelectView(frame: self.view.bounds) view.delegate = self view.selectNum = typeSelect view.tempNum = view.selectNum view.titleLbl.text = "请选择企业类型" view.dataArr = typeArr self.view.addSubview(view) glSelectView = view } } } func GLAlertSelectViewClick(selectNum: Int, view: GLAlertSelectView) { typeSelect = selectNum holderArr.insert(typeArr[selectNum], at: 4) holderArr.remove(at: 5) listView.reloadData() view.removeFromSuperview() glSelectView = nil } //MARK:--绑定用户选择回调 func BingDingKeHuViewControllerSelec(sender: GetBindUserDataModel) { bindKehu = sender.user_name! user_id = sender.user_id! listView.reloadData() } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if indexPath.row == 3 || indexPath.row == 4 { let cell = tableView.dequeueReusableCell(withIdentifier: "TitleAndBtnCell") as! TitleAndBtnCell cell.nameLbl.text = titleArr[indexPath.row] cell.contentLbl.text = holderArr[indexPath.row] cell.btn.isUserInteractionEnabled = false if indexPath.row == 3 { if bindKehu.count > 0 { cell.contentLbl.text = bindKehu } }else{ cell.contentLbl.text = typeArr[typeSelect] } return cell } if indexPath.row == 6 { let cell = tableView.dequeueReusableCell(withIdentifier: "Title_Btn_Cell") as! Title_Btn_Cell cell.title_lbl.text = titleArr[indexPath.row] if count != 0 { cell.add_adr_lbl.isHidden = true cell.arrow_img.isHidden = false }else{ cell.add_adr_lbl.isHidden = false cell.arrow_img.isHidden = true } return cell } let cell = tableView.dequeueReusableCell(withIdentifier: "TitleAndTFCell") as! TitleAndTFCell cell.nameLbl.text = titleArr[indexPath.row] cell.textTF.placeholder = holderArr[indexPath.row] cell.textTF.delegate = self if (titleStr?.contains("编辑"))! { cell.textTF.clearButtonMode = .always } cell.textTF.tag = indexPath.row switch indexPath.row { case 0: cell.textTF.keyboardType = .default cell.textTF.text = kehuName break case 1: cell.textTF.keyboardType = .numberPad cell.textTF.text = phoneNum break case 2: cell.textTF.keyboardType = .default cell.textTF.text = companyName break case 5: cell.textTF.isUserInteractionEnabled = false cell.textTF.clearButtonMode = .never if discount != "0" && discount != "100"{ cell.textTF.text = discount } break default: break } return cell // } } func textFieldDidEndEditing(_ textField: UITextField) { switch textField.tag { case 0: kehuName = textField.text! break case 1: phoneNum = textField.text! break case 2: companyName = textField.text! break case 5: let str = textField.text! as NSString if str.integerValue > 100 { HUD.flash(.label("不能超过100,请重新填写"), delay: 1.2) textField.text = "100" discount = "100" return } discount = textField.text! break default: break } } }