<template>
  <div class="page-card">
    <h3>健康监测</h3>
    <el-form :model="form" label-width="140px">
      <el-form-item label="长者ID"><el-input v-model="form.elderId"/></el-form-item>
      <el-form-item label="体温"><el-input v-model="form.temperature"/></el-form-item>
      <el-form-item label="血压">
        <div style="display:flex; gap:8px;">
          <el-input v-model="form.bpSystolic" placeholder="收缩压" />
          <el-input v-model="form.bpDiastolic" placeholder="舒张压" />
        </div>
      </el-form-item>
      <el-form-item label="心率"><el-input v-model="form.heartRate"/></el-form-item>
      <el-form-item label="备注"><el-input v-model="form.note"/></el-form-item>
      <el-form-item label="记录时间"><el-date-picker v-model="form.recordTime" type="datetime"/></el-form-item>
      <el-button type="primary" @click="create">保存</el-button>
    </el-form>

    <div style="margin-top: 16px;">
      <el-input v-model="filterElderId" placeholder="长者ID" style="width: 200px;" />
      <el-button @click="load" style="margin-left: 8px;">查询</el-button>
      <el-table :data="items" stripe style="margin-top: 12px;">
        <el-table-column prop="elderId" label="长者ID" width="100" />
        <el-table-column prop="temperature" label="体温" />
        <el-table-column prop="bpSystolic" label="收缩压" />
        <el-table-column prop="bpDiastolic" label="舒张压" />
        <el-table-column prop="heartRate" label="心率" />
        <el-table-column prop="recordTime" label="记录时间" />
      </el-table>
    </div>
  </div>
</template>

<script>
import { nurseHealthCreate, nurseHealthList } from "../../api";
import { formatDateTime } from "../../utils/date";

export default {
  data() {
    return {
      form: { elderId: "", temperature: "", bpSystolic: "", bpDiastolic: "", heartRate: "", note: "", recordTime: "" },
      filterElderId: "",
      items: []
    };
  },
  methods: {
    async create() {
      try {
        const payload = { ...this.form, recordTime: formatDateTime(this.form.recordTime) };
        await nurseHealthCreate(payload);
        this.$message.success("保存成功");
      } catch (e) {
        this.$message.error(e.message || "保存失败");
      }
    },
    async load() {
      if (!this.filterElderId) return;
      try {
        const res = await nurseHealthList(this.filterElderId);
        this.items = res.data.data;
      } catch (e) {
        this.$message.error(e.message || "加载失败");
      }
    }
  }
};
</script>


