<template>
  <!-- search -->
  <el-card shadow="always" :body-style="{ padding: '20px' }">
    <div class="domain">
      <el-form :inline="true" label-width="100px">
        <el-form-item label="录入时间" size="normal">
          <el-date-picker
            v-model="searchFormData.recordingDate"
            type="date"
            placeholder="请选择时间"
            :size="size"
            format="YYYY/MM/DD"
            value-format="YYYY-MM-DD"
            @change="selectTimeChange"
          />
        </el-form-item>
        <el-form-item label="体温单类型" size="normal">
          <el-select
            v-model="searchFormData.temperatureType"
            placeholder="请选择"
            clearable
            filterable
            @change=""
          >
            <el-option
              v-for="item in temOptions"
              :label="item.label"
              :key="item.value"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </div>
  </el-card>
  <!-- table -->
  <el-card shadow="always" style="margin-top: 10px">
    <div>
      <el-form :model="formData" ref="formRef" label-width="80px" :inline="false" size="normal">
        <el-table border :data="formData.fillTableData" style="width: 100%">
          <el-table-column width="100px" label="" fixed="left">
            <template #default="scoped">
              <span>{{ timePointTime(scoped.row.timePoint) }}</span>
            </template>
          </el-table-column>
          <el-table-column width="250px" label="体温">
            <template #default="scoped">
              <el-form-item
                class="el-form-item"
                size="normal"
                :prop="`fillTableData.${scoped.$index}.temperature`"
              >
                <div style="display: flex; margin-left: -80px">
                  <el-input
                    class="el-input"
                    v-model="scoped.row.temperature"
                    placeholder="请输入体温(℃)"
                    @input="handleInput(scoped.row, scoped.row.temperature, 1)"
                  />
                  <el-select
                    v-model="scoped.row.temperatureUnit"
                    placeholder="请选择"
                    style="margin-left: 5px"
                    @change="temperChange(scoped.row, 1)"
                  >
                    <el-option
                      v-for="item in temperature_select_type"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    ></el-option>
                  </el-select>
                </div>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="脉搏">
            <template #default="scoped">
              <el-form-item size="normal" :prop="`fillTableData.${scoped.$index}.pulse`">
                <div style="margin-left: -80px">
                  <el-input
                    v-model="scoped.row.pulse"
                    placeholder="请输入脉搏(分/次)"
                    @input="handleInput(scoped.row, scoped.row.pulse)"
                  />
                </div>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="呼吸(次/分)">
            <template #default="scoped">
              <el-form-item size="normal" :prop="`fillTableData.${scoped.$index}.breathe`">
                <div style="display: flex; margin-left: -80px">
                  <el-input
                    v-model="scoped.row.breathe"
                    placeholder="请输入呼吸次数(分/次)"
                    @input="handleInput(scoped.row, scoped.row.breathe, 2)"
                  />
                  <el-select
                    v-model="scoped.row.breatheUnit"
                    placeholder="请选择"
                    style="margin-left: 5px"
                    @change="temperChange(scoped.row, 2)"
                  >
                    <el-option
                      v-for="item in breathe_unit"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    ></el-option>
                  </el-select>
                </div>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="心率">
            <template #default="scoped">
              <el-form-item size="normal" :prop="`fillTableData.${scoped.$index}.heartRate`">
                <div style="margin-left: -80px">
                  <el-input v-model="scoped.row.heartRate" placeholder="请输入心率(bpm)" />
                </div>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column width="300px" label="血压">
            <template #default="scoped">
              <el-form-item size="normal" :prop="`fillTableData.${scoped.$index}.tw`">
                <div style="display: flex; margin-left: -80px">
                  <el-input
                    v-model="scoped.row.systolicPressure"
                    placeholder="请输入收缩压(mmHg)"
                    @input="systolic(scoped.row, 1)"
                  />
                  <el-input
                    v-model="scoped.row.diastolicPressure"
                    placeholder="请输入舒张压(mmHg)"
                    style="margin-left: 5px"
                    @input="systolic(scoped.row, 2)"
                  />
                  <el-select
                    v-model="scoped.row.pressureUnit"
                    placeholder="请选择"
                    style="margin-left: 5px"
                    @change="temperChange(scoped.row, 3)"
                  >
                    <el-option
                      v-for="item in temperature_select_type"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    ></el-option>
                  </el-select>
                </div>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column label="疼痛等级">
            <template #default="scoped">
              <el-form-item size="normal" :prop="`fillTableData.${scoped.$index}.heartRate`">
                <div style="margin-left: -80px">
                  <el-input
                    v-model="scoped.row.painScore"
                    placeholder="请输入疼痛等级"
                    @input="handleInput(scoped.row, scoped.row.painScore)"
                  />
                </div>
              </el-form-item>
            </template>
          </el-table-column>
          <!-- <el-table-column width="200px" label="血氧">
            <template #default="scoped">
              <el-form-item size="normal" :prop="`fillTableData.${scoped.$index}.bloodOxygen`">
                <div style="margin-left: -80px">
                  <el-input
                    v-model="scoped.row.bloodOxygen"
                    placeholder="请输入血氧(毫升/100毫升)"
                  />
                </div>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column width="200px" label="血糖">
            <template #default="scoped">
              <el-form-item size="normal" :prop="`fillTableData.${scoped.$index}.bloodGlucose`">
                <div style="margin-left: -80px">
                  <el-input v-model="scoped.row.bloodGlucose" placeholder="请输入血糖(mmol/L)" />
                </div>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column width="200px" label="物理降温">
            <template #default="scoped">
              <el-form-item size="normal" :prop="`fillTableData.${scoped.$index}.physicalCooling`">
                <div style="margin-left: -80px">
                  <el-input v-model="scoped.row.physicalCooling" placeholder="请输入物理降温" />
                </div>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column width="200px" label="CCU心率">
            <template #default="scoped">
              <el-form-item size="normal" :prop="`fillTableData.${scoped.$index}.ccuHeartRate`">
                <div style="margin-left: -80px">
                  <el-input v-model="scoped.row.ccuHeartRate" placeholder="请输入CCU心率" />
                </div>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column width="200px" label="新生儿箱温">
            <template #default="scoped">
              <el-form-item
                size="normal"
                :prop="`fillTableData.${scoped.$index}.newbornsIncubator`"
              >
                <div style="margin-left: -80px">
                  <el-input v-model="scoped.row.newbornsIncubator" placeholder="请输入新生儿温箱" />
                </div>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column width="200px" label="血酮">
            <template #default="scoped">
              <el-form-item size="normal" :prop="`fillTableData.${scoped.$index}.bloodKetone`">
                <div style="margin-left: -80px">
                  <el-input v-model="scoped.row.bloodKetone" placeholder="请输入血酮" />
                </div>
              </el-form-item>
            </template>
          </el-table-column> -->
        </el-table>
      </el-form>
    </div>
  </el-card>

  <!-- 值测量一次 -->
  <el-card shadow="always" style="margin-top: 10px">
    <div class="fix-content">
      <div class="left-content">
        <el-form
          :model="form"
          ref="form"
          :rules="rules"
          label-width="100px"
          :inline="false"
          size="normal"
        >
          <el-form-item style="width: 300px" label="体重(kg)" size="normal">
            <div style="display: flex">
              <el-input
                placeholder="请输入体重"
                clearable
                v-model="formData.weight"
                @input="handleInput(formData, formData.weight, 4)"
              />
              <el-select
                v-model="formData.weightUnit"
                placeholder="请选择"
                @change="temperChange(formData, 4)"
              >
                <el-option
                  v-for="item in measurement_select_type"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </div>
          </el-form-item>
          <el-form-item class="sub-spacing" style="width: 300px" label="腹围(cm)" size="normal">
            <div style="display: flex">
              <el-input
                v-model="formData.waistCircumference"
                placeholder="请输入腹围"
                clearable
                @input="handleInput(formData, formData.waistCircumference, 5)"
              />
              <el-select
                v-model="formData.waistCircumferenceUnit"
                placeholder="请选择"
                @change="temperChange(formData, 5)"
              >
                <el-option
                  v-for="item in measurement_select_type"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </div>
          </el-form-item>
          <el-form-item class="sub-spacing" style="width: 300px" label="身高(cm)" size="normal">
            <div style="display: flex">
              <el-input
                placeholder="请输入身高"
                clearable
                v-model="formData.height"
                @input="handleInput(formData, formData.height, 6)"
              />
              <el-select
                v-model="formData.heightUnit"
                placeholder="请选择"
                @change="temperChange(formData, 6)"
              >
                <el-option
                  v-for="item in measurement_select_type"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </div>
          </el-form-item>
          <el-form-item class="sub-spacing" style="width: 300px" label="皮试阳性" size="normal">
            <el-input v-model="formData.skinTest" placeholder="请输入皮试阳性" clearable />
          </el-form-item>
          <el-form-item
            v-model="formData.urineVolume"
            class="sub-spacing"
            style="width: 300px"
            label="尿量(ml)"
            size="normal"
          >
            <el-input
              v-model="formData.urineVolume"
              placeholder="请输入尿量"
              @input="handleInput(formData, formData.urineVolume)"
            />
          </el-form-item>
          <el-form-item
            v-model="formData.urineVolume"
            class="sub-spacing"
            style="width: 300px"
            label="其他(ml)"
            size="normal"
          >
            <el-input
              v-model="formData.other"
              placeholder="请输入其他"
              @input="handleInput(formData, formData.other)"
            />
          </el-form-item>
          <!-- <el-form-item class="sub-spacing" style="width: 300px" label="大便量(ml)" size="normal">
            <el-input v-model="formData.stoolVolume" placeholder="请输入大便量(ml)" clearable />
          </el-form-item> -->
        </el-form>
      </div>
      <div class="right-content">
        <el-form
          :model="form"
          ref="form"
          :rules="rules"
          label-width="150px"
          :inline="false"
          size="normal"
        >
          <el-form-item style="width: 360px" label="小便次数(次)" size="normal">
            <div style="display: flex">
              <el-input
                v-model="formData.urinationFrequency"
                placeholder="请输入小便次数"
                clearable
                @input="handleInput(formData, formData.urinationFrequency, 7)"
              />
              <el-select
                v-model="formData.urinationFrequencyUnit"
                placeholder="请选择"
                @change="temperChange(formData, 7)"
              >
                <el-option
                  v-for="item in urination_frequency_unit"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </div>
          </el-form-item>
          <el-form-item class="sub-spacing" style="width: 360px" label="大便次数(次)" size="normal">
            <div style="display: flex">
              <el-input
                v-model="formData.stoolFrequency"
                placeholder="请输入大便次数"
                clearable
                @input="handleInput(formData, formData.stoolFrequency, 8)"
              />
              <el-select
                v-model="formData.stoolFrequencyUnit"
                placeholder="请选择"
                @change="temperChange(formData, 8)"
              >
                <el-option
                  v-for="item in stoolfrequency_unit"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </div>
          </el-form-item>
          <!-- <el-form-item class="sub-spacing" style="width: 360px" label="灌肠次数(次)" size="normal">
            <el-input
              v-model="formData.enemaFrequency"
              placeholder="请输入灌肠次数"
              clearable
              @input="handleInput(formData, formData.enemaFrequency)"
            />
          </el-form-item>
          <el-form-item
            class="sub-spacing"
            style="width: 360px"
            label="灌肠后大便次数(次)"
            size="normal"
          >
            <el-input
              v-model="formData.sfAfterEnema"
              placeholder="请输入灌肠后大便次数"
              @input="handleInput(formData, formData.sfAfterEnema)"
            />
          </el-form-item> -->
          <el-form-item class="sub-spacing" style="width: 360px" label="入量(ml)" size="normal">
            <el-input
              v-model="formData.input"
              placeholder="请输入入量"
              clearable
              @input="handleInput(formData, formData.input)"
            />
          </el-form-item>
          <!-- <el-form-item class="sub-spacing" style="width: 300px" label="出量(ml)" size="normal">
            <el-input v-model="formData.output" placeholder="请输入出量" clearable />
          </el-form-item>
          <el-form-item
            v-model="formData.urineVolume"
            class="sub-spacing"
            style="width: 300px"
            label="尿量(ml)"
            size="normal"
          >
            <el-input v-model="formData.urineVolume" placeholder="请输入尿量" />
          </el-form-item> -->
        </el-form>
      </div>
    </div>
  </el-card>
