<template>
  <div class="page_patientManagement">
    <div style="position: fixed;width:100%;z-index:99">
    <van-sticky>
      <div class="patientManagementTitle">
        <i class="iconfont icon-zuojiantou jiantou" @click="toReturn"></i>
        <span class="titleName">患者管理</span>
        <div class="iconBox" @click="addPatient">
          <van-icon class="iconOne add" name="plus" />
        </div>
      </div>

     <!-- <div class="searchBox" style="margin-left:10px">
        <el-button type="primary" size="small" @click="commit">脚本</el-button>
      </div> -->

      <div class="searchBox">
        <van-search
          v-model="value"
          placeholder="搜索患者透析号/姓名"
          @search="SearchAllPatient"
          
        />
      </div>
    </van-sticky>
    </div>
    <div class="chooseBox">
      <van-tabs v-model="active" @change="changeActive">
        <van-tab title="全部患者">
          <div class="patientBox" v-if="patients.length > 0">
            <van-list
              v-model="loading"
              finished-text="没有更多了"
              @load="onLoad"
              :finished="finished"
            >
              <div class="patientMain">
                <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>
              </div>
            </van-list>
          </div>
          <div class="noData" v-else>
            <img src="../../assets/images/none.png" alt />
          </div>
        </van-tab>
        <van-tab title="血透患者">
          <Blood :searchValue="value" :seacherActive="active"></Blood>
        </van-tab>
        <van-tab title="慢病患者">
          <Slow :searchValue="value" :seacherActive="active"></Slow>
        </van-tab>
        <van-tab title="会员患者">
          <Member :searchValue="value" :seacherActive="active"></Member>
        </van-tab>
      </van-tabs>
    </div>
    <!-- 弹出层 -->
    <div>
      <van-popup
        v-model="typeShow"
        position="bottom"
        :style="{ height: '40%' }"
      >
        <van-picker
          show-toolbar
          :columns="columns"
          @cancel="onCancel"
          @confirm="onConfirm"
        />
      </van-popup>
    </div>
  </div>
</template>

<script>
import '../../styles/resetStyle.scss'
import {
  getBloodDialysisPatient,
  SearchAllPatient,
  commitDialysisOrder
} from '@/api/patient/patient'
import Slow from '@/pages/patientManagement/components/Slow'
import Member from '@/pages/patientManagement/components/Member'
import Blood from '@/pages/patientManagement/components/Blood'
import { setRem, setHeight } from '@/libs/functionRem'
import { Toast} from 'vant'
export default {
  components: {
    Slow,
    Member,
    Blood
  },
  data () {
    return {
      value: '',
      name_value:'',
      typeShow: false,
      startShow: false,
      endShow: false,
      type: '归转状态',
      columns: [
        '杭州',
        '宁波',
        '温州',
        '嘉兴',
        '湖州',
        '杭州',
        '宁波',
        '温州',
        '嘉兴',
        '湖州'
      ],
      searchVal: '',
      active: 1,
      list: [],
      loading: false,
      finished: false,
      page: 1,
      limit: 10,
      total: 0,
      patients: [],
      searchValue: ''
    }
  },
 
  methods: {
    onCancel () {
      this.typeShow = false
    },
    onConfirm (value) {
      this.type = value
      this.typeShow = false
    },
    onLoad () {
      setTimeout(() => {
        for (let i = 0; i < this.limit; i++) {
          this.list.push(this.list.length + 1)
        }
        // 加载状态结束
        this.loading = false
        if (this.patients.length >= 10) {
          this.page++
          this.getBloodDialysisPatient(this.page, this.limit)
        }
        // 数据全部加载完成
        if (this.list.length >= this.total) {
          this.finished = true
        }
      }, 1000)
    },
    getBloodDialysisPatient () {
      getBloodDialysisPatient(this.page, this.limit).then(response => {
        if (response.data.state == 1) {
          var patient = response.data.data.patient
          let arr = this.patients
          arr.push(...patient)
          this.patients = arr
          var total = response.data.data.total
          this.total = total
        }
      })
    },
    addPatient () {
      this.$router.push('/addPatints')
    },
    toPatientDetail (id) {
      this.$router.push(
        '/patientdetail?patientid=' + id + '&seacherActive=' + this.active
      )
    },
    SearchAllPatient (val) {
      SearchAllPatient(val).then(response => {
        if (response.data.state === 1) {
          var patient = response.data.data.patient
          this.patients = patient
        }
      })
    },
    changeActive (name, title) {
      this.active = name
    },
    toReturn () {
      this.$router.push('/homeIndex')
    },
    commit () {
      Toast.loading({forbidClick: true, duration: 0})
      commitDialysisOrder().then(response => {
        if (response.data.state == 1) {
          var list = response.data.data.list
          Toast.loading({forbidClick: false, duration: 0})
          Toast.success('保存成功!')
        }
      })
    }
    
  },
  created () {
    setRem()
    setHeight()
    // if(this.name_value.length<0){
      this.getBloodDialysisPatient()
    // }else{
    //   this.SearchAllPatient()
    // }
    
  },mounted () {
    setRem()
  },
  watch: {
    value (newVal) {
      if (newVal == '') {
        this.value = newVal
        this.getBloodDialysisPatient()
      } else {
        this.value = newVal
        this.SearchAllPatient(newVal)
      }
    }
  },
  
}
</script>

<style lang="scss" scoped>
.page_patientManagement {
  overflow-y: auto;
  height: 100%;
  .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: 2rem;
  }
  .titleName {
    font-size: 1.125rem;
    font-weight: 600;
    color: #000;
  }
  .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;
    background: #fff;
    .patientMain {
      > div:last-child {
        border: none;
      }
    }
    .patientOne {
      display: flex;
      align-items: center;
      height: 3.75rem;
      font-size: 1rem;
      border-bottom: 1px solid #e5e5e5;
      img {
        width: 2.5rem;
        height: 2.5rem;
        margin-right: 0.875rem;
      }
    }
  }
  .noData {
    width: 12.5rem;
    height: 12.5rem;
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    img {
      width: 100%;
      height: 100%;
    }
  }
}
::-webkit-scrollbar {
  width: 0;
}
</style>

<style lang="scss">
.page_patientManagement {
  .searchBox {
    .van-search__content {
      border-radius: 1.875rem;
    }
    .van-cell__value {
      display: flex;
      align-items: center;
    }
    .van-field__body {
      width: 100%;
    }
  }
  .chooseBox {
    // margin-top: -2px;
    .van-tabs__wrap {
      position: fixed;
      width: 100%;
      top: 6.375rem;
    }
    .van-tabs__content {
      padding-top: 9.25rem;
    }
  }
  .van-tab--active {
    font-size: 1rem;
    color: #000;
    font-weight: bold;
  }
  .van-tabs__line {
    background-color: #5b98ff;
  }
}
</style>
