<template>
  <!-- <div> -->
    <div class="flexBox" v-loading="loading">
      <div class="screening">
        <!-- <div @click="reloads()">刷新</div> -->
        <ul>
          <li
            v-for="(item, i) in menuList"
            :class="select_index == i ? 'active' : ''"
            @click="menuTabClick(i)"
            :key="i"
          >
            {{ item.label + (item.count > 0 ? "(" + item.count + ")" : "") }}
          </li>

          <el-popover
            v-model="patient_options_visible"
            placement="bottom"
            trigger="click"
          >
            <li slot="reference">
              {{ patient_types[patient_selected].text }}
              <span class="iconfont">&#xe74a;</span>
            </li>
            <div class="popover-demo-content">
              <ul>
                <li
                  v-for="patientType in patient_types"
                  :key="patientType.value"
                  @click="handlePatientType(patientType.value)"
                  :class="
                    patient_selected == patientType.value ? 'tick' : ''
                  "
                >
                  {{ patientType.text }}
                </li>
              </ul>
            </div>
          </el-popover>

          <el-popover
            v-model="zone_options_visible"
            placement="bottom"
            trigger="click"
          >
            <li slot="reference">
              {{ zone_options[zone_selected].text }}
              <span class="iconfont">&#xe74a;</span>
            </li>
            <div class="popover-demo-content">
              <ul>
                <li
                  v-for="(option, index) in zone_options"
                  :key="index"
                  @click="handleZoneChange(index, option)"
                  :class="zone_selected == index ? 'tick' : ''"
                >
                  {{ option.text }}
                </li>
              </ul>
            </div>
          </el-popover>

          <el-popover
            v-model="time_options_visible"
            placement="bottom"
            trigger="click"
          >
            <li slot="reference">
              {{ time_options[time_selected].text }}
              <span class="iconfont">&#xe74a;</span>
            </li>
            <div class="popover-demo-content">
              <ul>
                <li
                  v-for="(option, index) in time_options"
                  :key="index"
                  @click="handleTimeChange(index)"
                  :class="time_selected == index ? 'tick' : ''"
                >
                  {{ option.text }}
                </li>
              </ul>
            </div>
          </el-popover>
        </ul>
      </div>
      <div class="stateBox" ref="waitScroll">
        <div style="margin-top:10px;">今日排班总人数：{{ schedualsLength }}人 上午:{{ schedualsLengthOne }}人 下午:{{ schedualsLengthTwo }}人 晚上:{{ schedualsLengthThree }}人</div>
        <!-- <patient-box class="clearfix" :patients="filtedScheduals "></patient-box> -->
        <div v-for="(item, index) in allPatient" :key="index">
          <h2 class="title" v-if='patient_selected != 2'>{{ item.zone_name }}</h2>
          <patient-box
            class="clearfix"
            :patients="item.scheduals"
            :newIndex='1'
            :information="information"
            :devicetypelist="deviceTypeList"
          ></patient-box>
        </div>
        <div class="NoData" v-if="allPatient.length == 0 && networkStates">
          <img
            style="margin-top: 50px; margin-bottom: 50px"
            src="@/assets/login/data.jpg"
            alt
          />
        </div>
        
        <div
          class="NoData"
          v-if="!networkStates"
          style="display: block;text-align: center;"
        >
          <!--<img style="margin-top: 50px; margin-bottom: 50px" src="@/assets/login/no_network.jpg" alt="">-->
          <p style="margin-top: 100px;font-size: 18px">
            网络异常，请点击重新加载
          </p>
          <van-button
            slot="button"
            size="normal"
            type="info"
            style="display:block;margin:0 auto"
            @click="reloads()"
            >重新加载</van-button
          >
        </div>
        <div class="fixedCalling" v-if="queueConfig.txglsyxs == 1">
          <div class="nowCalling">
            <div class="callingName">{{ fisrtQueueInfo && fisrtQueueInfo.patient_name ? fisrtQueueInfo.patient_name : '暂无叫号' }}</div>
            <p v-if="fisrtQueueInfo != null && fisrtQueueInfo.patient_name">当前叫号</p>
          </div>
          <div class="fixedVolume" @click="call(fisrtQueueInfo && fisrtQueueInfo.patient_id ? fisrtQueueInfo.patient_id : '')">
            <van-icon name="volume" />
          </div>
          <div class="callingName" @click="next(fisrtQueueInfo && fisrtQueueInfo.patient_id ? fisrtQueueInfo.patient_id : '')">下一位</div>
        </div>
      </div>
    </div>
  <!-- </div> -->
</template>

<script>
import Utils from './utils.js'
import axios from 'axios'
import PatientBox from './PatientBox'
import { getWaitingScheduals } from '@/api/dialysis'
import { parseTime } from '@/utils'
import { Popover } from 'vux'
import { Toast } from 'vant'

import {
  getSelectedAreaDataConfigList,
  getSelectedTimesDataConfigList,
  setSelectedAreaDataConfigList,
  setSelectedTimesDataConfigList,
  setWaitTypeSelectedConfig,
  getWaitTypeSelectedConfig,
  setPatientTypeSelectedConfig,
  getPatientTypeSelectedConfig
} from '@/utils/data_config'
import { constants } from 'crypto'
const moment = require('moment')

