<template>
  <div class="container-wrapper">
    <div class="content">
      <div class="left">
        <div class="left-top">
          <Panel title="日历">
            <Calendar></Calendar>
          </Panel>
        </div>
        <div class="left-bottom">
          <Panel title="医生列表">
            <div class="search" style="padding: 0 24px">
              <el-input v-model="keyword" placeholder="搜索医生"
                        @keydown.enter="initDoctor"></el-input>
            </div>
            <div class="content_list" style="padding: 0 24px">
              <div class="role_list">
                <ul>
                  <li v-for="(item, index) in roleList" :key="index"
                      @click="openDialog(item,index)" :class="{active:isShowNum==index}" >
                    <span class="name">{{ item.name }}</span>
                    <span class="section_name">{{ item.sectionNames }}</span>
                    <span class="btn">挂号</span>
                  </li>
                </ul>
              </div>
            </div>
          </Panel>
        </div>

      </div>
      <div class="right">
        <Panel title="挂号列表">
          <div class="right-content">
            <div class="top">
              <div class="date">
                <el-date-picker
                    v-model="selectedDate"
                    type="daterange"
                    range-separator="-"
                    @change="handleDateChange"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间"
                />
              </div>
            </div>
            <div class="middle">
              <List :patientList="patientList" @rowClick="rowClick"></List>
            </div>
            <div class="bottom">
              <div class="page_btn_list">
                <el-pagination
                    background
                    layout="prev, pager, next"
                    :page-size="size"
                    :current-page="page"
                    :total="total"
                    @current-change="changePage"
                />
              </div>
            </div>
          </div>
        </Panel>
      </div>
    </div>
    <Edit ref="editRef"  @close="getPatientList"></Edit>
  </div>
</template>
<script setup lang="ts">
import {nextTick, onMounted, ref} from 'vue'
import Picker from "@/components/Picker.vue";
import Mask from "@/components/common/Mask.vue";
import Edit from "@/components/registration/Edit.vue";
import List from "@/components/registration/List.vue";
import {post} from "@/utils/request";
import {formatDate, getToday, formatDateArray} from "@/utils/dateUtils.ts";
import Calendar from "@/components/common/Calendar.vue";
import Panel from "@/components/common/Panel.vue";
import {apiConfig} from "@/assets/config/apiConfig.ts";

const isShowNum = ref(-1)
const roleList = ref<any>([])

onMounted(() => {
  initDoctor()
  getPatientList()
})
const keyword = ref<any>('');

const initDoctor = () => {
  let query = {
    keyword: keyword.value,
    role: 1
  }
  post(apiConfig.organizationMemberSearch, {query: query}).then((res: any) => {
    roleList.value = res
  })
}
const patientList = ref<any>([])
const selectedDate = ref<any>([getToday().start, getToday().end])
const handleDateChange = (date: any[]) => {
  selectedDate.value = formatDateArray(date)
  getPatientList()
}
const getPatientList = () => {
  id.value = null
  post('registration/list', {
    page: page.value,
    size: size.value,
    startDate: selectedDate.value[0],
    endDate: selectedDate.value[1]
  }).then((res: any) => {
    patientList.value = res.list
    total.value = res.total_count
  })
}
const total = ref(0)
const size = ref(20)
const page = ref(1)
const changePage = (page: any) => {
  page.value = page
  getPatientList()
}
const id = ref<any>('')
const rowClick = (row: any) => {
  id.value = row.id
  nextTick(() => {
    editRef.value?.init(row.organizationDoctorId,row.id)
  })
}
const editRef = ref<any>('')
const openDialog = (item: any,index: any) => {
  isShowNum.value=index
  nextTick(() => {
    editRef.value?.init(item.id,null)
  })
}
const close = () => {
  id.value = null
  getPatientList()
}
</script>
<style scoped lang="scss">
.container-wrapper {
  background: none;
  height: 100%;
  padding: 0 24px;
}

.content {
  height: 100%;
  display: flex;

  .left {
    height: 100%;
    width: 319px;
    display: flex;
    flex-direction: column;

    .left-top {
      height: 380px;
    }

    .left-bottom {
      flex: 1;
      min-height: 0;
      margin-top: 20px;
    }

    li {
      height: 50px;
      display: flex;
      font-size: 14px;
      padding: 0 10px;
      border-radius: 5px;
      align-items: center;
      cursor: pointer;

      &:hover {
        background: #4D6DE4;

        .name {
          color: #fff;
        }

        .section_name {
          color: #fff;
        }

        .btn {
          color: #fff;
        }
      }

      .name {
        color: #999;
        width: 100px;
      }

      .section_name {
        flex: 1;
        color: #999;
      }

      .btn {
        width: 50px;
        color: #b9b9ba;
        padding: 5px;
        border-radius: 3px;
      }


    }

    .search {
      margin-top: 10px;
    }

    .content_list {
      margin-top: 10px;
    }

    .active {
      background: #4D6DE4;

      .name {
        color: #fff;
      }

      .section_name {
        color: #fff;
      }

      .btn {
        color: #fff;
      }
    }
  }

  .right {
    margin-left: 20px;
    flex: 1;
    height: 100%;
    min-width: 0;
    .right-content {
      padding-left: 20px;
      display: flex;
      flex-direction: column;
      height: 100%;

      .top {
        height: 40px;
      }

      .middle {
        flex: 1;
        min-height: 0;
        background: #fff;
        display: flex;
        flex-direction: column;

        .date {
          margin: 30px auto 0;
          height: 60px;
        }

        .list {
          flex: 1;
        }
      }

    }

    .bottom {
      width: 100%;
      height: 60px;
      background-color: #FFF;
      box-sizing: border-box;
      padding: 10px;
      position: relative;
      border-top: 1px solid #EEE;
      display: flex;
      justify-content: flex-end;
      align-items: center;
    }
  }
}


</style>