<template>
    <el-container>
        <el-aside width="280px">
          <PatientBaseList  :selectFlag="selectFlag" @allPatientList="selectAllPatientList"   @selectPatientInfo="selectPatientInfo" ></PatientBaseList>
        </el-aside>
        <el-container>
            <el-header style="height: 10%">
                录入日期
                    <el-date-picker
                            v-model="queryParam.recDateStr"
                            type="date"
                            size="small"
                            :clearable="clearable"
                            format="YYYY-MM-DD" value-format="YYYY-MM-DD"
                    ></el-date-picker>
                时间
                <el-select v-model="queryParam.recTimeStr"  style="width: 100px">
                    <el-option v-for="item in recTimeStrList" :key="item.code" :label="item.name" :value="item.code">
                        <span>{{ item.name }}</span>
                    </el-option>
                </el-select>
                <el-select v-model="queryParam.temperatureType"  style="width: 100px">
                    <el-option v-for="item in temperatureTypeList" :key="item.code" :label="item.name" :value="item.code">
                        <span style="color: #8492a6; font-size: 12px">{{ item.code }}</span>
                        <el-divider direction="vertical"></el-divider>
                        <span>{{ item.name }}</span>
                    </el-option>
                </el-select>
                <el-button icon="Search" type="primary" @click="queryInfo">查询</el-button>
                <el-button type="success" @click="saveThreeTestInfo">保存</el-button>
                <el-button icon="Search" type="primary" @click="openPsInfo">皮试信息</el-button>
            </el-header>
            <el-main>
                    <el-tabs
                            v-model="activeName"
                            type="card"
                            class="demo-tabs"
                            @tab-click="handleClick"
                    >
                        <el-tab-pane label="图表数据" name="first">
                            <div class="height670">
                            <el-table :data="yzTemperatureVOS"  highlight-current-row stripe border show-overflow-tooltip   style="width: 100%;height: 100%">
                                <el-table-column label="排序" type="index" width="40" />
                                <el-table-column prop="recDateStr" label="日期"/>
                                <el-table-column prop="inpatientNo" label="住院号"/>
                                <el-table-column prop="admissTimes" label="住院次数" width="80"/>
                                <el-table-column prop="name" label="病人姓名"/>
                                <el-table-column prop="sex" label="性别" width="40"/>
                                <el-table-column prop="bedNo" label="床号" width="40" />
                                <el-table-column prop="toStringRecTime" label="时间"/>
                                <el-table-column prop="temperatureType" label="类型" min-width="130">
                                    <template #default="scope">
                                        <el-select v-model="scope.row.temperatureType" style="width: 100px">
                                            <el-option v-for="item in temperatureTypeList" :key="item.code" :label="item.name" :value="item.code">
                                                <span style="color: #8492a6; font-size: 12px">{{ item.code }}</span>
                                                <el-divider direction="vertical"></el-divider>
                                                <span>{{ item.name }}</span>
                                            </el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="temperature" label="体温℃">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.temperature"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="physicalMethodFlag" label="降温">
                                    <template #default="scope">
                                        <span>x</span>
                                        <el-switch v-model="scope.row.physicalMethodFlag" active-value="1" inactive-value="0"  style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949" />
                                        <span>√</span>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="temperatureCool" label="降温后">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.temperatureCool"></el-input>
                                    </template>
                                </el-table-column>

                                <el-table-column prop="breathe" label="呼吸">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.breathe"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="breatheMachine" label="呼吸机">
                                    <template #default="scope">
                                        <el-select v-model="scope.row.breatheMachine" style="width: 100px">
                                            <el-option v-for="item in breatheMachineList" :key="item.code" :label="item.name" :value="item.code">

                                            </el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="pulse" label="脉搏">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.pulse"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="heart" label="心率">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.heart"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="scdSpecialtext" label="特殊标注"  min-width="100">
                                    <template #default="scope">
                                        <el-select v-model="scope.row.scdSpecialtext">
                                            <el-option v-for="item in scdSpecialtextList" :key="item.code" :label="item.name" :value="item.code">

                                            </el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="specialtextTimeStr" label="标注时间"  min-width="130">
                                    <template #default="scope">
                                        <el-time-picker v-model="scope.row.specialtextTimeStr" style="width: 110px" format="HH:mm" value-format="HH:mm"   />
                                    </template>
                                </el-table-column>
                                <el-table-column prop="userName" label="录入人"/>
                                <el-table-column prop="painLvl" label="疼痛强度"  min-width="130">
                                    <template #default="scope">
                                        <el-select v-model="scope.row.painLvl" style="width: 100px">
                                            <el-option v-for="item in painLvlList" :key="item.code" :label="item.name" :value="item.code">

                                            </el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column label="操作">
                                    <template #default="scope">
                                        <el-button type="danger" @click="delYzTemperature(scope.row,scope.$index)">删除</el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                            </div>
                        </el-tab-pane>
                        <el-tab-pane label="出入总量" name="second">
                            <div class="height670">
                                <el-table :data="yzTemperatureSums"  highlight-current-row stripe border show-overflow-tooltip   style="width: 100%;height: 100%">
                                    <el-table-column label="排序" type="index" width="40" />
                                    <el-table-column prop="recDateStr" label="日期"/>
                                    <el-table-column prop="inpatientNo" label="住院号"/>
                                    <el-table-column prop="admissTimes" label="住院次数" width="80"/>
                                    <el-table-column prop="name" label="病人姓名"/>
                                    <el-table-column prop="sex" label="性别" width="40"/>
                                    <el-table-column prop="bedNo" label="床号" width="40" />
                                    <el-table-column prop="pressureAm" style="color: red" label="血压(上午)">
                                        <template #default="scope">
                                            <el-input v-model="scope.row.pressureAm"></el-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column prop="pressurePm" style="color: red" label="血压(下午)" min-width="130">
                                        <template #default="scope">
                                            <el-input v-model="scope.row.pressurePm"></el-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column prop="intake" label="总入液量(ml)">
                                        <template #default="scope">
                                            <el-input v-model="scope.row.intake"></el-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column prop="intakeInfo" label="入量(特殊)" width="120">
                                        <template #default="scope">
                                            <el-select v-model="scope.row.intakeInfo" >
                                                <el-option  key="24小时入量" label="24小时入量" value="24小时入量">
                                                </el-option>
                                            </el-select>
                                        </template>
                                    </el-table-column>
                                    <el-table-column prop="shitOther" label="大便(次)">
                                        <template #default="scope">
                                            <el-select v-model="scope.row.shitOther" >
                                                <el-option v-for="item in shitOtherList" :key="item.code" :label="item.name" :value="item.code">
                                                </el-option>
                                            </el-select>
                                        </template>
                                    </el-table-column>
                                    <el-table-column prop="urineQuanInfo" label="尿量(ml)" >
                                        <template #default="scope">
                                            <el-input v-model="scope.row.urineQuanInfo"></el-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column prop="urineInfo" label="尿量(特殊)" width="120">
                                        <template #default="scope">
                                            <el-select v-model="scope.row.urineInfo" >
                                                <el-option v-for="item in urineInfoList" :key="item.code" :label="item.name" :value="item.code">

                                                </el-option>
                                            </el-select>
                                        </template>
                                    </el-table-column>
                                    <el-table-column prop="outputOther" label="出量">
                                        <template #default="scope">
                                            <el-input v-model="scope.row.outputOther"></el-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column prop="outputInfo" label="出量(特殊)" width="120">
                                        <template #default="scope">
                                            <el-select v-model="scope.row.outputInfo" >
                                                <el-option  key="24小时出量" label="24小时出量" value="24小时出量">
                                                </el-option>
                                            </el-select>
                                        </template>
                                    </el-table-column>
                                    <el-table-column prop="bodyWeight" label="体重">
                                        <template #default="scope">
                                            <el-input v-model="scope.row.bodyWeight"></el-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column prop="bodyLength" label="身高">
                                        <template #default="scope">
                                            <el-input v-model="scope.row.bodyLength"></el-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column prop="bodyWeightInfo" label="体重(特殊)" width="100px">
                                        <template #default="scope">
                                            <el-select v-model="scope.row.bodyWeightInfo" style="width: 80px">
                                                <el-option v-for="item in bodyWeightInfoList" :key="item.code" :label="item.name" :value="item.code">

                                                </el-option>
                                            </el-select>
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="操作">
                                        <template #default="scope">
                                            <el-button type="danger" @click="delYzTemperatureSum(scope.row,scope.$index)">删除</el-button>
                                        </template>
                                    </el-table-column>
                                </el-table>
                            </div>
                        </el-tab-pane>
                        <el-tab-pane label="过敏药物" name="third">
                            <div style="margin-bottom: 20px">
                                <el-button  type="primary" @click="onAdd">+</el-button>
                                <el-button  type="primary" @click="onReduce">-</el-button>
                                <el-button  icon="Search" type="primary" @click="queryGmInfo">查询过敏信息</el-button>
                                <el-button  type="success" @click="saveGmInfo">保存过敏信息</el-button>
                            </div>
                            <div >
                                <el-input v-for="(item,i) of items" v-model="items[i]" :key="i" clearable style="width: 150px"  placeholder=""></el-input>
                            </div>
                        </el-tab-pane>
                    </el-tabs>
            </el-main>
        </el-container>
    </el-container>
    <el-dialog v-model="psDialogFlag"  title="皮试信息" destroy-on-close="true" style="width:75%;height:75% ">
        <PsInfo :patintList="allPatientList"></PsInfo>
    </el-dialog>