export default {
  name: 'WaitingArea',
  components: {
    PatientBox,
    Popover
  },
  inject: ['reload'],
  data () {
    return {
      loading: false,
      menuList: [
        { value: '1', label: '全部', count: 0 },
        { value: '3', label: '待开处方', count: 0 }
        // { value: "2", label: "待称重", count: 0 }
      ],

      select_index: 0,
      zone_selected: 0,
      time_selected: 0,
      cur_zone_selected: 0,
      networkStates: true,
      scheduals: [],
      timer: null,
      zone_options: [{ value: 0, text: '全部分区'}],
      zone_scheduals: [],

      time_options: [
        { value: 0, text: '全部班' },
        { value: 1, text: '上午' },
        { value: 2, text: '下午' },
        { value: 3, text: '晚上' }
      ],

      zone_options_visible: false,
      time_options_visible: false,

      //
      patient_selected: 0,
      patient_types: [
        { value: 0, text: '全部签到', select: true },
        { value: 1, text: '待签到', select: false },
        { value: 2, text: '已签到', select: false }
      ],
      patient_options_visible: false,
      allPatient: [],

      // 叫号
      timers: null,
      fisrtQueueInfo: {},
      queueConfig: {},
      newFisrtQueueInfo: {},
      information: [],
      deviceTypeList:[],
      schedualsLength: 0,
      schedualsLengthOne:0,
      schedualsLengthTwo:0,
      schedualsLengthThree:0,
      zonesList: [],
      zoneMap: {}
    }
  },
  props: {
    search_keyword: {
      type: String
    }
  },
  computed: {
    websocket () {
      return this.$store.state.user.websocket
    },
    filtedScheduals: function () {
      var search_keyword = this.search_keyword
      if (this.search_keyword.length > 0) {
        var scheduals = []
        for (let index = 0; index < this.scheduals.length; index++) {
          const schedual = this.scheduals[index]
          if (schedual.patient.name.indexOf(search_keyword) != -1) {
            scheduals.push(schedual)
          }
        }
        return this.processScheduals(scheduals)
      }
      //
      if (this.zone_selected != 0) {
        var zone_name = this.zone_options[this.zone_selected].text
        var schedules = []
        var filtedSchedules = []
        for (let o_i = 0; o_i < this.zone_scheduals.length; o_i++) {
          const scheduleInfo = this.zone_scheduals[o_i]
          var originSchedules = scheduleInfo.scheduals

          for (let s_i = 0; s_i < originSchedules.length; s_i++) {
            const schedule = originSchedules[s_i]
            if (this.zone_selected == 0) {
              if (
                this.time_selected == 0 ||
                schedule.schedule_type == this.time_selected
              ) {
                filtedSchedules.push(schedule)
              }
            } else {
              if (
                zone_name.length > 0 &&
                zone_name == schedule.device_number.zone.name
              ) {
                if (
                  this.time_selected == 0 ||
                  schedule.schedule_type == this.time_selected
                ) {
                  filtedSchedules.push(schedule)
                }
              }
            }
          }
          // if (filtedSchedules.length > 0) {
          //   schedules.push({
          //     zone_name: scheduleInfo.zone_name,
          //     scheduals: filtedSchedules
          //   });
          // }
        }
        // console.log(filtedSchedules)
        return this.processScheduals(filtedSchedules)
      }

      if (this.time_selected != 0) {
        var zone_name = this.zone_options[this.zone_selected].text
        var schedules = []
        var filtedSchedules = []
        for (let o_i = 0; o_i < this.zone_scheduals.length; o_i++) {
          const scheduleInfo = this.zone_scheduals[o_i]
          var originSchedules = scheduleInfo.scheduals

          for (let s_i = 0; s_i < originSchedules.length; s_i++) {
            const schedule = originSchedules[s_i]
            if (this.zone_selected == 0) {
              if (
                this.time_selected == 0 ||
                schedule.schedule_type == this.time_selected
              ) {
                filtedSchedules.push(schedule)
              }
            } else {
              if (
                zone_name.length > 0 &&
                zone_name == schedule.device_number.zone.name
              ) {
                if (
                  this.time_selected == 0 ||
                  schedule.schedule_type == this.time_selected
                ) {
                  filtedSchedules.push(schedule)
                }
              }
            }
          }
          // if (filtedSchedules.length > 0) {
          //   schedules.push({
          //     zone_name: scheduleInfo.zone_name,
          //     scheduals: filtedSchedules
          //   });
          // }
        }
        // console.log(222, filtedSchedules)
        return this.processScheduals(filtedSchedules)
      }

      var zone_selected = this.zone_selected
      var timetype_selected = this.time_selected
      var assessment_before_dislysis_count = 0
      var prescription_count = 0
      if (zone_selected != 0 || timetype_selected != 0) {
        var zone_name =
          zone_selected == 0 ? '' : this.zone_options[zone_selected].text
        var schedules = []
        var filtedSchedules = []
        for (let o_i = 0; o_i < this.zone_scheduals.length; o_i++) {
          const scheduleInfo = this.zone_scheduals[o_i]
          var originSchedules = scheduleInfo.scheduals

          for (let s_i = 0; s_i < originSchedules.length; s_i++) {
            const schedule = originSchedules[s_i]
            if (
              zone_name.length == 0 ||
              (zone_name.length > 0 &&
                zone_name == schedule.device_number.zone.name)
            ) {
              if (
                timetype_selected == 0 ||
                schedule.schedule_type == timetype_selected
              ) {
                filtedSchedules.push(schedule)
              }
            }
          }
          // if (filtedSchedules.length > 0) {
          //   schedules.push({
          //     zone_name: scheduleInfo.zone_name,
          //     scheduals: filtedSchedules
          //   });
          // }
        }

        // console.log(111, filtedSchedules)
        return this.processScheduals(filtedSchedules)
        // eslint-disable-next-line no-unreachable
        if (this.select_index == 2) {
          var scheduals = []
          for (let index = 0; index < this.scheduals.length; index++) {
            const schedual = this.scheduals[index]
            if (
              schedual.assessment_before_dislysis == null ||
              schedual.assessment_before_dislysis.weight_before == 0
            ) {
              if (
                this.cur_zone_selected > 0 &&
                schedual.device_number.zone.id != this.cur_zone_selected
              ) {
                continue
              }
              if (
                timetype_selected > 0 &&
                schedual.schedule_type != timetype_selected
              ) {
                continue
              }
              scheduals.push(schedual)
            }
          }
          return this.processScheduals(scheduals)
          // return scheduals;
        } else if (this.select_index == 1) {
          var scheduals = []
          for (let index = 0; index < this.scheduals.length; index++) {
            const schedual = this.scheduals[index]
            if (
              schedual.prescription == null ||
              schedual.prescription.creater == 0
            ) {
              if (
                this.cur_zone_selected > 0 &&
                schedual.device_number.zone.id != this.cur_zone_selected
              ) {
                continue
              }
              if (
                timetype_selected > 0 &&
                schedual.schedule_type != timetype_selected
              ) {
                continue
              }
              scheduals.push(schedual)
            }
          }
          // return scheduals;
          return this.processScheduals(scheduals)
        } else {
          var scheduals = []
          for (let index = 0; index < this.scheduals.length; index++) {
            const schedual = this.scheduals[index]
            if (schedual.dialysis_order == null) {
              if (
                this.cur_zone_selected > 0 &&
                schedual.device_number.zone.id != this.cur_zone_selected
              ) {
                continue
              }
              if (
                timetype_selected > 0 &&
                schedual.schedule_type != timetype_selected
              ) {
                continue
              }
              scheduals.push(schedual)
            }
          }
          // return scheduals;
          return this.processScheduals(scheduals)
        }
      }

      if (this.select_index == 2) {
        var scheduals = []
        for (let index = 0; index < this.scheduals.length; index++) {
          const schedual = this.scheduals[index]
          if (
            schedual.assessment_before_dislysis == null ||
            schedual.assessment_before_dislysis.weight_before == 0
          ) {
            scheduals.push(schedual)
          }
        }
        return this.processScheduals(scheduals)
        // return scheduals;
      } else if (this.select_index == 1) {
        var scheduals = []
        for (let index = 0; index < this.scheduals.length; index++) {
          const schedual = this.scheduals[index]
          if (
            schedual.prescription == null ||
            schedual.prescription.creater == 0
          ) {
            scheduals.push(schedual)
          }
        }
        // return scheduals;
        return this.processScheduals(scheduals)
      } else {
        // return this.zone_scheduals;
        var scheduals = []
        for (let index = 0; index < this.scheduals.length; index++) {
          const schedual = this.scheduals[index]
          if (schedual.dialysis_order == null) {
            scheduals.push(schedual)
          }
        }
        // return scheduals;
        return this.processScheduals(scheduals)
      }
    }

  },
  created () {
    this.getPatientNum()
    this.initData = {
      cmd: 'queue/join',
      data: {type: 3, page: 0, size: 0}
    }
    this.websocketSend(this.initData)
    var area = getSelectedAreaDataConfigList()
    var time = getSelectedTimesDataConfigList()
    var type = getWaitTypeSelectedConfig()
    var patientType = getPatientTypeSelectedConfig()
    // console.log('type',type)
    if (area != null) {
      this.zone_options_visible = false
      this.zone_selected = parseInt(area)
      this.select_index = -1
    }

    if (time != null) {
      this.time_selected = parseInt(time)
      this.select_index = -1
      this.time_options_visible = false
    }
    if (type != null) {
      this.select_index = parseInt(type)
    }
    if (patientType != null) {
      this.patient_selected = parseInt(patientType)
      this.patient_options_visible = false
    }

    var storedata = this.$store.getters.waitscheduals
    // console.log('storedata', storedata)
    var scheduals = storedata.waitscheduals
    // console.log('scheduals', scheduals)

    if (Object.keys(storedata).length > 0) {
      var totalCount = scheduals.length
      var prescription_count = 0
      var assessment_before_dislysis_count = 0
      for (let index = 0; index < scheduals.length; index++) {
        const schedual = scheduals[index]
        if (schedual.assessment_before_dislysis == null) {
          assessment_before_dislysis_count += 1
        }
        if (schedual.prescription == null) {
          prescription_count += 1
        }
      }
      // this.menuList[2].count = assessment_before_dislysis_count;
      // this.menuList[1].count = prescription_count;
      this.scheduals = scheduals

      console.log('scheduals99999999', this.scheduals)
      var zoneMap = {}
      var schedualMap = {}
      for (let index = 0; index < scheduals.length; index++) {
        const schedual = scheduals[index]
        if (schedual.dialysis_order != null) {
          continue
        }
        if (schedualMap[schedual.device_number.zone.name] == null) {
          schedualMap[schedual.device_number.zone.name] = []
        }
        schedualMap[schedual.device_number.zone.name].push(schedual)
        if (zoneMap[schedual.device_number.zone.name] == null) {
          zoneMap[schedual.device_number.zone.name] =
            schedual.device_number.zone
        }
      }
      this.zoneMap = zoneMap
      var zones = []
      zones.push({ value: 0, text: '全部分区', zone_name: '全部分区',sort:0 })
      for (var zoneName in zoneMap) {
        zones.push({ value: zoneMap[zoneName].id, text: zoneName, zone_name: zoneName,sort:zoneMap[zoneName].sort })
      }

      zones = zones.sort(function (a, b) {
         return a.sort - b.sort
       })

      var total = 0
      if (this.scheduals != null && this.scheduals.length > 0) {
        for (let i = 0; i < this.scheduals.length; i++) {
          if (this.scheduals[i].dialysis_order == null) {
            total++
          }
        }
      }

      for (let i = 0; i < zones.length; i++) {
        if (zones[i].value == 0) {
          zones[i].zone_name = zones[i].text
          zones[i].text = zones[i].text + '(' + total + ')'
        }
      }
      this.zonesList = zones
      // this.zone_options = zones

      // eslint-disable-next-line camelcase
      var dialysis_scheduals = []
      for (let index = 0; index < zones.length; index++) {
        const zone = zones[index]
        // eslint-disable-next-line no-redeclare
        var scheduals = schedualMap[zone.text]
        if (scheduals == null) {
          continue
        }
        dialysis_scheduals.push({
          zone_id: zone.value,
          zone_name: zone.text,
          scheduals: scheduals
        })
      }

      if (dialysis_scheduals != null && dialysis_scheduals.length > 0) {
        for (let i = 0; i < zones.length; i++) {
          for (let j = 0; j < dialysis_scheduals.length; j++) {
            if (zones[i].value == dialysis_scheduals[j].zone_id) {
              zones[i].zone_name = zones[i].text
              zones[i].text = zones[i].text + '(' + dialysis_scheduals[j].scheduals.length + ')'
            }
          }
        }
      }
      this.zone_options = []
     
      this.zone_options = zones
      // eslint-disable-next-line camelcase
      console.log('dialysis_scheduals33223322323', dialysis_scheduals)

      this.zone_scheduals = dialysis_scheduals

      // 候诊区接口数据来源
      this.getData()
    }
  },
  beforeMount () {
    this.websocketMess()
  },
  mounted () {
    this.addEventListener()
    this.$nextTick(() => {
      if (this.$refs.waitScroll) {
        this.$refs.waitScroll.scrollTop = this.$store.getters.waitScrollTop
      }
    })
    var that = this
    Utils.$on('demo', function (msg) {
      let unObj = {
        cmd: 'queue/unjoin',
        data: {type: 3}
      }
      this.websocketSend(unObj)
      let obj = {
        cmd: 'queue/join',
        data: {type: 3, page: 0, size: 0}
      }
      that.websocketSend(obj)
    })
  },
  beforeDestroy () {
    clearInterval(this.timer)
    this.timer = null
    this.$once('hook:beforeDestroy', () => {
      clearInterval(this.timer)
    })

    let unObj = {
      cmd: 'queue/unjoin',
      data: {type: 3}
    }
    this.websocketSend(unObj)
  },
  methods: {

    addEventListener () {
      window.addEventListener('scroll', this.handleScroll, true)
    },
    removeEventListener () {
      window.removeEventListener('scroll', this.handleScroll, true)
    },
    handleScroll () {
      this.$nextTick(() => {
        if (this.$refs.waitScroll) {
          let waitScrollTop = this.$refs.waitScroll.scrollTop
          this.$store.dispatch('SetWaitScrollTop', waitScrollTop)
        }
      })
    },
    getPatientNum () {
      if (sessionStorage.getItem('schedualsLength')) {
        this.schedualsLength = Number(sessionStorage.getItem('schedualsLength'))
      }
      if (sessionStorage.getItem('schedualsOneLength')) {
        this.schedualsLengthOne = Number(sessionStorage.getItem('schedualsOneLength'))
      }
      if (sessionStorage.getItem('schedualsTwoLength')) {
        this.schedualsLengthTwo = Number(sessionStorage.getItem('schedualsTwoLength'))
      }
      if (sessionStorage.getItem('schedualsThreeLength')) {
        this.schedualsLengthThree = Number(sessionStorage.getItem('schedualsThreeLength'))
      }
    },
    websocketSend (data) {
      try {
        this.websocket.send(JSON.stringify(data))
      } catch (error) {
        this.showError = true
        this.showIndex = 4
        this.errorInfo = '网络异常，请稍后退出重试！'
      }
    },
    websocketMess () {
      this.websocket.onmessage = e => {
        let res = JSON.parse(e.data)
        if (res.channel == 'queue/join') {
          let timeType = null
          if (this.time_selected == 1) {
            timeType = 1
          } else if (this.time_selected == 2) {
            timeType = 2
          } else {
            if (new Date().getHours() < 10) {
              timeType = 1
            } else if (new Date().getHours() >= 10) {
              timeType = 2
            }
          }
          let fisrtQueueInfo = []
          this.newFisrtQueueInfo = res.data.fisrtQueueInfo
          if (res.data.fisrtQueueInfo != null) {
            if (timeType == 1) {
              fisrtQueueInfo = res.data.fisrtQueueInfo.morning
              if (fisrtQueueInfo != null) {
                if (fisrtQueueInfo.create_time) {
                  fisrtQueueInfo.create_time = moment(parseInt(fisrtQueueInfo.create_time) * 1000).format('HH:mm')
                }
              }
            } else if (timeType == 2) {
              fisrtQueueInfo = res.data.fisrtQueueInfo.afternoon
              if (fisrtQueueInfo != null) {
                if (fisrtQueueInfo.create_time) {
                  fisrtQueueInfo.create_time = moment(parseInt(fisrtQueueInfo.create_time) * 1000).format('HH:mm')
                }
              }
            }
          }
          this.fisrtQueueInfo = fisrtQueueInfo
          this.queueConfig = res.data.queueConfig
          // this.fisrtQueueInfo = res.data.fisrtQueueInfo
          let arr = res.data.patientQueueList.data
          let waitingCalledArr = []
          let calledArr = []
          arr.map(item => {
            if (item.status == 1) {
              // item.create_time = moment(item.create_time * 1000).format('HH:mm:ss')
              waitingCalledArr.push(item)
            } else if (item.status == 2) {
              // item.create_time = moment(item.create_time * 1000).format('HH:mm:ss')
              calledArr.push(item)
            }
          })
          // console.log('waitingCalledArr待叫号',waitingCalledArr)
          // console.log('waitingCalledArr以较好',calledArr)
          this.waitingCalled = waitingCalledArr
          this.called = calledArr
        } else if (res.channel == 'allQueueList') {
          let arr = res.data.queue_list.data
          let waitingCalledArr = []
          let calledArr = []
          arr.map(item => {
            if (item.status == 1) {
              // item.create_time = moment(item.create_time * 1000).format('HH:mm:ss')
              waitingCalledArr.push(item)
            } else if (item.status == 2) {
              // item.create_time = moment(item.create_time * 1000).format('HH:mm:ss')
              calledArr.push(item)
            }
          })
          this.waitingCalled = waitingCalledArr
          this.called = calledArr
        } else if (res.channel == 'patientCallInfo') {
          res.data.patientInfo.create_time = moment(res.data.patientInfo.create_time * 1000).format('HH:mm')
          this.fisrtQueueInfo = res.data.patientInfo
        } else if (res.channel == 'fisrtQueueInfo') {
          let timeType = null
          if (this.time_selected == 1) {
            timeType = 1
          } else if (this.time_selected == 2) {
            timeType = 2
          } else {
            if (new Date().getHours() < 10) {
              timeType = 1
            } else if (new Date().getHours() >= 10) {
              timeType = 2
            }
          }
          let fisrtQueueInfo = []
          this.newFisrtQueueInfo = res.data.patientInfo
          if (res.data.patientInfo != null) {
            if (timeType == 1) {
              fisrtQueueInfo = res.data.patientInfo.morning
              if (fisrtQueueInfo != null) {
                if (fisrtQueueInfo.create_time) {
                  fisrtQueueInfo.create_time = moment(parseInt(fisrtQueueInfo.create_time) * 1000).format('HH:mm')
                }
              }
            } else if (timeType == 2) {
              fisrtQueueInfo = res.data.patientInfo.afternoon
              if (fisrtQueueInfo != null) {
                if (fisrtQueueInfo.create_time) {
                  fisrtQueueInfo.create_time = moment(parseInt(fisrtQueueInfo.create_time) * 1000).format('HH:mm')
                }
              }
            }
          }
          this.fisrtQueueInfo = fisrtQueueInfo
        }
      },
      this.websocket.onerror = function (event, e) {
        // console.log('error '+event.data);
        let unObj = {
          cmd: 'queue/unjoin',
          data: {type: 3}
        }
        this.websocketSend(unObj)

        let obj = {
          cmd: 'queue/join',
          data: {type: 3, page: 0, size: 0}
        }
        this.websocketSend(obj)
      }
    },
    call (patient_id) {
      if (patient_id == undefined || patient_id == '') {
        Toast.success('已经是最后一位了')
        return
      }
      let schedule_type = null
      if (new Date().getHours() < 11) {
        schedule_type = 1
      } else {
        schedule_type = 2
      }
      // console.log('patient_id',patient_id)
      let org_id = parseInt(sessionStorage.getItem('org_id'))
      let admin_user_id = parseInt(sessionStorage.getItem('admin_user_id'))
      axios.get('/api/index/callpatient?org_id=' + org_id + '&patient_id=' + patient_id + '&admin_user_id=' + admin_user_id + '&schedule_type=' + schedule_type).then(res => {
        // console.log(res)
        // let patientArr = res.data.queue_list.data
        // this.patientArr = patientArr
        // this.$emit('child-event',this.patientArr)
        if (res.data.code == 200) {
          Toast.success('叫号成功')
        }
      })
    },
    next (patient_id) {
      if (patient_id == undefined || patient_id == '') {
        Toast.success('已经是最后一位了')
        return
      }
      // console.log('patient_id',patient_id)
      let schedule_type = null
      if (this.time_selected == 0) {
        if (new Date().getHours() < 11) {
          schedule_type = 1
        } else {
          schedule_type = 2
        }
      } else if (this.time_selected == 1) {
        schedule_type = 1
      } else if (this.time_selected == 2) {
        schedule_type = 2
      }
      let org_id = parseInt(sessionStorage.getItem('org_id'))
      let admin_user_id = parseInt(sessionStorage.getItem('admin_user_id'))
      axios.get('/api/index/nextcall?org_id=' + org_id + '&patient_id=' + patient_id + '&admin_user_id=' + admin_user_id + '&schedule_type=' + schedule_type).then(res => {
        // console.log(res)
        // let patientArr = res.data.queue_list.data
        // this.patientArr = patientArr
        // this.$emit('child-event',this.patientArr)
        if (res.data.data.patientInfo == null) {
          Toast.success('已经是最后一位了')
          return
        }
        if (res.data.code == 200) {
          Toast.success('叫号成功')
        }
      })
    },
    processScheduals: function (scheduals) {
      var zoneMap = {}
      var schedualMap = {}
      var assessment_before_dislysis_count = 0
      var prescription_count = 0
      for (let index = 0; index < scheduals.length; index++) {
        const schedual = scheduals[index]
        if (schedualMap[schedual.device_number.zone.id] == null) {
          schedualMap[schedual.device_number.zone.id] = []
        }
        if (this.select_index == 1) {
          if (
            schedual.prescription == null ||
            schedual.prescription.creater == 0
          ) {
            schedualMap[schedual.device_number.zone.id].push(schedual)
            prescription_count++
          }
        } else if (this.select_index == 2) {
          if (
            schedual.assessment_before_dislysis == null ||
            schedual.assessment_before_dislysis.weight_before == 0
          ) {
            schedualMap[schedual.device_number.zone.id].push(schedual)
            assessment_before_dislysis_count++
          }
        } else {
          if (schedual.dialysis_order == null) {
            schedualMap[schedual.device_number.zone.id].push(schedual)
          }
        }
        if (zoneMap[schedual.device_number.zone.id] == null) {
          zoneMap[schedual.device_number.zone.id] = schedual.device_number.zone
        }
      }

      if (this.select_index == 1) {
        // this.menuList[1].count = prescription_count;
      }
      // if (this.select_index == 2) {
      //   this.menuList[2].count = assessment_before_dislysis_count;
      // }

      var zones = []
      // zones.push({ value: 0, text: "全部分区" })
      for (var zoneId in zoneMap) {
        zones.push({ id: zoneMap[zoneId].id, name: zoneMap[zoneId].name })
      }

      zones = zones.sort(function (a, b) {
        return a.id > b.id
      })
      // this.zones = zones

      var zone_scheduals = []
      for (let index = 0; index < zones.length; index++) {
        const zone = zones[index]
        var scheduals = schedualMap[zone.id]
        zone_scheduals.push({
          zone_id: zone.id,
          zone_name: zone.name,

          scheduals: scheduals
        })
      }
      // this.zone_scheduals = zone_scheduals;
      return zone_scheduals
    },
    reloads: function () {
      this.reload()
    },
    handleAllChange: function (tabIndex) {
      this.select_index = tabIndex
      this.zone_selected = 0
      this.time_selected = 0
    },
    menuTabClick: function (tabIndex) {
      this.select_index = tabIndex
      this.zone_selected = 0
      this.time_selected = 0
      this.patient_selected = 0
      setSelectedAreaDataConfigList(this.zone_selected)
      setSelectedTimesDataConfigList(this.time_selected)
      setWaitTypeSelectedConfig(tabIndex)
      this.getData()
    },
    //
    handlePatientType: function (index) {
      this.patient_options_visible = false
      this.patient_selected = index
      setPatientTypeSelectedConfig(this.patient_selected)
      this.getData()
    },
    handleZoneChange: function (index, zone) {
      console.log('中国232322323', zone)
      this.zone_options_visible = false
      this.zone_selected = index
      this.cur_zone_selected = zone.value
      // this.select_index = -1;
      setSelectedAreaDataConfigList(index.toString())
      setSelectedTimesDataConfigList(this.time_selected)
      setWaitTypeSelectedConfig(this.select_index)
      this.getDataTwo()
    },
    handleTimeChange: function (index) {
     
      let obj = {
        cmd: 'queue/join',
        data: {type: 3, page: 0, size: 0}
      }
      this.websocketSend(obj)
      this.time_selected = index
      this.time_options_visible = false
      setSelectedAreaDataConfigList(this.zone_selected)
      setSelectedTimesDataConfigList(index.toString())
      setWaitTypeSelectedConfig(this.select_index)
      this.getDataOne(index)
    },

    requestScheduals: function () {
      // this.loading = true;
      // var date = parseTime(Date.parse(new Date()), '{y}-{m}-{d}')
      // getWaitingScheduals({ date: date }).then(rs => {
      // var resp = rs.data
      // if (resp.state == 1) {

      this.loading = false
      var storedata = this.$store.getters.waitscheduals

      var scheduals = storedata.waitscheduals
      console.log('我的时间我做主', scheduals)
      // var scheduals = resp.data.scheduals
      // this.$store.dispatch('SetWaitScheduals', {
      //   waitscheduals: scheduals
      // })
      var totalCount = scheduals.length
      var prescription_count = 0
      var assessment_before_dislysis_count = 0
      for (let index = 0; index < scheduals.length; index++) {
        const schedual = scheduals[index]
        if (schedual.assessment_before_dislysis == null) {
          assessment_before_dislysis_count += 1
        }
        if (schedual.prescription == null) {
          prescription_count += 1
        }
      }
      // this.menuList[2].count = assessment_before_dislysis_count;
      // this.menuList[1].count = prescription_count;
      this.scheduals = scheduals

      var zoneMap = {}
      var schedualMap = {}
      for (let index = 0; index < scheduals.length; index++) {
        const schedual = scheduals[index]
        if (schedual.dialysis_order != null) {
          continue
        }
        if (schedualMap[schedual.device_number.zone.name] == null) {
          schedualMap[schedual.device_number.zone.name] = []
        }
        schedualMap[schedual.device_number.zone.name].push(schedual)
        if (zoneMap[schedual.device_number.zone.name] == null) {
          zoneMap[schedual.device_number.zone.name] =
            schedual.device_number.zone
        }
      }
      this.zoneMap = zoneMap
      var zones = []
      zones.push({ value: 0, text: '全部分区', zone_name: '全部分区',sort:0 })
      for (var zoneName in zoneMap) {
        zones.push({ value: zoneMap[zoneName].id, text: zoneName, zone_name: zoneName,sort:zoneMap[zoneName].sort })
      }

      zones = zones.sort(function (a, b) {
          return a.sort - b.sort
      })

      var total = 0
      if (this.scheduals != null && this.scheduals.length > 0) {
        for (let i = 0; i < this.scheduals.length; i++) {
          if (this.scheduals[i].dialysis_order == null) {
            total++
          }
        }
      }

      for (let i = 0; i < zones.length; i++) {
        if (zones[i].value == 0) {
          zones[i].zone_name = zones[i].text
          zones[i].text = zones[i].text + '(' + total + ')'
          zones[i].sort= zones[i].sort
        }
      }
      this.zonesList = zones

      // this.zone_options = zones

      // eslint-disable-next-line camelcase
      var dialysis_scheduals = []
      for (let index = 0; index < zones.length; index++) {
        const zone = zones[index]
        // eslint-disable-next-line no-redeclare
        var scheduals = schedualMap[zone.text]
        if (scheduals == null) {
          continue
        }
        dialysis_scheduals.push({
          zone_id: zone.value,
          zone_name: zone.text,
          scheduals: scheduals
        })
      }
      // eslint-disable-next-line camelcase
      if (dialysis_scheduals != null && dialysis_scheduals.length > 0) {
        for (let i = 0; i < zones.length; i++) {
          for (let j = 0; j < dialysis_scheduals.length; j++) {
            if (zones[i].value == dialysis_scheduals[j].zone_id) {
              zones[i].zone_name = zones[i].text
              zones[i].text = zones[i].text + '(' + dialysis_scheduals[j].scheduals.length + ')'
            }
          }
        }
      }
      this.zone_options = []
      console.log('zones33223232332', zones)
      this.zone_options = zones

      this.zone_scheduals = dialysis_scheduals
      this.getData()

      // this.zone_options = this.makeZones(scheduals);
      // this.zone_scheduals = this.processScheduals(scheduals);
      // console.log('this.zone_options',this.zone_options)
      // console.log('this.zone_scheduals',this.dialysis_scheduals)
      // } else {
      //   this.loading = false

      //   this.$toast({
      //     message: resp.msg
      //   })
      // }
      // }).catch(error => {
      //     this.loading = false

      //     // 超时之后在这里捕抓错误信息.
      //     if (error.response) {
      //       this.networkStates = false
      //     } else if (error.request) {
      //       this.networkStates = false
      //       // if(error.request.readyState == 4 && error.request.status == 0){
      //       //   //我在这里重新请求
      //       //   this.networkStates = false
      //       // }
      //     } else {
      //       this.networkStates = false
      //     }
      //   })
    },
    makeZones: function (scheduals) {
      console.log('schedualsjianmie', scheduals)
      var zoneMap = {}
      for (let index = 0; index < scheduals.length; index++) {
        const schedual = scheduals[index]
        if (zoneMap[schedual.device_number.zone.id] == null) {
          zoneMap[schedual.device_number.zone.id] = schedual.device_number.zone
        }
      }

      var zones = []
      zones.push({ value: 0, text: '全部分区', zone_name: '全部分区',sort:0 })

      for (var zoneId in zoneMap) {
        zones.push({ value: zoneMap[zoneId].id, text: zoneMap[zoneId].name, zone_name: zoneMap[zoneId].name,sort:zoneMap[zoneId].sort })
      }
      console.log('zones233223232wi', zones)
      return zones
    },
    getData () {
      this.menuList[1].count = 0
      let patientArr = this.zone_scheduals

      let arr1 = []
      if (this.select_index == 0) {
        arr1 = JSON.parse(JSON.stringify(patientArr))
      } else if (this.select_index == 1) {
        let arr = JSON.parse(JSON.stringify(patientArr))

        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if ((arr[i].scheduals[j] && arr[i].scheduals[j].prescription != null) && (arr[i].scheduals[j] && arr[i].scheduals[j].prescription && arr[i].scheduals[j].prescription.creater != 0)) {
              // 删除元素后改变i的值
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr1 = arr
      }

      let arr2 = []
      if (this.patient_selected == 0) {
        arr2 = JSON.parse(JSON.stringify(arr1))
      } else if (this.patient_selected == 1) {
        let arr = JSON.parse(JSON.stringify(arr1))
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if (arr[i].scheduals.length > 0 && (arr[i].scheduals[j].assessment_before_dislysis != null && (arr[i].scheduals[j].assessment_before_dislysis.weight_before != 0 || arr[i].scheduals[j].assessment_before_dislysis.diastolic_blood_pressure != 0 || arr[i].scheduals[j].assessment_before_dislysis.systolic_blood_pressure != 0))) {
              // 删除元素后改变i的值
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr2 = arr
      } else if (this.patient_selected == 2) {
        let arr = JSON.parse(JSON.stringify(arr1))
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if (arr[i].scheduals.length > 0 && (arr[i].scheduals[j].assessment_before_dislysis == null || (arr[i].scheduals[j].assessment_before_dislysis.weight_before == '' && arr[i].scheduals[j].assessment_before_dislysis.diastolic_blood_pressure == '' && arr[i].scheduals[j].assessment_before_dislysis.systolic_blood_pressure == ''))) {
              // 删除元素后改变i的值
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }

        arr2 = arr
      }
      console.log('机构ID', this.$store.getters.user.template_info.org_id)
      if (this.$store.getters.user.template_info.org_id == 10346 || this.$store.getters.user.template_info.org_id == 10490 ||  this.$store.getters.user.template_info.org_id == 10340 || this.$store.getters.user.template_info.org_id == 10579 || this.$store.getters.user.template_info.org_id == 10587 || this.$store.getters.user.template_info.org_id == 10597 || this.$store.getters.user.template_info.org_id == 10599 || this.$store.getters.user.template_info.org_id == 10679  || this.$store.getters.user.template_info.org_id == 10702 || this.$store.getters.user.template_info.org_id == 10740 ) {
        console.log('进来23323223233223')
        arr2.map(item => {
          item.scheduals.map(it => {
            it.sort = parseInt(it.device_number.sort)
          })
        })
        arr2.map(item => {
          item.scheduals.sort(this.compareOne('sort'))
        })
      }
      console.log('机构ID', this.$store.getters.user.template_info.org_id)
      console.log('this.zone_selected', this.zone_selected)
      console.log('热爱生活', arr2)
      let arr3 = []
      if (this.zone_selected == 0) {
        arr3 = JSON.parse(JSON.stringify(arr2))
      } else {
        let arr = JSON.parse(JSON.stringify(arr2))

        for (let i = 0; i < arr.length; i++) {
          if (this.zone_options[this.zone_selected].zone_name != arr[i].zone_name) {
            // 删除元素后改变i的值
            arr.splice(i--, 1)
          }
        }
        arr3 = arr
      }

      let arr4 = []
      if (this.time_selected == 0) {
        arr4 = JSON.parse(JSON.stringify(arr3))
      } else {
        let arr = JSON.parse(JSON.stringify(arr3))
        // console.log('arr',arr)
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if (this.time_selected != arr[i].scheduals[j].schedule_type) {
              // 删除元素后改变i的值
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr4 = arr
      }

      if (this.patient_selected == 2) {
        arr4.map((item, index) => {
          if (index != 0) {
            arr4[0].scheduals.push(...arr4[index].scheduals)
            arr4[index].scheduals = []
          }
        })
        arr4[0].scheduals.map(item => {
          item.created_time = item.assessment_before_dislysis.created_time
          item.sort = item.device_number.sort
        })
        if (this.$store.getters.user.template_info.org_id != 10346 && this.$store.getters.user.template_info.org_id != 10490 &&  this.$store.getters.user.template_info.org_id != 10340 &&  this.$store.getters.user.template_info.org_id != 10702 &&  this.$store.getters.user.template_info.org_id != 10740  ) {
          arr4[0].scheduals.sort(this.compare('created_time'))
        }

        if (this.$store.getters.user.template_info.org_id == 10346 || this.$store.getters.user.template_info.org_id == 10490 ||  this.$store.getters.user.template_info.org_id == 10340 ||  this.$store.getters.user.template_info.org_id == 10702  || this.$store.getters.user.template_info.org_id == 10740 ) {
          arr4[0].scheduals.sort(this.compareOne('sort'))
        }
        console.log("arr4[0]", arr4[0])
       
        this.allPatient = arr4
        console.log('arr4', arr4)
      } else {
        this.allPatient = arr4
      }

      let arr5 = JSON.parse(JSON.stringify(arr4))
      for (let i = 0; i < arr5.length; i++) {
        for (let j = 0; j < arr5[i].scheduals.length; j++) {
          if ((arr5[i].scheduals[j] && arr5[i].scheduals[j].prescription != null) && (arr5[i].scheduals[j] && arr5[i].scheduals[j].prescription && arr5[i].scheduals[j].prescription.creater != 0)) {
            // 删除元素后改变i的值
            // arr[i].scheduals.splice(j--, 1);
          } else {
            this.menuList[1].count++
          }
        }
      }
    },

    getDataOne (index) {
      console.log("寄哪里地我哦我我",this.patient_selected)
      this.menuList[1].count = 0
      let patientArr = this.zone_scheduals

      var zones = []
      zones.push({ value: 0, text: '全部分区', zone_name: '全部分区',sort:0 })
      for (var zoneName in this.zoneMap) {
        zones.push({ value: this.zoneMap[zoneName].id, text: zoneName, zone_name: zoneName,sort:this.zoneMap[zoneName].sort })
      }
      zones = zones.sort(function (a, b) {
          return a.sort - b.sort
       })
       console.log("this.zone_scheduals",this.zone_scheduals)
     
     
     
      if (index > 0) {
        var total = 0
        for (let i = 0; i < this.zone_scheduals.length; i++) {
          this.zone_scheduals[i].bedList = []
          for (let j = 0; j < this.zone_scheduals[i].scheduals.length; j++) {
            if (index == this.zone_scheduals[i].scheduals[j].schedule_type) {
              this.zone_scheduals[i].bedList.push(this.zone_scheduals[i].scheduals[j])
            }
          }
          total += this.zone_scheduals[i].bedList.length
        }

        for (let i = 0; i < zones.length; i++) {
          for (let j = 0; j < this.zone_scheduals.length; j++) {
            if (zones[i].value == 0 && total > 0) {
              zones[i].text = '全部分区'
              zones[i].zone_name = '全部分区'
              zones[i].text = zones[i].text + '(' + total + ')'
              zones[i].sort = 0
            }
            if (zones[i].text == this.zone_scheduals[j].zone_name) {
              zones[i].text = zones[i].text + '(' + this.zone_scheduals[j].bedList.length + ')'
            }
          }
        }
        console.log('zones232332233', zones)
        this.zone_options = []
        this.zone_options = zones
      } else {
        var total = 0
        for (let i = 0; i < this.zone_scheduals.length; i++) {
          this.zone_scheduals[i].bedList = []
          for (let j = 0; j < this.zone_scheduals[i].scheduals.length; j++) {
            console.log('999988wo', this.zone_scheduals[i].scheduals[j].schedule_type, this.zone_scheduals[i].scheduals[j].schedule_type)
            if (this.zone_scheduals[i].scheduals[j].schedule_type == 1 || this.zone_scheduals[i].scheduals[j].schedule_type == 2 || this.zone_scheduals[i].scheduals[j].schedule_type == 3) {
              this.zone_scheduals[i].bedList.push(this.zone_scheduals[i].scheduals[j])
            }
          }
          total += this.zone_scheduals[i].bedList.length
        }
        for (let i = 0; i < zones.length; i++) {
          for (let j = 0; j < this.zone_scheduals.length; j++) {
            if (zones[i].value == 0 && total > 0) {
              zones[i].text = '全部分区'
              zones[i].zone_name = '全部分区'
              zones[i].text = zones[i].text + '(' + total + ')'
              zones[i].sort = 0
            }
            if (zones[i].text == this.zone_scheduals[j].zone_name) {
              zones[i].text = zones[i].text + '(' + this.zone_scheduals[j].bedList.length + ')'
            }
          }
        }
        console.log('zones9999999999999999', zones)
        this.zone_options = []
        this.zone_options = zones
      }

      let arr1 = []
      if (this.select_index == 0) {
        arr1 = JSON.parse(JSON.stringify(patientArr))
      } else if (this.select_index == 1) {
        let arr = JSON.parse(JSON.stringify(patientArr))

        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if ((arr[i].scheduals[j] && arr[i].scheduals[j].prescription != null) && (arr[i].scheduals[j] && arr[i].scheduals[j].prescription && arr[i].scheduals[j].prescription.creater != 0)) {
              // 删除元素后改变i的值
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        console.log("arrwoowowowow",arr)
        arr1 = arr
      }

      let arr2 = []
      if (this.patient_selected == 0) {
        arr2 = JSON.parse(JSON.stringify(arr1))
        console.log("arr2owoowowowowowowowo",arr2)
      } else if (this.patient_selected == 1) {
        let arr = JSON.parse(JSON.stringify(arr1))
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if (arr[i].scheduals.length > 0 && (arr[i].scheduals[j].assessment_before_dislysis != null && (arr[i].scheduals[j].assessment_before_dislysis.weight_before != 0 || arr[i].scheduals[j].assessment_before_dislysis.diastolic_blood_pressure != 0 || arr[i].scheduals[j].assessment_before_dislysis.systolic_blood_pressure != 0))) {
              // 删除元素后改变i的值
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr2 = arr
      } else if (this.patient_selected == 2) {
        let arr = JSON.parse(JSON.stringify(arr1))
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if (arr[i].scheduals.length > 0 && (arr[i].scheduals[j].assessment_before_dislysis == null || (arr[i].scheduals[j].assessment_before_dislysis.weight_before == '' && arr[i].scheduals[j].assessment_before_dislysis.diastolic_blood_pressure == '' && arr[i].scheduals[j].assessment_before_dislysis.systolic_blood_pressure == ''))) {
              // 删除元素后改变i的值
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr2 = arr
      }

      let arr3 = []
      if (this.zone_selected == 0) {
        arr3 = JSON.parse(JSON.stringify(arr2))
      } else {
        let arr = JSON.parse(JSON.stringify(arr2))

        for (let i = 0; i < arr.length; i++) {
          if (this.zone_options[this.zone_selected].zone_name != arr[i].zone_name) {
            // 删除元素后改变i的值
            arr.splice(i--, 1)
          }
        }
        arr3 = arr
      }

      let arr4 = []
      if (this.time_selected == 0) {
        arr4 = JSON.parse(JSON.stringify(arr3))
      } else {
        let arr = JSON.parse(JSON.stringify(arr3))
        // console.log('arr',arr)
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if (this.time_selected != arr[i].scheduals[j].schedule_type) {
              // 删除元素后改变i的值
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr4 = arr
      }

      if (this.patient_selected == 2) {
        arr4.map((item, index) => {
          if (index != 0) {
            arr4[0].scheduals.push(...arr4[index].scheduals)
            arr4[index].scheduals = []
          }
        })
        arr4[0].scheduals.map(item => {
          item.created_time = item.assessment_before_dislysis.created_time
          item.sort = item.device_number.sort
        })
        if (this.$store.getters.user.template_info.org_id != 10346 && this.$store.getters.user.template_info.org_id != 10490 && this.$store.getters.user.template_info.org_id != 10340 && this.$store.getters.user.template_info.org_id != 10579 && this.$store.getters.user.template_info.org_id != 10587  && this.$store.getters.user.template_info.org_id != 10597 && this.$store.getters.user.template_info.org_id != 10599 && this.$store.getters.user.template_info.org_id != 10679 && this.$store.getters.user.template_info.org_id != 10702 && this.$store.getters.user.template_info.org_id != 10740) {
          arr4[0].scheduals.sort(this.compare('created_time'))
        }

        if (this.$store.getters.user.template_info.org_id == 10346 || this.$store.getters.user.template_info.org_id == 10490 || this.$store.getters.user.template_info.org_id == 10340  || this.$store.getters.user.template_info.org_id == 10579 || this.$store.getters.user.template_info.org_id == 10587 || this.$store.getters.user.template_info.org_id == 10597 || this.$store.getters.user.template_info.org_id == 10599 || this.$store.getters.user.template_info.org_id == 10679 || this.$store.getters.user.template_info.org_id == 10702 || this.$store.getters.user.template_info.org_id == 10740)  {
          arr4[0].scheduals.sort(this.compareOne('sort'))
        }
        this.allPatient = arr4
        console.log('arr4', arr4)
      } else {
        console.log('arr6666666666666666666', arr4)
        arr4.map((item, index) => {
          if (index != 0) {
            arr4[0].scheduals.push(...arr4[index].scheduals)
            arr4[index].scheduals = []
          }
        })
        arr4[0].scheduals.map(item => {
          item.sort = item.device_number.sort
        })
       
        if (this.$store.getters.user.template_info.org_id == 10346 || this.$store.getters.user.template_info.org_id == 10490 || this.$store.getters.user.template_info.org_id == 10340  || this.$store.getters.user.template_info.org_id == 10579 || this.$store.getters.user.template_info.org_id == 10587 || this.$store.getters.user.template_info.org_id == 10597 || this.$store.getters.user.template_info.org_id == 10599 || this.$store.getters.user.template_info.org_id == 10702 || this.$store.getters.user.template_info.org_id == 10740 || this.$store.getters.user.template_info.org_id == 10679) {
          arr4[0].scheduals.sort(this.compareOne('sort'))
        }
        this.allPatient = arr4
      }

      let arr5 = JSON.parse(JSON.stringify(arr4))
      for (let i = 0; i < arr5.length; i++) {
        for (let j = 0; j < arr5[i].scheduals.length; j++) {
          if ((arr5[i].scheduals[j] && arr5[i].scheduals[j].prescription != null) && (arr5[i].scheduals[j] && arr5[i].scheduals[j].prescription && arr5[i].scheduals[j].prescription.creater != 0)) {
            // 删除元素后改变i的值
            // arr[i].scheduals.splice(j--, 1);
          } else {
            this.menuList[1].count++
          }
        }
      }
    },
    compare (property) {
      return function (a, b) {
        var value1 = a[property]
        var value2 = b[property]
        return value2 - value1
      }
    },
    compareOne (property) {
      return function (a, b) {
        var value1 = a[property]
        var value2 = b[property]
        return value1 - value2
      }
    },
    searchVal (searchValue) {
      var search_keyword = searchValue
      if (searchValue.length > 0) {
        var scheduals = []
        for (let index = 0; index < this.scheduals.length; index++) {
          const schedual = this.scheduals[index]
          // console.log("schedual.patient.name",schedual.patient)
          if(schedual.patient!=null && schedual.patient.name!=undefined){
            if (schedual.patient.name.indexOf(search_keyword) != -1 || schedual.patient.dialysis_no.indexOf(search_keyword) != -1) {
              scheduals.push(schedual)
            }
          }
        
        }
        this.allPatient = this.processScheduals(scheduals)
      } else {
        this.getData()
      }
    },

    getDataTwo () {
      console.log("patient_selected",this.patient_selected)
      this.menuList[1].count = 0
      let patientArr = this.zone_scheduals

      let arr1 = []
      if (this.select_index == 0) {
        arr1 = JSON.parse(JSON.stringify(patientArr))
      } else if (this.select_index == 1) {
        let arr = JSON.parse(JSON.stringify(patientArr))

        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if ((arr[i].scheduals[j] && arr[i].scheduals[j].prescription != null) && (arr[i].scheduals[j] && arr[i].scheduals[j].prescription && arr[i].scheduals[j].prescription.creater != 0)) {
              // 删除元素后改变i的值
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr1 = arr
      }

      let arr2 = []
      if (this.patient_selected == 0) {
        arr2 = JSON.parse(JSON.stringify(arr1))
      } else if (this.patient_selected == 1) {
        let arr = JSON.parse(JSON.stringify(arr1))
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if (arr[i].scheduals.length > 0 && (arr[i].scheduals[j].assessment_before_dislysis != null && (arr[i].scheduals[j].assessment_before_dislysis.weight_before != 0 || arr[i].scheduals[j].assessment_before_dislysis.diastolic_blood_pressure != 0 || arr[i].scheduals[j].assessment_before_dislysis.systolic_blood_pressure != 0))) {
              // 删除元素后改变i的值
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr2 = arr
      } else if (this.patient_selected == 2) {
        let arr = JSON.parse(JSON.stringify(arr1))
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if (arr[i].scheduals.length > 0 && (arr[i].scheduals[j].assessment_before_dislysis == null || (arr[i].scheduals[j].assessment_before_dislysis.weight_before == '' && arr[i].scheduals[j].assessment_before_dislysis.diastolic_blood_pressure == '' && arr[i].scheduals[j].assessment_before_dislysis.systolic_blood_pressure == ''))) {
              // 删除元素后改变i的值
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr2 = arr
      }
      console.log('this.zone_selected', this.zone_selected)
      console.log('arr2', arr2)
      let arr3 = []
      if (this.zone_selected == 0) {
        arr3 = JSON.parse(JSON.stringify(arr2))
      } else {
        let arr = JSON.parse(JSON.stringify(arr2))
       
        for (let i = 0; i < arr.length; i++) {
          if (this.zone_options[this.zone_selected].zone_name != arr[i].zone_name) {
            // 删除元素后改变i的值
            arr.splice(i--, 1)
          }
        }
        arr3 = arr
      }

      let arr4 = []
      if (this.time_selected == 0) {
        arr4 = JSON.parse(JSON.stringify(arr3))
      } else {
        let arr = JSON.parse(JSON.stringify(arr3))
        // console.log('arr',arr)
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if (this.time_selected != arr[i].scheduals[j].schedule_type) {
              // 删除元素后改变i的值
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr4 = arr
      }

      if (this.patient_selected == 2) {
        arr4.map((item, index) => {
          if (index != 0) {
            arr4[0].scheduals.push(...arr4[index].scheduals)
            arr4[index].scheduals = []
          }
        })
        arr4[0].scheduals.map(item => {
          item.created_time = item.assessment_before_dislysis.created_time
          item.sort = item.device_number.sort
        })

        if (this.$store.getters.user.template_info.org_id != 10346 && this.$store.getters.user.template_info.org_id != 10490  && this.$store.getters.user.template_info.org_id != 10340 && this.$store.getters.user.template_info.org_id != 10679 && this.$store.getters.user.template_info.org_id != 10702 && this.$store.getters.user.template_info.org_id != 10740 ) {
          arr4[0].scheduals.sort(this.compare('created_time'))
        }

        if (this.$store.getters.user.template_info.org_id == 10346 || this.$store.getters.user.template_info.org_id ==10490 || this.$store.getters.user.template_info.org_id ==10340  || this.$store.getters.user.template_info.org_id ==10679  || this.$store.getters.user.template_info.org_id ==10702 || this.$store.getters.user.template_info.org_id ==10740 ) {
          arr4[0].scheduals.sort(this.compareOne('sort'))
        }
        this.allPatient = arr4
        console.log('arr4', arr4)
      } else {
        this.allPatient = arr4
      }

      let arr5 = JSON.parse(JSON.stringify(arr4))
      for (let i = 0; i < arr5.length; i++) {
        for (let j = 0; j < arr5[i].scheduals.length; j++) {
          if ((arr5[i].scheduals[j] && arr5[i].scheduals[j].prescription != null) && (arr5[i].scheduals[j] && arr5[i].scheduals[j].prescription && arr5[i].scheduals[j].prescription.creater != 0)) {
            // 删除元素后改变i的值
            // arr[i].scheduals.splice(j--, 1);
          } else {
            this.menuList[1].count++
          }
        }
      }
    }

  }
}
</script>

<style style="stylesheet/scss" lang="scss" scoped>
.flexBox{
  display: flex;
  flex-direction: column;
  height: 100%;
}
.screening {
  border-bottom: 1px #e5e5e5 solid;
  width: 100%;
  // position: fixed;
  // top: 86px;
  // @media only screen and (min-width: 768px) {
  //   top: 143px;
  // }
  // @media only screen and (min-width: 415px) and (max-width: 767px) {
  //   top: 114px;
  // }
  // right: 0;
  // z-index: 66;
  // left: 0;
  background: #fff;
  // @media only screen and (max-width: 812px) {
  //   top: 50px !important;
  // }
  ul {
    @include display-flex;
    @include align-items-center;
    @include text-align;
    @include justify-content-between;
    width: 96%;
    margin: 0 auto;
    font-size: 0.45rem;
    color: $title-color;
    li {
      padding: 0.3rem 0;
      .iconfont {
        font-size: 0.45rem;
        margin-left: 0.1rem;
      }
    }
    .active {
      position: relative;
      &::before {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 2px;
        background: $main-color;
        // border-bottom: 0.04rem $main-color solid;
        content: "";
      }
    }
  }
}
.stateBox {
  // padding: 0.5rem 0 0 0.6rem;
  flex: 1;
  overflow-y: auto;
  .title {
    font-size: 0.34rem;
    color: #34495e;
    font-weight: 600;
    height: 1rem;
    line-height: 1rem;
    display: inline-block;
  }
}
.shadow {
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
  z-index: 998;
  background-color: #000;
  opacity: 0.6;
  display: none;
}

.fixedCalling{
  height: 2.1rem;
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background: #fff;
  display: flex;
  justify-content: space-around;
  .nowCalling{
    p{
      font-size: 0.4rem;
      text-align: center;
    }
  }
  .callingName{
    width: 3rem;
    height: 1rem;
    background: #DBDFE7;
    opacity: 0.9;
    border-radius: 0.53rem;
    color:#3389FB;
    text-align: center;
    font-size: 0.53rem;
    line-height: 1rem;
    margin-top: 0.5rem;
  }
  .fixedVolume{
    width: 2rem;
    height: 2rem;
    background: linear-gradient(0deg, #1965E5 0%, #33ACF9 100%);
    box-shadow: 0px 4px 10px 0px rgba(69, 143, 243, 0.27);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: absolute;
    top: -0.33rem;
    .van-icon-volume{
      color: #fff;
      font-size: 1rem;
      margin: 0 auto;
    }
  }
}
</style>
