package com.zj365.health.fragment.bloodlipid

import android.annotation.SuppressLint
import android.graphics.Color
import android.graphics.Typeface
import android.os.Build
import android.os.Bundle
import android.text.SpannableString
import android.text.Spanned
import android.text.TextUtils
import android.text.style.AbsoluteSizeSpan
import android.text.style.ForegroundColorSpan
import android.text.style.StyleSpan
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.text.isDigitsOnly
import com.bigkoo.pickerview.adapter.ArrayWheelAdapter
import com.blankj.utilcode.util.TimeUtils
import com.contrarywind.view.WheelView
import com.github.mikephil.charting.charts.BarChart
import com.github.mikephil.charting.charts.LineChart
import com.github.mikephil.charting.data.BarData
import com.github.mikephil.charting.data.BarDataSet
import com.github.mikephil.charting.data.BarEntry
import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.data.LineData
import com.github.mikephil.charting.data.LineDataSet
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.tamsiree.rxkit.RxConstTool
import com.tamsiree.rxkit.RxTimeTool
import com.xty.base.fragment.BaseVmFrag
import com.xty.base.utils.OrganStatusCalcUtil
import com.xty.common.Const
import com.xty.common.Dateutils
import com.xty.common.LogUtils
import com.xty.common.MMkvHelper
import com.xty.common.TimeSelect
import com.xty.common.arouter.ARouterUrl
import com.xty.common.arouter.RouteManager
import com.xty.common.event.BloodFilipOpenSuccessEvent
import com.xty.common.util.CommonToastUtils
import com.xty.common.util.SpannableUtils
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.act.HealthMainAct
import com.zj365.health.act.exception.BaseExceptionDataAct
import com.zj365.health.databinding.BloodFatChartBinding
import com.zj365.health.databinding.BloodFatViewBinding
import com.zj365.health.databinding.FragBooldFatBinding
import com.zj365.health.util.HealthDateAndTimeUtils
import com.zj365.health.vm.BloodFatVm
import com.zj365.health.weight.DialogTip
import com.zj365.health.weight.HealthDialog
import com.zj365.health.weight.IMarkView
import com.xty.network.model.*
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import java.lang.Float.max
import java.lang.Float.min
import java.text.SimpleDateFormat
import java.util.*

/**
 * 血脂
 */
class BloodFatFrag : BaseVmFrag<BloodFatVm>() {

    val binding by lazy { FragBooldFatBinding.inflate(layoutInflater) }
    override fun setLayout(): View = binding.root
    override fun setViewModel() = BloodFatVm()

    private var dayDate: String = ""
    private var isDemonstrate: Boolean = false  //新用户暂未绑定手表，显示相关演示数据
    var type = 1 //查询的时间类型 1 日 2 周 3 月 4 年
    val fomartStr by lazy { arrayOf("HH:mm", "HH:mm", "MM-dd", "MM-dd", "yy-MM") }
    private val weekStr by lazy { resources.getStringArray(R.array.week_day) }
    val dialogBind by lazy {
        DialogTip(requireContext(), "需绑定安瑜健康手表，才能查看", "去绑定") {
            RouteManager.goAct(ARouterUrl.DEVICE_CHOICE)
        }
    }
    private val icons = arrayOf(
        R.mipmap.shuzhuangtu,
        R.mipmap.ic_shuzhuangtu_yixuan,
        R.mipmap.ic_zhexiant,
        R.mipmap.zhexiant_yixuan
    )

    val timeSelect by lazy {
        TimeSelect(requireContext()) {
            type = 1
            dayDate = binding.tvShowDate.text.toString()
            mViewModel.getBloodFatInfo(type, binding.tvShowDate.text.toString(), id, isDemonstrate)
//            mViewModel.getBloodFatInfo(type, binding.tvShowDate.text.toString(), id, isDemonstrate)
        }
    }

    val timeMonthSelect by lazy {
        TimeSelect(requireContext()) {
            type = 3
            mouthDate = binding.tvShowDate.text.toString()
            mViewModel.getBloodFatInfo(type, binding.tvShowDate.text.toString(), id, isDemonstrate)
        }
    }

    private var expireTimeStr: String = ""


    val timeYearSelect by lazy {
        TimeSelect(requireContext()) {
            type = 4
            yearDate = binding.tvShowDate.text.toString()
            mViewModel.getBloodFatInfo(type, binding.tvShowDate.text.toString(), id, isDemonstrate)
        }
    }

    private var tips = ""
    val tipDialog by lazy {
        HealthDialog(requireContext(), true, tips) {
        }
    }

    var id = ""

    /*    //血脂4个圈相关控件和适配器
        val bloodFatAdapter by lazy { BloodFatAdapter() }*/
    private var tcExceptionData = ArrayList<String>()
    private var tgExceptionData = ArrayList<String>()
    private var hdlExceptionData = ArrayList<String>()
    private var ldlExceptionData = ArrayList<String>()

    private var tcExceptionTime = ArrayList<String>()
    private var tgExceptionTime = ArrayList<String>()
    private var hdlExceptionTime = ArrayList<String>()
    private var ldlExceptionTime = ArrayList<String>()

    private var bloodFatStatus = 0 //血脂开通状态 0 未开通 1 建模中 2 已开通

    override fun initData() {
        super.initData()
        id = arguments?.getString("id").toString()
        if (id == "0" || id.isNullOrEmpty() || id == "null") {
            id = if (MMkvHelper.getLong(Const.USER_ID).toString() == "0") {
                ""
            } else {
                MMkvHelper.getLong(Const.USER_ID).toString()
            }
        }
    }