</template>

<script setup name='ThreeTestList'>
import PatientBaseList from "@/components/medical-advice/PatientBaseList.vue"
import PsInfo from "@/views/medical-advice/nursing-manage/PsInfo.vue"
import {queryThreeTestList,saveThreeTest,queyGm,saveGm,deleteYzTemperature,deleteYzTemperatureSum} from "@/api/medical-advice/nursing-manage";
import { getFormatDatetime } from "@/utils/date";
import {onMounted} from "vue";
import {stringNotBlank} from "@/utils/blank-utils";
import {ElMessage, ElMessageBox} from 'element-plus'
const selectFlag = ref(true)
const clearable = ref(false)
//图表数据
const yzTemperatureVOS = ref([])
//总量数据
const yzTemperatureSums = ref([])
const allPatientList = ref([])
//过敏信息

const psDialogFlag = ref(false)
const queryParam = ref({
    recDateStr:getFormatDatetime(new Date(),'YYYY-MM-DD'),
    recTimeStr:'0',
    temperatureType:'2',
    visitIds:[],
    patientInfoList:[]
})

const openPsInfo = ()=>{
    psDialogFlag.value = true
}
//过敏药物
const items = ref([])
const onAdd = ()=>{
    items.value.push('')
}

const onReduce = ()=>{
    items.value.pop()
}

