<template>
        <el-container>
            <el-header>
                床位范围:<el-select v-model="queryParam.startBedNo"
                                :clearable="wardsClearable"
                                style="width: 110px"
            >
                <el-option v-for="item in props.patintList"
                           :key="item.bedNo"
                           :label="item.bedNo"
                           :value="item.bedNo">
                    <span>{{ item.bedNo }}</span>
                    <el-divider direction="vertical"></el-divider>
                    <span>{{ item.inpatientNo }}</span>
                    <el-divider direction="vertical"></el-divider>
                    <span>{{ item.name }}</span>
                </el-option>

            </el-select>
                至
                <el-select v-model="queryParam.endBedNo"
                           style="width: 110px"
                >
                    <el-option v-for="item in reverPatintList"
                               :key="item.bedNo"
                               :label="item.bedNo"
                               :value="item.bedNo">
                        <span>{{ item.bedNo }}</span>
                        <el-divider direction="vertical"></el-divider>
                        <span>{{ item.inpatientNo }}</span>
                        <el-divider direction="vertical"></el-divider>
                        <span>{{ item.name }}</span>
                    </el-option>
                </el-select>
                执行时间:
                <el-time-picker v-model="excuTime" style="width: 110px" format="HH:mm" value-format="HH:mm"   />
                    <el-radio-group v-model="queryParam.confirmFlag">
                        <el-radio label="0" size="small">未确认</el-radio>
                        <el-radio label="1" size="small">已确认</el-radio>
                    </el-radio-group>
                <el-button icon="Search" type="primary" @click="queryInfo">查询</el-button>
                <el-button type="success" @click="savePsInfo">保存</el-button>
            </el-header>
            <el-main>
                <div style="width: 100%;height: 60%">
                <el-table :data="psInfo"  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="bedNo" label="床号" width="40" />
                    <el-table-column prop="inpatientNo" label="住院号"/>
                    <el-table-column prop="name" label="病人姓名"/>
                    <el-table-column prop="actOrderNo" label="医嘱号"/>
                    <el-table-column prop="orderName" label="医嘱名称" min-width="120" />
                    <el-table-column prop="orderTime" label="医嘱时间" min-width="125"/>
                    <el-table-column prop="dose" label="剂量" width="40"/>
                    <el-table-column prop="doseUnit" label="剂量单位" width="80"/>
                    <el-table-column prop="supplyName" label="给药方式" min-width="100"/>
                    <el-table-column prop="psStatus" label="皮试结果" min-width="140">
                        <template #default="scope">
                            <el-radio-group v-model="scope.row.psStatus">
                                <el-radio label="0" size="small">阴性</el-radio>
                                <el-radio label="1" size="small">阳性</el-radio>
                            </el-radio-group>
                        </template>
                    </el-table-column>
                    <el-table-column prop="psOper" label="皮试执行人" min-width="140">
                        <template #default="scope">
                            <SelectStaffCode v-model="scope.row" :name="['psOper', 'psOperName']"></SelectStaffCode>
                        </template>
                    </el-table-column>
                    <el-table-column prop="psResultTime" label="皮试结果时间" min-width="150">
                        <template #default="scope">
                        <el-date-picker
                                v-model="scope.row.psResultTime"
                                type="datetime"
                                format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss"
                                style="width: 130px;"
                        />
                        </template>
                    </el-table-column>
                    <el-table-column prop="enterTime" label="录入时间" min-width="125"/>
                </el-table>
                </div>
            </el-main>
        </el-container>
</template>
<script setup name='PsInfo'>
import {queryPsInfo,updatePsInfo,selectEmpInfo} from "@/api/medical-advice/nursing-manage";
import { getFormatDatetime } from "@/utils/date";
import {onMounted,computed} from "vue";
import {stringNotBlank} from "@/utils/blank-utils";
import {ElMessage, ElMessageBox} from 'element-plus'
import SelectStaffCode from '@/components/SelectStaffCode.vue'

const props = defineProps({
    patintList: {
        type: Array,
        default:[]
    },
    curWard:{
        type: String,
        default:''
    }
})

const  queryInfo = ()=>{
    queryPsInfo(queryParam.value).then((res)=>{
        psInfo.value = res
    })
}

const  savePsInfo = ()=>{
    ElMessageBox.confirm('请确认是否保存', {
        cancelButtonText: '取消',
        confirmButtonText: '确定',
    })
        .then(() => {
            updatePsInfo(psInfo.value).then((res)=>{
            })
        })
        .catch(() => {
        })
}

const psInfo = ref([])


const reverPatintList = computed(() => reverseArray(props.patintList))


function reverseArray(arr) {
    let newArr = [];
    arr.forEach(element => {
        // unshift() 方法可向数组的开头添加一个或更多元素，并返回新的长度。
        newArr.unshift(element);
    });
    return newArr;
}
const queryParam = ref({
    curWard:'',
    startBedNo: '',
    endBedNo: '',
    confirmFlag:'0'
})

const excuTime = ref(getFormatDatetime(new Date(),'HH:mm'))




onMounted(() => {
    queryParam.value.curWard =props.curWard
    queryParam.value.startBedNo = props.patintList[0].bedNo ? props.patintList[0].bedNo:''
    queryParam.value.endBedNo = reverPatintList.value[0].bedNo ? reverPatintList.value[0].bedNo : ''
})

</script>