package com.zj365.health.fragment.bloodlipid

import android.annotation.SuppressLint
import android.os.Build
import android.text.TextUtils
import android.view.LayoutInflater
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.bigkoo.pickerview.adapter.ArrayWheelAdapter
import com.blankj.utilcode.util.TimeUtils
import com.contrarywind.view.WheelView
import com.github.mikephil.charting.data.BarEntry
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.xty.base.fragment.BaseVmFrag
import com.xty.common.TimeSelectCompare
import com.xty.common.weight.tablayout.TabEntity
import com.xty.common.weight.tablayout.listener.CustomTabEntity
import com.xty.common.weight.tablayout.listener.OnTabSelectListener
import com.zj365.health.R
import com.zj365.health.adapter.CompareAdapter
import com.zj365.health.databinding.FragBloodLipidCompareDataBinding
import com.zj365.health.util.HealthDateAndTimeUtils
import com.zj365.health.vm.BloodFatCompareVm

import com.zj365.health.weight.ICompareMarkView
import com.xty.network.model.BloodFatType
import com.xty.network.model.BloodLipidDataBean
import com.xty.network.model.ModelCompare
import com.xty.network.model.ValueMap
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Date
import java.util.Locale


/**
 *  血脂数据对比
 */
class BloodFatCompareDataFrag : BaseVmFrag<BloodFatCompareVm>() {

    val binding by lazy { FragBloodLipidCompareDataBinding.inflate(layoutInflater) }
    override fun setLayout() = binding.root
    override fun setViewModel() = BloodFatCompareVm()

    private var week: Int = 1//默认点击时间是选择时间还是对比时间 1，选择， 2 对比
    private val tcAdapter by lazy { CompareAdapter() }
    private val tgAdapter by lazy { CompareAdapter() }
    private val hdlAdapter by lazy { CompareAdapter() }
    private val ldlAdapter by lazy { CompareAdapter() }

    val fomartStr by lazy { arrayOf("HH:mm", "HH:mm", "MM-dd", "MM-dd", "yy-MM") }

    val weeker by lazy { arrayOf("周一", "周二", "周三", "周四", "周五", "周六", "周日") }

    private val mTabEntities: ArrayList<CustomTabEntity> = ArrayList()
    private val mTitles = arrayOf(
        "日", "周", "月", "年"
    )
    /*    var lineValue = arrayListOf<Entry>()  //曲线数据
        var lineValueCompare = arrayListOf<Entry>()  //曲线数据*/


    var id: String = ""
    var type = 1

    var dayDate = ""
    var weekDate = ""
    var mouthDate = ""
    var yearDate = ""
    private var timeSelect: TimeSelectCompare? = null
    private var timeSelectCompare: TimeSelectCompare? = null

    private var timeMonthSelect: TimeSelectCompare? = null

    private var timeMonthSelectCompare: TimeSelectCompare? = null

    var timeYearSelect: TimeSelectCompare? = null

    var timeYearSelectCompare: TimeSelectCompare? = null

    private var bottomSheetDialog: BottomSheetDialog? = null
    private var weekWheelView: WheelView? = null
    private lateinit var tcList: MutableList<BloodLipidDataBean.ModelBean>
    private lateinit var tcListCompare: MutableList<BloodLipidDataBean.ModelBean>

    private var tcBarValue = arrayListOf<BarEntry>()  //柱形数据
    private var tcBarValueCompare = arrayListOf<BarEntry>()  //柱形数据