</template>

<script setup>
import { patientInfo } from '../../../inpatientDoctor/home/store/patient';
import { ElMessage } from 'element-plus';
import { getTemperatureType, getTemperatureHistory, addRecord } from '../api/api';
import { nextTick } from 'vue';
import dayjs from 'dayjs';
import moment from 'moment';
const { proxy } = getCurrentInstance();
const {
  temperature_select_type,
  measurement_select_type,
  breathe_unit,
  urination_frequency_unit,
  stoolfrequency_unit,
  adm_way,
  medcas_qlt_code,
  sys_yes_no,
  naty,
  patn_rlts,
} = proxy.useDict(
  'temperature_select_type',
  'measurement_select_type',
  'breathe_unit',
  'urination_frequency_unit',
  'stoolfrequency_unit',
  'adm_way',
  'medcas_qlt_code',
  'sys_yes_no',
  'naty',
  'patn_rlts'
);
const formRef = ref('');
const searchFormData = ref({
  recordingDate: '',
  temperatureType: '',
});
const temOptions = ref([]);
const emit = defineEmits(['onSearcTem']);
/*
recordingDate 记录时间
timePoint 记录时间
temperature 体温
temperatureUnit 单位
temperature 心率
pulse 脉搏
breathe 呼吸次数
bloodOxygen 血氧
bloodGlucose 血糖
physicalCooling 物理降温
ccuHeartRate CCU心率
newbornsIncubator 新生儿温箱
bloodKetone 血酮
height 身高
waistCircumference 腹围
urinationFrequency 小便次数
stoolFrequency 大便次数
stoolFrequencyUnit 大变次数符号
enemaFrequency 灌肠次数
sfAfterEnema 灌肠后大便次数
output 出量
input 入量
urineVolume 尿量
stoolVolume 大便量
systolicPressure 收缩压
diastolicPressure 舒张压
painScore 疼痛等级
skinTest 皮试阳性
other 其他
bloodPressure 血压
*/
const systolic = (item, type) => {
  item.bloodPressure = item.systolicPressure + '/' + item.diastolicPressure;
  if (type == 1) {
    handleInput(item, item.systolicPressure, 3);
  } else {
    handleInput(item, item.diastolicPressure, 3);
  }
};
// 拼接血压
const selectTimeChange = (time) => {
  searchData();
};