    @SuppressLint("SetTextI18n")
    override fun initView() {
        super.initView()
        binding.tgLayout.tvBloodValue.text = "甘油三酯 (TG)"
        binding.hdlLayout.tvBloodValue.text = "高密度脂蛋白(HDL)"
        binding.ldlLayout.tvBloodValue.text = "低密度脂蛋白(LDL)"

        binding.tgLayout.mDesc.text = "正常范围：0.45-1.69mmol/L"
        binding.hdlLayout.mDesc.text = "正常范围：0.93-1.93mmol/L"
        binding.ldlLayout.mDesc.text = "正常范围：0-3.12mmol/L"

        binding.clCurTg.tvBloodName.text = "甘油三酯 (TG)"
        binding.clCurHdl.tvBloodName.text = "高密度脂蛋白(HDL)"
        binding.clCurLdl.tvBloodName.text = "低密度脂蛋白(LDL)"
        binding.clCurHdl.mOrganView.tvSecondName.text = "偏低"

        initTab()
        initTimeSelect()
        isDemonstrate = (requireActivity() as HealthMainAct).isDemonstrate

        binding.compareTv.setOnClickListener {
            if (isDemonstrate) {
                (requireActivity() as HealthMainAct).dialogBind.show()
                return@setOnClickListener
            }
            bundle.clear()
            bundle.putString("id", id)
            bundle.putString("type", "9")//1 心率
            RouteManager.goAct(ARouterUrl.COMPARE_DATA_ACT, bundle)
        }

        binding.tvRenew.setOnClickListener {
            bundle.clear()
            bundle.putString("expireTime", expireTimeStr)
            bundle.putString("userId", id)
            bundle.putInt("pageType", 3)
            RouteManager.goAct(ARouterUrl.OPEN_OR_RENEW, bundle)
        }

        setKindLayoutClickListener(binding.tcLayout)
        setKindLayoutClickListener(binding.tgLayout)
        setKindLayoutClickListener(binding.hdlLayout)
        setKindLayoutClickListener(binding.ldlLayout)

        setAbnormalLayoutClickListener(binding.clCurTc.mOrganView, 0)
        setAbnormalLayoutClickListener(binding.clCurTg.mOrganView, 1)

        setAbnormalLayoutClickListener(binding.clCurHdl.mOrganView, 2)

        setAbnormalLayoutClickListener(binding.clCurLdl.mOrganView, 3)


        binding.tvOpen.setOnClickListener {
            bundle.clear()
            bundle.putString("expireTime", expireTimeStr)
            bundle.putString("userId", id)
            bundle.putInt("pageType", 3)
            RouteManager.goAct(ARouterUrl.OPEN_OR_RENEW, bundle)
        }

        binding.tcLayout.mTip.setOnClickListener {
            tips = "胆固醇(TC)可作为动脉粥样硬化。冠心病等疾病的患病风险评估指标依据。"
            tipDialog.setContent(tips)
            tipDialog.show()
        }
        binding.tgLayout.mTip.setOnClickListener {
            tips = "甘油三酯(TG)可作为冠心病、脑血栓、胰腺炎等疾病的风险评估指标依据。"
            tipDialog.setContent(tips)
            tipDialog.show()
        }
        binding.hdlLayout.mTip.setOnClickListener {
            tips = "高密度脂蛋白胆固醇（HDL-C）水平降低是公认的主要心" +
                    "血管危险因素之一，是评估未来粥样硬化心血管疾病风险的重要指标依据。"
            tipDialog.setContent(tips)
            tipDialog.show()
        }
        binding.ldlLayout.mTip.setOnClickListener {
            tips = "低密度脂蛋白胆固醇(LDL-C)是公认的动脉粥样硬化致病性危险因素，同" +
                    "时也是防治此类解绑的主要降脂靶点，LDL-C水平是否达标是动脉粥样硬化性心血管解绑防治的关键环节。"
            tipDialog.setContent(tips)
            tipDialog.show()
        }

        binding.tvBloodLipidAdjust.setOnClickListener {
            if (bloodFatStatus == 1) {
                tips = "1、建模期间，累计有效佩戴满72小时；\n" +
                        "2、建模完成后，每天18:00至第二天6:00期间，佩戴时长累计满6小时，APP出具血脂值；\n" +
                        "3、血脂值每天7：00出值。本次值为前一天18:00到当天早上6:00血脂平均值。"
                tipDialog.setContent(tips)
                tipDialog.show()
            } else {
                RouteManager.goAct(ARouterUrl.BL_ADJUST)
            }
        }
        if (isDemonstrate) {
            setDemostrateInfo()
        } else {
            mViewModel.getBloodFatHead(id)

        }
        mViewModel.getBloodFatInfo(type, binding.tvShowDate.text.toString(), id, isDemonstrate)
    }

    private fun setKindLayoutClickListener(view: BloodFatChartBinding) {
        view.mLineChart.setNoDataText(getString(R.string.line_chart_not_data))
        view.mLineChart.setNoDataTextColor(
            ContextCompat.getColor(
                requireContext(),
                R.color.col_455
            )
        )
        view.mBarChart.setNoDataText(getString(R.string.line_chart_not_data))
        view.mBarChart.setNoDataTextColor(
            ContextCompat.getColor(
                requireContext(),
                R.color.col_455
            )
        )

        view.zhexianTv.setOnClickListener {
            view.mLineChart.visibility = View.VISIBLE
            view.mBarChart.visibility = View.GONE
            view.zhuzhuanTv.setImageResource(icons[0])
            view.zhexianTv.setImageResource(icons[3])
        }
        view.zhuzhuanTv.setOnClickListener {
            view.mLineChart.visibility = View.GONE
            view.mBarChart.visibility = View.VISIBLE
            view.zhuzhuanTv.setImageResource(icons[1])
            view.zhexianTv.setImageResource(icons[2])
        }
    }

    private fun setAbnormalLayoutClickListener(view: BloodFatViewBinding, chartType: Int) {
        view.ivSecond.setOnClickListener {
            if (isDemonstrate) {
                (requireActivity() as HealthMainAct).dialogBind.show()
                return@setOnClickListener
            } else {
                when (chartType) {
                    0 -> {
                        bundle.clear()
                        bundle.putString(BaseExceptionDataAct.exceptionKey, "总胆固醇偏高")
                        bundle.putStringArrayList(
                            BaseExceptionDataAct.exceptionList,
                            tcExceptionData
                        )
                        bundle.putStringArrayList(
                            BaseExceptionDataAct.exceptionListTime,
                            tcExceptionTime
                        )
                        moveToErrorShow(bundle)
                    }

                    1 -> {
                        bundle.clear()
                        bundle.putString(BaseExceptionDataAct.exceptionKey, "甘油三酯偏高")
                        bundle.putStringArrayList(
                            BaseExceptionDataAct.exceptionList,
                            tgExceptionData
                        )
                        bundle.putStringArrayList(
                            BaseExceptionDataAct.exceptionListTime,
                            tgExceptionTime
                        )
                        moveToErrorShow(bundle)
                    }

                    2 -> {
                        bundle.clear()
                        bundle.putString(BaseExceptionDataAct.exceptionKey, "高密度脂蛋白偏低")
                        bundle.putStringArrayList(
                            BaseExceptionDataAct.exceptionList,
                            hdlExceptionData
                        )
                        bundle.putStringArrayList(
                            BaseExceptionDataAct.exceptionListTime,
                            hdlExceptionTime
                        )
                        moveToErrorShow(bundle)
                    }

                    else -> {
                        bundle.clear()
                        bundle.putString(BaseExceptionDataAct.exceptionKey, "低密度脂蛋白偏高")
                        bundle.putStringArrayList(
                            BaseExceptionDataAct.exceptionList,
                            ldlExceptionData
                        )
                        bundle.putStringArrayList(
                            BaseExceptionDataAct.exceptionListTime,
                            ldlExceptionTime
                        )
                        moveToErrorShow(bundle)
                    }
                }
            }
        }
    }