const outputInfo = ref('24小时出量')

const painLvlList = ref([])

const bodyWeightInfoList = ref([
    {
        code:'',
        name:'',
    },{
        code:'卧床',
        name:'卧床',
    },{
        code:'平车',
        name:'平车',
    }
])

const urineInfoList = ref([
    {
        code:'0',
        name:'0',
    },{
        code:'+',
        name:'+',
    },{
        code:'24小时尿量',
        name:'24小时尿量',
    },{
        code:'*',
        name:'*',
    }
])

const shitOtherList = ref([
    {
        code:'☆',
        name:'☆',
    },{
        code:'0/E',
        name:'0/E',
    },{
        code:'1/E',
        name:'1/E',
    },{
        code:'2/E',
        name:'2/E',
    },{
        code:'*/E',
        name:'*/E',
    },{
        code:'1 1/E',
        name:'1 1/E',
    },{
        code:'1,2/E',
        name:'1,2/E',
    },{
        code:'2/2E',
        name:'2/2E',
    }
])

const scdSpecialtextList = ref([
    {
        code:'',
        name:'',
    },{
        code:'外出',
        name:'外出',
    },{
        code:'转入',
        name:'转入',
    },{
        code:'死亡',
        name:'死亡',
    },{
        code:'手术',
        name:'手术',
    },{
        code:'分娩',
        name:'分娩',
    },{
        code:'出生',
        name:'出生',
    },{
        code:'转科',
        name:'转科',
    }
])

const breatheMachineList = ref([
    {
        code:'A',
        name:'A',
    },{
        code:'R',
        name:'R',
    }
])

