﻿<template>
  <div class="page-card">
    <h3>交班记录</h3>
    <el-form :model="form" label-width="120px">
      <el-form-item label="日期"><el-date-picker v-model="form.date" type="date"/></el-form-item>
      <el-form-item label="内容"><el-input v-model="form.content" type="textarea"/></el-form-item>
      <el-button type="primary" @click="create">保存</el-button>
    </el-form>

    <el-table :data="items" stripe style="margin-top: 12px;">
      <el-table-column prop="date" label="日期" />
      <el-table-column prop="content" label="内容" />
    </el-table>
  </div>
</template>

<script>
import { nurseHandoverCreate, nurseHandoverList } from "../../api";
import { formatDate } from "../../utils/date";

export default {
  data() {
    return {
      form: { date: "", content: "" },
      items: []
    };
  },
  created() {
    this.load();
  },
  methods: {
    async load() {
      try {
        const res = await nurseHandoverList();
        this.items = res.data.data;
      } catch (e) {
        this.$message.error(e.message || "load failed");
      }
    },
    async create() {
      try {
        const payload = { ...this.form, date: formatDate(this.form.date) };
        await nurseHandoverCreate(payload);
        this.$message.success("saved");
        this.load();
      } catch (e) {
        this.$message.error(e.message || "save failed");
      }
    }
  }
};
</script>