    private fun moveToErrorShow(bundle: Bundle) {
        RouteManager.goAct(ARouterUrl.BL_FAT_EXCEPTION_DATA, bundle)
    }

    @SuppressLint("SetTextI18n", "SimpleDateFormat")
    override fun observer() {
        mViewModel.bloodFatHeadInfo.observe(this) {
            expireTimeStr = it.data.expireTime
            bloodFatStatus = it.data.status
            if (!TextUtils.isEmpty(expireTimeStr)) {
                binding.tvEndTime.text = "到期时间：${expireTimeStr}"
            } else {
                binding.tvEndTime.text = ""
            }
            when (it.data.status) {
                0 -> { //没有开通
                    setNoOpenBloodLipid(0, it.data.data)
                }

                1 -> { //建模中
                    setNoOpenBloodLipid(1, it.data.data)
                }

                else -> {
                    binding.clCurTc.tvBloodValue.text = "${it.data.data.tc}"

                    binding.clCurTg.tvBloodValue.text = "${it.data.data.tg}"

                    binding.clCurHdl.tvBloodValue.text = "${it.data.data.hdl}"

                    binding.clCurLdl.tvBloodValue.text = "${it.data.data.ldl}"

                    if (id == MMkvHelper.getLong(Const.USER_ID).toString()) {
                        binding.tvBloodLipidAdjust.visibility = View.VISIBLE
                    } else {
                        binding.tvBloodLipidAdjust.visibility = View.GONE
                    }

                    val expireDay = RxTimeTool.getIntervalByNow(
                        expireTimeStr,
                        RxConstTool.TimeUnit.DAY,
                        SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                    ) + 1
                    LogUtils.d("过期时间还剩：$expireDay 天；有效期截至：$expireTimeStr")
                    if (expireDay > 30) {
                        binding.tvRenew.visibility = View.GONE
                    } else if (it.data.status == 2) {
                        binding.tvRenew.visibility = View.VISIBLE
                    }

                    val format = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                    val calendar = Calendar.getInstance()
                    calendar.time = format.parse(it.data.data.time!!)!!
                    val myFormat = SimpleDateFormat("HH:mm")

                    binding.clCurTc.tvTestTime.text = "mmol/L ${myFormat.format(calendar.time)}"
                    binding.clCurTg.tvTestTime.text = "mmol/L ${myFormat.format(calendar.time)}"
                    binding.clCurHdl.tvTestTime.text = "mmol/L ${myFormat.format(calendar.time)}"
                    binding.clCurLdl.tvTestTime.text = "mmol/L ${myFormat.format(calendar.time)}"
                }
            }
        }

        mViewModel.dataLive.observe(this) {
            if (it == null || it[type] == null) {
                return@observe
            }

            // 这里把日的原始数据暂存起来，跳转异常页面时使用
            val daysModelList: MutableList<BloodFatBean.Model> = it[type]!!.model
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                when (type) {
                    1 -> {//日
                        it[type]!!.tcTempData = it[type]!!.mapDataToTime(it[type]!!.tcModel)
                        it[type]!!.tgTempData = it[type]!!.mapDataToTime(it[type]!!.tgModel)
                        it[type]!!.hdlTempData = it[type]!!.mapDataToTime(it[type]!!.hdlModel)
                        it[type]!!.ldlempData = it[type]!!.mapDataToTime(it[type]!!.ldlModel)
                    }

                    2 -> {//周
                        val split = binding.tvShowDate.text.toString().split("至")
                        val start = split[0]
                        val end = split[1]
                        it[type]!!.tcTempData =
                            it[type]!!.fillMissingData(it[type]!!.tcModel, start, end)
                        it[type]!!.tgTempData =
                            it[type]!!.fillMissingData(it[type]!!.tgModel, start, end)
                        it[type]!!.hdlTempData =
                            it[type]!!.fillMissingData(it[type]!!.hdlModel, start, end)
                        it[type]!!.ldlempData =
                            it[type]!!.fillMissingData(it[type]!!.ldlModel, start, end)
                    }

                    3 -> {//月
                        it[type]!!.tcTempData = it[type]!!.fillMissingData(
                            it[type]!!.tcModel,
                            binding.tvShowDate.text.toString()
                        )

                        it[type]!!.tgTempData = it[type]!!.fillMissingData(
                            it[type]!!.tgModel,
                            binding.tvShowDate.text.toString()
                        )

                        it[type]!!.hdlTempData = it[type]!!.fillMissingData(
                            it[type]!!.hdlModel,
                            binding.tvShowDate.text.toString()
                        )

                        it[type]!!.ldlempData = it[type]!!.fillMissingData(
                            it[type]!!.ldlModel,
                            binding.tvShowDate.text.toString()
                        )
                    }

                    4 -> {//年
                        it[type]!!.tcTempData = it[type]!!.fillMissingData(it[type]!!.tcModel)
                        it[type]!!.tgTempData = it[type]!!.fillMissingData(it[type]!!.tgModel)
                        it[type]!!.hdlTempData = it[type]!!.fillMissingData(it[type]!!.hdlModel)
                        it[type]!!.ldlempData = it[type]!!.fillMissingData(it[type]!!.ldlModel)
                    }
                }
            }
            setValuss(daysModelList, it[type])
            setValuss(daysModelList, it[type], 1)
            setValuss(daysModelList, it[type], 2)
            setValuss(daysModelList, it[type], 3)
        }
    }

    //设置数据
    private fun setValuss(
        daysModelList: MutableList<BloodFatBean.Model>,
        bean: BloodFatBean?,
        chartType: Int = 0
    ) {
        if (bean == null) {
            return
        }

        val lineValue = arrayListOf<Entry>()  //曲线数据
        val barValue = arrayListOf<BarEntry>()  //柱状数据
//        setAvgInfo(bean.value)
        val list = when (chartType) {
            0 -> {
                bean.tcTempData
            }

            1 -> {
                bean.tgTempData
            }

            2 -> {
                bean.hdlTempData
            }

            else -> {
                bean.ldlempData
            }
        }
        lineValue.clear()
        barValue.clear()

        if (selectDay()) {//如果是当天才操作
            when (chartType) {
                0 -> {
                    tcNormalTime = 0
                    tcAbNormalTime = 0
                    tcExceptionTime.clear()
                    tcExceptionData.clear()
                }

                1 -> {
                    tgNormalTime = 0
                    tgAbNormalTime = 0
                    tgExceptionData.clear()
                    tgExceptionTime.clear()
                }

                2 -> {
                    hdlNormalTime = 0
                    hdlAbNormalTime = 0
                    hdlExceptionTime.clear()
                    hdlExceptionData.clear()
                }

                else -> {
                    ldlNormalTime = 0
                    ldlAbNormalTime = 0
                    ldlExceptionTime.clear()
                    ldlExceptionData.clear()
                }
            }
        }

        for (t in daysModelList.indices) {
            if (selectDay()) {//如果是当天才操作
                getOrganStatu(daysModelList[daysModelList.size - t - 1], chartType)
            }
        }

        if (selectDay()) {
            setOrganStatus(chartType)
        }

        when (chartType) {
            0 -> {
                binding.tcLayout.mLineChart.clear()
                binding.tcLayout.mBarChart.clear()
            }

            1 -> {
                binding.tgLayout.mLineChart.clear()
                binding.tgLayout.mBarChart.clear()
            }

            2 -> {
                binding.hdlLayout.mLineChart.clear()
                binding.hdlLayout.mBarChart.clear()
            }

            else -> {
                binding.ldlLayout.mLineChart.clear()
                binding.ldlLayout.mBarChart.clear()
            }
        }

        if (list.isNullOrEmpty()) {
            return
        }

        for ((index, modelCompare) in list.withIndex()) {
            modelCompare.index = index
//                modelCompare.uaValue = if (modelCompare.uaValue > 0f) {
//                    modelCompare.uaValue
//                } else {
//                    Float.NaN
//                }
        }

        for (i in list.indices) {
            //中间两端在x轴显示尺度 其他情况下不显示
            lineValue.add(
                Entry(
                    i.toFloat(),
                    list[i].uaValue,
                    group(list[i])
                )
            )
            barValue.add(
                BarEntry(
                    i.toFloat(),
                    list[i].uaValue,
                    group(list[i])
                )
            )
        }

        when (chartType) {
            0 -> {
//                binding.tcLayout.mLineChart.clear()
//                binding.tcLayout.mBarChart.clear()
                initChart(
                    list,
                    bean.value.minTc,
                    bean.value.maxTc,
                    chartType,
                    lineValue,
                    barValue
                )
            }

            1 -> {
//                binding.tgLayout.mLineChart.clear()
//                binding.tgLayout.mBarChart.clear()
                initChart(
                    list,
                    bean.value.minTg,
                    bean.value.maxTg,
                    chartType,
                    lineValue,
                    barValue
                )
            }

            2 -> {
//                binding.hdlLayout.mLineChart.clear()
//                binding.hdlLayout.mBarChart.clear()
                initChart(
                    list,
                    bean.value.minHdl,
                    bean.value.maxHdl,
                    chartType,
                    lineValue,
                    barValue
                )
            }

            else -> {
//                binding.ldlLayout.mLineChart.clear()
//                binding.ldlLayout.mBarChart.clear()
                initChart(
                    list,
                    bean.value.minLdl,
                    bean.value.maxLdl,
                    chartType,
                    lineValue,
                    barValue
                )
            }
        }
    }

    private fun setSpan(time: Int): SpannableString {
        val statuSpan = SpannableString("${time}次")

        statuSpan.setSpan(
            ForegroundColorSpan(
                //设置字体颜色
                ContextCompat.getColor(
                    requireContext(), R.color.black
                )
            ), 0, statuSpan.length - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        )
        //设置字体大小(绝对值,单位：像素),第二个参数boolean dip，如果为true，表示前面的字体大小单位为dip，否则为像素
        statuSpan.setSpan(
            AbsoluteSizeSpan(24, true),
            0, statuSpan.length - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        )
        //设置字体样式: NORMAL正常，BOLD粗体，ITALIC斜体，BOLD_ITALIC粗斜体
        statuSpan.setSpan(
            StyleSpan(Typeface.BOLD),
            0, statuSpan.length - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        )
        return statuSpan
    }

    private fun group(
        bean: BloodFatBean.ModelCompare
    ): String {
        when (type) {
            1 -> {
//                if (bean.uaValue == 0f) {
//                    bean.uaValue = Float.NaN
//                }
                return bean.time
            }

            3 -> {
                /* if (bean.uaValue == 0f) {
                     bean.uaValue = Float.NaN
                 }*/
                return bean.formatTime
            }

            2 -> {
                val parts = bean.formatTime.split("-")
                val year = parts[0]
                val month = parts[1]
                val day = parts[2]

                return "$month-$day"
            }

            else -> {
                return "${bean.time}月"
            }
        }
    }

    private fun selectDay(): Boolean {
        return type < 2
    }

    private var tcNormalTime: Int = 0
    private var tcAbNormalTime: Int = 0

    private var tgNormalTime: Int = 0
    private var tgAbNormalTime: Int = 0

    private var hdlNormalTime: Int = 0
    private var hdlAbNormalTime: Int = 0

    private var ldlNormalTime: Int = 0
    private var ldlAbNormalTime: Int = 0

    fun getOrganStatu(data: BloodFatBean.Model, chartType: Int) {
        when (chartType) {
            0 -> {
                when (OrganStatusCalcUtil.tcStatus(data.tc)) {
                    1 -> {
                        tcAbNormalTime++
                        tcExceptionData.add(data.tc.toString())
                        tcExceptionTime.add(data.time)
                    }

                    else -> {
                        tcNormalTime++
                    }
                }
            }

            1 -> {
                when (OrganStatusCalcUtil.tgStatus(data.tg)) {
                    1 -> {
                        tgAbNormalTime++
                        tgExceptionData.add(data.tg.toString())
                        tgExceptionTime.add(data.time)
                    }

                    else -> {
                        tgNormalTime++
                    }
                }
            }

            2 -> {
                when (OrganStatusCalcUtil.hdlStatus(data.hdl)) {
                    1 -> {
                        hdlAbNormalTime++
                        hdlExceptionData.add(data.hdl.toString())
                        hdlExceptionTime.add(data.time)
                    }

                    else -> {
                        hdlNormalTime++
                    }
                }
            }

            else -> {
                when (OrganStatusCalcUtil.ldlStatus(data.ldl)) {
                    1 -> {
                        ldlAbNormalTime++
                        ldlExceptionData.add(data.ldl.toString())
                        ldlExceptionTime.add(data.time)
                    }

                    else -> {
                        ldlNormalTime++
                    }
                }
            }
        }
    }

    /**
     * 周数据
     */
    private fun getWeeks(time: Long): String {
        val calendear = Calendar.getInstance()
        val strData = RxTimeTool.milliseconds2String(time, SimpleDateFormat("yyyy-MM-dd"))
        val times = strData.split("-")
        calendear.set(times[0].toInt(), times[1].toInt() - 1, times[2].toInt())
        val intWeek = calendear.get(Calendar.DAY_OF_WEEK)
        return weekStr[intWeek - 1]
    }

    /**
     * 初始化 曲线
     */
    private fun initChart(
        list: MutableList<BloodFatBean.ModelCompare>,
        min: Float,
        max: Float,
        chartType: Int = 0,
        lineValue: ArrayList<Entry>,
        barValue: ArrayList<BarEntry>
    ) {
        val lineChart: LineChart
        val barChart: BarChart
        val mark: IMarkView.MarkPage

        when (chartType) {
            0 -> {
                lineChart = binding.tcLayout.mLineChart
                barChart = binding.tcLayout.mBarChart
                mark = IMarkView.MarkPage.Tc
            }

            1 -> {
                lineChart = binding.tgLayout.mLineChart
                barChart = binding.tgLayout.mBarChart
                mark = IMarkView.MarkPage.Tg
            }

            2 -> {
                lineChart = binding.hdlLayout.mLineChart
                barChart = binding.hdlLayout.mBarChart
                mark = IMarkView.MarkPage.Hdl
            }

            3 -> {
                lineChart = binding.ldlLayout.mLineChart
                barChart = binding.ldlLayout.mBarChart
                mark = IMarkView.MarkPage.Ldl
            }

            else -> {
                lineChart = binding.tcLayout.mLineChart
                barChart = binding.tcLayout.mBarChart
                mark = IMarkView.MarkPage.Tc
            }
        }

        BaseChartInitUtils.initLineChart(
            requireContext(),
            lineChart,
            min,
            max,
            lineValue,
            mark,
            "mmol/L",
            1f
        )

        val barsetsNew = ArrayList<ILineDataSet>()
        val segments = splitDataIntoSegments(list)
//        if (segments.size > 0) {
//            segments = checkData(segments)
//        }

        val dataSets = segments.mapNotNull { segment ->
            if (segment.isEmpty()) return@mapNotNull null

            val entries = segment.mapIndexed { index, model ->
                Entry(
                    model.index.toFloat(),
                    model.uaValue,
                    lineValue[model.index].data
                )
            }
            return@mapNotNull setData(entries, chartType)
        }

        if (!lineValue.isNullOrEmpty()) {
            barsetsNew.addAll(dataSets)
            val bard = LineData(barsetsNew)
            lineChart.data = bard
            lineChart.invalidate()
            loop@ for (i in 0 until lineValue.size) {
                if (lineValue[i].y != 0f) {
                    lineChart.moveViewToX(lineValue[i].x)
                    break@loop
                }
            }
        }

        BaseChartInitUtils.initBarChart(
            requireContext(),
            barChart,
            min,
            max,
            barValue,
            mark,
            type,
            "mmol/L",
            1f
        )

        if (barValue.isEmpty()) {
            return
        }

        loop@ for (i in 0 until barValue.size) {
            if (barValue[i].y != 0f) {
                barChart.moveViewToX(barValue[i].x)
                break@loop
            }
        }

        val dataBarSets = segments.mapNotNull { segment ->
            if (segment.isEmpty()) return@mapNotNull null

            val entries = segment.mapIndexed { index, model ->
                BarEntry(
                    model.index.toFloat(),
                    model.uaValue,
                    barValue[model.index].data
                )
            }
            return@mapNotNull setBarData(entries, chartType)
        }

        val bard = BarData(dataBarSets)
        if (type == 1) {
            bard.barWidth = calculateBarWidth(bard.dataSetCount) / 4
        } else {
            bard.barWidth = calculateBarWidth(bard.dataSetCount)
        }
        barChart.data = bard
        barChart.invalidate()
    }

    private fun setBarData(entries: List<BarEntry>, chartType: Int = 0): BarDataSet {
        val set1: BarDataSet

        val barChart = when (chartType) {
            0 -> {
                binding.tcLayout.mBarChart
            }

            1 -> {
                binding.tgLayout.mBarChart
            }

            2 -> {
                binding.hdlLayout.mBarChart
            }

            3 -> {
                binding.ldlLayout.mBarChart
            }

            else -> {
                binding.tcLayout.mBarChart
            }
        }

        if (barChart.data != null && barChart.data.dataSetCount > 0) {
            set1 = barChart.data.getDataSetByIndex(1) as BarDataSet
            set1.entries = entries
            barChart.data.notifyDataChanged()
            barChart.notifyDataSetChanged()
        } else {
            set1 = BarDataSet(entries, "DataSet 2")
            set1.setDrawValues(false) // 不显示值
            set1.valueTextColor = ContextCompat.getColor(requireContext(), R.color.col_9BDd)
            set1.highLightColor =
                ContextCompat.getColor(requireContext(), R.color.col_EFF)  //设置点后高亮颜色
            set1.color = ContextCompat.getColor(requireContext(), R.color.col_9BDd) //xian de yanse
            val data = BarData(set1)
            data.setValueTextSize(9f)
            data.setDrawValues(false)
        }
        return set1
    }

    private fun calculateBarWidth(dataCount: Int): Float {
        val maximumBarWidth = 0.3f // 设置最大柱形图宽度
        val minimumBarWidth = 0.3f // 设置最小柱形图宽度

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

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

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

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

        // 将最后一个线段添加到结果中
        if (currentSegment.isNotEmpty()) {
            segments.add(currentSegment)
        }

        return segments
    }

    private fun checkData(
        segmentsCompare: MutableList<MutableList<BloodFatBean.ModelCompare>>
    ): MutableList<MutableList<BloodFatBean.ModelCompare>> {
        when (type) {
            1 -> {
                if (segmentsCompare[0][0].time != "05:00") {
                    val d = mutableListOf<BloodFatBean.ModelCompare>()
                    val b = BloodFatBean.ModelCompare(0f, "05:00")
                    d.add(b)
                    segmentsCompare.add(d)
                }
                if (!TimeUtils.isToday(
                        binding.tvShowDate.text.toString(),
                        SimpleDateFormat("yyyy-MM-dd")
                    ) &&
                    segmentsCompare[segmentsCompare.size - 1]
                        [segmentsCompare[segmentsCompare.size - 1].size - 1].time != "09:00"
                ) {
                    val d = mutableListOf<BloodFatBean.ModelCompare>()
                    val b = BloodFatBean.ModelCompare(0f, "09:00")
                    d.add(b)
                    segmentsCompare.add(d)
                }
            }

            2 -> {
                val split = binding.tvShowDate.text.toString().split("至")
                val start = split[0]
                val end = split[1]

                if (segmentsCompare[0][0].formatTime != start) {
                    val d = mutableListOf<BloodFatBean.ModelCompare>()
                    val b = BloodFatBean.ModelCompare(0f, start)
                    d.add(b)
                    segmentsCompare.add(d)
                }
                if (segmentsCompare[segmentsCompare.size - 1][segmentsCompare[segmentsCompare.size - 1].size - 1].formatTime != end) {
                    val d = mutableListOf<BloodFatBean.ModelCompare>()
                    val b = BloodFatBean.ModelCompare(0f, end)
                    d.add(b)
                    segmentsCompare.add(d)
                }
            }

            3 -> {
                val split = binding.tvShowDate.text.toString().split("-")
                val year = split[0]//2023
                val month = split[1]//08

                val calendar = Calendar.getInstance()
                calendar.set(Calendar.YEAR, year.toInt())
                calendar.set(Calendar.MONTH, month.toInt() - 1) // Calendar.MONTH is 0-based
                val daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH)

                if (segmentsCompare[0][0].formatTime != "$month-01") {
                    val d = mutableListOf<BloodFatBean.ModelCompare>()
                    val b = BloodFatBean.ModelCompare(0f, "$month-01")
                    d.add(b)
                    segmentsCompare.add(d)
                }
                if (!HealthDateAndTimeUtils.isCurYearMonth(
                        binding.tvShowDate.text.toString(),
                        SimpleDateFormat("yyyy-MM")
                    ) &&
                    segmentsCompare[segmentsCompare.size - 1][segmentsCompare[segmentsCompare.size - 1].size - 1].time != "$month-$daysInMonth"
                ) {
                    val d = mutableListOf<BloodFatBean.ModelCompare>()
                    val b = BloodFatBean.ModelCompare(0f, "$month-$daysInMonth")
                    d.add(b)
                    segmentsCompare.add(d)
                }
            }

            4 -> {
                if (segmentsCompare[0][0].time != "01") {
                    val d = mutableListOf<BloodFatBean.ModelCompare>()
                    val b = BloodFatBean.ModelCompare(0f, "01")
                    d.add(b)
                    segmentsCompare.add(d)
                }
                if (segmentsCompare[segmentsCompare.size - 1][segmentsCompare[segmentsCompare.size - 1].size - 1].time != "12") {
                    val d = mutableListOf<BloodFatBean.ModelCompare>()
                    val b = BloodFatBean.ModelCompare(0f, "12")
                    d.add(b)
                    segmentsCompare.add(d)
                }
            }
        }
        return segmentsCompare
    }


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

            2 -> {
                val split = binding.tvShowDate.text.toString().split("至")
                val rangeStart = split[0]
                val rangeEnd = split[1]
                val formatter = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
                try {
                    val startDate = formatter.parse(rangeStart)
                    val endDate = formatter.parse(rangeEnd)
                    val inputDateObj = formatter.parse(time)
                    if (startDate == null || endDate == null || inputDateObj == null) {
                        LogUtils.w("data formatter result is null")
                        return 0
                    }
                    val calendar = Calendar.getInstance()
                    calendar.time = startDate
                    while (calendar.time <= endDate) {
                        if (calendar.time == inputDateObj) {
                            println("Index: $index")
                            break
                        }
                        calendar.add(Calendar.DATE, 1)
                        index++
                    }

                } catch (e: java.text.ParseException) {
                    e.printStackTrace()
                }
            }

            3 -> {
                // 将08-01格式转换为序号
                if (time.isNotEmpty()) {
                    val parts = time.split("-")
                    val month = parts[0].toInt()
                    val day = parts[1].toInt()
                    index = day - 1
                }
            }

            else -> {
                index = if (time.isDigitsOnly()) (time.toInt() - 1) else 0
            }
        }
        return if (index < 0) cur + 1 else index
    }

    /**
     * 设置曲线数据
     */
    private fun setData(values: List<Entry>?, chartType: Int = 0): LineDataSet {
        val lineChart = when (chartType) {
            0 -> {
                binding.tcLayout.mLineChart
            }

            1 -> {
                binding.tgLayout.mLineChart
            }

            2 -> {
                binding.hdlLayout.mLineChart
            }

            3 -> {
                binding.ldlLayout.mLineChart
            }

            else -> {
                binding.tcLayout.mLineChart
            }
        }

        return BaseChartInitUtils.setLineDataStyleOne(
            requireContext(),
            values,
            lineChart,
            2.5f,
            4f,
            true
        )
    }

    var weekDate = ""
    var mouthDate = ""
    var yearDate = ""
    private fun getDateAdd(days: Int): Date? {
        val c = Calendar.getInstance()
        c.add(Calendar.DAY_OF_MONTH, -days)
        return c.time
    }

    private val mTabEntities: ArrayList<CustomTabEntity> = ArrayList()
    private val mTitles = arrayOf(
        "日", "周", "月", "年"
    )

    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 -> {
                        binding.tvShowDate.text = dayDate
                        type = 1
                    }


                    1 -> {  //周
                        binding.tvShowDate.text = weekDate
                        type = 2
                    }

                    2 -> {  //月
                        binding.tvShowDate.text = mouthDate
                        type = 3
                    }

                    3 -> {  //年
                        binding.tvShowDate.text = yearDate
                        type = 4
                    }
                }
                mViewModel.getBloodFatInfo(
                    type,
                    binding.tvShowDate.text.toString(),
                    id,
                    isDemonstrate
                )
            }

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

    private fun initTimeSelect() {
        //日筛选
        val calendar = Calendar.getInstance()
        timeSelect.startDate.set(1922, 1, 1)
        timeSelect.endDate.set(
            calendar[Calendar.YEAR], calendar[Calendar.MONTH], if (calendar[Calendar.HOUR] >= 11) {
                calendar[Calendar.DATE]
            } else {
                calendar[Calendar.DATE]
            }
        )
        binding.tvShowDate.text = RxTimeTool.getCurTimeString(SimpleDateFormat("yyyy-MM-dd"))

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

                2 -> {
                    bottomSheetDialog?.show()
                }

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

                4 -> {
                    timeYearSelect.selectTimeWithYear(it, "yyyy")
                }
            }
        }

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

                2 -> {
                    bottomSheetDialog?.show()
                }

                3 -> {
                    timeMonthSelect.selectTimeWithYearMonth(binding.tvShowDate, "yyyy-MM")
                }

                4 -> {
                    timeYearSelect.selectTimeWithYear(binding.tvShowDate, "yyyy")
                }
            }
        }
        initBottomDialog()
    }

    private var bottomSheetDialog: BottomSheetDialog? = null

    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)
                val wheelView = view.findViewById<WheelView>(R.id.wheelView)
                wheelView.setCyclic(false)
                wheelView.adapter = ArrayWheelAdapter(buildWeekLower26())
                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 {
                    // 点击确定按钮的操作
                    val item = wheelView.adapter.getItem(wheelView.currentItem)
                    binding.tvShowDate.text = item.toString()
                    weekDate = binding.tvShowDate.text.toString()
                    mViewModel.getBloodFatInfo(
                        2,
                        binding.tvShowDate.text.toString(),
                        id,
                        isDemonstrate
                    )
                    // 点击确定按钮的操作
                    dialog.dismiss()
                }
            }
        }
    }

    @SuppressLint("SimpleDateFormat")
    fun buildWeekLower26(): MutableList<String> {
        val startDate = Calendar.getInstance()
        startDate.firstDayOfWeek = Calendar.MONDAY
        startDate.add(Calendar.YEAR, -1)
        val endDate = Calendar.getInstance()

        val dateRanges: MutableList<String> = ArrayList()
        val 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
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun onRefresh(event: BloodFilipOpenSuccessEvent) {
        Log.e("simon", event.toString())
        mViewModel.getBloodFatHead(id)
        mViewModel.getBloodFatInfo(type, binding.tvShowDate.text.toString(), id, isDemonstrate)
    }

    private fun setOrganStatus(chartType: Int = 0) {
        when (chartType) {
            0 -> {
                binding.clCurTc.mOrganView.tvFirstValue.text = SpannableUtils.setSpan(
                    tcNormalTime,
                    Color.parseColor("#313131")
                )
                if (tcNormalTime >= 0) {
                    binding.clCurTc.mOrganView.ivFirst.visibility = View.VISIBLE
                } else {
                    binding.clCurTc.mOrganView.ivFirst.visibility = View.INVISIBLE
                }

                binding.clCurTc.mOrganView.tvSecondValue.text = SpannableUtils.setSpan(
                    tcAbNormalTime,
                    Color.parseColor("#313131")
                )
                if (tcAbNormalTime > 0) {
                    binding.clCurTc.mOrganView.ivSecond.visibility = View.VISIBLE
                } else {
                    binding.clCurTc.mOrganView.ivSecond.visibility = View.INVISIBLE
                }
            }

            1 -> {
                binding.clCurTg.mOrganView.tvFirstValue.text = SpannableUtils.setSpan(
                    tgNormalTime,
                    Color.parseColor("#313131")
                )
                if (tgNormalTime >= 0) {
                    binding.clCurTg.mOrganView.ivFirst.visibility = View.VISIBLE
                } else {
                    binding.clCurTg.mOrganView.ivFirst.visibility = View.INVISIBLE
                }

                binding.clCurTg.mOrganView.tvSecondValue.text =
                    SpannableUtils.setSpan(tgAbNormalTime, Color.parseColor("#313131"))
                if (tgAbNormalTime > 0) {
                    binding.clCurTg.mOrganView.ivSecond.visibility = View.VISIBLE
                } else {
                    binding.clCurTg.mOrganView.ivSecond.visibility = View.INVISIBLE
                }
            }

            2 -> {
                binding.clCurHdl.mOrganView.tvFirstValue.text =
                    SpannableUtils.setSpan(hdlNormalTime, Color.parseColor("#313131"))
                if (hdlNormalTime >= 0) {
                    binding.clCurHdl.mOrganView.ivFirst.visibility = View.VISIBLE
                } else {
                    binding.clCurHdl.mOrganView.ivFirst.visibility = View.INVISIBLE
                }

                binding.clCurHdl.mOrganView.tvSecondValue.text =
                    SpannableUtils.setSpan(hdlAbNormalTime, Color.parseColor("#313131"))
                if (hdlAbNormalTime > 0) {
                    binding.clCurHdl.mOrganView.ivSecond.visibility = View.VISIBLE
                } else {
                    binding.clCurHdl.mOrganView.ivSecond.visibility = View.INVISIBLE
                }
            }

            else -> {
                binding.clCurLdl.mOrganView.tvFirstValue.text =
                    SpannableUtils.setSpan(ldlNormalTime, Color.parseColor("#313131"))
                if (ldlNormalTime >= 0) {
                    binding.clCurLdl.mOrganView.ivFirst.visibility = View.VISIBLE
                } else {
                    binding.clCurLdl.mOrganView.ivFirst.visibility = View.INVISIBLE
                }

                binding.clCurLdl.mOrganView.tvSecondValue.text =
                    SpannableUtils.setSpan(ldlAbNormalTime, Color.parseColor("#313131"))
                if (ldlAbNormalTime > 0) {
                    binding.clCurLdl.mOrganView.ivSecond.visibility = View.VISIBLE
                } else {
                    binding.clCurLdl.mOrganView.ivSecond.visibility = View.INVISIBLE
                }
            }
        }
    }

    @SuppressLint("SetTextI18n")
    fun setNoOpenBloodLipid(status: Int, data: BloodFatHeadInfo.Data?) {
        var valueDesc = ""
        if (status == 0) {
            if (TextUtils.isEmpty(expireTimeStr)) {
                valueDesc = "未开通"
                binding.tvOpen.visibility = View.VISIBLE
                binding.tvRenew.visibility = View.GONE
                binding.compareTv.visibility = View.GONE
                binding.llRenew.visibility = View.GONE

                binding.tcLayout.llEmpty.visibility = View.VISIBLE
                binding.tgLayout.llEmpty.visibility = View.VISIBLE
                binding.hdlLayout.llEmpty.visibility = View.VISIBLE
                binding.ldlLayout.llEmpty.visibility = View.VISIBLE
                binding.tcLayout.mBarChart.visibility = View.GONE
                binding.tcLayout.mLineChart.visibility = View.GONE
                binding.tgLayout.mBarChart.visibility = View.GONE
                binding.tgLayout.mLineChart.visibility = View.GONE
                binding.hdlLayout.mBarChart.visibility = View.GONE
                binding.hdlLayout.mLineChart.visibility = View.GONE
                binding.ldlLayout.mBarChart.visibility = View.GONE
                binding.ldlLayout.mLineChart.visibility = View.GONE
                binding.tcLayout.zhexianTv.visibility = View.GONE
                binding.tcLayout.zhuzhuanTv.visibility = View.GONE
                binding.tcLayout.mDesc.visibility = View.GONE
                binding.tgLayout.zhexianTv.visibility = View.GONE
                binding.tgLayout.zhuzhuanTv.visibility = View.GONE
                binding.tgLayout.mDesc.visibility = View.GONE
                binding.hdlLayout.zhexianTv.visibility = View.GONE
                binding.hdlLayout.zhuzhuanTv.visibility = View.GONE
                binding.hdlLayout.mDesc.visibility = View.GONE
                binding.ldlLayout.zhexianTv.visibility = View.GONE
                binding.ldlLayout.zhuzhuanTv.visibility = View.GONE
                binding.ldlLayout.mDesc.visibility = View.GONE
            } else {
                valueDesc = "--"
                binding.tvOpen.visibility = View.GONE
                binding.compareTv.visibility = View.VISIBLE
                binding.tvRenew.visibility = View.VISIBLE
                binding.llRenew.visibility = View.VISIBLE
            }
        } else if (status == 1) {
            valueDesc = "建模中"
            binding.llRenew.visibility = View.VISIBLE
            binding.tvBloodLipidAdjust.text = "建模说明"
            binding.tvRenew.visibility = View.GONE
            binding.tvOpen.visibility = View.GONE
            binding.compareTv.visibility = View.VISIBLE

            binding.tcLayout.llEmpty.visibility = View.VISIBLE
            binding.tgLayout.llEmpty.visibility = View.VISIBLE
            binding.hdlLayout.llEmpty.visibility = View.VISIBLE
            binding.ldlLayout.llEmpty.visibility = View.VISIBLE
            binding.tcLayout.mBarChart.visibility = View.GONE
            binding.tcLayout.mLineChart.visibility = View.GONE
            binding.tgLayout.mBarChart.visibility = View.GONE
            binding.tgLayout.mLineChart.visibility = View.GONE
            binding.hdlLayout.mBarChart.visibility = View.GONE
            binding.hdlLayout.mLineChart.visibility = View.GONE
            binding.ldlLayout.mBarChart.visibility = View.GONE
            binding.ldlLayout.mLineChart.visibility = View.GONE
            binding.tcLayout.zhexianTv.visibility = View.GONE
            binding.tcLayout.zhuzhuanTv.visibility = View.GONE
            binding.tcLayout.mDesc.visibility = View.GONE
            binding.tgLayout.zhexianTv.visibility = View.GONE
            binding.tgLayout.zhuzhuanTv.visibility = View.GONE
            binding.tgLayout.mDesc.visibility = View.GONE
            binding.hdlLayout.zhexianTv.visibility = View.GONE
            binding.hdlLayout.zhuzhuanTv.visibility = View.GONE
            binding.hdlLayout.mDesc.visibility = View.GONE
            binding.ldlLayout.zhexianTv.visibility = View.GONE
            binding.ldlLayout.zhuzhuanTv.visibility = View.GONE
            binding.ldlLayout.mDesc.visibility = View.GONE
        }

        binding.clCurTc.tvBloodValue.text = if (data != null) {
            if (data.tc > 0) {
                data.tc.toString()
            } else {
                valueDesc
            }
        } else {
            valueDesc
        }
        binding.clCurTc.tvTestTime.text = "mmol/L ${
            Dateutils.formatTime(System.currentTimeMillis(), Dateutils.HH_MM_Format)
        }"
        binding.clCurTc.mOrganView.tvFirstValue.text = SpannableUtils.setSpan(
            0,
            Color.parseColor("#313131")
        )
        binding.clCurTc.mOrganView.tvSecondValue.text = SpannableUtils.setSpan(
            tcAbNormalTime,
            Color.parseColor("#313131")
        )

        binding.clCurTg.tvBloodValue.text = if (data != null) {
            if (data.tg > 0) {
                data.tg.toString()
            } else {
                valueDesc
            }
        } else {
            valueDesc
        }
        binding.clCurTg.tvTestTime.text = "mmol/L ${
            Dateutils.formatTime(
                System.currentTimeMillis(),
                Dateutils.HH_MM_Format
            )
        }"
        binding.clCurTg.mOrganView.tvFirstValue.text = SpannableUtils.setSpan(
            0,
            Color.parseColor("#313131")
        )
        binding.clCurTg.mOrganView.tvSecondValue.text = SpannableUtils.setSpan(
            tgAbNormalTime,
            Color.parseColor("#313131")
        )

        binding.clCurHdl.tvBloodValue.text = if (data != null) {
            if (data.hdl > 0) {
                data.hdl.toString()
            } else {
                valueDesc
            }
        } else {
            valueDesc
        }
        binding.clCurHdl.tvTestTime.text = "mmol/L ${
            Dateutils.formatTime(
                System.currentTimeMillis(),
                Dateutils.HH_MM_Format
            )
        }"
        binding.clCurHdl.mOrganView.tvFirstValue.text = SpannableUtils.setSpan(
            0,
            Color.parseColor("#313131")
        )
        binding.clCurHdl.mOrganView.tvSecondValue.text = SpannableUtils.setSpan(
            hdlAbNormalTime,
            Color.parseColor("#313131")
        )

        binding.clCurLdl.tvBloodValue.text = if (data != null) {
            if (data.ldl > 0) {
                data.ldl.toString()
            } else {
                valueDesc
            }
        } else {
            valueDesc
        }
        binding.clCurLdl.tvTestTime.text = "mmol/L ${
            Dateutils.formatTime(
                System.currentTimeMillis(),
                Dateutils.HH_MM_Format
            )
        }"
        binding.clCurLdl.mOrganView.tvFirstValue.text = SpannableUtils.setSpan(
            0,
            Color.parseColor("#313131")
        )
        binding.clCurLdl.mOrganView.tvSecondValue.text = SpannableUtils.setSpan(
            ldlAbNormalTime,
            Color.parseColor("#313131")
        )
    }

    @SuppressLint("SetTextI18n")
    fun setDemostrateInfo() {
        binding.tvOpen.visibility = View.GONE
        binding.tvRenew.visibility = View.GONE
        binding.compareTv.visibility = View.VISIBLE
        binding.llRenew.visibility = View.GONE
        binding.tvEndTime.text = "2088-12-21 18:00:00"

        binding.clCurTc.tvBloodValue.text = "5.07"
        binding.clCurTc.tvTestTime.text = "mmol/L ${
            Dateutils.formatTime(System.currentTimeMillis(), Dateutils.HH_MM_Format)
        }"
        binding.clCurTc.mOrganView.tvFirstValue.text = SpannableUtils.setSpan(
            0, Color.parseColor("#313131")
        )
        binding.clCurTc.mOrganView.tvSecondValue.text = SpannableUtils.setSpan(
            0, Color.parseColor("#313131")
        )

        binding.clCurTg.tvBloodValue.text = "0.57"
        binding.clCurTg.tvTestTime.text = "mmol/L ${
            Dateutils.formatTime(System.currentTimeMillis(), Dateutils.HH_MM_Format)
        }"
        binding.clCurTg.mOrganView.tvFirstValue.text = SpannableUtils.setSpan(
            0, Color.parseColor("#313131")
        )
        binding.clCurTg.mOrganView.tvSecondValue.text = SpannableUtils.setSpan(
            0, Color.parseColor("#313131")
        )

        binding.clCurHdl.tvBloodValue.text = "5.07"
        binding.clCurHdl.tvTestTime.text = "mmol/L ${
            Dateutils.formatTime(System.currentTimeMillis(), Dateutils.HH_MM_Format)
        }"
        binding.clCurHdl.mOrganView.tvFirstValue.text = SpannableUtils.setSpan(
            0, Color.parseColor("#313131")
        )
        binding.clCurHdl.mOrganView.tvSecondValue.text = SpannableUtils.setSpan(
            0, Color.parseColor("#313131")
        )

        binding.clCurLdl.tvBloodValue.text = "5.07"
        binding.clCurLdl.tvTestTime.text = "mmol/L ${
            Dateutils.formatTime(System.currentTimeMillis(), Dateutils.HH_MM_Format)
        }"
        binding.clCurLdl.mOrganView.tvFirstValue.text = SpannableUtils.setSpan(
            0, Color.parseColor("#313131")
        )
        binding.clCurLdl.mOrganView.tvSecondValue.text = SpannableUtils.setSpan(
            0, Color.parseColor("#313131")
        )
    }
}