123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- //
- // OrderViewController.swift
- // xingchuangke
- //
- // Created by 李晓飞 on 2020/8/21.
- // Copyright © 2020 Virgil. All rights reserved.
- //
- import UIKit
- class AchiveViewController: BaseViewController, UITableViewDelegate, UITableViewDataSource {
- @IBOutlet weak var imgBgView: UIImageView!
- @IBOutlet weak var searchView: UIView!
- @IBOutlet weak var searchTextField: UITextField!
- @IBOutlet weak var searchBtn: UIButton!
- @IBOutlet weak var topView: UIView!
- @IBOutlet weak var startTimeBtn: UIButton!
- @IBOutlet weak var endTimeBtn: UIButton!
- @IBOutlet weak var queryBtn: UIButton!
- @IBOutlet weak var accountTableView: UITableView!
- @IBOutlet weak var dataTableView: UITableView!
- var teamStr: String = "0"
- let dataTitles = ["新增商户", "新增代理", "交易总额"]
- var lastIndexPath: IndexPath = IndexPath.init(row: 0, section: 0)
- var endTime: String = ""
- var startTime: String = ""
- var isTeam: String = "0"
- var userId: String = CommonValue.getUserId()
- var likeStr: String = ""
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- appDelegate.setNavigationBarHidden(isHidden: true)
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- navInit() // 自定义导航栏
- tableViewInit() // tableView初始化
- drawForTimeBtn() // 给时间按钮添加边框
- if teamStr == "0" { // 团队
- loadDataForAgentList()
- } else { // 个人
- loadDataForAchive()
- }
- }
- // 自定义导航栏
- func navInit() {
- var title = "业绩"
- if teamStr == "0" { // 团队
- title = "团队业绩"
- isTeam = "0"
- } else { // 个人
- title = "个人业绩"
- isTeam = "1"
- }
- let viewNav = (CommonViewUntils.getViewForXIB(xibName: "NavView") as! NavView)
- viewNav.initView(title: title) {[weak self] (index, _) in
- if index == 0 {
- self!.handleBack()
- }
- }
- self.view.addSubview(viewNav)
- viewNav.marginTop(top: 0)
- searchView.marginTop(top: viewNav.bottom())
- imgBgView.translatesAutoresizingMaskIntoConstraints = false
- let h: NSLayoutConstraint = NSLayoutConstraint(item: imgBgView as Any, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 0.0, constant: searchView.bottom())
- imgBgView.addConstraint(h)
- }
- // 初始化tableView
- func tableViewInit() {
- accountTableView.delegate = self
- accountTableView.dataSource = self
- accountTableView.tableFooterView = UIView.init()
- dataTableView.delegate = self
- dataTableView.dataSource = self
- dataTableView.tableFooterView = UIView.init()
- accountTableView.register(UINib(nibName: "AchiveAccountCell", bundle: nil), forCellReuseIdentifier: "AchiveAccountCell")
- dataTableView.register(UINib(nibName: "AchiveDataCell", bundle: nil), forCellReuseIdentifier: "AchiveDataCell")
- }
- // 为时间按钮添加边框
- func drawForTimeBtn() {
- startTimeBtn.layer.borderWidth = 1.0
- startTimeBtn.layer.borderColor = CommonUntils.getUIColorFromRGB(rgbValue: 0xF5F5F5).cgColor
- endTimeBtn.layer.borderWidth = 1.0
- endTimeBtn.layer.borderColor = CommonUntils.getUIColorFromRGB(rgbValue: 0xF5F5F5).cgColor
- startTime = getCurrentDate()
- startTimeBtn.setTitle(startTime, for: .normal)
- endTime = getCurrentDate()
- endTimeBtn.setTitle(endTime, for: .normal)
- }
- // MARK: - -- action
- @IBAction func searchBtnClick(_ sender: Any) {
- likeStr = searchTextField.text ?? ""
- self.view.endEditing(true)
- loadDataForAgentList()
- }
- @IBAction func btnMenuClick(_ sender: UIButton) {
- switch (sender as UIButton).tag {
- case 1001: // 开始时间
- let viewDatePicer = (CommonViewUntils.getViewForXIB(anyClass: Virgil_SelectDateForPickerView.self) as! Virgil_SelectDateForPickerView)
- var defaultDate: Date!
- if self.startTime.length() == 0 || self.startTime.length() != 10 {
- defaultDate = CommonDate.addMonth(date: Date(), month: 0)
- } else {
- defaultDate = CommonDate.getDateForString(dateStr: self.startTime, dateFormat: "yyyy-MM-dd")
- }
- viewDatePicer.datePicker.maximumDate = Date()
- viewDatePicer.showDatePickerView(defaultDate: defaultDate) {[weak self] (str) in
- self!.startTime = str
- self?.startTimeBtn.setTitle(str, for: .normal)
- }
- break
- case 1002: // 结束时间
- let viewDatePicer = (CommonViewUntils.getViewForXIB(anyClass: Virgil_SelectDateForPickerView.self) as! Virgil_SelectDateForPickerView)
- var defaultDate: Date!
- if self.endTime.length() == 0 || self.endTime.length() != 10 {
- defaultDate = CommonDate.addMonth(date: Date(), month: 0)
- } else {
- defaultDate = CommonDate.getDateForString(dateStr: self.endTime, dateFormat: "yyyy-MM-dd")
- }
- viewDatePicer.datePicker.maximumDate = Date()
- viewDatePicer.showDatePickerView(defaultDate: defaultDate) {[weak self] (str) in
- self!.endTime = str
- self?.endTimeBtn.setTitle(str, for: .normal)
- }
- break
- case 1003: // 查询
- loadDataForAchive()
- break
- default:
- break
- }
- }
- // MARK: - -- request
- func loadDataForAgentList() { // 获取代理列表
- let url = RequestURL.myAgentList
- let params = NSMutableDictionary()
- params.setValue(CommonValue.getUserId(), forKey: "userId")
- params.setValue(likeStr, forKey: "likeStr")
- loadDataList(url: url, params: params, tag: 2002)
- }
- func loadDataForAchive() { // 获取业绩数据
- var url = RequestURL.myAgentsPerformance
- if teamStr == "1" {
- url = RequestURL.myPerformance
- }
- let params = NSMutableDictionary()
- params.setValue(userId, forKey: "userId")
- params.setValue(self.startTime, forKey: "starTime")
- params.setValue(self.endTime, forKey: "endTime")
- params.setValue(isTeam, forKey: "isTeam") // 0 团队; 1 个人
- loadDataInfo(url: url, params: params, tag: 2001)
- }
- override func returnData(tag: Int) {
- if tag == 2002 {
- accountTableView.reloadData()
- userId = CommonValue.getUserId()
- lastIndexPath = IndexPath.init(row: 0, section: 0)
- loadDataForAchive()
- return
- }
- dataTableView.reloadData()
- }
- override func returnError(tag: Int, type: String) {
- if tag == 2001 {
- dicData.removeAllObjects()
- }
- }
- // MARK: - -- UITableViewDelegate/UITableViewDataSource
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- if tableView == accountTableView {
- if teamStr == "1" {
- return 1
- }
- return arrData.count + 1
- }
- return 3
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- if tableView == accountTableView {
- let cell = tableView.dequeueReusableCell(withIdentifier: "AchiveAccountCell", for: indexPath as IndexPath) as! AchiveAccountCell
- cell.selectionStyle = .none
- if indexPath == lastIndexPath {
- cell.isSelected = true
- }
- if indexPath.row == 0 {
- cell.nameLabel.text = teamStr == "0" ? "团队业绩" : "个人业绩"
- } else {
- let dic: NSDictionary = arrData[indexPath.row - 1] as! NSDictionary
- var name: String = dic["realName"] as! String
- if name.length() == 0 {
- name = dic["phone"] as! String
- }
- cell.nameLabel.text = name
- }
- return cell
- } else {
- let cell = tableView.dequeueReusableCell(withIdentifier: "AchiveDataCell", for: indexPath as IndexPath) as! AchiveDataCell
- cell.selectionStyle = .none
- cell.titleLbl.text = dataTitles[indexPath.row]
- if indexPath.row == 0 {
- cell.numLbl.text = "\(dicData["momthCount"] ?? "0")个"
- } else if indexPath.row == 1 {
- cell.numLbl.text = "\(dicData["fromUser"] ?? "0")个"
- } else if indexPath.row == 2 {
- cell.numLbl.text = "\(dicData["transactionTotal"] ?? "0.0")元"
- cell.numLbl.textColor = CommonUntils.getUIColorFromRGB(rgbValue: 0x2094F5, alpha: 1.0)
- }
- return cell
- }
- }
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- if tableView == accountTableView {
- if lastIndexPath == indexPath {
- return
- }
- if indexPath.row == 0 {
- userId = CommonValue.getUserId()
- isTeam = "0"
- } else {
- let dic: NSDictionary = arrData[indexPath.row - 1] as! NSDictionary
- userId = dic["id"] as! String
- isTeam = "1"
- }
- loadDataForAchive()
- let lastSelectedCell = tableView.cellForRow(at: lastIndexPath)
- lastSelectedCell?.isSelected = false
- let curCell = tableView.cellForRow(at: indexPath)
- curCell?.isSelected = true
- lastIndexPath = indexPath
- } else if tableView == dataTableView {
- if dicData.allKeys.count == 0 {
- return
- }
- let timeStr = "\(startTime)至\(endTime)"
- if indexPath.row == 0 {
- let vc = NewlyAddedMercViewController()
- vc.timeStr = timeStr
- vc.dictData = dicData
- self.navigationController?.pushViewController(vc, animated: true)
- } else if indexPath.row == 1 {
- let vc = NewlyAddedDelegateViewController()
- vc.timeStr = timeStr
- vc.dictData = dicData
- self.navigationController?.pushViewController(vc, animated: true)
- } else if indexPath.row == 2 {
- let vc = TotalTradeViewController()
- vc.timeStr = timeStr
- vc.userId = userId
- vc.isTeam = isTeam
- vc.dictData = dicData
- vc.startTime = self.startTime
- vc.endTime = self.endTime
- self.navigationController?.pushViewController(vc, animated: true)
- }
- }
- }
- // MARK: - -- private
- func getCurrentDate() -> String {
- let formatter = DateFormatter()
- formatter.locale = Locale.init(identifier: "zh_CN")
- formatter.dateFormat = "YYYY-MM-dd"
- let lastDay = Date.init(timeInterval: -24*60*60, since: Date())
- let date = formatter.string(from: lastDay)
- return date
- }
- /*
- // MARK: - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- // Get the new view controller using segue.destination.
- // Pass the selected object to the new view controller.
- }
- */
- }
|