const timePointTime = (value) => {
  let time = '';
  if (value == '0200') {
    time = '2:00';
  } else if (value == '0600') {
    time = '6:00';
  } else if (value == '1000') {
    time = '10:00';
  } else if (value == '1400') {
    time = '14:00';
  } else if (value == '1800') {
    time = '18:00';
  } else if (value == '2200') {
    time = '22:00';
  }
  return time;
};
// 表单数据
const formData = ref({
  height: '',
  heightUnit: '',
  weight: '',
  weightUnit: '',
  urinationFrequency: '',
  urinationFrequencyUnit: '',
  waistCircumference: '',
  waistCircumferenceUnit: '',
  stoolFrequency: '',
  stoolFrequencyUnit: '',
  enemaFrequency: '',
  stoolVolume: '',
  sfAfterEnema: '',
  output: '',
  input: '',
  urineVolume: '',
  systolicPressure: '',
  skinTest: '',
  other: '',
  fillTableData: [
    {
      timePoint: '0200',
      temperature: '',
      temperatureUnit: '',
      heartRate: '',
      pulse: '',
      breathe: '',
      breatheUnit: '',
      bloodOxygen: '',
      bloodGlucose: '',
      physicalCooling: '',
      ccuHeartRate: '',
      newbornsIncubator: '',
      bloodKetone: '',
      height: '',
      waistCircumference: '',
      stoolFrequency: '',
      enemaFrequency: '',
      sfAfterEnema: '',
      output: '',
      input: '',
      urineVolume: '',
      stoolVolume: '',
      systolicPressure: '',
      diastolicPressure: '',
      pressureUnit: '',
      painScore: '',
      bloodPressure: '',
    },
    {
      timePoint: '0600',
      temperature: '',
      temperatureUnit: '',
      heartRate: '',
      pulse: '',
      breathe: '',
      breatheUnit: '',
      bloodOxygen: '',
      bloodGlucose: '',
      physicalCooling: '',
      ccuHeartRate: '',
      newbornsIncubator: '',
      bloodKetone: '',
      height: '',
      waistCircumference: '',
      stoolFrequency: '',
      enemaFrequency: '',
      sfAfterEnema: '',
      output: '',
      input: '',
      urineVolume: '',
      stoolVolume: '',
      systolicPressure: '',
      diastolicPressure: '',
      pressureUnit: '',
      painScore: '',
      bloodPressure: '',
    },
    {
      timePoint: '1000',
      temperature: '',
      temperatureUnit: '',
      heartRate: '',
      pulse: '',
      breathe: '',
      breatheUnit: '',
      bloodOxygen: '',
      bloodGlucose: '',
      physicalCooling: '',
      ccuHeartRate: '',
      newbornsIncubator: '',
      bloodKetone: '',
      height: '',
      waistCircumference: '',
      stoolFrequency: '',
      enemaFrequency: '',
      sfAfterEnema: '',
      output: '',
      input: '',
      urineVolume: '',
      stoolVolume: '',
      systolicPressure: '',
      diastolicPressure: '',
      pressureUnit: '',
      painScore: '',
      bloodPressure: '',
    },
    {
      timePoint: '1400',
      temperature: '',
      temperatureUnit: '',
      heartRate: '',
      pulse: '',
      breathe: '',
      breatheUnit: '',
      bloodOxygen: '',
      bloodGlucose: '',
      physicalCooling: '',
      ccuHeartRate: '',
      newbornsIncubator: '',
      bloodKetone: '',
      height: '',
      waistCircumference: '',
      stoolFrequency: '',
      enemaFrequency: '',
      sfAfterEnema: '',
      output: '',
      input: '',
      urineVolume: '',
      stoolVolume: '',
      systolicPressure: '',
      diastolicPressure: '',
      pressureUnit: '',
      painScore: '',
      bloodPressure: '',
    },
    {
      timePoint: '1800',
      temperature: '',
      temperatureUnit: '',
      heartRate: '',
      pulse: '',
      breathe: '',
      breatheUnit: '',
      bloodOxygen: '',
      bloodGlucose: '',
      physicalCooling: '',
      ccuHeartRate: '',
      newbornsIncubator: '',
      bloodKetone: '',
      height: '',
      waistCircumference: '',
      stoolFrequency: '',
      enemaFrequency: '',
      sfAfterEnema: '',
      output: '',
      input: '',
      urineVolume: '',
      stoolVolume: '',
      systolicPressure: '',
      diastolicPressure: '',
      pressureUnit: '',
      painScore: '',
      bloodPressure: '',
    },
    {
      timePoint: '2200',
      temperature: '',
      temperatureUnit: '',
      heartRate: '',
      pulse: '',
      breathe: '',
      breatheUnit: '',
      bloodOxygen: '',
      bloodGlucose: '',
      physicalCooling: '',
      ccuHeartRate: '',
      newbornsIncubator: '',
      bloodKetone: '',
      height: '',
      waistCircumference: '',
      stoolFrequency: '',
      enemaFrequency: '',
      sfAfterEnema: '',
      output: '',
      input: '',
      urineVolume: '',
      stoolVolume: '',
      systolicPressure: '',
      diastolicPressure: '',
      pressureUnit: '',
      painScore: '',
      bloodPressure: '',
    },
  ],
});
// 校验规则
const rules = {
  zt1: [{ required: true, message: '请选择目的仓库', trigger: ['blur', 'change'] }],
  tw: [{ required: true, message: '请输入体温', trigger: ['blur', 'change'] }],
  mb: [{ required: true, message: '请输入mb', trigger: ['blur', 'change'] }],
};
const editForm = ref({
  id: '',
  definitionId: '',
  definitionBusNo: '',
  contentJson: '',
  statusEnum: 1, // 0草稿/暂存 1提交 2归档 3修改
  organizationId: 0,
  encounterId: '',
  patientId: '',
  recordTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
  createBy: '',
  source: '4',
});
// 获取当前时间时分秒
const getTime = () => {
  let time = '';
  const currentDate = dayjs().format('YYYY-MM-DD HH:mm:ss');
  const timeArr = currentDate.split(' ');
  if (timeArr && timeArr.length > 1) {
    time = timeArr[1];
  }
  return time;
};
// 保存数据
const saveData = () => {
  if (!patientInfo.value) {
    ElMessage({
      type: 'error',
      message: '请选择患者',
    });
  }
  formRef.value.validate(async (res) => {
    if (res) {
      const params = {
        ...formData.value,
        recordTime: searchFormData.value.recordingDate,
      };
      params.fillTableData.forEach((item) => {
        item.recordTime = searchFormData.value.recordingDate;
      });

      editForm.value.contentJson = JSON.stringify(formData.value);
      editForm.value.encounterId = patientInfo.value.encounterId;
      editForm.value.patientId = patientInfo.value.patientId;
      editForm.value.recordTime = searchFormData.value.recordingDate + ' ' + getTime();
      console.log('dayjs()=================>', JSON.stringify(editForm));

      await addRecord(editForm.value);
      if (editForm.value.id && editForm.value.id.length > 0) {
        ElMessage.success('体温单修改成功');
      } else {
        ElMessage.success('体温单保存成功');
      }
      emit('onSearcTem');
    }
  });
};
// 查询数据
const searchData = async () => {
  const params = {
    recordTime: searchFormData.value.recordingDate, //查询时间
    encounterId: patientInfo.value.encounterId, //病历id
    patientId: patientInfo.value.patientId, //患者ID
    definitionId: editForm.value.definitionId, //体温单类型id
  };
  console.log('property===========>', JSON.stringify(params));

  const res = await getTemperatureHistory(params);
  if (res.data && res.data.length > 0) {
    editForm.value.id = res.data[res.data.length - 1]['id'];
    formData.value = JSON.parse(res.data[res.data.length - 1]['contentJson']);
  } else {
    resetData('1');
  }
};
// const onSearch = async () => {
//   if (editForm.value.definitionId.length <= 0) {
//     return;
//   }