const temperatureTypeList=ref([{
    code:'1',
    name:'口表',
},{
    code:'2',
    name:'腋表',
},{
    code:'3',
    name:'肛表',
}])
const recTimeStrList=ref([{
    code:'0',
    name:'全部',
},{
    code:'3',
    name:'3',
},{
    code:'7',
    name:'7',
},{
    code:'11',
    name:'11',
},{
    code:'15',
    name:'15',
},{
    code:'19',
    name:'19',
},{
    code:'23',
    name:'23',
}])

const companyFunc = (val, company) => {
    if (stringNotBlank(val)) {
        return val + company
    } else {
        return ''
    }
}
const queryInfo=()=>{
    if(queryParam.value.visitIds.length === 0){
        return ElMessage.error('选中要查询的病人')
    }
    queryThreeTestList(queryParam.value).then((res) => {
        yzTemperatureVOS.value = res.yzTemperatureVOS
        yzTemperatureSums.value = res.yzTemperatureSums
    })
}

const delYzTemperature=(row,index)=>{
    ElMessageBox.confirm('请确认是否删除', {
        cancelButtonText: '取消',
        confirmButtonText: '确定',
    })
        .then(() => {
            deleteYzTemperature(row).then((res) => {
                yzTemperatureVOS.value.splice(index,1)
            })
        })
        .catch(() => {
        })


}


const delYzTemperatureSum = (row,index)=>{
    ElMessageBox.confirm('请确认是否删除', {
        cancelButtonText: '取消',
        confirmButtonText: '确定',
    })
        .then(() => {
            deleteYzTemperatureSum(row).then((res) => {
                yzTemperatureSums.value.splice(index,1)
            })
        })
        .catch(() => {
        })



}

//保存过敏信息
const saveGmInfo =()=>{
    for (let i = 0; i < items.value.length; i++) {
        if(!stringNotBlank(items.value[i])){
          return   ElMessage.error('要保存的过敏药物不能为空')
        }
    }
    ElMessageBox.confirm('请确认是否保存', {
        cancelButtonText: '取消',
        confirmButtonText: '确定',
    })
        .then(() => {
            let saveData = {
                visitIds:queryParam.value.visitIds,
                gmItems:items.value
            }
            saveGm(saveData).then(() => {
            })
        })
        .catch(() => {
        })

}
//查询过敏信息
const queryGmInfo=()=>{
    if(queryParam.value.visitIds.length != 1){
        return ElMessage.error('请选择一个病人')
    }
    queyGm(queryParam.value).then((res) => {
        items.value = res
    })

}
const selectAllPatientList = (val)=>{
    allPatientList.value=val
}

const selectPatientInfo=(val)=>{
    queryParam.value.patientInfoList = val
    let tempVisitIds = []
    for (let i = 0; i < val.length; i++) {
        let visitId = val[i].inpatientNo + '_' + val[i].admissTimes
        tempVisitIds.push(visitId)
    }
    queryParam.value.visitIds= tempVisitIds;
}

const activeName = ref('first')
//保存数据
const saveThreeTestInfo = () =>{
    ElMessageBox.confirm('请确认是否保存', {
        cancelButtonText: '取消',
        confirmButtonText: '确定',
    })
        .then(() => {
            let saveData = {
                yzTemperatureVOS: yzTemperatureVOS.value,
                yzTemperatureSums: yzTemperatureSums.value,
            }
            saveThreeTest(saveData).then((res) => {

            })
        })
        .catch(() => {
        })

}

const handleClick = (tab,event) => {
    console.log(tab, event)
}

onMounted(() => {
    let items = []
    items.push({ code:'',
        name:'空',})
    for (let i = 0; i < 12; i++) {
        let item = {
            code: i+'',name:i+''
        }
        items.push(item)
    }
    painLvlList.value = items
    console.log('painLvlList',items)
})
</script>

<style scoped>
.status_color {
    width: 10px;
    height: 10px;
}
.demo-tabs > .el-tabs__content {
    padding: 32px;
    color: #6b778c;
    font-size: 32px;
    font-weight: 600;
}
.height670{
   height: 670px;
}

</style>
