<template>
  <div>
    <van-list
      width="100%"
      v-model="loading"
      :finished="finished"
      @load="onLoad"
    >
      <table class="table">
        <tr style="background: #409EFF">
          <th style="color: white" width="20%">日期</th>
          <th style="color: white" width="20%">班次</th>
          <th style="color: white" width="20%">分区</th>
          <th style="color: white" width="20%">机号</th>
          <th style="color: white" width="20%">治疗模式</th>
        </tr>

        <tr
          style="background: #ebf1f7"
          v-for="(item, index) in tableDate"
          :key="index"
          :value="item.value"
        >
          <td width="20%">
            {{ parseTime(item.schedule_date, "{y}-{m}-{d}") }}
          </td>
          <td width="20%">{{ scheduleType(item.schedule_type) }}</td>
          <td width="20%">{{ item.zone.name }}</td>
          <td width="20%">{{ item.bed.number }}</td>
          <td width="20%">{{ item.mode.name }}</td>
        </tr>
      </table>
    </van-list>
  </div>
</template>

<script>
import { parseTime } from "@/utils";
import { getSchedualList } from "@/api/patient";

export default {
  name: "schedual",
  created() {
    this.tableDate = [];
    let params = {
      page: this.page + 1,
      limit: this.limit,
      patient_id: this.$route.query.patient_id
    };
    getSchedualList(params).then(response => {
      if (response.data.state == 0) {
        return false;
      } else {
        if (response.data.data.schedules.length == 0) {
        } else {
          for (let i = 0; i < response.data.data.schedules.length; i++) {
            this.tableDate.push(response.data.data.schedules[i]);
          }
        }
      }
    });
  },

  data() {
    return {
      tableDate: [],
      loading: false,
      finished: false,
      page: 0,
      limit: 15
    };
  },
  methods: {
    parseTime(time, layout) {
      return parseTime(time, layout);
    },
    onLoad() {
      this.page = this.page + 1;
      let params = {
        page: this.page + 1,
        limit: this.limit,
        patient_id: this.$route.query.patient_id
      };
      getAllEducationList(params).then(response => {
        if (response.data.state == 0) {
          this.finished = true;
          this.loading = false;
          return false;
        } else {
          if (response.data.data.schedules.length == 0) {
            this.finished = true;
            this.loading = false;
          } else {
            for (let i = 0; i < response.data.data.schedules.length; i++) {
              this.tableDate.push(response.data.data.schedules[i]);
            }
            this.loading = false;
          }
        }
      });
    },
    scheduleType(scheduleType) {
      var typeName = "";
      switch (scheduleType) {
        case 1:
          typeName = "上午";
          break;
        case 2:
          typeName = "下午";
          break;
        case 3:
          typeName = "晚上";
          break;

        default:
          break;
      }
      return typeName;
    }
  }
};
</script>

<style scoped lang="scss">
.table {
  background: #ffffff;
  width: 100%;
  overflow: auto;
  font-size: 0.28rem;
  text-align: center;
  border: $border-color;
  padding-bottom: 0.02rem;
  tr {
    padding: 0;
    margin: 0;
    padding: 0.1rem 0;
    th {
      border: none;
      color: #fff;
      padding: 0;
      margin: 0;
      height: 0.88rem;
      font-weight: normal;
      padding: 0.18rem 0;
    }
  }
}
</style>
