package com.zj365.health.vm

import androidx.lifecycle.MutableLiveData
import com.xty.base.vm.BaseVm
import com.xty.common.util.CommonUtils
import com.xty.network.model.MedicalDataBean
import com.xty.network.model.PaingBean
import com.xty.network.model.RespBody
import org.json.JSONObject

class HealthRecordVm:BaseVm() {

    val getHealthData by lazy{ MutableLiveData<RespBody<PaingBean<MedicalDataBean>>>() }
    val deleteData  by lazy { MutableLiveData<RespBody<Any>>() }

    //	6，体检，7，用药,9:住院
    fun getHealthDataList(page:Int,type:String,userId:String?="",order:String = "1",searchKey:String="",year:String="",month:String="",hospitalExplain:String=""){
        startHttp {
            val json= JSONObject()
            json.put("pageNum",page)
            json.put("pageSize", 20)
            json.put("dataType",type)
            json.put("name",searchKey)
            json.put("year",year)
            json.put("month",month)
            json.put("orderSort",order)
            json.put("userId",userId)
            json.put("hospitalExplain",hospitalExplain)
            val response =apiInterface().getHealthFileData(retrofits.getRequestBody(json.toString()))
            response.getCodeStatus(getHealthData,nowData)
        }
    }

    fun deleteMedical(list: MutableList<MedicalDataBean>) {
        var builder = java.lang.StringBuilder()
        for (s in list) {
            builder.append(s.id)
            val index = list.indexOf(s)
            if (index != 0 || index != list.size - 1) {
                builder.append(",")
            }
        }
        startHttp {
            var json = JSONObject()
            json.put("ids", builder.toString())
            var response = apiInterface().deleteHealthData(builder.toString())
            response.getCodeStatus(deleteData, nowData)
        }
    }
}