//   const params = {
//     recordTime: searchFormData.value.recordingDate, //查询时间
//     encounterId: patientInfo.value.encounterId, //病历id
//     patientId: patientInfo.value.patientId, //患者ID
//     definitionId: editForm.value.definitionId, //体温单类型id
//   };
//   console.log('property===========>', JSON.stringify(params));

//   const res = await getTemperatureHistory(params);
//   if (res.data && res.data.length > 0) {
//     editForm.value.id = res.data[res.data.length - 1]['id'];
//     formData.value = JSON.parse(res.data[res.data.length - 1]['contentJson']);
//   } else {
//     resetData('1');
//   }
// };
// 重置数据
const resetData = (type = '0') => {
  if (type == '1') {
    editForm.value.id = '';
  }
  formData.value = {
    height: '',
    waistCircumference: '',
    stoolFrequency: '',
    enemaFrequency: '',
    stoolVolume: '',
    sfAfterEnema: '',
    output: '',
    input: '',
    urineVolume: '',
    systolicPressure: '',
    fillTableData: [
      {
        timePoint: '0200',
        temperature: '',
        heartRate: '',
        pulse: '',
        breathe: '',
        breatheUnit: '',
        bloodOxygen: '',
        bloodGlucose: '',
        physicalCooling: '',
        ccuHeartRate: '',
        newbornsIncubator: '',
        bloodKetone: '',
        height: '',
        waistCircumference: '',
        stoolFrequency: '',
        enemaFrequency: '',
        sfAfterEnema: '',
        output: '',
        input: '',
        urineVolume: '',
        stoolVolume: '',
        systolicPressure: '',
        diastolicPressure: '',
      },
      {
        timePoint: '0600',
        temperature: '',
        heartRate: '',
        pulse: '',
        breathe: '',
        breatheUnit: '',
        bloodOxygen: '',
        bloodGlucose: '',
        physicalCooling: '',
        ccuHeartRate: '',
        newbornsIncubator: '',
        bloodKetone: '',
        height: '',
        waistCircumference: '',
        stoolFrequency: '',
        enemaFrequency: '',
        sfAfterEnema: '',
        output: '',
        input: '',
        urineVolume: '',
        stoolVolume: '',
        systolicPressure: '',
        diastolicPressure: '',
      },
      {
        timePoint: '1000',
        temperature: '',
        heartRate: '',
        pulse: '',
        breathe: '',
        breatheUnit: '',
        bloodOxygen: '',
        bloodGlucose: '',
        physicalCooling: '',
        ccuHeartRate: '',
        newbornsIncubator: '',
        bloodKetone: '',
        height: '',
        waistCircumference: '',
        stoolFrequency: '',
        enemaFrequency: '',
        sfAfterEnema: '',
        output: '',
        input: '',
        urineVolume: '',
        stoolVolume: '',
        systolicPressure: '',
        diastolicPressure: '',
      },
      {
        timePoint: '1400',
        temperature: '',
        heartRate: '',
        pulse: '',
        breathe: '',
        breatheUnit: '',
        bloodOxygen: '',
        bloodGlucose: '',
        physicalCooling: '',
        ccuHeartRate: '',
        newbornsIncubator: '',
        bloodKetone: '',
        height: '',
        waistCircumference: '',
        stoolFrequency: '',
        enemaFrequency: '',
        sfAfterEnema: '',
        output: '',
        input: '',
        urineVolume: '',
        stoolVolume: '',
        systolicPressure: '',
        diastolicPressure: '',
      },
      {
        timePoint: '1800',
        temperature: '',
        heartRate: '',
        pulse: '',
        breathe: '',
        breatheUnit: '',
        bloodOxygen: '',
        bloodGlucose: '',
        physicalCooling: '',
        ccuHeartRate: '',
        newbornsIncubator: '',
        bloodKetone: '',
        height: '',
        waistCircumference: '',
        stoolFrequency: '',
        enemaFrequency: '',
        sfAfterEnema: '',
        output: '',
        input: '',
        urineVolume: '',
        stoolVolume: '',
        systolicPressure: '',
        diastolicPressure: '',
      },
      {
        timePoint: '2200',
        temperature: '',
        heartRate: '',
        pulse: '',
        breathe: '',
        breatheUnit: '',
        bloodOxygen: '',
        bloodGlucose: '',
        physicalCooling: '',
        ccuHeartRate: '',
        newbornsIncubator: '',
        bloodKetone: '',
        height: '',
        waistCircumference: '',
        stoolFrequency: '',
        enemaFrequency: '',
        sfAfterEnema: '',
        output: '',
        input: '',
        urineVolume: '',
        stoolVolume: '',
        systolicPressure: '',
        diastolicPressure: '',
      },
    ],
  };
};
// 获取体温单类型
const getTemRequset = async () => {
  resetData();
  const res = await getTemperatureType({ menuEnum: 4 });
  const newData = res.data?.map((item) => {
    let obj = {
      label: item.name,
      value: item.id,
    };
    return obj;
  });
  // 选择类型
  temOptions.value = newData;
  //默认选中第一个
  nextTick(() => {
    if (res.data?.length > 0) {
      const obj = res.data[0];
      searchFormData.value.temperatureType = obj.id;
      editForm.value.definitionId = obj.id;
      editForm.value.definitionBusNo = obj.busNo;
      // 第一次进入查询当天数据
      searchData();
    }
  });
};
// 获取体温单类型
const onActionEdit = async (type) => {
  const beginTime = moment(new Date()).format('YYYY-MM-DD');
  searchFormData.value.recordingDate = beginTime;
  getTemRequset();
};
// 根据code获取文字
const selectContent = (code, type) => {
  let title = '';
  if (type == 1) {
    if (code == 1) {
      title = '拒测';
    } else if (code == 2) {
      title = '外出';
    } else {
      title = '请假';
    }
  } else if (type == 2) {
    if (code == 1) {
      title = '@';
    }
  } else if (type == 3) {
    if (code == 1) {
      title = '拒测';
    } else if (code == 2) {
      title = '外出';
    } else {
      title = '请假';
    }
  } else if (type == 4 || type == 5 || type == 6) {
    if (code == 1) {
      title = '卧床';
    } else if (code == 2) {
      title = '未测';
    }
  } else if (type == 7) {
    if (code == 1) {
      title = '※';
    } else if (code == 2) {
      title = 'C';
    }
  } else if (type == 8) {
    if (code == 1) {
      title = '※';
    } else if (code == 2) {
      title = '☆';
    } else {
      title = '人工肛门';
    }
  }
  return title;
};
const temperChange = (row, type = 0) => {
  if (type == 1) {
    row.temperature = selectContent(row.temperatureUnit, type);
  } else if (type == 2) {
    row.breathe = selectContent(row.breatheUnit, type);
  } else if (type == 3) {
    row.systolicPressure = selectContent(row.pressureUnit, type);
    row.diastolicPressure = selectContent(row.pressureUnit, type);
    row.bloodPressure = selectContent(row.pressureUnit, type);
  } else if (type == 4) {
    row.weight = selectContent(row.weightUnit, type);
  } else if (type == 5) {
    row.waistCircumference = selectContent(row.waistCircumferenceUnit, type);
  } else if (type == 6) {
    row.height = selectContent(row.heightUnit, type);
  } else if (type == 7) {
    row.urinationFrequency = selectContent(row.urinationFrequencyUnit, type);
  } else if (type == 8) {
    console.log('uuuuuu=========>', row.stoolFrequencyUnit);
    row.stoolFrequency = selectContent(row.stoolFrequencyUnit, type);
  }
};
// 正则只能输入数字（包含小数）
const handleInput = (row, text, type = 0) => {
  // 你可以在这里添加更多的逻辑，比如限制小数点后的位数等
  if (type == 1) {
    row.temperatureUnit = '';
  } else if (type == 2) {
    row.breatheUnit = '';
  } else if (type == 3) {
    row.pressureUnit = '';
  } else if (type == 4) {
    row.weightUnit = '';
  } else if (type == 5) {
    row.waistCircumferenceUnit = '';
  } else if (type == 6) {
    row.heightUnit = '';
  } else if (type == 7) {
    row.urinationFrequencyUnit = '';
  } else if (type == 8) {
    row.stoolFrequencyUnit = '';
  }

  // 例如，限制小数点后最多两位数
  const regex = /^\d*\.?\d{0,2}$/;
  if (!regex.test(text)) {
    ElMessage({
      type: 'error',
      message: '只能输入数字',
    });
  } else {
    // row.value = newValue; // 更新原始值
  }
};
defineExpose({ saveData, onActionEdit });
</script>

<style scoped>
.el-form-item {
  /* background: red; */
  margin: 0;
}
.domain {
  height: 100px;
  display: flex;
  align-items: center;
  .search-button {
    margin-left: 20px;
  }
}
.fix-content {
  /* background: red; */
  /* height: 160px; */
  display: flex;
  margin-top: 20px;
  .left-content {
    flex: 1;
    display: flex;
    justify-content: center;
    /* background: green; */
    /* .son-content {
      width: 100%;
      padding: 0 100px;
      background: yellow;
    } */
  }
  .right-content {
    flex: 1;
    display: flex;
    justify-content: center;
    /* align-items: center; */
  }
  .sub-spacing {
    margin-top: 10px;
  }
}
</style>
