|
@@ -0,0 +1,321 @@
|
|
|
+//
|
|
|
+// MDPMajorCell.swift
|
|
|
+// Koala
|
|
|
+//
|
|
|
+// Created by 刘千军 on 2023/10/17.
|
|
|
+// Copyright © 2023 刘千军. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+import UIKit
|
|
|
+import Charts
|
|
|
+class MDPMajorCell: BaseTableViewCell {
|
|
|
+ @IBOutlet weak var titleLab: UILabel!
|
|
|
+ @IBOutlet weak var timerLab: UILabel!
|
|
|
+
|
|
|
+ @IBOutlet weak var chartBgView: UIView!
|
|
|
+
|
|
|
+ @IBOutlet weak var stack1View: UIStackView!
|
|
|
+ @IBOutlet weak var dot1View: UIView!
|
|
|
+ @IBOutlet weak var name1Lab: UILabel!
|
|
|
+
|
|
|
+ @IBOutlet weak var stack2View: UIStackView!
|
|
|
+ @IBOutlet weak var dot2View: UIView!
|
|
|
+ @IBOutlet weak var name2Lab: UILabel!
|
|
|
+
|
|
|
+ @IBOutlet weak var stack3View: UIStackView!
|
|
|
+ @IBOutlet weak var dot3View: UIView!
|
|
|
+ @IBOutlet weak var name3Lab: UILabel!
|
|
|
+
|
|
|
+ @IBOutlet weak var leftLab: UILabel!
|
|
|
+ @IBOutlet weak var conter1Lab: UILabel!
|
|
|
+ @IBOutlet weak var conter2Lab: UILabel!
|
|
|
+ @IBOutlet weak var rightLab: UILabel!
|
|
|
+
|
|
|
+ @IBOutlet weak var tableView: UITableView!
|
|
|
+
|
|
|
+ var listData:[MDMajorListModel] = [MDMajorListModel]()
|
|
|
+
|
|
|
+ var colors:[UIColor] = [UIColor]()
|
|
|
+
|
|
|
+ lazy var pieChartView: PieChartView = {
|
|
|
+ let pieChartView: PieChartView = PieChartView()
|
|
|
+ pieChartView.delegate = self
|
|
|
+ pieChartView.backgroundColor = .clear
|
|
|
+ return pieChartView
|
|
|
+ }()
|
|
|
+
|
|
|
+ override func awakeFromNib() {
|
|
|
+ super.awakeFromNib()
|
|
|
+
|
|
|
+ self.backgroundColor = ALLBackGroundColor
|
|
|
+
|
|
|
+ self.titleLab.text = switchLanguage("主要股东")
|
|
|
+ self.titleLab.textColor = TitleTextColor
|
|
|
+ self.titleLab.setTextFont(.PFSM, 18)
|
|
|
+
|
|
|
+ self.timerLab.text = ""
|
|
|
+ self.timerLab.textColor = MidTextColor
|
|
|
+ self.timerLab.setTextFont(.PFSR, 14)
|
|
|
+
|
|
|
+ self.dot1View.setViewLayerBorderColor(myColor: .clear, borderWidth: 0, maskBounds: 5)
|
|
|
+ self.name1Lab.textColor = TitleTextColor
|
|
|
+ self.name1Lab.setTextFont(.PFSR, 10)
|
|
|
+
|
|
|
+ self.dot2View.setViewLayerBorderColor(myColor: .clear, borderWidth: 0, maskBounds: 5)
|
|
|
+ self.name2Lab.textColor = TitleTextColor
|
|
|
+ self.name2Lab.setTextFont(.PFSR, 10)
|
|
|
+
|
|
|
+ self.dot3View.setViewLayerBorderColor(myColor: .clear, borderWidth: 0, maskBounds: 5)
|
|
|
+ self.name3Lab.textColor = TitleTextColor
|
|
|
+ self.name3Lab.setTextFont(.PFSR, 10)
|
|
|
+
|
|
|
+ leftLab.textColor = MidTextColor
|
|
|
+ leftLab.setTextFont(.PFSR, 10)
|
|
|
+ leftLab.text = switchLanguage("持股数")
|
|
|
+
|
|
|
+ conter1Lab.textColor = MidTextColor
|
|
|
+ conter1Lab.setTextFont(.PFSR, 10)
|
|
|
+ conter1Lab.text = switchLanguage("持股比例")
|
|
|
+
|
|
|
+ conter2Lab.textColor = MidTextColor
|
|
|
+ conter2Lab.setTextFont(.PFSR, 10)
|
|
|
+ conter2Lab.text = switchLanguage("报告期")
|
|
|
+
|
|
|
+ rightLab.textColor = MidTextColor
|
|
|
+ rightLab.setTextFont(.PFSR, 10)
|
|
|
+ rightLab.text = switchLanguage("持股人类型")
|
|
|
+
|
|
|
+ self.tableView.delegate = self
|
|
|
+ self.tableView.dataSource = self
|
|
|
+ tableView.separatorStyle = .none
|
|
|
+ tableView.backgroundColor = .clear
|
|
|
+ tableView.tableFooterView = UIView()
|
|
|
+ tableView.tableHeaderView = UIView()
|
|
|
+ tableView.showsVerticalScrollIndicator = false
|
|
|
+ tableView.showsVerticalScrollIndicator = false
|
|
|
+ tableView.register(UINib.init(nibName: "MDPMajorListCell", bundle: nil), forCellReuseIdentifier: "MDPMajorListCell")
|
|
|
+
|
|
|
+
|
|
|
+ self.chartBgView.addSubview(self.pieChartView)
|
|
|
+ self.pieChartView.snp.makeConstraints { make in
|
|
|
+ make.edges.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ setPieChartViewBaseStyle()
|
|
|
+ }
|
|
|
+
|
|
|
+ override func setSelected(_ selected: Bool, animated: Bool) {
|
|
|
+ super.setSelected(selected, animated: animated)
|
|
|
+
|
|
|
+ // Configure the view for the selected state
|
|
|
+ }
|
|
|
+
|
|
|
+ func setPieChartViewBaseStyle() -> Void {
|
|
|
+ //基本样式
|
|
|
+ pieChartView.setExtraOffsets(left: 0, top: 0, right: 0, bottom: 0)//饼状图距离边缘的间隙
|
|
|
+ pieChartView.usePercentValuesEnabled = false//是否根据所提供的数据, 将显示数据转换为百分比格式
|
|
|
+ pieChartView.dragDecelerationEnabled = false//拖拽饼状图后是否有惯性效果
|
|
|
+ pieChartView.drawSlicesUnderHoleEnabled = false//是否显示区块文本
|
|
|
+ pieChartView.noDataText = switchLanguage("暂无收益")
|
|
|
+ pieChartView.noDataFont = _PFSSM(14)
|
|
|
+ pieChartView.noDataTextColor = TitleTextColor
|
|
|
+
|
|
|
+ //空(实)心饼状图样式
|
|
|
+ pieChartView.drawHoleEnabled = true//饼状图是否是空心 true为空心 false为实心
|
|
|
+ //饼状图中间描述
|
|
|
+ if pieChartView.isDrawHoleEnabled == true {
|
|
|
+
|
|
|
+ }
|
|
|
+ else{}
|
|
|
+
|
|
|
+ pieChartView.legend.enabled = false
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ func updateCellWith(list:[MDMajorListModel]) -> Void {
|
|
|
+ self.listData = list
|
|
|
+
|
|
|
+
|
|
|
+ self.colors = ChartColorTemplates.liberty()
|
|
|
+ + ChartColorTemplates.material()
|
|
|
+ + ChartColorTemplates.vordiplom()
|
|
|
+ + ChartColorTemplates.colorful()
|
|
|
+ + ChartColorTemplates.pastel()
|
|
|
+ + ChartColorTemplates.joyful()
|
|
|
+
|
|
|
+ self.stack1View.isHidden = true
|
|
|
+ self.stack2View.isHidden = true
|
|
|
+ self.stack3View.isHidden = true
|
|
|
+
|
|
|
+ for (i,model) in list.enumerated(){
|
|
|
+ if i == 0{
|
|
|
+ self.stack1View.isHidden = false
|
|
|
+ self.dot1View.backgroundColor = self.colors[i]
|
|
|
+ self.name1Lab.text = model.holderName
|
|
|
+ self.timerLab.text = switchLanguage("更新时间") + model.reportDate
|
|
|
+ }
|
|
|
+ else if i == 1{
|
|
|
+ self.stack2View.isHidden = false
|
|
|
+ self.dot2View.backgroundColor = self.colors[i]
|
|
|
+ self.name2Lab.text = model.holderName
|
|
|
+ }
|
|
|
+ else if i == 2 {
|
|
|
+ self.stack3View.isHidden = false
|
|
|
+ self.dot3View.backgroundColor = self.colors[i]
|
|
|
+ self.name3Lab.text = model.holderName
|
|
|
+ }else{
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ self.updataDataWith()
|
|
|
+ self.tableView.reloadData()
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+extension MDPMajorCell: ChartViewDelegate{
|
|
|
+
|
|
|
+ func updataDataWith(){
|
|
|
+
|
|
|
+
|
|
|
+ var yVals: NSMutableArray = NSMutableArray.init()
|
|
|
+ for (i,model) in self.listData.enumerated() {
|
|
|
+ let val = precisionString(with: model.holdingRatio, precision: "2", isRound: true)
|
|
|
+ let entry:PieChartDataEntry = PieChartDataEntry.init(value: Double(val)!, label:val + "%")
|
|
|
+ yVals.add(entry)
|
|
|
+ if colors.count > i{
|
|
|
+ model.color = colors[i]
|
|
|
+ }else{
|
|
|
+ model.color = RandomColor
|
|
|
+ colors.append(model.color)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //创建PieChartDataSet对象
|
|
|
+ let set1: PieChartDataSet = PieChartDataSet.init(entries: yVals as? [ChartDataEntry], label: "饼状图")
|
|
|
+ set1.drawIconsEnabled = false //是否在饼状图上面显示图片
|
|
|
+ set1.sliceSpace = 2 //相邻区块之间的间距
|
|
|
+ set1.selectionShift = 8//选中区块时, 放大的半径
|
|
|
+ set1.drawValuesEnabled = false //是否在饼状图上面显示数值
|
|
|
+ set1.highlightEnabled = true //点击选饼状图是否有高亮效果,(单击空白处取消选中)
|
|
|
+ set1.valueColors = [.clear]//设置柱形图颜色(是一个循环,例如:你设置5个颜色,你设置8个柱形,后三个对应的颜色是该设置中的前三个,依次类推)
|
|
|
+ set1.colors = colors
|
|
|
+
|
|
|
+
|
|
|
+ set1.xValuePosition = PieChartDataSet.ValuePosition.insideSlice//名称位置
|
|
|
+ //PieChartDataSet.ValuePosition.insideSlice 数据显示在饼图内部 PieChartDataSet.ValuePosition.outsideSlice外部
|
|
|
+
|
|
|
+ //外部条件下有折线
|
|
|
+ set1.yValuePosition = PieChartDataSet.ValuePosition.insideSlice//数据位置
|
|
|
+ //数据与区块之间的用于指示的折线样式
|
|
|
+ set1.valueLinePart1OffsetPercentage = 1 //折线中第一段起始位置相对于区块的偏移量, 数值越大, 折线距离区块越远
|
|
|
+ set1.valueLinePart1Length = 0//折线中第一段长度占比
|
|
|
+ set1.valueLinePart2Length = 0//折线中第二段长度最大占比
|
|
|
+ set1.valueLineWidth = 0//折线的粗细
|
|
|
+
|
|
|
+ // set1.yValuePosition = .outsideSlice //这个折线外部展示
|
|
|
+ set1.drawValuesEnabled = false
|
|
|
+ set1.xValuePosition = .insideSlice
|
|
|
+ set1.useValueColorForLine = false
|
|
|
+
|
|
|
+ let dataSets: NSMutableArray = NSMutableArray.init()
|
|
|
+ dataSets.add(set1)
|
|
|
+ //创建BarChartData对象, 此对象就是barChartView需要最终数据对象
|
|
|
+ let data: PieChartData = PieChartData.init(dataSets: dataSets as? [IChartDataSet])
|
|
|
+ let formatter: NumberFormatter = NumberFormatter.init()
|
|
|
+ //formatter.numberStyle = NumberFormatter.Style.currency//自定义数据显示格式 小数点形式(可以尝试不同看效果)
|
|
|
+ formatter.numberStyle = NumberFormatter.Style.none //自定义数据显示格式 小数点形式(可以尝试不同看效果)
|
|
|
+ formatter.maximumFractionDigits = 0
|
|
|
+ formatter.multiplier = 1
|
|
|
+ let forma :DefaultValueFormatter = DefaultValueFormatter.init(formatter: formatter)
|
|
|
+ data.setValueFormatter(forma)
|
|
|
+ data.setValueFont(UIFont.systemFont(ofSize: 10))
|
|
|
+ pieChartView.data = data
|
|
|
+ pieChartView.animate(xAxisDuration: 1, easingOption: ChartEasingOption.easeOutExpo)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //1.点击选中
|
|
|
+ func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {
|
|
|
+
|
|
|
+ self.showBalloonMarkerView(pieChartView: chartView as! PieChartView, entry: entry as! PieChartDataEntry)
|
|
|
+ }
|
|
|
+ //2.没有选中
|
|
|
+ func chartValueNothingSelected(_ chartView: ChartViewBase) {
|
|
|
+
|
|
|
+ }
|
|
|
+ //3.捏合放大或缩小
|
|
|
+ func chartScaled(_ chartView: ChartViewBase, scaleX: CGFloat, scaleY: CGFloat) {
|
|
|
+
|
|
|
+ }
|
|
|
+ //4.拖拽图表
|
|
|
+ func chartTranslated(_ chartView: ChartViewBase, dX: CGFloat, dY: CGFloat) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ func showBalloonMarkerView(pieChartView: PieChartView,entry: PieChartDataEntry){
|
|
|
+
|
|
|
+ let marker = BalloonMarker(color:exchangeColorAndImage(increase: 1).0,
|
|
|
+ font: _PFSR(12),
|
|
|
+ textColor: WhiteTextColor,
|
|
|
+ insets: UIEdgeInsets(top: 5, left: 5, bottom: 15, right: 5))
|
|
|
+ marker.chartView = pieChartView
|
|
|
+ marker.minimumSize = CGSize(width: 50, height: 30)
|
|
|
+
|
|
|
+
|
|
|
+ marker.setLabel(String(format: "%@",entry.label ?? ""))
|
|
|
+ pieChartView.marker = marker
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+//代理
|
|
|
+extension MDPMajorCell: UITableViewDelegate,UITableViewDataSource{
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
|
+ return self.listData.count
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
|
+ let cell:MDPMajorListCell = tableView.dequeueReusableCell(withIdentifier: "MDPMajorListCell") as! MDPMajorListCell
|
|
|
+ let model = self.listData[indexPath.row]
|
|
|
+
|
|
|
+ cell.updateCellWith(model: model)
|
|
|
+
|
|
|
+ return cell
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
|
|
+ return UIView()
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
|
|
|
+ return UIView()
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
|
|
+ return 30
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|