<template>
  <div class="page_patientManagement">
    <div class="toolBox">
      <div class="toolOne" @click="typeShow = true">
        <div style="display: flex;align-items: center;">
          {{ type }}
          <van-icon name="arrow-down" />
        </div>
      </div>
      <div class="toolOne" @click="typeShowOne = true">
        <div style="display: flex;align-items: center;">
          {{ typeOne }}
          <van-icon name="arrow-down" />
        </div>
      </div>
    </div>
    <div class="patientBox">
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
      >
        <div
          class="patientOne"
          v-for="(item, index) in patients"
          :key="index"
          @click="toPatientDetail(item.id)"
        >
          <img :src="item.avatar" alt />
          <p>{{ item.name }}</p>
        </div>
      </van-list>
    </div>
    <!-- 弹出层 -->
    <div>
      <van-popup
        v-model="typeShow"
        position="bottom"
        :style="{ height: '40%' }"
      >
        <van-picker
          show-toolbar
          :columns="columns"
          @cancel="onCancel"
          @confirm="onConfirm"
        />
      </van-popup>
      <van-popup
        v-model="typeShowOne"
        position="bottom"
        :style="{ height: '40%' }"
      >
        <van-picker
          show-toolbar
          :columns="columnsOne"
          @cancel="onCancelOne"
          @confirm="onConfirmOne"
        />
      </van-popup>
    </div>
  </div>
</template>

<script>
import {
  getAllBloodDialysisPatient,
  SearchAllBlood
} from "@/api/patient/patient";
export default {
  props: {
    searchValue: String
  },
  data() {
    return {
      value: "",
      typeShow: false,
      typeShowOne: false,
      startShow: false,
      endShow: false,
      type: "归转状态",
      typeOne: "患者来源",
      columns: ["留治", "转出"],
      columnsOne: ["门诊", "转院"],
      searchVal: "",
      active: 0,
      list: [],
      loading: false,
      finished: false,
      page: 1,
      limit: 10,
      total: 0,
      value1: 0,
      value2: "a",
      value3: "a",
      option1: [
        { text: "患者类型", value: 0 },
        { text: "新款商品新款商品新款商品", value: 1 },
        { text: "活动商品", value: 2 }
      ],
      option2: [
        { text: "转规状态", value: "a" },
        { text: "好评排序", value: "b" },
        { text: "销量排序", value: "c" }
      ],
      option3: [
        { text: "患者来源", value: "a" },
        { text: "好评排序", value: "b" },
        { text: "销量排序", value: "c" }
      ],
      list: [],
      loading: false,
      finished: false,
      patients: []
    };
  },
  methods: {
    onCancel(value) {
      this.typeShow = false;
    },
    onConfirm(value) {
      this.type = value;
      this.typeShow = false;
    },
    onCancelOne(value) {
      this.typeOne = value;
      this.typeShowOne = false;
    },
    onConfirmOne(value) {
      this.typeOne = value;
      this.typeShowOne = false;
    },
    getAllBloodDialysisPatient() {
      getAllBloodDialysisPatient(this.page, this.limit).then(response => {
        if (response.data.state === 1) {
          var patient = response.data.data.bloodpatient;
          let arr = this.patients;
          arr.push(...patient);
          this.patients = arr;
          var total = response.data.data.total;
          this.total = total;
        }
      });
    },
    onLoad() {
      setTimeout(() => {
        for (let i = 0; i < this.limit; i++) {
          this.list.push(this.list.length + 1);
        }
        // 加载状态结束
        this.loading = false;
        console.log("长度", this.patients.length);
        if (this.patients.length >= 10) {
          this.page++;
          this.getAllBloodDialysisPatient(this.page, this.limit);
        }
        console.log("页数", this.page);
        // 数据全部加载完成
        if (this.list.length >= this.total) {
          this.finished = true;
        }
      }, 1000);
    },
    toPatientDetail(id) {
      this.$router.push("/patientdetail?patientid=" + id);
    },
    SearchAllBlood(val) {
      SearchAllBlood(val).then(response => {
        if (response.data.state === 1) {
          var bloodpatient = response.data.data.bloodPatient;
          console.log("血透病人", bloodpatient);
        }
      });
    }
  },
  created() {
    console.log(this.searchValue);
    this.getAllBloodDialysisPatient();
  },
  watch: {
    searchValue(newVal) {
      console.log("监听", newVal);
      this.SearchAllBlood(newVal);
    }
  }
};
</script>

<style lang="scss" scoped>
.page_patientManagement {
  overflow-y: auto;
  height: 100%;
  background: #fff;
  .patientManagementTitle {
    background: #fff;
    padding: 0 1.125rem;
    height: 3.125rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .jiantou {
    font-size: 1.5rem;
    font-weight: 600;
    margin-right: 3rem;
  }
  .titleName {
    font-size: 1.125rem;
    font-weight: 600;
  }
  .iconBox {
    display: flex;
    align-items: center;
    float: right;
  }
  .iconOne {
    font-size: 1.5rem;
  }
  .add {
    margin-left: 1.25rem;
  }
  .toolBox {
    display: flex;
    height: 3.125rem;

    align-items: center;

    .toolOne {
      width: 5.625rem;
      height: 1.875rem;
      background: rgba(246, 246, 246, 1);
      border-radius: 5px;
      text-align: center;
      font-size: 0.8125rem;
      color: #8d8d8d;
      display: flex;
      align-items: center;
      justify-content: space-around;
      margin-left: 0.875rem;
    }
  }
  .van-dropdown-menu__title {
    width: 5.625rem;
    height: 1.875rem;
    line-height: 1.875rem;
    background: rgba(246, 246, 246, 1);
    border-radius: 5px;
    color: #8d8d8d;
    font-size: 0.875rem;
  }
  .van-dropdown-menu__title::after {
    right: 0.5rem;
  }
  .patientBox {
    padding: 0 0.875rem;
    .patientOne {
      display: flex;
      align-items: center;
      height: 3.75rem;
      img {
        width: 2.5rem;
        height: 2.5rem;
        margin-right: 0.875rem;
      }
    }
  }
}
::-webkit-scrollbar {
  width: 0;
}
</style>

<style lang="scss">
.page_patientManagement {
  .searchBox {
    .van-cell__value {
      display: flex;
      align-items: center;
    }
    .van-field__body {
      width: 100%;
    }
  }
}
</style>
