AchiveViewController.swift 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. //
  2. // OrderViewController.swift
  3. // xingchuangke
  4. //
  5. // Created by 李晓飞 on 2020/8/21.
  6. // Copyright © 2020 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. class AchiveViewController: BaseViewController, UITableViewDelegate, UITableViewDataSource {
  10. @IBOutlet weak var imgBgView: UIImageView!
  11. @IBOutlet weak var searchView: UIView!
  12. @IBOutlet weak var searchTextField: UITextField!
  13. @IBOutlet weak var searchBtn: UIButton!
  14. @IBOutlet weak var topView: UIView!
  15. @IBOutlet weak var startTimeBtn: UIButton!
  16. @IBOutlet weak var endTimeBtn: UIButton!
  17. @IBOutlet weak var queryBtn: UIButton!
  18. @IBOutlet weak var accountTableView: UITableView!
  19. @IBOutlet weak var dataTableView: UITableView!
  20. var teamStr: String = "0"
  21. let dataTitles = ["新增商户", "新增代理", "交易总额"]
  22. var lastIndexPath: IndexPath = IndexPath.init(row: 0, section: 0)
  23. var endTime: String = ""
  24. var startTime: String = ""
  25. var isTeam: String = "0"
  26. var userId: String = CommonValue.getUserId()
  27. var likeStr: String = ""
  28. override func viewWillAppear(_ animated: Bool) {
  29. super.viewWillAppear(animated)
  30. appDelegate.setNavigationBarHidden(isHidden: true)
  31. }
  32. override func viewDidLoad() {
  33. super.viewDidLoad()
  34. navInit() // 自定义导航栏
  35. tableViewInit() // tableView初始化
  36. drawForTimeBtn() // 给时间按钮添加边框
  37. if teamStr == "0" { // 团队
  38. loadDataForAgentList()
  39. } else { // 个人
  40. loadDataForAchive()
  41. }
  42. }
  43. // 自定义导航栏
  44. func navInit() {
  45. var title = "业绩"
  46. if teamStr == "0" { // 团队
  47. title = "团队业绩"
  48. isTeam = "0"
  49. } else { // 个人
  50. title = "个人业绩"
  51. isTeam = "1"
  52. }
  53. let viewNav = (CommonViewUntils.getViewForXIB(xibName: "NavView") as! NavView)
  54. viewNav.initView(title: title) {[weak self] (index, _) in
  55. if index == 0 {
  56. self!.handleBack()
  57. }
  58. }
  59. self.view.addSubview(viewNav)
  60. viewNav.marginTop(top: 0)
  61. searchView.marginTop(top: viewNav.bottom())
  62. imgBgView.translatesAutoresizingMaskIntoConstraints = false
  63. let h: NSLayoutConstraint = NSLayoutConstraint(item: imgBgView as Any, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 0.0, constant: searchView.bottom())
  64. imgBgView.addConstraint(h)
  65. }
  66. // 初始化tableView
  67. func tableViewInit() {
  68. accountTableView.delegate = self
  69. accountTableView.dataSource = self
  70. accountTableView.tableFooterView = UIView.init()
  71. dataTableView.delegate = self
  72. dataTableView.dataSource = self
  73. dataTableView.tableFooterView = UIView.init()
  74. accountTableView.register(UINib(nibName: "AchiveAccountCell", bundle: nil), forCellReuseIdentifier: "AchiveAccountCell")
  75. dataTableView.register(UINib(nibName: "AchiveDataCell", bundle: nil), forCellReuseIdentifier: "AchiveDataCell")
  76. }
  77. // 为时间按钮添加边框
  78. func drawForTimeBtn() {
  79. startTimeBtn.layer.borderWidth = 1.0
  80. startTimeBtn.layer.borderColor = CommonUntils.getUIColorFromRGB(rgbValue: 0xF5F5F5).cgColor
  81. endTimeBtn.layer.borderWidth = 1.0
  82. endTimeBtn.layer.borderColor = CommonUntils.getUIColorFromRGB(rgbValue: 0xF5F5F5).cgColor
  83. startTime = getCurrentDate()
  84. startTimeBtn.setTitle(startTime, for: .normal)
  85. endTime = getCurrentDate()
  86. endTimeBtn.setTitle(endTime, for: .normal)
  87. }
  88. // MARK: - -- action
  89. @IBAction func searchBtnClick(_ sender: Any) {
  90. likeStr = searchTextField.text ?? ""
  91. self.view.endEditing(true)
  92. loadDataForAgentList()
  93. }
  94. @IBAction func btnMenuClick(_ sender: UIButton) {
  95. switch (sender as UIButton).tag {
  96. case 1001: // 开始时间
  97. let viewDatePicer = (CommonViewUntils.getViewForXIB(anyClass: Virgil_SelectDateForPickerView.self) as! Virgil_SelectDateForPickerView)
  98. var defaultDate: Date!
  99. if self.startTime.length() == 0 || self.startTime.length() != 10 {
  100. defaultDate = CommonDate.addMonth(date: Date(), month: 0)
  101. } else {
  102. defaultDate = CommonDate.getDateForString(dateStr: self.startTime, dateFormat: "yyyy-MM-dd")
  103. }
  104. viewDatePicer.datePicker.maximumDate = Date()
  105. viewDatePicer.showDatePickerView(defaultDate: defaultDate) {[weak self] (str) in
  106. self!.startTime = str
  107. self?.startTimeBtn.setTitle(str, for: .normal)
  108. }
  109. break
  110. case 1002: // 结束时间
  111. let viewDatePicer = (CommonViewUntils.getViewForXIB(anyClass: Virgil_SelectDateForPickerView.self) as! Virgil_SelectDateForPickerView)
  112. var defaultDate: Date!
  113. if self.endTime.length() == 0 || self.endTime.length() != 10 {
  114. defaultDate = CommonDate.addMonth(date: Date(), month: 0)
  115. } else {
  116. defaultDate = CommonDate.getDateForString(dateStr: self.endTime, dateFormat: "yyyy-MM-dd")
  117. }
  118. viewDatePicer.datePicker.maximumDate = Date()
  119. viewDatePicer.showDatePickerView(defaultDate: defaultDate) {[weak self] (str) in
  120. self!.endTime = str
  121. self?.endTimeBtn.setTitle(str, for: .normal)
  122. }
  123. break
  124. case 1003: // 查询
  125. loadDataForAchive()
  126. break
  127. default:
  128. break
  129. }
  130. }
  131. // MARK: - -- request
  132. func loadDataForAgentList() { // 获取代理列表
  133. let url = RequestURL.myAgentList
  134. let params = NSMutableDictionary()
  135. params.setValue(CommonValue.getUserId(), forKey: "userId")
  136. params.setValue(likeStr, forKey: "likeStr")
  137. loadDataList(url: url, params: params, tag: 2002)
  138. }
  139. func loadDataForAchive() { // 获取业绩数据
  140. var url = RequestURL.myAgentsPerformance
  141. if teamStr == "1" {
  142. url = RequestURL.myPerformance
  143. }
  144. let params = NSMutableDictionary()
  145. params.setValue(userId, forKey: "userId")
  146. params.setValue(self.startTime, forKey: "starTime")
  147. params.setValue(self.endTime, forKey: "endTime")
  148. params.setValue(isTeam, forKey: "isTeam") // 0 团队; 1 个人
  149. loadDataInfo(url: url, params: params, tag: 2001)
  150. }
  151. override func returnData(tag: Int) {
  152. if tag == 2002 {
  153. accountTableView.reloadData()
  154. userId = CommonValue.getUserId()
  155. lastIndexPath = IndexPath.init(row: 0, section: 0)
  156. loadDataForAchive()
  157. return
  158. }
  159. dataTableView.reloadData()
  160. }
  161. override func returnError(tag: Int, type: String) {
  162. if tag == 2001 {
  163. dicData.removeAllObjects()
  164. }
  165. }
  166. // MARK: - -- UITableViewDelegate/UITableViewDataSource
  167. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  168. if tableView == accountTableView {
  169. if teamStr == "1" {
  170. return 1
  171. }
  172. return arrData.count + 1
  173. }
  174. return 3
  175. }
  176. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  177. if tableView == accountTableView {
  178. let cell = tableView.dequeueReusableCell(withIdentifier: "AchiveAccountCell", for: indexPath as IndexPath) as! AchiveAccountCell
  179. cell.selectionStyle = .none
  180. if indexPath == lastIndexPath {
  181. cell.isSelected = true
  182. }
  183. if indexPath.row == 0 {
  184. cell.nameLabel.text = teamStr == "0" ? "团队业绩" : "个人业绩"
  185. } else {
  186. let dic: NSDictionary = arrData[indexPath.row - 1] as! NSDictionary
  187. var name: String = dic["realName"] as! String
  188. if name.length() == 0 {
  189. name = dic["phone"] as! String
  190. }
  191. cell.nameLabel.text = name
  192. }
  193. return cell
  194. } else {
  195. let cell = tableView.dequeueReusableCell(withIdentifier: "AchiveDataCell", for: indexPath as IndexPath) as! AchiveDataCell
  196. cell.selectionStyle = .none
  197. cell.titleLbl.text = dataTitles[indexPath.row]
  198. if indexPath.row == 0 {
  199. cell.numLbl.text = "\(dicData["momthCount"] ?? "0")个"
  200. } else if indexPath.row == 1 {
  201. cell.numLbl.text = "\(dicData["fromUser"] ?? "0")个"
  202. } else if indexPath.row == 2 {
  203. cell.numLbl.text = "\(dicData["transactionTotal"] ?? "0.0")元"
  204. cell.numLbl.textColor = CommonUntils.getUIColorFromRGB(rgbValue: 0x2094F5, alpha: 1.0)
  205. }
  206. return cell
  207. }
  208. }
  209. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  210. if tableView == accountTableView {
  211. if lastIndexPath == indexPath {
  212. return
  213. }
  214. if indexPath.row == 0 {
  215. userId = CommonValue.getUserId()
  216. isTeam = "0"
  217. } else {
  218. let dic: NSDictionary = arrData[indexPath.row - 1] as! NSDictionary
  219. userId = dic["id"] as! String
  220. isTeam = "1"
  221. }
  222. loadDataForAchive()
  223. let lastSelectedCell = tableView.cellForRow(at: lastIndexPath)
  224. lastSelectedCell?.isSelected = false
  225. let curCell = tableView.cellForRow(at: indexPath)
  226. curCell?.isSelected = true
  227. lastIndexPath = indexPath
  228. } else if tableView == dataTableView {
  229. if dicData.allKeys.count == 0 {
  230. return
  231. }
  232. let timeStr = "\(startTime)至\(endTime)"
  233. if indexPath.row == 0 {
  234. let vc = NewlyAddedMercViewController()
  235. vc.timeStr = timeStr
  236. vc.dictData = dicData
  237. self.navigationController?.pushViewController(vc, animated: true)
  238. } else if indexPath.row == 1 {
  239. let vc = NewlyAddedDelegateViewController()
  240. vc.timeStr = timeStr
  241. vc.dictData = dicData
  242. self.navigationController?.pushViewController(vc, animated: true)
  243. } else if indexPath.row == 2 {
  244. let vc = TotalTradeViewController()
  245. vc.timeStr = timeStr
  246. vc.userId = userId
  247. vc.isTeam = isTeam
  248. vc.dictData = dicData
  249. vc.startTime = self.startTime
  250. vc.endTime = self.endTime
  251. self.navigationController?.pushViewController(vc, animated: true)
  252. }
  253. }
  254. }
  255. // MARK: - -- private
  256. func getCurrentDate() -> String {
  257. let formatter = DateFormatter()
  258. formatter.locale = Locale.init(identifier: "zh_CN")
  259. formatter.dateFormat = "YYYY-MM-dd"
  260. let lastDay = Date.init(timeInterval: -24*60*60, since: Date())
  261. let date = formatter.string(from: lastDay)
  262. return date
  263. }
  264. /*
  265. // MARK: - Navigation
  266. // In a storyboard-based application, you will often want to do a little preparation before navigation
  267. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  268. // Get the new view controller using segue.destination.
  269. // Pass the selected object to the new view controller.
  270. }
  271. */
  272. }