    @SuppressLint("SuspiciousIndentation")
    fun initBottomDialog() {
        if (bottomSheetDialog == null) {
            bottomSheetDialog = BottomSheetDialog(this.requireContext())
            bottomSheetDialog?.let { dialog ->
                val view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_layout, null)
                dialog.setContentView(view)
                weekWheelView = view.findViewById<WheelView>(R.id.wheelView)
                weekWheelView?.setCyclic(false)
                val list = HealthDateAndTimeUtils.buildWeekLower26(null)
                list.removeAt(0)
                weekWheelView?.adapter = ArrayWheelAdapter(list)
                val windowHeight = (resources.displayMetrics.heightPixels * 0.6).toInt()
                dialog.behavior.peekHeight = windowHeight

                dialog.behavior.isHideable = false
                dialog.behavior.state = BottomSheetBehavior.STATE_EXPANDED

                val cancelButton = view.findViewById<TextView>(R.id.cancel_button)
                val confirmButton = view.findViewById<TextView>(R.id.confirm_button)

                cancelButton.setOnClickListener {
                    // 点击取消按钮的操作
                    dialog.dismiss()
                }

                confirmButton.setOnClickListener {
                    if (weekWheelView == null) {
                        return@setOnClickListener
                    }
                    // 点击确定按钮的操作
                    val item = weekWheelView!!.adapter.getItem(weekWheelView!!.currentItem)
                    if (week == 1) {
                        binding.tvShowDate.text = item.toString()
                        weekDate = binding.tvShowDate.text.toString()
                        mViewModel.getBloodLipidData(
                            type,
                            binding.tvShowDate.text.toString(),
                            binding.tvHideDate.text.toString(), id
                        )
                    } else {
                        binding.tvHideDate.text = item.toString()
                        mViewModel.getBloodLipidData(
                            type,
                            binding.tvShowDate.text.toString(),
                            binding.tvHideDate.text.toString(), id
                        )
                    }
                    // 点击确定按钮的操作
                    dialog.dismiss()
                }
            }
        }
    }

    /*private fun buildWeekLower26(shouldEnd: Date?): MutableList<String> {
        val startDate = Calendar.getInstance()
        startDate.firstDayOfWeek = Calendar.MONDAY
        startDate.add(Calendar.YEAR, -1)
        val endDate = Calendar.getInstance()
        if (shouldEnd != null) {
            endDate.time = shouldEnd
        }
        val dateRanges: MutableList<String> = ArrayList()
        var currentMonday = startDate.clone() as Calendar
        currentMonday.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY)

        while (currentMonday.before(endDate)) {
            val currentSunday = currentMonday.clone() as Calendar
            currentSunday.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY)

            val formattedDateRange =
                SimpleDateFormat("yyyy-MM-dd").format(currentMonday.time) + "至" + SimpleDateFormat(
                    "yyyy-MM-dd"
                ).format(
                    currentSunday.time
                )
            dateRanges.add(formattedDateRange)

            currentMonday.add(Calendar.WEEK_OF_YEAR, 1)
        }

        dateRanges.reverse()
        return dateRanges
    }*/

    override fun initData() {
        super.initData()
        id = arguments?.getString("id").toString()
    }

    @SuppressLint("SimpleDateFormat")
    override fun initView() {
        super.initView()
        initTab()
        initCharts()
        initRecycle()
        setTimeSelect()
        binding.clTc.tvTitle.text = "总胆固醇"
        binding.clTg.tvTitle.text = "甘油三酯"
        binding.clHdl.tvTitle.text = "高密度脂蛋白"
        binding.clLdl.tvTitle.text = "低密度脂蛋白"

        binding.tvShowDate.setOnClickListener {
            when (type) {
                1 -> {
                    timeSelect!!.selectTime(it, "yyyy-MM-dd")
                }

                2 -> {
                    week = 1
                    val list = HealthDateAndTimeUtils.buildWeekLower26(null)
                    weekWheelView?.adapter = ArrayWheelAdapter(list)
                    bottomSheetDialog?.show()
                }

                3 -> {
                    timeMonthSelect?.selectTimeWithYearMonth(it, "yyyy-MM")
                }

                4 -> {
                    timeYearSelect?.selectTimeWithYear(it, "yyyy")
                }
            }
        }
        binding.tvHideDate.setOnClickListener {
            when (type) {
                1 -> {
                    val calendar = Calendar.getInstance()
                    if (!TextUtils.isEmpty(timeSelect!!.selectTime)) {
                        val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
                        val date = dateFormat.parse(timeSelect!!.selectTime)
                        if (date != null) {
                            calendar.time = date
                        }
                        calendar.add(Calendar.DAY_OF_YEAR, -1)

                    } else {
                        val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
                        val date = dateFormat.parse(binding.tvHideDate.text.toString())
                        if (date != null) {
                            calendar.time = date
                        }
                    }
                    timeSelectCompare!!.createPvTime(requireContext(), calendar, 1) {
                        // 在选择时间后执行的逻辑
                        type = 1
//            dayDate = binding.tvHideDate.text.toString()
                        mViewModel.getBloodLipidData(
                            type,
                            binding.tvShowDate.text.toString(),
                            binding.tvHideDate.text.toString(), id
                        )
                    }
                    timeSelectCompare!!.selectTime(it, "yyyy-MM-dd")
                }

                2 -> {
                    val selectedDateStr = binding.tvShowDate.text
                    if (selectedDateStr != null) {
                        val selectedDateSpit = selectedDateStr.split("至")
                        selectedDateSpit.let { split ->
                            if (split.size >= 2) {
                                val selectedStartStr = split[0]
                                val list = HealthDateAndTimeUtils.buildWeekLower26(
                                    SimpleDateFormat("yyyy-MM-dd").parse(selectedStartStr)
                                )
                                weekWheelView?.adapter = ArrayWheelAdapter(list)
                            }
                        }
                    }
                    bottomSheetDialog?.show()
                    week = 2
                }

                3 -> {
                    val calendar = Calendar.getInstance()
                    timeMonthSelect!!.selectTime
                    if (!TextUtils.isEmpty(timeMonthSelect!!.selectTime)) {
                        val dateFormat = SimpleDateFormat("yyyy-MM", Locale.getDefault())
                        val date = dateFormat.parse(timeMonthSelect!!.selectTime)
                        if (date != null) {
                            calendar.time = date
                        }
                        if (calendar!!.get(Calendar.MONTH) == Calendar.JANUARY) {
                            calendar.add(Calendar.YEAR, -1)
                            calendar.set(Calendar.MONTH, Calendar.DECEMBER)
                        } else {
                            calendar.add(Calendar.MONTH, -1)
                        }
                    } else {
                        val dateFormat = SimpleDateFormat("yyyy-MM", Locale.getDefault())
                        val date = dateFormat.parse(binding.tvHideDate.text.toString())
                        if (date != null) {
                            calendar.time = date
                        }
                    }


                    timeMonthSelectCompare!!.createPvTime(requireContext(), calendar, 3) {
                        // 在选择时间后执行的逻辑
                        type = 3
//                        mouthDate = binding.tvHideDate.text.toString()
                        mViewModel.getBloodLipidData(
                            type,
                            binding.tvShowDate.text.toString(),
                            binding.tvHideDate.text.toString(), id
                        )
                    }

                    timeMonthSelectCompare!!.selectTimeWithYearMonth(
                        it, "yyyy-MM"
                    )

                    // 如果当前月份是一月，将年份减一，并将月份设置为十二月
                }

                4 -> {
                    val calendar = Calendar.getInstance()
                    if (!TextUtils.isEmpty(timeYearSelect!!.selectTime)) {
                        val dateFormat = SimpleDateFormat("yyyy", Locale.getDefault())
                        val date = dateFormat.parse(timeYearSelect!!.selectTime)
                        if (date != null) {
                            calendar.time = date
                        }
                        calendar.add(Calendar.YEAR, -1)
                    } else {
                        val dateFormat = SimpleDateFormat("yyyy", Locale.getDefault())
                        val date = dateFormat.parse(binding.tvHideDate.text.toString())
                        if (date != null) {
                            calendar.time = date
                        }
                    }
                    timeYearSelectCompare!!.createPvTime(requireContext(), calendar, 4) {
                        // 在选择时间后执行的逻辑
                        type = 4
//                        mouthDate = binding.tvHideDate.text.toString()
                        mViewModel.getBloodLipidData(
                            type,
                            binding.tvShowDate.text.toString(),
                            binding.tvHideDate.text.toString(), id
                        )
                    }
                    timeYearSelectCompare!!.selectTimeWithYear(it, "yyyy")
                }
            }
        }
        initBottomDialog()
        mViewModel.getBloodLipidData(
            type,
            /* RxTimeTool.getCurTimeString(SimpleDateFormat("yyyy-MM-dd"))*/
            SimpleDateFormat("yyyy-MM-dd").format(getdateMunise(-1)),
            SimpleDateFormat("yyyy-MM-dd").format(getdateMunise(-2)), id
        )
    }

    /**
     * 初始化时间选择器
     */
    @SuppressLint("SimpleDateFormat")
    private fun setTimeSelect() {
        var calendar = Calendar.getInstance()
        calendar.time = getdateMunise(-1)
        binding.tvShowDate.text = SimpleDateFormat("yyyy-MM-dd").format(calendar.time)
        binding.tvHideDate.text = SimpleDateFormat("yyyy-MM-dd").format(getdateMunise(-2))
        //日 的选择时间器
        timeSelect = TimeSelectCompare()
        timeSelect!!.createPvTime(requireContext(), calendar, 1) {
            // 在选择时间后执行的逻辑
            type = 1
            dayDate = binding.tvShowDate.text.toString()
            mViewModel.getBloodLipidData(
                type,
                dayDate,
                binding.tvHideDate.text.toString(),
                id
            )
        }
        timeSelect!!.startDate.set(1922, 1, 1)
        timeSelect!!.endDate = calendar
        //日 的对比时间器
        timeSelectCompare = TimeSelectCompare()

//-------------------------------------------------月
        calendar = Calendar.getInstance()
        val dateFormat = SimpleDateFormat("yyyy-MM", Locale.getDefault())
        dateFormat.format(calendar.time)
        if (calendar.get(Calendar.MONTH) == Calendar.JANUARY) {
            calendar.add(Calendar.YEAR, -1)
            calendar.set(Calendar.MONTH, Calendar.DECEMBER)
        } else {
            calendar.add(Calendar.MONTH, -1)
        }
        timeMonthSelect = TimeSelectCompare()
        timeMonthSelect!!.createPvTime(requireContext(), calendar, 3) {
            // 在选择时间后执行的逻辑
            type = 3
            mouthDate = binding.tvHideDate.text.toString()
            mViewModel.getBloodLipidData(
                type,
                binding.tvShowDate.text.toString(),
                binding.tvHideDate.text.toString(),
                id
            )
            timeMonthSelect?.selectTimeWithYearMonth(
                binding.tvShowDate,
                "yyyy-MM"
            )
        }
        timeMonthSelect!!.startDate.set(Calendar.YEAR, 1922)
        timeMonthSelect!!.startDate.set(Calendar.MONTH, 1)
        timeMonthSelect!!.endDate = calendar


        calendar.add(Calendar.MONTH, -1)
        //月 的对比时间器
        timeMonthSelectCompare = TimeSelectCompare()
        timeMonthSelectCompare!!.startDate.set(Calendar.YEAR, 1922)
        timeMonthSelectCompare!!.startDate.set(Calendar.MONTH, 1)
        timeMonthSelectCompare!!.endDate = calendar
//-------------------------------------------------年
        val calendaryear = Calendar.getInstance()
        val lastYear = SimpleDateFormat("yyyy", Locale.getDefault()).format(calendaryear.time)
        val date = lastYear.format(calendaryear.time)
        timeYearSelect = TimeSelectCompare()
        timeYearSelect!!.createPvTime(requireContext(), calendaryear, 4) {
            // 在选择时间后执行的逻辑
            type = 4
            mouthDate = binding.tvHideDate.text.toString()
            mViewModel.getBloodLipidData(
                type,
                binding.tvShowDate.text.toString(),
                binding.tvHideDate.text.toString(), id
            )
            timeYearSelect?.selectTimeWithYearMonth(
                binding.tvShowDate,
                "yyyy"
            )
        }

        timeYearSelect!!.startDate.set(Calendar.YEAR, 1922)
        timeYearSelect!!.endDate = calendaryear
        //年 的对比时间器
        timeYearSelectCompare = TimeSelectCompare()
        calendaryear.add(Calendar.YEAR, -1)
        timeYearSelectCompare!!.createPvTime(requireContext(), calendaryear, 4) {
            // 在选择时间后执行的逻辑
            type = 4
//            dayDate = binding.tvHideDate.text.toString()
            mViewModel.getBloodLipidData(
                type,
                binding.tvShowDate.text.toString(),
                binding.tvHideDate.text.toString(),
                id
            )
        }
        timeYearSelectCompare!!.startDate.set(Calendar.YEAR, 1922)
        timeYearSelectCompare!!.endDate = calendaryear
    }

    private fun getdateMunise(int: Int): Date {
        val calendar = Calendar.getInstance()
        calendar.add(Calendar.DAY_OF_YEAR, int)
        return calendar.time
    }

    fun convertTimeToIndex(time: String): Int {
        // 将时间格式转换为小时和分钟
        val parts = time.split(":")
        val hours = parts[0].toInt()
        val minutes = parts[1].toInt()
        // 计算对应的分钟数
        val totalMinutes = hours * 60 + minutes
        // 计算对应的索引值
        return totalMinutes / 10
    }

    fun splitDataIntoSegments(dataList: MutableList<ModelCompare>): MutableList<MutableList<ModelCompare>> {
        val segments = mutableListOf<MutableList<ModelCompare>>()
        var currentSegment = mutableListOf<ModelCompare>()

        for (model in dataList) {
            if (model.uaValue.toFloat().isNaN()) {
                // 遇到 Float.NaN，如果当前线段不为空，则添加到结果中，并开始新的线段
                if (currentSegment.isNotEmpty()) {
                    segments.add(currentSegment)
                    currentSegment = mutableListOf()
                }
            } else {
                // 遇到有效数据，将其添加到当前线段中
                currentSegment.add(model)
            }
        }
        // 将最后一个线段添加到结果中
        if (currentSegment.isNotEmpty()) {
            segments.add(currentSegment)
        }
        return segments
    }

    private fun checkData(segmentsCompare: MutableList<MutableList<ModelCompare>>): MutableList<MutableList<ModelCompare>> {
        if (segmentsCompare[0][0].time != "00:00") {
            val d = mutableListOf<ModelCompare>()
            val b = ModelCompare("00:00", 0f)
            d.add(b)
            segmentsCompare.add(d)
        }
        if (segmentsCompare[segmentsCompare.size - 1][segmentsCompare[segmentsCompare.size - 1].size - 1].time != "23:50") {
            val d = mutableListOf<ModelCompare>()
            val b = ModelCompare("23:50", 0f)
            d.add(b)
            segmentsCompare.add(d)
        }
        return segmentsCompare
    }

    override fun observer() {
        mViewModel.dataLive.observe(this) {
//            var list  =  it.data.model
//            var modelCompare  =  it.data.model
//            var list= mutableListOf<UricAcidBean>()
//             adapter.setNewInstance(it.data.compareModel)
            if (it.data.model.isEmpty() && it.data.modelCompare.isEmpty()) {

            } else {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                    when (type) {
                        1 -> {//日
                            it.data.model = it.data.mapDataToTime(it.data.model)
                            it.data.modelCompare = it.data.mapDataToTime(it.data.modelCompare)
                        }

                        2 -> {//周
                            var split = binding.tvShowDate.text.toString().split("至")
                            var start = split[0]
                            var end = split[1]
                            it.data.model = it.data.fillMissingData(it.data.model, start, end)
                            split = binding.tvHideDate.text.toString().split("至")
                            start = split[0]
                            end = split[1]
                            it.data.modelCompare =
                                it.data.fillMissingData(it.data.modelCompare, start, end)
                        }

                        3 -> {//月
                            it.data.model = it.data.fillMissingData(
                                it.data.model,
                                binding.tvShowDate.text.toString()
                            )
                            it.data.modelCompare = it.data.fillMissingData(
                                it.data.modelCompare,
                                binding.tvHideDate.text.toString()
                            )
                        }

                        4 -> {//年
                            it.data.model = it.data.fillMissingData(it.data.model)
                            it.data.modelCompare = it.data.fillMissingData(it.data.modelCompare)
                        }
                    }
                }
            }
            setTCChartData(it.data)
            setTGChartData(it.data)
            setHDLChartData(it.data)
            setLDLChartData(it.data)

            binding.clTc.comprehensiveContent.text = it.data.tcContent
            binding.clTg.comprehensiveContent.text = it.data.tgContent
            binding.clHdl.comprehensiveContent.text = it.data.hdlContent
            binding.clLdl.comprehensiveContent.text = it.data.ldlContent

            binding.comprehensiveBlContent.text = it.data.comprehensiveContent
        }
    }

    private fun initTab() {
        val currentDay = Date()
        dayDate = TimeUtils.date2String(currentDay, "yyyy-MM-dd")
//        weekDate = "${TimeUtils.date2String(getDateAdd(6), "yyyy-MM-dd")}至$dayDate"
        mouthDate = TimeUtils.date2String(currentDay, "yyyy-MM")
        yearDate = TimeUtils.date2String(currentDay, "yyyy")
        mTabEntities.clear()
        mTitles.forEach {
            mTabEntities.add(
                TabEntity(
                    it, android.R.drawable.ic_delete, android.R.drawable.ic_delete
                )
            )
        }
        binding.commonTabLayout.setTabData(mTabEntities)
        binding.commonTabLayout.setOnTabSelectListener(object : OnTabSelectListener {
            @SuppressLint("SetTextI18n")
            override fun onTabSelect(position: Int) {
                binding.commonTabLayout.currentTab = position
                when (position) {
                    0 -> {
                        type = 1
                        binding.showTitle.text = "选择日期"
                        binding.hideTitle.text = "对比日期"
                        binding.tvShowDate.text =
                            SimpleDateFormat("yyyy-MM-dd").format(getdateMunise(-1))
                        binding.tvHideDate.text =
                            SimpleDateFormat("yyyy-MM-dd").format(getdateMunise(-2))
                        mViewModel.getBloodLipidData(
                            type,
                            /* RxTimeTool.getCurTimeString(SimpleDateFormat("yyyy-MM-dd"))*/
                            binding.tvShowDate.text.toString(),
                            binding.tvHideDate.text.toString(), id
                        )
//                        binding.mLineChart.visibility = View.VISIBLE
//                        binding.mBarChart.visibility = View.GONE

                    }

                    1 -> {
                        type = 2
                        binding.showTitle.text = "选择周"
                        binding.hideTitle.text = "对比周"
                        binding.tvShowDate.text = HealthDateAndTimeUtils.getPreviousWeekDateRange(1)
                        binding.tvHideDate.text = HealthDateAndTimeUtils.getPreviousWeekDateRange(2)
                        mViewModel.getBloodLipidData(
                            type,
                            /* RxTimeTool.getCurTimeString(SimpleDateFormat("yyyy-MM-dd"))*/
                            binding.tvShowDate.text.toString(),
                            binding.tvHideDate.text.toString(), id
                        )
//                        binding.mLineChart.visibility = View.GONE
//                        binding.mBarChart.visibility = View.VISIBLE
                    }

                    2 -> {
                        binding.showTitle.text = "选择月"
                        binding.hideTitle.text = "对比月"
                        binding.tvShowDate.text =
                            HealthDateAndTimeUtils.getPreviousMonthDateRange(1)
                        binding.tvHideDate.text =
                            HealthDateAndTimeUtils.getPreviousMonthDateRange(2)
                        type = 3
                        mViewModel.getBloodLipidData(
                            type,
                            /* RxTimeTool.getCurTimeString(SimpleDateFormat("yyyy-MM-dd"))*/
                            binding.tvShowDate.text.toString(),
                            binding.tvHideDate.text.toString(), id
                        )
//                        binding.mLineChart.visibility = View.GONE
//                        binding.mBarChart.visibility = View.VISIBLE

                    }

                    3 -> {
                        val calendar = Calendar.getInstance()
                        calendar.add(Calendar.YEAR, -1)
                        val lastYear =
                            SimpleDateFormat("yyyy", Locale.getDefault()).format(calendar.time)
                        binding.tvShowDate.text = yearDate
                        binding.tvHideDate.text = lastYear
                        type = 4
                        mViewModel.getBloodLipidData(
                            type,
                            /* RxTimeTool.getCurTimeString(SimpleDateFormat("yyyy-MM-dd"))*/
                            binding.tvShowDate.text.toString(),
                            binding.tvHideDate.text.toString(), id
                        )
//                        binding.mLineChart.visibility = View.GONE
//                        binding.mBarChart.visibility = View.VISIBLE
                    }
                }
//                mViewModel.getUricAcidData(type, binding.tvShowDate.text.toString(), id)TODO
            }

            override fun onTabReselect(position: Int) {
            }
        })
    }

    /* */
    /**
     * 获取上个月  monthCount 月数
     *//*
    fun getPreviousMonthDateRange(monthCount: Int): String {
        val calendar = Calendar.getInstance()
        calendar.add(Calendar.MONTH, -monthCount)

        val dateFormat = SimpleDateFormat("yyyy-MM", Locale.getDefault())
        val previousMonth = dateFormat.format(calendar.time)

        return previousMonth
    }

    */
    /**
     * 获取上周的礼拜 周数
     *//*
    fun getPreviousWeekDateRange(weekCount: Int): String {
        val calendar = Calendar.getInstance()
        calendar.firstDayOfWeek = Calendar.MONDAY

        val currentDate = calendar.time

        val startOfWeek = calendar.clone() as Calendar
        startOfWeek.add(Calendar.WEEK_OF_YEAR, -weekCount)
        startOfWeek.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY)

        val endOfWeek = calendar.clone() as Calendar
        endOfWeek.add(Calendar.WEEK_OF_YEAR, -weekCount)
        endOfWeek.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY)

        val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
        val startDate = dateFormat.format(startOfWeek.time)
        val endDate = dateFormat.format(endOfWeek.time)

        return startDate + "至$endDate"
    }*/

    private fun setTCChartData(data: BloodLipidDataBean) {
        setAvgInfo(data, BloodFatType.Tc)
        tcList = data.model
        tcListCompare = data.modelCompare
        tcBarValue.clear()
        tcBarValueCompare.clear()
        val rever = if (tcList.size < tcListCompare.size) {
            (tcListCompare.indices).reversed()
        } else {
            (tcList.indices).reversed()
        }
        if (type == 3) {
            var compare = tcListCompare.size - tcList.size
            if (compare > 0) {
                for (Int in 1..compare) {
                    tcList.add(
                        tcList.size,
                        BloodLipidDataBean.ModelBean(
                            0f,
                            0f,
                            0f,
                            0f,
                            tcListCompare[tcList.size].time
                        )
                    )
                }
            } else if (compare < 0) {
                compare = 0 - compare
                for (Int in 1..compare) {
                    tcListCompare.add(
                        tcListCompare.size,
                        BloodLipidDataBean.ModelBean(
                            0f,
                            0f,
                            0f,
                            0f,
                            tcList[tcListCompare.size].time
                        )
                    )
                }
            }
        }
        for (i in rever) {
            //中间两端在x轴显示尺度 其他情况下不显示
            when (type) {
                1 -> {
                    val listTipG = mutableListOf<String>()
                    listTipG.add(tcList[tcList.size - 1 - i].time)
                    listTipG.add("0")
                    listTipG.add(tcList[tcList.size - 1 - i].tc.toString())
                    listTipG.add(tcListCompare[tcListCompare.size - 1 - i].tc.toString())

                    if (tcList[tcList.size - 1 - i].tc == 0f) {
                        tcList[tcList.size - 1 - i].tc = Float.NaN
                    } else {
                        tcList[tcList.size - 1 - i].tc
                    }
                    tcBarValue.add(
                        BarEntry(
                            (tcList.size - 1 - i).toFloat(),
                            tcList[tcList.size - 1 - i].tc,
                            listTipG
                        )
                    )

                    if (tcListCompare[tcListCompare.size - 1 - i].tc == 0f)
                        tcListCompare[tcListCompare.size - 1 - i].tc = Float.NaN
                    else
                        tcListCompare[tcListCompare.size - 1 - i].tc

                    tcBarValueCompare.add(
                        BarEntry(
                            (tcListCompare.size - 1 - i).toFloat(),
                            tcListCompare[tcListCompare.size - 1 - i].tc,
                            listTipG
                        )
                    )

                }

                2 -> {
                    val listTipW = mutableListOf<String>()
                    listTipW.add(weeker[weeker.size - i - 1])
                    listTipW.add("0")
                    listTipW.add(tcList[tcList.size - 1 - i].tc.toString())
                    listTipW.add(tcListCompare[tcListCompare.size - 1 - i].tc.toString())
                    tcBarValue.add(
                        BarEntry(
                            (tcList.size - 1 - i).toFloat(),
                            tcList[tcList.size - 1 - i].tc,
                            listTipW

                        )
                    )
                    tcBarValueCompare.add(
                        BarEntry(
                            (tcListCompare.size - 1 - i).toFloat(),
                            tcListCompare[tcListCompare.size - 1 - i].tc,
                            listTipW
                        )
                    )
                }

                3 -> {
                    val listTipY = mutableListOf<String>()
                    listTipY.add(tcList[tcList.size - 1 - i].time)
                    listTipY.add("0")
                    listTipY.add(tcList[tcList.size - 1 - i].tc.toString())
                    listTipY.add(tcListCompare[tcListCompare.size - 1 - i].tc.toString())
                    tcBarValue.add(
                        BarEntry(
                            (tcList.size - 1 - i).toFloat(),
                            tcList[tcList.size - 1 - i].tc,
                            listTipY
                        )
                    )
                    tcBarValueCompare.add(
                        BarEntry(
                            (tcListCompare.size - 1 - i).toFloat(),
                            tcListCompare[tcListCompare.size - 1 - i].tc,
                            listTipY
                        )
                    )
                }

                else -> {
                    val listTipY = mutableListOf<String>()
                    listTipY.add(tcList[tcList.size - 1 - i].time)
                    listTipY.add("0")
                    listTipY.add(tcList[tcList.size - 1 - i].tc.toString())
                    listTipY.add(tcListCompare[tcListCompare.size - 1 - i].tc.toString())
                    tcBarValue.add(
                        BarEntry(
                            (tcList.size - 1 - i).toFloat(),
                            tcList[tcList.size - 1 - i].tc,
                            listTipY
                        )
                    )
                    tcBarValueCompare.add(
                        BarEntry(
                            (tcListCompare.size - 1 - i).toFloat(),
                            tcListCompare[tcListCompare.size - 1 - i].tc,
                            listTipY
                        )
                    )
                }
            }
        }
        binding.clTc.mBarChart.clear()

        val min = BloodLipidGetMinMaxChart.getBloodLipidMix(
            data.value.minTc,
            data.valueCompare.minTc
        )
        val max = BloodLipidGetMinMaxChart.getBloodLipidMax(
            data.value.maxTc,
            data.valueCompare.maxTc
        )

        BaseChartInitUtils.initBarChartTwo(
            requireContext(),
            binding.clTc.mBarChart,
            min,
            max,
            tcBarValue,
            tcBarValueCompare,
            ICompareMarkView.MarkPage.BloodFilip,
            "mmol/L",
            type,
            1f
        )
    }

    lateinit var tgList: MutableList<BloodLipidDataBean.ModelBean>
    private lateinit var tgListCompare: MutableList<BloodLipidDataBean.ModelBean>

    var tgBarValue = arrayListOf<BarEntry>()  //柱形数据
    var tgBarValueCompare = arrayListOf<BarEntry>()  //柱形数据
    private fun setTGChartData(data: BloodLipidDataBean) {
        setAvgInfo(data, BloodFatType.Tg)
        tgList = data.model
        tgListCompare = data.modelCompare
        tgBarValue.clear()
        tgBarValueCompare.clear()
        val rever = if (tgList.size < tgListCompare.size) {
            (tgListCompare.indices).reversed()
        } else {
            (tgList.indices).reversed()
        }
        if (type == 3) {
            var compare = tgListCompare.size - tgList.size
            if (compare > 0) {
                for (Int in 1..compare) {
                    tgList.add(
                        tgList.size,
                        BloodLipidDataBean.ModelBean(
                            0f,
                            0f,
                            0f,
                            0f,
                            tgListCompare[tgList.size].time
                        )
                    )
                }
            } else if (compare < 0) {
                compare = 0 - compare
                for (Int in 1..compare) {
                    tgListCompare.add(
                        tgListCompare.size,
                        BloodLipidDataBean.ModelBean(
                            0f,
                            0f,
                            0f,
                            0f,
                            tgList[tgListCompare.size].time
                        )
                    )
                }
            }
        }
        for (i in rever) {
            //中间两端在x轴显示尺度 其他情况下不显示
            when (type) {
                1 -> {
                    val listTipG = mutableListOf<String>()
                    listTipG.add(tgList[tgList.size - 1 - i].time)
                    listTipG.add("0")
                    listTipG.add(tgList[tgList.size - 1 - i].tg.toString())
                    listTipG.add(tgListCompare[tgListCompare.size - 1 - i].tg.toString())

                    if (tgList[tgList.size - 1 - i].tg == 0f) {
                        tgList[tgList.size - 1 - i].tg = Float.NaN
                    } else {
                        tgList[tgList.size - 1 - i].tg
                    }
                    tgBarValue.add(
                        BarEntry(
                            (tgList.size - 1 - i).toFloat(),
                            tgList[tgList.size - 1 - i].tg,
                            listTipG
                        )
                    )

                    if (tgListCompare[tgListCompare.size - 1 - i].tg == 0f)
                        tgListCompare[tgListCompare.size - 1 - i].tg = Float.NaN
                    else
                        tgListCompare[tgListCompare.size - 1 - i].tg

                    tgBarValueCompare.add(
                        BarEntry(
                            (tgListCompare.size - 1 - i).toFloat(),
                            tgListCompare[tgListCompare.size - 1 - i].tg,
                            listTipG
                        )
                    )

                }

                2 -> {
                    var listTipW = mutableListOf<String>()
                    listTipW.add(weeker[weeker.size - i - 1])
                    listTipW.add("0")
                    listTipW.add(tgList[tgList.size - 1 - i].tg.toString())
                    listTipW.add(tgListCompare[tgListCompare.size - 1 - i].tg.toString())
                    tgBarValue.add(
                        BarEntry(
                            (tgList.size - 1 - i).toFloat(),
                            tgList[tgList.size - 1 - i].tg,
                            listTipW

                        )
                    )
                    tgBarValueCompare.add(
                        BarEntry(
                            (tgListCompare.size - 1 - i).toFloat(),
                            tgListCompare[tgListCompare.size - 1 - i].tg,
                            listTipW
                        )
                    )
                }

                3 -> {

                    var listTipY = mutableListOf<String>()
                    listTipY.add(tgList[tgList.size - 1 - i].time)
                    listTipY.add("0")
                    listTipY.add(tgList[tgList.size - 1 - i].tg.toString())
                    listTipY.add(tgListCompare[tgListCompare.size - 1 - i].tg.toString())
                    tgBarValue.add(
                        BarEntry(
                            (tgList.size - 1 - i).toFloat(),
                            tgList[tgList.size - 1 - i].tg,
                            listTipY
                        )
                    )
                    tgBarValueCompare.add(
                        BarEntry(
                            (tgListCompare.size - 1 - i).toFloat(),
                            tgListCompare[tgListCompare.size - 1 - i].tg,
                            listTipY
                        )
                    )
                }

                else -> {
                    var listTipY = mutableListOf<String>()
                    listTipY.add(tgList[tgList.size - 1 - i].time)
                    listTipY.add("0")
                    listTipY.add(tgList[tgList.size - 1 - i].tg.toString())
                    listTipY.add(tgListCompare[tgListCompare.size - 1 - i].tg.toString())
                    tgBarValue.add(
                        BarEntry(
                            (tgList.size - 1 - i).toFloat(),
                            tgList[tgList.size - 1 - i].tg,
                            listTipY
                        )
                    )
                    tgBarValueCompare.add(
                        BarEntry(
                            (tgListCompare.size - 1 - i).toFloat(),
                            tgListCompare[tgListCompare.size - 1 - i].tg,
                            listTipY
                        )
                    )
                }
            }
        }
        binding.clTg.mBarChart.clear()

        val min =
            BloodLipidGetMinMaxChart.getBloodLipidMix(data.value.minTg, data.valueCompare.minTg)
        val max =
            BloodLipidGetMinMaxChart.getBloodLipidMax(data.value.maxTg, data.valueCompare.maxTg)

        BaseChartInitUtils.initBarChartTwo(
            requireContext(), binding.clTg.mBarChart, min, max, tgBarValue, tgBarValueCompare,
            ICompareMarkView.MarkPage.BloodFilip, "mmol/L", type, 1f
        )
    }

    lateinit var hdlList: MutableList<BloodLipidDataBean.ModelBean>
    private lateinit var hdlListCompare: MutableList<BloodLipidDataBean.ModelBean>

    var hdlBarValue = arrayListOf<BarEntry>()  //柱形数据
    var hdlBarValueCompare = arrayListOf<BarEntry>()  //柱形数据
    private fun setHDLChartData(data: BloodLipidDataBean) {
        setAvgInfo(data, BloodFatType.Hdl)
        hdlList = data.model
        hdlListCompare = data.modelCompare
        hdlBarValue.clear()
        hdlBarValueCompare.clear()
        var rever: IntProgression
        if (hdlList.size < hdlListCompare.size) {
            rever = (hdlListCompare.indices).reversed()
        } else {
            rever = (hdlList.indices).reversed()
        }
        if (type == 3) {
            var compare = hdlListCompare.size - hdlList.size
            if (compare > 0) {
                for (Int in 1..compare) {
                    hdlList.add(
                        hdlList.size,
                        BloodLipidDataBean.ModelBean(
                            0f,
                            0f,
                            0f,
                            0f,
                            hdlListCompare[hdlList.size].time
                        )
                    )
                }
            } else if (compare < 0) {
                compare = 0 - compare
                for (Int in 1..compare) {
                    hdlListCompare.add(
                        hdlListCompare.size,
                        BloodLipidDataBean.ModelBean(
                            0f,
                            0f,
                            0f,
                            0f,
                            hdlList[hdlListCompare.size].time
                        )
                    )
                }
            }
        }
        for (i in rever) {
            //中间两端在x轴显示尺度 其他情况下不显示
            if (type == 1) {
                var listTipG = mutableListOf<String>()
                listTipG.add(hdlList[hdlList.size - 1 - i].time)
                listTipG.add("0")
                listTipG.add(hdlList[hdlList.size - 1 - i].hdl.toString())
                listTipG.add(hdlListCompare[hdlListCompare.size - 1 - i].hdl.toString())

                if (hdlList[hdlList.size - 1 - i].hdl == 0f) {
                    hdlList[hdlList.size - 1 - i].hdl = Float.NaN
                } else {
                    hdlList[hdlList.size - 1 - i].hdl
                }
                hdlBarValue.add(
                    BarEntry(
                        (hdlList.size - 1 - i).toFloat(),
                        hdlList[hdlList.size - 1 - i].hdl,
                        listTipG
                    )
                )

                if (hdlListCompare[hdlListCompare.size - 1 - i].hdl == 0f)
                    hdlListCompare[hdlListCompare.size - 1 - i].hdl = Float.NaN
                else
                    hdlListCompare[hdlListCompare.size - 1 - i].hdl

                hdlBarValueCompare.add(
                    BarEntry(
                        (hdlListCompare.size - 1 - i).toFloat(),
                        hdlListCompare[hdlListCompare.size - 1 - i].hdl,
                        listTipG
                    )
                )

            } else if (type == 2) {
                var listTipW = mutableListOf<String>()
                listTipW.add(weeker[weeker.size - i - 1])
                listTipW.add("0")
                listTipW.add(hdlList[hdlList.size - 1 - i].hdl.toString())
                listTipW.add(hdlListCompare[hdlListCompare.size - 1 - i].hdl.toString())
                hdlBarValue.add(
                    BarEntry(
                        (hdlList.size - 1 - i).toFloat(),
                        hdlList[hdlList.size - 1 - i].hdl,
                        listTipW

                    )
                )
                hdlBarValueCompare.add(
                    BarEntry(
                        (hdlListCompare.size - 1 - i).toFloat(),
                        hdlListCompare[hdlListCompare.size - 1 - i].hdl,
                        listTipW
                    )
                )
            } else if (type == 3) {

                var listTipY = mutableListOf<String>()
                listTipY.add(hdlList[hdlList.size - 1 - i].time)
                listTipY.add("0")
                listTipY.add(hdlList[hdlList.size - 1 - i].hdl.toString())
                listTipY.add(hdlListCompare[hdlListCompare.size - 1 - i].hdl.toString())
                hdlBarValue.add(
                    BarEntry(
                        (hdlList.size - 1 - i).toFloat(),
                        hdlList[hdlList.size - 1 - i].hdl,
                        listTipY
                    )
                )
                hdlBarValueCompare.add(
                    BarEntry(
                        (hdlListCompare.size - 1 - i).toFloat(),
                        hdlListCompare[hdlListCompare.size - 1 - i].hdl,
                        listTipY
                    )
                )
            } else {
                var listTipY = mutableListOf<String>()
                listTipY.add(hdlList[hdlList.size - 1 - i].time)
                listTipY.add("0")
                listTipY.add(hdlList[hdlList.size - 1 - i].hdl.toString())
                listTipY.add(hdlListCompare[hdlListCompare.size - 1 - i].hdl.toString())
                hdlBarValue.add(
                    BarEntry(
                        (hdlList.size - 1 - i).toFloat(),
                        hdlList[hdlList.size - 1 - i].hdl,
                        listTipY
                    )
                )
                hdlBarValueCompare.add(
                    BarEntry(
                        (hdlListCompare.size - 1 - i).toFloat(),
                        hdlListCompare[hdlListCompare.size - 1 - i].hdl,
                        listTipY
                    )
                )
            }
        }
        binding.clHdl.mBarChart.clear()

        val min =
            BloodLipidGetMinMaxChart.getBloodLipidMix(data.value.minHdl, data.valueCompare.minHdl)
        val max =
            BloodLipidGetMinMaxChart.getBloodLipidMax(data.value.maxHdl, data.valueCompare.maxHdl)

        BaseChartInitUtils.initBarChartTwo(
            requireContext(), binding.clHdl.mBarChart, min, max, hdlBarValue, hdlBarValueCompare,
            ICompareMarkView.MarkPage.BloodFilip, "mmol/L", type, 1f
        )
    }

    lateinit var ldlList: MutableList<BloodLipidDataBean.ModelBean>
    private lateinit var ldlListCompare: MutableList<BloodLipidDataBean.ModelBean>

    var ldlBarValue = arrayListOf<BarEntry>()  //柱形数据
    var ldlBarValueCompare = arrayListOf<BarEntry>()  //柱形数据
    private fun setLDLChartData(data: BloodLipidDataBean) {
        setAvgInfo(data, BloodFatType.Ldl)
        ldlList = data.model
        ldlListCompare = data.modelCompare
        ldlBarValue.clear()
        ldlBarValueCompare.clear()
        var rever: IntProgression
        if (ldlList.size < ldlListCompare.size) {
            rever = (ldlListCompare.indices).reversed()
        } else {
            rever = (ldlList.indices).reversed()
        }
        if (type == 3) {
            var compare = ldlListCompare.size - ldlList.size
            if (compare > 0) {
                for (Int in 1..compare) {
                    ldlList.add(
                        ldlList.size,
                        BloodLipidDataBean.ModelBean(
                            0f,
                            0f,
                            0f,
                            0f,
                            ldlListCompare[ldlList.size].time
                        )
                    )
                }
            } else if (compare < 0) {
                compare = 0 - compare
                for (Int in 1..compare) {
                    ldlListCompare.add(
                        ldlListCompare.size,
                        BloodLipidDataBean.ModelBean(
                            0f,
                            0f,
                            0f,
                            0f,
                            ldlList[ldlListCompare.size].time
                        )
                    )
                }
            }
        }
        for (i in rever) {
            //中间两端在x轴显示尺度 其他情况下不显示
            if (type == 1) {
                var listTipG = mutableListOf<String>()
                listTipG.add(ldlList[ldlList.size - 1 - i].time)
                listTipG.add("0")
                listTipG.add(ldlList[ldlList.size - 1 - i].ldl.toString())
                listTipG.add(ldlListCompare[ldlListCompare.size - 1 - i].ldl.toString())

                if (ldlList[ldlList.size - 1 - i].ldl == 0f) {
                    ldlList[ldlList.size - 1 - i].ldl = Float.NaN
                } else {
                    ldlList[ldlList.size - 1 - i].ldl
                }
                ldlBarValue.add(
                    BarEntry(
                        (ldlList.size - 1 - i).toFloat(),
                        ldlList[ldlList.size - 1 - i].ldl,
                        listTipG
                    )
                )

                if (ldlListCompare[ldlListCompare.size - 1 - i].ldl == 0f)
                    ldlListCompare[ldlListCompare.size - 1 - i].ldl = Float.NaN
                else
                    ldlListCompare[ldlListCompare.size - 1 - i].ldl

                ldlBarValueCompare.add(
                    BarEntry(
                        (ldlListCompare.size - 1 - i).toFloat(),
                        ldlListCompare[ldlListCompare.size - 1 - i].ldl,
                        listTipG
                    )
                )

            } else if (type == 2) {
                var listTipW = mutableListOf<String>()
                listTipW.add(weeker[weeker.size - i - 1])
                listTipW.add("0")
                listTipW.add(ldlList[ldlList.size - 1 - i].ldl.toString())
                listTipW.add(ldlListCompare[ldlListCompare.size - 1 - i].ldl.toString())
                ldlBarValue.add(
                    BarEntry(
                        (ldlList.size - 1 - i).toFloat(),
                        ldlList[ldlList.size - 1 - i].ldl,
                        listTipW

                    )
                )
                ldlBarValueCompare.add(
                    BarEntry(
                        (ldlListCompare.size - 1 - i).toFloat(),
                        ldlListCompare[ldlListCompare.size - 1 - i].ldl,
                        listTipW
                    )
                )
            } else if (type == 3) {

                var listTipY = mutableListOf<String>()
                listTipY.add(ldlList[ldlList.size - 1 - i].time)
                listTipY.add("0")
                listTipY.add(ldlList[ldlList.size - 1 - i].ldl.toString())
                listTipY.add(ldlListCompare[ldlListCompare.size - 1 - i].ldl.toString())
                ldlBarValue.add(
                    BarEntry(
                        (ldlList.size - 1 - i).toFloat(),
                        ldlList[ldlList.size - 1 - i].ldl,
                        listTipY
                    )
                )
                ldlBarValueCompare.add(
                    BarEntry(
                        (ldlListCompare.size - 1 - i).toFloat(),
                        ldlListCompare[ldlListCompare.size - 1 - i].ldl,
                        listTipY
                    )
                )
            } else {
                var listTipY = mutableListOf<String>()
                listTipY.add(ldlList[ldlList.size - 1 - i].time)
                listTipY.add("0")
                listTipY.add(ldlList[ldlList.size - 1 - i].ldl.toString())
                listTipY.add(ldlListCompare[ldlListCompare.size - 1 - i].ldl.toString())
                ldlBarValue.add(
                    BarEntry(
                        (ldlList.size - 1 - i).toFloat(),
                        ldlList[ldlList.size - 1 - i].ldl,
                        listTipY
                    )
                )
                ldlBarValueCompare.add(
                    BarEntry(
                        (ldlListCompare.size - 1 - i).toFloat(),
                        ldlListCompare[ldlListCompare.size - 1 - i].ldl,
                        listTipY
                    )
                )
            }
        }
        binding.clLdl.mBarChart.clear()


        val min =
            BloodLipidGetMinMaxChart.getBloodLipidMix(data.value.minLdl, data.valueCompare.minLdl)

        val max =
            BloodLipidGetMinMaxChart.getBloodLipidMax(data.value.maxLdl, data.valueCompare.maxLdl)
        BaseChartInitUtils.initBarChartTwo(
            requireContext(), binding.clLdl.mBarChart, min, max, ldlBarValue, ldlBarValueCompare,
            ICompareMarkView.MarkPage.BloodFilip, "mmol/L", type, 1f
        )
    }

    @SuppressLint("SuspiciousIndentation")
    private fun setAvgInfo(valueData: BloodLipidDataBean, dataType: BloodFatType) {
        var list: MutableList<ValueMap> = mutableListOf()
        list = BloodLipidDataDealWithList.setDataList(
            valueData.value,
            valueData.valueCompare,
            binding.tvHideDate.text.toString(),
            binding.tvShowDate.text.toString(),
            type,
            dataType,
            list
        )
        when (dataType) {
            BloodFatType.Tc -> {
                tcAdapter.setNewInstance(list)
            }

            BloodFatType.Tg -> {
                tgAdapter.setNewInstance(list)
            }

            BloodFatType.Hdl -> {
                hdlAdapter.setNewInstance(list)

            }

            BloodFatType.Ldl -> {
                ldlAdapter.setNewInstance(list)
            }
        }
    }
    /*private fun calculateBarWidth(dataCount: Int): Float {
        val maximumBarWidth = 0.38f // 设置最大柱形图宽度
        val minimumBarWidth = 0.29f // 设置最小柱形图宽度

        val defaultBarWidth = 0.3f // 默认柱形图宽度
        val availableWidth = 1.0f - (dataCount - 1) * 0.1f // 可用宽度减去间距占用

        val calculatedBarWidth = availableWidth / dataCount.toFloat()
        return max(minimumBarWidth, min(maximumBarWidth, calculatedBarWidth))
    }

    private fun setChartData(count: Int, mChart: BarChart) {
        val m = Matrix()
        m.postScale(scaleNum(count), 1f) //两个参数分别是x,y轴的缩放比例。例如：将x轴的数据放大为之前的1.5倍
        mChart.viewPortHandler.refresh(m, mChart, false) //将图表动画显示之前进行缩放
    }*/

    //30个横坐标时，缩放4f是正好的。
    private val scalePercent = 4f / 30f

    private fun scaleNum(xCount: Int): Float {
        return xCount * scalePercent
    }


    fun initRecycle() {
        binding.clTc.mRecycle.layoutManager = LinearLayoutManager(requireContext())
        binding.clTc.mRecycle.adapter = tcAdapter

        binding.clTg.mRecycle.layoutManager = LinearLayoutManager(requireContext())
        binding.clTg.mRecycle.adapter = tgAdapter

        binding.clHdl.mRecycle.layoutManager = LinearLayoutManager(requireContext())
        binding.clHdl.mRecycle.adapter = hdlAdapter

        binding.clLdl.mRecycle.layoutManager = LinearLayoutManager(requireContext())
        binding.clLdl.mRecycle.adapter = ldlAdapter
    }

    fun initCharts() {
        binding.clTc.mBarChart.setNoDataText(getString(R.string.line_chart_not_data))
        binding.clTc.mBarChart.setNoDataTextColor(
            ContextCompat.getColor(
                requireContext(),
                R.color.col_455
            )
        )

        binding.clTg.mBarChart.setNoDataText(getString(R.string.line_chart_not_data))
        binding.clTg.mBarChart.setNoDataTextColor(
            ContextCompat.getColor(
                requireContext(),
                R.color.col_455
            )
        )

        binding.clHdl.mBarChart.setNoDataText(getString(R.string.line_chart_not_data))
        binding.clHdl.mBarChart.setNoDataTextColor(
            ContextCompat.getColor(
                requireContext(),
                R.color.col_455
            )
        )

        binding.clLdl.mBarChart.setNoDataText(getString(R.string.line_chart_not_data))
        binding.clLdl.mBarChart.setNoDataTextColor(
            ContextCompat.getColor(
                requireContext(),
                R.color.col_455
            )
        )
    }
}