<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="9%">序号</th>
          <th style="color: white" width="15.4%">日期</th>
          <th style="color: white" width="42%">宣教</th>
        </tr>

        <tr
          style="background: #ebf1f7"
          v-for="(item, index) in tableDate"
          :key="index"
          :value="item.value"
        >
          <td width="9%">{{ item.id }}</td>
          <td width="15.4%">
            {{ parseTime(item.assessment_date, "{y}-{m}-{d}") }}
          </td>
          <td width="42%">{{ item.mission }}</td>
        </tr>
      </table>
    </van-list>
  </div>
</template>

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

export default {
  name: "education",
  created() {
    this.tableDate = [];
    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) {
        return false;
      } else {
        if (response.data.data.total == 0) {
        } else {
          for (let i = 0; i < response.data.data.edus.length; i++) {
            this.tableDate.push(response.data.data.edus[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.edus.length == 0) {
            this.finished = true;
            this.loading = false;
          } else {
            for (let i = 0; i < response.data.data.edus.length; i++) {
              this.tableDate.push(response.data.data.edus[i]);
            }
            this.loading = false;
          }
        }
      });

      // 异步更新数据
      // setTimeout(() => {
      //   for (let i = 0; i < 10; i++) {
      //     this.list.push(this.list.length + 1);
      //   }
      //   // 加载状态结束
      //   this.loading = false;
      //
      //   // 数据全部加载完成
      //   if (this.list.length >= 40) {
      //     this.finished = true;
      //   }
      // }, 500);
    }
  }
};
</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>
