<template>
    <div class="flexBox" v-loading="loading">
      <div class="screening">
        <ul>
          <el-popover
            v-model="zone_options_visible"

            placement="bottom"
            trigger="click"
          >
            <li slot="reference">
              {{
                zones.length <= 1 && zone_selected > 0
                  ? "全部分区"
                  : zones[zone_selected].text
              }}
              <span class="iconfont">&#xe74a;</span>
            </li>

            <div class="popover-demo-content">
              <ul>
                <li
                  v-for="(zone, index) in zones"
                  :key="zone.value"
                  @click="handleZoneChange(index,zone.value)"
                  :class="zone_selected == index ? 'tick' : ''"
                >
                  <span>{{ zone.text }}</span>
                  <!-- <span style="color:#ee7070;"> {{'(100人)'}}</span> -->
                </li>
              </ul>
            </div>
          </el-popover>

          <el-popover
            v-model="sch_type_options_visible"
            placement="bottom"
            trigger="click"
          >
            <li slot="reference">
              {{ schedual_types[schedual_type_selected].text }}
              <span class="iconfont">&#xe74a;</span>
            </li>
            <div class="popover-demo-content">
              <ul>
                <li
                  v-for="schedualType in schedual_types"
                  :key="schedualType.value"
                  @click="handletimeType(schedualType.value)"
                  :class="
                    schedual_type_selected == schedualType.value ? 'tick' : ''
                  "
                >
                  {{ schedualType.text }}
                </li>
              </ul>
            </div>
          </el-popover>
          <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="state_options_visible"
            placement="bottom"
            trigger="click"
          >
            <li slot="reference">
              {{ patient_states[state_selected].text }}
              <span class="iconfont">&#xe74a;</span>
            </li>
            <div class="popover-demo-content">
              <ul>
                <li
                  v-for="patientType in patient_states"
                  :key="patientType.value"
                  @click="handlePatientState(patientType.value)"
                  :class="
                    state_selected == patientType.value ? 'tick' : ''
                  "
                >
                  {{ patientType.text }}
                </li>
              </ul>
            </div>
          </el-popover>

          <li @click="openPicker()">
            {{ selected_date_str }}
            <span class="iconfont">&#xe74a;</span>
          </li>

          <!-- <li @click="mypatient()" :class="newMypatient == 1 ? 'active' : ''">
            我的病人
          </li> -->
        </ul>
      </div>

      <div class="stateBox" ref="dialysisScroll">
        <div v-for="(item, index) in allPatient" :key="index">
          <h2 class="title">{{ item.zone_name }}</h2>
          <patient-box
            class="clearfix"
            :patients="item.scheduals"
            :newIndex='2'
            :is_run="is_run"
            :information="information"
            :devicetypelist="deviceTypeList"
            ref='dialysisArea'
          ></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"
        >
          <p>
            网络异常，请点击重新加载
          </p>

          <!--<img style="margin-top: 50px; margin-bottom: 50px" src="@/assets/login/no_network.jpg" alt="">-->
          <van-button
            slot="button"
            size="normal"
            type="info"
            style="display:block;margin:0 auto"
            @click="reloads()"
            >重新加载</van-button
          >
        </div>
      </div>
      <mt-datetime-picker
        v-model="selected_date"
        ref="picker"
        type="date"
        year-format="{value} "
        month-format="{value} "
        date-format="{value} "
        @confirm="handleScheduleDateChange"
      ></mt-datetime-picker>
    </div>
</template>

<script>
import PatientBox from './PatientBox'
import { Popover, Datetime } from 'vux'

import { parseTime } from '@/utils/index'
import { getDialysisScheduals, getLatestDialysisScheduals, getScheduleTypeById } from '@/api/dialysis'
import { Toast } from 'vant'
import $ from 'jquery'
import { getEquitAutoInfo, getDeviceInformation} from '@/api/manage'
export default {
  name: 'DialysisArea',
  components: {
    PatientBox,
    Popover,
    Datetime
  },
  inject: ['reload'],
  data () {
    return {
      loading: false,
      user_id: 0,
      networkStates: true,
      timer: null,
      ismypatient: this.$store.getters.app.dialysis_area.ismypatient,
      selected_date: this.$store.getters.app.dialysis_area.schedule_date, // new Date(),
      schedual_types: [
        { value: 0, text: '全部班', select: true },
        { value: 1, text: '上午', select: false },
        { value: 2, text: '下午', select: false },
        { value: 3, text: '晚上', select: false }
      ],
      schedual_type_selected: this.$store.getters.app.dialysis_area
        .schedule_type_select_index,

      zone_selected: this.$store.getters.app.dialysis_area.zone_select_index,
      zones: [{ value: 0, text: '全部分区', select: true }],
      zoneList: [{value: 0, text: '全部分区', select: true}],
      dialysis_scheduals: [],

      zone_options_visible: false,
      sch_type_options_visible: false,
      newMypatient: 0,
      //
      patient_selected: this.$store.getters.app.dialysis_area.patient_type,
      patient_types: [
        { value: 0, text: '全部病人', select: true },
        { value: 1, text: '我的病人', select: false }
      ],
      patient_options_visible: false,

      state_selected: this.$store.getters.app.dialysis_area.patient_state,
      patient_states: [
        { value: 0, text: '全部状态', select: true },
        { value: 1, text: '医嘱核对', select: false },
        { value: 2, text: '待开小结', select: false },
        { value: 3, text: '待下机', select: false },
        { value: 4, text: '待消毒', select: false },
        { value: 5, text: '待双人核对', select: false },
        { value: 6, text: '医嘱未执行', select: false },
        { value: 7, text: '患者未签名', select: false },
       
      ],
      state_options_visible: false,

      summaryNum: 0,
      isSummary: false,
      allPatient: [],
      is_run: 0,
      start_time: '',
      information: [],
      schedualsLength: 0,
      zonesList: [],
      zoneMapObj: {},
      deviceTypeList:[],

    }
  },
  props: {
    search_keyword: {
      type: String,
      default: ''
    }
  },
  computed: {
    selected_date_str: function () {
      return parseTime(this.selected_date, '{y}-{m}-{d}')
    },

    filtedScheduals: function () {
      if (this.dialysis_scheduals.length == 0) {
        return []
      }

      var search_keyword = this.search_keyword
      if (search_keyword.length > 0) {
        var schedules = []
        for (let o_i = 0; o_i < this.dialysis_scheduals.length; o_i++) {
          const scheduleInfo = this.dialysis_scheduals[o_i]
          var originSchedules = scheduleInfo.scheduals
          if (originSchedules.length == 0) {
            continue
          }
          var filtedSchedules = []
          for (let s_i = 0; s_i < originSchedules.length; s_i++) {
            const schedule = originSchedules[s_i]
            if (schedule.patient.name.indexOf(search_keyword) != -1) {
              filtedSchedules.push(schedule)
            }
          }
          if (filtedSchedules.length > 0) {
            // console.log('scheduleInfo', scheduleInfo)
            schedules.push({
              zone_name: scheduleInfo.zone_name,
              scheduals: filtedSchedules
            })
          }
        }
        return schedules
      }
      console.log('我的患者--------------', this.ismypatient)
      if (this.ismypatient) {
        var zone_selected = this.zone_selected
        var timetype_selected = this.schedual_type_selected
        var zone_name =
          zone_selected == 0 ? '' : this.zones[zone_selected].text
        var schedules = []
        for (let o_i = 0; o_i < this.dialysis_scheduals.length; o_i++) {
          const scheduleInfo = this.dialysis_scheduals[o_i]
          var originSchedules = scheduleInfo.scheduals
          if (originSchedules.length == 0) {
            continue
          }
          var filtedSchedules = []
          for (let s_i = 0; s_i < originSchedules.length; s_i++) {
            const schedule = originSchedules[s_i]
            if (schedule.dialysis_order.start_nurse == this.user_id) {
              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)
                }
              }
              // break;
            }
          }
          if (filtedSchedules.length > 0) {
            schedules.push({
              zone_name: scheduleInfo.zone_name,
              scheduals: filtedSchedules
            })
          }
        }
        return schedules
      }

      var zone_selected = this.zone_selected
      var timetype_selected = this.schedual_type_selected
      if (
        (zone_selected == 0 && timetype_selected == 0) ||
        this.zones.length <= 1
      ) {
        return this.dialysis_scheduals
      }

      var zone_name = zone_selected == 0 ? '' : this.zones[zone_selected].text
      var schedules = []
      for (let o_i = 0; o_i < this.dialysis_scheduals.length; o_i++) {
        const scheduleInfo = this.dialysis_scheduals[o_i]
        var originSchedules = scheduleInfo.scheduals
        var filtedSchedules = []
        for (let s_i = 0; s_i < originSchedules.length; s_i++) {
          const schedule = originSchedules[s_i]
          if (this.ismypatient) {
            if (schedule.dialysis_order.creator == this.user_id) {
              filtedSchedules.push(schedule)
            }
          } else {
            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
          })
        }
      }
      this.ismypatient = false
      return schedules
    }
  },

  created () {
    this.user_id = this.$store.getters.user.admin.id
    var storedata = this.$store.getters.scheduals
    var scheduals = storedata.scheduals

    if (Object.keys(storedata).length > 0) {
      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.zoneMapObj = zoneMap
      console.log('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
       })
      // this.zones = zones
      console.log('zones323232332', zones)
      this.zonesList = zones

      var dialysis_scheduals = []
      for (let index = 0; index < zones.length; index++) {
        const zone = zones[index]
        var scheduals = schedualMap[zone.text]
        if (scheduals == null) {
          continue
        }
        dialysis_scheduals.push({
          zone_name: zone.text,
          scheduals: scheduals
        })
      }

      if (dialysis_scheduals != null && dialysis_scheduals.length > 0) {
        var total = 0
        for (let i = 0; i < dialysis_scheduals.length; i++) {
          total += dialysis_scheduals[i].scheduals.length
        }
        for (let i = 0; i < zones.length; i++) {
          for (let j = 0; j < dialysis_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 == dialysis_scheduals[j].zone_name) {
              zones[i].zone_name = zones[i].text
              zones[i].text = zones[i].text + '(' + dialysis_scheduals[j].scheduals.length + ')'
              zones[i].sort = zones[i].sort
            }
          }
        }

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

        console.log("总过=================================",zones)
        this.zones = []
        this.zones = zones

        
      }

      this.dialysis_scheduals = dialysis_scheduals

      // var schedule_type_four = 0
      // var schedule_type_five = 0
      // var schedule_type_six = 0
      // if (dialysis_scheduals != null && dialysis_scheduals.length > 0) {
      //   for (let i = 0; i < dialysis_scheduals.length; i++) {
      //     for (let j = 0; j < dialysis_scheduals[i].scheduals.length; j++) {
      //       if (dialysis_scheduals[i].scheduals[j].schedule_type == 1) {
      //         schedule_type_four++
      //       }
      //       if (dialysis_scheduals[i].scheduals[j].schedule_type == 2) {
      //         schedule_type_five++
      //       }
      //       if (dialysis_scheduals[i].scheduals[j].schedule_type == 3) {
      //         schedule_type_six++
      //       }
      //     }
      //   }
      // }
      // var total_one = 0
      // total_one = schedule_type_four + schedule_type_five + schedule_type_six

      // for (let i = 0; i < this.schedual_types.length; i++) {
      //   if (this.schedual_types[i].value == 0) {
      //     this.schedual_types[i].text = this.schedual_types[i].text + '(' + total_one + ')'
      //   }
      //   if (this.schedual_types[i].value == 1) {
      //     this.schedual_types[i].text = this.schedual_types[i].text + '(' + schedule_type_four + ')'
      //   }
      //   if (this.schedual_types[i].value == 2) {
      //     this.schedual_types[i].text = this.schedual_types[i].text + '(' + schedule_type_five + ')'
      //   }
      //   if (this.schedual_types[i].value == 3) {
      //     this.schedual_types[i].text = this.schedual_types[i].text + '(' + schedule_type_six + ')'
      //   }
      // }
      this.getData()
    } else {
      this.requestDialysisScheduals()
    }

    this.getEquitAutoInfo()
    this.getDeviceInformation()
  },
  mounted () {
    this.timer = window.setInterval(() => {
      setTimeout(this.requestDialysisScheduals(), 0)
    }, 60000)
    this.addEventListener()
    this.$nextTick(() => {
      if (this.$refs.dialysisScroll) {
        this.$refs.dialysisScroll.scrollTop = this.$store.getters.dialysisScrollTop
      }
    })
  },
  beforeDestroy () {
    clearInterval(this.timer)
    this.timer = null
  },
  methods: {

    addEventListener () {
      window.addEventListener('scroll', this.handleScroll, true)
    },
    removeEventListener () {
      window.removeEventListener('scroll', this.handleScroll, true)
    },
    handleScroll () {
      this.$nextTick(() => {
        if (this.$refs.dialysisScroll) {
          let dialysisScrollTop = this.$refs.dialysisScroll.scrollTop
          this.$store.dispatch('SetDialysisScrollTop', dialysisScrollTop)
        }
      })
    },
    clearPatient () {
      this.search_keyword = ''
      this.ismypatient = false
      this.$emit('clear_search_keyword')
      this.$store.dispatch('SaveDialysisAreaSelectIndexs', {
        zone: this.zone_selected,
        schedule_type: this.schedual_type_selected,
        schedule_date: this.selected_date,
        ismypatient: this.ismypatient
      })
    },
    mypatient () {
      this.search_keyword = ''
      this.ismypatient = true
      this.$emit('clear_search_keyword')
      this.$store.dispatch('SaveDialysisAreaSelectIndexs', {
        zone: this.zone_selected,
        schedule_type: this.schedual_type_selected,
        schedule_date: this.selected_date,
        ismypatient: this.ismypatient
      })
      this.newMypatient = 1
    },
    reloads: function () {
      this.reload()
    },
    //
    openSummary () {
      this.isSummary = true
      this.getData()
    },
    handlePatientState: function (index) {
      if (!this.ismypatient) {
        this.ismypatient = false
      }
      this.state_options_visible = false
      this.state_selected = index
      this.$emit('clear_search_keyword')
      this.$store.dispatch('SaveDialysisAreaSelectIndexs', {
        zone: this.zone_selected,
        schedule_type: this.schedual_type_selected,
        patient_type: this.patient_selected,
        patient_state: this.state_selected,
        schedule_date: this.selected_date,
        ismypatient: this.ismypatient
      })
      this.isSummary = false
      this.getData()
    },
    handlePatientType: function (index) {
      if (!this.ismypatient) {
        this.ismypatient = false
      }
      this.patient_options_visible = false
      this.patient_selected = index
      this.$emit('clear_search_keyword')
      this.$store.dispatch('SaveDialysisAreaSelectIndexs', {
        zone: this.zone_selected,
        schedule_type: this.schedual_type_selected,
        patient_type: this.patient_selected,
        patient_state: this.state_selected,
        schedule_date: this.selected_date,
        ismypatient: this.ismypatient
      })
      this.isSummary = false
      this.getData()
    },
    handletimeType: function (index) {
      if (!this.ismypatient) {
        this.ismypatient = false
      }
      this.sch_type_options_visible = false
      this.schedual_type_selected = index
      this.$emit('clear_search_keyword')
      this.$store.dispatch('SaveDialysisAreaSelectIndexs', {
        zone: this.zone_selected,
        schedule_type: this.schedual_type_selected,
        patient_type: this.patient_selected,
        patient_state: this.state_selected,
        schedule_date: this.selected_date,
        ismypatient: this.ismypatient
      })
      this.isSummary = false
      // this.getData()
      this.getDataOne(index)
    },
    handleZoneChange: function (index, value) {
      this.ismypatient = false
      this.zone_options_visible = false
      this.zone_selected = index
      this.$emit('clear_search_keyword')
      this.$store.dispatch('SaveDialysisAreaSelectIndexs', {
        zone: this.zone_selected,
        schedule_type: this.schedual_type_selected,
        patient_type: this.patient_selected,
        patient_state: this.state_selected,
        schedule_date: this.selected_date,
        ismypatient: this.ismypatient
      })
      this.newMypatient = 0
      this.isSummary = false
      // this.getData()
      this.getDataThree()
    },
    handleScheduleDateChange: function (date) {
      if (!this.ismypatient) {
        this.ismypatient = false
      }
      this.zone_selected = 0
      this.schedual_type_selected = 0
      this.patient_selected = 0
      this.$emit('clear_search_keyword')
      this.$store.dispatch('SaveDialysisAreaSelectIndexs', {
        zone: this.zone_selected,
        schedule_type: this.schedual_type_selected,
        patient_type: this.patient_selected,
        patient_state: this.state_selected,
        schedule_date: this.selected_date,
        ismypatient: this.ismypatient
      })
      this.isSummary = false
      this.requestDialysisScheduals()
      this.start_time = parseTime(date, '{y}-{m}-{d}')
      this.getDeviceInformation()
    },

    requestDialysisScheduals () {
    
      var type = 0
      getDialysisScheduals({ type: type, date: this.selected_date_str })
        .then(rs => {
          this.networkStates = true
          var resp = rs.data

          if (resp.state == 1) {
            this.loading = false
            // 候诊区数据入口
            var scheduals = resp.data.scheduals

            var project = resp.data.project

            if (project != null && project.length > 0) {
              for (let i = 0; i < scheduals.length; i++) {
                scheduals[i].project = []
                for (let j = 0; j < project.length; j++) {
                  if (scheduals[i].patient_id == project[j].patient_id) {
                    scheduals[i].project.push(project[j])
                  }
                }
              }
            }
        

            let schedualsLength = scheduals.length
            if(scheduals!=null&&scheduals.length>0){
              var arr = []
              var arrTwo = []
              var arrThree = []
               for(let i=0;i<scheduals.length;i++){
                 if(scheduals[i].schedule_type == 1){
                    arr.push(scheduals[i])
                 }
                 if(scheduals[i].schedule_type == 2){
                  arrTwo.push(scheduals[i])
                 }
                 if(scheduals[i].schedule_type == 3){
                  arrThree.push(scheduals[i])
                 }
               }
               sessionStorage.setItem('schedualsOneLength', arr.length)
               sessionStorage.setItem('schedualsTwoLength', arrTwo.length)
               sessionStorage.setItem('schedualsThreeLength', arrThree.length)
            }
            sessionStorage.setItem('schedualsLength', schedualsLength)

          
            
            this.schedualsLength = schedualsLength
            this.$store.dispatch('SetScheduals', { scheduals: scheduals })
            this.$store.dispatch('SetWaitScheduals', { waitscheduals: scheduals })

            this.$emit('refWaitingArea')

            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.zoneMapObj = zoneMap
            var zones = []
            zones.push({ value: 0, text: '全部分区', zone_name: '全部分区',sort:0 })
              
            console.log("zoneMap-================================",zoneMap)
            for (var zoneName in zoneMap) {
              console.log("zoneNmae-----------------",zoneName)
              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
            })
            // this.zones = zones
            this.zoneAllList = zones
            this.zonesList = zones

            var dialysis_scheduals = []
            for (let index = 0; index < zones.length; index++) {
              const zone = zones[index]

              var scheduals = schedualMap[zone.text]
              if (scheduals == null) {
                continue
              }
              dialysis_scheduals.push({
                zone_name: zone.text,
                scheduals: scheduals,
                sort:zone.sort,
              })
            }

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

              for (let i = 0; i < zones.length; i++) {
                for (let j = 0; j < dialysis_scheduals.length; j++) {
                  if (zones[i].value == 0 && total > 0) {
                    zones[i].text = '全部分区'
                    zones[i].zone_name = '全部分区'
                    zones[i].text = zones[i].text + '(' + (total).toString() + ')'
                    zones[i].sort = 0
                  }
                  if (zones[i].text == dialysis_scheduals[j].zone_name) {
                    zones[i].zone_name = zones[i].text
                    zones[i].text = zones[i].text + '(' + (dialysis_scheduals[j].scheduals.length).toString() + ')'
                    zones[i].sort = zones[i].sort
                  }
                }
              }
              this.zones = []

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

              this.zones = zones
            }

            // console.log('zones', zones)

            // var schedule_type_one = 0
            // var schedule_type_two = 0
            // var schedule_type_three = 0
            // if (dialysis_scheduals != null && dialysis_scheduals.length > 0) {
            //   for (let i = 0; i < dialysis_scheduals.length; i++) {
            //     for (let j = 0; j < dialysis_scheduals[i].scheduals.length; j++) {
            //       if (dialysis_scheduals[i].scheduals[j].schedule_type == 1) {
            //         schedule_type_one++
            //       }
            //       if (dialysis_scheduals[i].scheduals[j].schedule_type == 2) {
            //         schedule_type_two++
            //       }
            //       if (dialysis_scheduals[i].scheduals[j].schedule_type == 3) {
            //         schedule_type_three++
            //       }
            //     }
            //   }
            // }
            // var total = 0
            // total = schedule_type_one + schedule_type_two + schedule_type_three

            // for (let i = 0; i < this.schedual_types.length; i++) {
            //   if (this.schedual_types[i].value == 0) {
            //     this.schedual_types[i].text = this.schedual_types[i].text + '(' + total + ')'
            //   }
            //   if (this.schedual_types[i].value == 1) {
            //     this.schedual_types[i].text = this.schedual_types[i].text + '(' + schedule_type_one + ')'
            //   }
            //   if (this.schedual_types[i].value == 2) {
            //     this.schedual_types[i].text = this.schedual_types[i].text + '(' + schedule_type_two + ')'
            //   }
            //   if (this.schedual_types[i].value == 3) {
            //     this.schedual_types[i].text = this.schedual_types[i].text + '(' + schedule_type_three + ')'
            //   }
            // }

            this.dialysis_scheduals = dialysis_scheduals

            this.getData()
          } 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
          } else {
            this.networkStates = false
          }
        })
    },
    requestLatestDialysisScheduals (time) {
      if (time != null) {
        this.selected_date = time
        this.$store.dispatch('SaveDialysisAreaSelectIndexs', {
          zone: this.zone_selected,
          schedule_type: this.schedual_type_selected,
          patient_type: this.patient_selected,
          patient_state: this.state_selected,
          schedule_date: this.selected_date,
          ismypatient: this.ismypatient
        })
        this.selected_date_str = parseTime(this.selected_date, '{y}-{m}-{d}')
      }
      var type = 0
      getLatestDialysisScheduals({ type: type, date: this.selected_date_str })
        .then(rs => {
          this.networkStates = true
          var resp = rs.data
          if (resp.state == 1) {
            this.loading = false
            var scheduals = resp.data.scheduals
            console.log('刷新后的数据', scheduals)
            this.$store.dispatch('SetScheduals', { scheduals: scheduals })
            this.$store.dispatch('SetWaitScheduals', { waitscheduals: scheduals })

            this.$emit('refWaitingArea')
            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
              }
            }

            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
             })
            this.zonesList = []
            this.zonesList = zones
            var dialysis_scheduals = []
            for (let index = 0; index < zones.length; index++) {
              const zone = zones[index]
              var scheduals = schedualMap[zone.text]
              if (scheduals == null) {
                continue
              }
              dialysis_scheduals.push({
                zone_name: zone.text,
                scheduals: scheduals
              })
            }
            // eslint-disable-next-line camelcase
            this.dialysis_scheduals = dialysis_scheduals

            this.getData()
            let state = false
            this.$emit('func', state)
          } else {
            console.log('网络异常')
            this.loading = false
            let state = false
            this.$emit('func', state)
            this.$toast({
              message: resp.msg
            })
          }
        }).catch(error => {
          console.log('网络异常23332')
          this.loading = false
          // 超时之后在这里捕抓错误信息.
          if (error.response) {
            this.networkStates = false
          } else if (error.request) {
            // console.log(error.request)
            this.networkStates = false
          } else {
            this.networkStates = false
          }
        })
    },

    openPicker () {
      this.$refs.picker.open()
      this.newMypatient = 0
    },
    getData () {
      this.summaryNum = 0
      let patientArr = this.dialysis_scheduals
      let arr1 = []
      if (this.zone_selected == 0) {
        arr1 = JSON.parse(JSON.stringify(patientArr))
      } else {
        let arr = JSON.parse(JSON.stringify(patientArr))

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

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

      let arr3 = []
      if (this.patient_selected == 0) {
        if (this.$store.getters.user.user.user_type != 2 || this.$store.getters.user.user.user_type != 3) {
          arr3 = JSON.parse(JSON.stringify(arr2))
        }
      } else {
        let arr = JSON.parse(JSON.stringify(arr2))
        var newArr = []
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if (this.$store.getters.user.user.user_type == 2) {
              // 删除元素后改变i的值
              if (arr[i].scheduals[j].prescription == null || ((arr[i].scheduals[j] && arr[i].scheduals[j].prescription != null) ? arr[i].scheduals[j].prescription.creater != this.$store.getters.user.admin.id : false)) {
                arr[i].scheduals.splice(j--, 1)
              }
            } else if (this.$store.getters.user.user.user_type == 3) {
              console.log('武警机构ID', this.$store.getters.user.template_info.org_id)
              if (this.$store.getters.user.template_info.org_id == 10340) {
                if ((arr[i].scheduals[j].dialysis_order == null || ((arr[i].scheduals[j] && arr[i].scheduals[j].dialysis_order != null) ? arr[i].scheduals[j].dialysis_order.start_nurse != this.$store.getters.user.admin.id : false)) && ((arr[i].scheduals[j].dobule_check == null) || ((arr[i].scheduals[j].dobule_check != null && (arr[i].scheduals[j].dobule_check.creater != this.$store.getters.user.admin.id)) && ((arr[i].scheduals[j].dobule_check != null && (arr[i].scheduals[j].dobule_check.modifier != this.$store.getters.user.admin.id)))))) {
                  arr[i].scheduals.splice(j--, 1)
                }
              } else {
                if (arr[i].scheduals[j].dialysis_order == null || (arr[i].scheduals[j] && arr[i].scheduals[j].dialysis_order != null) ? arr[i].scheduals[j].dialysis_order.start_nurse != this.$store.getters.user.admin.id : false) {
                  arr[i].scheduals.splice(j--, 1)
                }
              }
            }
          }
        }
        console.log('上机', newArr)
        arr3 = arr
      }

      let arr4 = []
      if (this.state_selected == 0) {
        let arr = JSON.parse(JSON.stringify(arr3))
        arr4 = arr
        this.allPatient = arr4
      } else if (this.state_selected == 1) {
        let arr = JSON.parse(JSON.stringify(arr3))
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if (arr[i].scheduals[j].doctor_advice.length == 0) {
              arr[i].scheduals.splice(j--, 1)
            }
            if (arr[i].scheduals && arr[i].scheduals[j] && arr[i].scheduals[j].doctor_advice) {
              let sign = 0
              arr[i].scheduals[j].doctor_advice.map(item => {
                if (item.check_state == 1) {
                  sign++
                }
              })
              if (sign == arr[i].scheduals[j].doctor_advice.length && arr[i].scheduals[j].doctor_advice.length > 0) {
                arr[i].scheduals.splice(j--, 1)
              }
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      } else if (this.state_selected == 2) {
        let arr = JSON.parse(JSON.stringify(arr3))
        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].treatment_summary != null) {
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      } else if (this.state_selected == 3) {
        let arr = JSON.parse(JSON.stringify(arr3))
        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].dialysis_order != null && arr[i].scheduals[j] && arr[i].scheduals[j].dialysis_order.stage == 2) {
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      } else if (this.state_selected == 4) {
        let arr = JSON.parse(JSON.stringify(arr3))
        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].device_information != null) {
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      } else if (this.state_selected == 5) {
        let arr = JSON.parse(JSON.stringify(arr3))
        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].dobule_check != null && arr[i].scheduals[j] && arr[i].scheduals[j].dobule_check.modifier > 0) {
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      }else if(this.state_selected == 6){
        let arr = JSON.parse(JSON.stringify(arr3))
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if (arr[i].scheduals[j].doctor_advice.length == 0) {
              arr[i].scheduals.splice(j--, 1)
            }
            if (arr[i].scheduals && arr[i].scheduals[j] && arr[i].scheduals[j].doctor_advice) {
              let sign = 0
              arr[i].scheduals[j].doctor_advice.map(item => {
                console.log("待执行itmewowowowo",item.patient_id,item.execution_state)
                if (item.execution_state == 1) {
                  sign++
                }
              })
              if (sign == arr[i].scheduals[j].doctor_advice.length && arr[i].scheduals[j].doctor_advice.length > 0) {
                arr[i].scheduals.splice(j--, 1)
              }
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      }else if(this.state_selected == 7){
        let arr = JSON.parse(JSON.stringify(arr3))
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            console.log("arr[i]",arr[i].scheduals[j])
            if (arr[i].scheduals[j] && arr[i].scheduals[j].dialysis_order != null && arr[i].scheduals[j] && arr[i].scheduals[j].dialysis_order.url != "") {
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      }
      
      let arr5 = JSON.parse(JSON.stringify(this.allPatient))
      arr5.map(item => {
        item.scheduals.map(it => {
          it.bedNumber = parseInt(it.device_number.number)
          it.sort = parseInt(it.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 != 10599 && this.$store.getters.user.template_info.org_id != 10597 && 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 != 10721  && this.$store.getters.user.template_info.org_id != 10740) {
        arr5.map(item => {
          item.scheduals.sort(this.compare('bedNumber'))
        })
      }
      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 == 10599 || this.$store.getters.user.template_info.org_id == 10597  || 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 == 10721 || this.$store.getters.user.template_info.org_id == 10740 ) {
        arr5.map(item => {
          item.scheduals.sort(this.compare('sort'))
        })
      }

      this.allPatient = arr5
    },

    getDataOne (index) {
      console.log("index---------------",index)
      this.summaryNum = 0
      let patientArr = this.dialysis_scheduals

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

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

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

      let arr3 = []
      if (this.patient_selected == 0) {
        if (this.$store.getters.user.user.user_type != 2 || this.$store.getters.user.user.user_type != 3) {
          arr3 = JSON.parse(JSON.stringify(arr2))
        }
      } else {
        let arr = JSON.parse(JSON.stringify(arr2))
        console.log('arr23332232323', this.$store.getters.user.admin.id)

        var newArr = []
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if (this.$store.getters.user.user.user_type == 2) {
              // 删除元素后改变i的值
              if (arr[i].scheduals[j].prescription == null || ((arr[i].scheduals[j] && arr[i].scheduals[j].prescription != null) ? arr[i].scheduals[j].prescription.creater != this.$store.getters.user.admin.id : false)) {
                arr[i].scheduals.splice(j--, 1)
              }
            } else if (this.$store.getters.user.user.user_type == 3) {
              if (this.$store.getters.user.template_info.org_id == 10340) {
                if ((arr[i].scheduals[j].dialysis_order == null || ((arr[i].scheduals[j] && arr[i].scheduals[j].dialysis_order != null) ? arr[i].scheduals[j].dialysis_order.start_nurse != this.$store.getters.user.admin.id : false)) && ((arr[i].scheduals[j].dobule_check == null) || ((arr[i].scheduals[j].dobule_check != null && (arr[i].scheduals[j].dobule_check.creater != this.$store.getters.user.admin.id)) && ((arr[i].scheduals[j].dobule_check != null && (arr[i].scheduals[j].dobule_check.modifier != this.$store.getters.user.admin.id)))))) {
                  arr[i].scheduals.splice(j--, 1)
                }
              } else {
                if (arr[i].scheduals[j].dialysis_order == null || (arr[i].scheduals[j] && arr[i].scheduals[j].dialysis_order != null) ? arr[i].scheduals[j].dialysis_order.start_nurse != this.$store.getters.user.admin.id : false) {
                  arr[i].scheduals.splice(j--, 1)
                }
              }
            }
          }
        }
        console.log('上机', newArr)
        arr3 = arr
      }

      let arr4 = []
      if (this.state_selected == 0) {
        let arr = JSON.parse(JSON.stringify(arr3))
        arr4 = arr
        this.allPatient = arr4
      } else if (this.state_selected == 1) {
        let arr = JSON.parse(JSON.stringify(arr3))
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if (arr[i].scheduals[j].doctor_advice.length == 0) {
              arr[i].scheduals.splice(j--, 1)
            }
            if (arr[i].scheduals && arr[i].scheduals[j] && arr[i].scheduals[j].doctor_advice) {
              let sign = 0
              arr[i].scheduals[j].doctor_advice.map(item => {
                if (item.check_state == 1) {
                  sign++
                }
              })
              if (sign == arr[i].scheduals[j].doctor_advice.length && arr[i].scheduals[j].doctor_advice.length > 0) {
                arr[i].scheduals.splice(j--, 1)
              }
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      } else if (this.state_selected == 2) {
        let arr = JSON.parse(JSON.stringify(arr3))
        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].treatment_summary != null) {
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      } else if (this.state_selected == 3) {
        let arr = JSON.parse(JSON.stringify(arr3))
        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].dialysis_order != null && arr[i].scheduals[j] && arr[i].scheduals[j].dialysis_order.stage == 2) {
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      } else if (this.state_selected == 4) {
        let arr = JSON.parse(JSON.stringify(arr3))
        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].device_information != null) {
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      } else if (this.state_selected == 5) {
        let arr = JSON.parse(JSON.stringify(arr3))
        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].dobule_check != null && arr[i].scheduals[j] && arr[i].scheduals[j].dobule_check.modifier > 0) {
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      }else if(this.state_selected == 6){
        let arr = JSON.parse(JSON.stringify(arr3))
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if (arr[i].scheduals[j].doctor_advice.length == 0) {
              arr[i].scheduals.splice(j--, 1)
            }
            if (arr[i].scheduals && arr[i].scheduals[j] && arr[i].scheduals[j].doctor_advice) {
              let sign = 0
              arr[i].scheduals[j].doctor_advice.map(item => {
               
                if (item.execution_state == 1) {
                  sign++
                }
              })
              if (sign == arr[i].scheduals[j].doctor_advice.length && arr[i].scheduals[j].doctor_advice.length > 0) {
                arr[i].scheduals.splice(j--, 1)
              }
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      }else if(this.state_selected == 7){
        let arr = JSON.parse(JSON.stringify(arr3))
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            console.log("arr[i]",arr[i].scheduals[j])
            if (arr[i].scheduals[j] && arr[i].scheduals[j].dialysis_order != null && arr[i].scheduals[j] && arr[i].scheduals[j].dialysis_order.url != "") {
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      }
      
      let arr5 = JSON.parse(JSON.stringify(this.allPatient))
      arr5.map(item => {
        item.scheduals.map(it => {
          it.bedNumber = parseInt(it.device_number.number)
          it.sort = parseInt(it.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 != 10599  &&  this.$store.getters.user.template_info.org_id != 10597  &&  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 != 10721  &&  this.$store.getters.user.template_info.org_id != 10740) {
        arr5.map(item => {
          item.scheduals.sort(this.compare('bedNumber'))
        })
      }
      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 == 10599 ||this.$store.getters.user.template_info.org_id == 10597 ||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 == 10721 ||  this.$store.getters.user.template_info.org_id == 10740 ) {
        arr5.map(item => {
          item.scheduals.sort(this.compare('sort'))
        })
      }
      console.log('zoneMapObj', this.zoneMapObj)
      var zones = []
      zones.push({ value: 0, text: '全部分区', zone_name: '全部分区',sort:0 })

      for (var zoneName in this.zoneMapObj) {
        zones.push({ value: this.zoneMapObj[zoneName].id, text: zoneName, zone_name: zoneName,sort: this.zoneMapObj[zoneName].sort })
      }

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

      if (index > 0) {
        var total = 0
        for (let i = 0; i < this.dialysis_scheduals.length; i++) {
          this.dialysis_scheduals[i].bedList = []
          for (let j = 0; j < this.dialysis_scheduals[i].scheduals.length; j++) {
            if (index == this.dialysis_scheduals[i].scheduals[j].schedule_type) {
              this.dialysis_scheduals[i].bedList.push(this.dialysis_scheduals[i].scheduals[j])
            }
          }
          total += this.dialysis_scheduals[i].bedList.length
        }
        for (let i = 0; i < zones.length; i++) {
          for (let j = 0; j < this.dialysis_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.dialysis_scheduals[j].zone_name) {
              zones[i].text = zones[i].text + '(' + this.dialysis_scheduals[j].bedList.length + ')'
              zones[i].sort = zones[i].sort
            }
          }
        }
        console.log('zones', zones)
        this.zones = []
        this.zones = zones
      } else {
        var total = 0
        for (let i = 0; i < this.dialysis_scheduals.length; i++) {
          this.dialysis_scheduals[i].bedList = []
          for (let j = 0; j < this.dialysis_scheduals[i].scheduals.length; j++) {
            if (this.dialysis_scheduals[i].scheduals[j].schedule_type == 1 || this.dialysis_scheduals[i].scheduals[j].schedule_type == 2 || this.dialysis_scheduals[i].scheduals[j].schedule_type == 3) {
              this.dialysis_scheduals[i].bedList.push(this.dialysis_scheduals[i].scheduals[j])
            }
          }
          total += this.dialysis_scheduals[i].bedList.length
        }
        for (let i = 0; i < zones.length; i++) {
          for (let j = 0; j < this.dialysis_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.dialysis_scheduals[j].zone_name) {
              zones[i].text = zones[i].text + '(' + this.dialysis_scheduals[j].bedList.length + ')'
              zones[i].sort = zones[i].sort
            }
          }
        }
        console.log('zones', zones)
        this.zones = []
        this.zones = zones
      }

      console.log('哈哈哈哈哈', arr5)

      this.allPatient = arr5
    },
    getDataTwo (index) {
     
      this.summaryNum = 0
      let patientArr = this.dialysis_scheduals

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

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

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

      let arr3 = []
      if (this.patient_selected == 0) {
        if (this.$store.getters.user.user.user_type != 2 || this.$store.getters.user.user.user_type != 3) {
          arr3 = JSON.parse(JSON.stringify(arr2))
        }
      } else {
        let arr = JSON.parse(JSON.stringify(arr2))
        console.log('arr23332232323', this.$store.getters.user.admin.id)

        var newArr = []
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if (this.$store.getters.user.user.user_type == 2) {
              // 删除元素后改变i的值
              if (arr[i].scheduals[j].prescription == null || ((arr[i].scheduals[j] && arr[i].scheduals[j].prescription != null) ? arr[i].scheduals[j].prescription.creater != this.$store.getters.user.admin.id : false)) {
                arr[i].scheduals.splice(j--, 1)
              }
            } else if (this.$store.getters.user.user.user_type == 3) {
              console.log('武警机构ID', this.$store.getters.user.template_info.org_id)
              if (this.$store.getters.user.template_info.org_id == 10340) {
                if ((arr[i].scheduals[j].dialysis_order == null || ((arr[i].scheduals[j] && arr[i].scheduals[j].dialysis_order != null) ? arr[i].scheduals[j].dialysis_order.start_nurse != this.$store.getters.user.admin.id : false)) && ((arr[i].scheduals[j].dobule_check == null) || ((arr[i].scheduals[j].dobule_check != null && (arr[i].scheduals[j].dobule_check.creater != this.$store.getters.user.admin.id)) && ((arr[i].scheduals[j].dobule_check != null && (arr[i].scheduals[j].dobule_check.modifier != this.$store.getters.user.admin.id)))))) {
                  arr[i].scheduals.splice(j--, 1)
                }
              } else {
                if (arr[i].scheduals[j].dialysis_order == null || (arr[i].scheduals[j] && arr[i].scheduals[j].dialysis_order != null) ? arr[i].scheduals[j].dialysis_order.start_nurse != this.$store.getters.user.admin.id : false) {
                  arr[i].scheduals.splice(j--, 1)
                }
              }
            }
          }
        }
        console.log('上机', newArr)
        arr3 = arr
      }

      let arr4 = []
      if (this.state_selected == 0) {
        let arr = JSON.parse(JSON.stringify(arr3))
        arr4 = arr
        this.allPatient = arr4
      } else if (this.state_selected == 1) {
        let arr = JSON.parse(JSON.stringify(arr3))
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if (arr[i].scheduals[j].doctor_advice.length == 0) {
              arr[i].scheduals.splice(j--, 1)
            }
            if (arr[i].scheduals && arr[i].scheduals[j] && arr[i].scheduals[j].doctor_advice) {
              let sign = 0
              arr[i].scheduals[j].doctor_advice.map(item => {
                if (item.check_state == 1) {
                  sign++
                }
              })
              if (sign == arr[i].scheduals[j].doctor_advice.length && arr[i].scheduals[j].doctor_advice.length > 0) {
                arr[i].scheduals.splice(j--, 1)
              }
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      } else if (this.state_selected == 2) {
        let arr = JSON.parse(JSON.stringify(arr3))
        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].treatment_summary != null) {
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      } else if (this.state_selected == 3) {
        let arr = JSON.parse(JSON.stringify(arr3))
        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].dialysis_order != null && arr[i].scheduals[j] && arr[i].scheduals[j].dialysis_order.stage == 2) {
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      } else if (this.state_selected == 4) {
        let arr = JSON.parse(JSON.stringify(arr3))
        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].device_information != null) {
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      } else if (this.state_selected == 5) {
        let arr = JSON.parse(JSON.stringify(arr3))
        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].dobule_check != null && arr[i].scheduals[j] && arr[i].scheduals[j].dobule_check.modifier > 0) {
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      }else if(this.state_selected == 6){
        let arr = JSON.parse(JSON.stringify(arr3))
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if (arr[i].scheduals[j].doctor_advice.length == 0) {
              arr[i].scheduals.splice(j--, 1)
            }
            if (arr[i].scheduals && arr[i].scheduals[j] && arr[i].scheduals[j].doctor_advice) {
              let sign = 0
              arr[i].scheduals[j].doctor_advice.map(item => {
                console.log("待执行itmewowowowo",item)
                if (item.execution_state == 1) {
                  sign++
                }
              })
              if (sign == arr[i].scheduals[j].doctor_advice.length && arr[i].scheduals[j].doctor_advice.length > 0) {
                arr[i].scheduals.splice(j--, 1)
              }
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      }else if(this.state_selected == 7){
        let arr = JSON.parse(JSON.stringify(arr3))
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            console.log("arr[i]",arr[i].scheduals[j])
            if (arr[i].scheduals[j] && arr[i].scheduals[j].dialysis_order != null && arr[i].scheduals[j] && arr[i].scheduals[j].dialysis_order.url != "") {
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      }
      
      let arr5 = JSON.parse(JSON.stringify(this.allPatient))
      arr5.map(item => {
        item.scheduals.map(it => {
          it.bedNumber = parseInt(it.device_number.number)
          it.sort = parseInt(it.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 != 10721 && this.$store.getters.user.template_info.org_id != 10740) {
        arr5.map(item => {
          item.scheduals.sort(this.compare('bedNumber'))
        })
      }
      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 == 10721 || this.$store.getters.user.template_info.org_id == 10740) {
        arr5.map(item => {
          item.scheduals.sort(this.compare('sort'))
        })
      }
      // console.log('zoneMapObj', this.zoneMapObj)
      // var zones = []
      // zones.push({ value: 0, text: '全部分区' })

      // for (var zoneName in this.zoneMapObj) {
      //   zones.push({ value: this.zoneMapObj[zoneName].id, text: zoneName })
      // }

      // zones = zones.sort(function (a, b) {
      //   return a.value > b.value
      // })
      // console.log('分区this.dialysis_scheduals', this.dialysis_scheduals)
      // var total = 0
      // for (let i = 0; i < this.dialysis_scheduals.length; i++) {
      //   this.dialysis_scheduals[i].bedList = []
      //   for (let j = 0; j < this.dialysis_scheduals[i].scheduals.length; j++) {
      //     if (index == this.dialysis_scheduals[i].scheduals[j].schedule_type) {
      //       this.dialysis_scheduals[i].bedList.push(this.dialysis_scheduals[i].scheduals[j])
      //     }
      //   }
      //   total += this.dialysis_scheduals[i].bedList.length
      // }
      // for (let i = 0; i < zones.length; i++) {
      //   for (let j = 0; j < this.dialysis_scheduals.length; j++) {
      //     if (zones[i].value == 0 && total > 0) {
      //       zones[i].text = '全部分区'
      //       zones[i].text = zones[i].text + '(' + total + ')'
      //     }
      //     if (zones[i].text == this.dialysis_scheduals[j].zone_name) {
      //       zones[i].text = zones[i].text + '(' + this.dialysis_scheduals[j].bedList.length + ')'
      //     }
      //   }
      // }
      // console.log('zones', zones)
      // this.zones = []
      // this.zones = zones
      console.log('哈哈哈哈哈', arr5)
    
      this.allPatient = arr5
    },
    compare (property) {
      return function (a, b) {
        var value1 = a[property]
        var value2 = b[property]
        return value1 - value2
      }
    },
    searchVal (searchValue) {
      var search_keyword = searchValue
      if (search_keyword.length > 0) {
        var schedules = []
        for (let o_i = 0; o_i < this.dialysis_scheduals.length; o_i++) {
          const scheduleInfo = this.dialysis_scheduals[o_i]
          var originSchedules = scheduleInfo.scheduals
          if (originSchedules.length == 0) {
            continue
          }
          var filtedSchedules = []
          for (let s_i = 0; s_i < originSchedules.length; s_i++) {
            const schedule = originSchedules[s_i]
            if (schedule.patient.name.indexOf(search_keyword) != -1 || schedule.patient.dialysis_no.indexOf(search_keyword) != -1) {
              filtedSchedules.push(schedule)
            }
          }
          if (filtedSchedules.length > 0) {
            schedules.push({
              zone_name: scheduleInfo.zone_name,
              scheduals: filtedSchedules
            })
          }
        }

        this.allPatient = schedules
      } else {
        this.getData()
      }
    },

    getEquitAutoInfo () {
      getEquitAutoInfo().then(response => {
        if (response.data.state == 1) {
          var remander = response.data.data.remander
          // console.log('remander2222', remander)
          this.is_run = remander.is_run
        }
      })
    },

    getDeviceInformation () {
      var date = parseTime(this.selected_date, '{y}-{m}-{d}')
      this.start_time = date
      const params = {
        schedule_date: this.start_time
      }
      getDeviceInformation(params).then(response => {
        if (response.data.state == 1) {
          var information = response.data.data.information
          this.information = information
          this.deviceTypeList= response.data.data.devicetype
        }
      })
    },

    getDataThree () {
      this.summaryNum = 0
      let patientArr = this.dialysis_scheduals
      let arr1 = []
      if (this.zone_selected == 0) {
        arr1 = JSON.parse(JSON.stringify(patientArr))
      } else {
        let arr = JSON.parse(JSON.stringify(patientArr))
        console.log('zoneList', this.zones)
        console.log('this.zoneList[this.zone_selected].text', this.zones[this.zone_selected].zone_name)
        for (let i = 0; i < arr.length; i++) {
          if (this.zones[this.zone_selected].zone_name != arr[i].zone_name) {
            // 删除元素后改变i的值
            arr.splice(i--, 1)
          }
        }
        arr1 = arr
      }

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

      let arr3 = []
      if (this.patient_selected == 0) {
        if (this.$store.getters.user.user.user_type != 2 || this.$store.getters.user.user.user_type != 3) {
          arr3 = JSON.parse(JSON.stringify(arr2))
        }
      } else {
        let arr = JSON.parse(JSON.stringify(arr2))
        console.log('arr23332232323', this.$store.getters.user.admin.id)

        var newArr = []
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if (this.$store.getters.user.user.user_type == 2) {
              // 删除元素后改变i的值
              if (arr[i].scheduals[j].prescription == null || ((arr[i].scheduals[j] && arr[i].scheduals[j].prescription != null) ? arr[i].scheduals[j].prescription.creater != this.$store.getters.user.admin.id : false)) {
                arr[i].scheduals.splice(j--, 1)
              }
            } else if (this.$store.getters.user.user.user_type == 3) {
              console.log('woowowo', this.$store.getters.user.template_info.org_id)
              if (this.$store.getters.user.template_info.org_id == 10340) {
                if ((arr[i].scheduals[j].dialysis_order == null || ((arr[i].scheduals[j] && arr[i].scheduals[j].dialysis_order != null) ? arr[i].scheduals[j].dialysis_order.start_nurse != this.$store.getters.user.admin.id : false)) && ((arr[i].scheduals[j].dobule_check == null) || ((arr[i].scheduals[j].dobule_check != null && (arr[i].scheduals[j].dobule_check.creater != this.$store.getters.user.admin.id)) && ((arr[i].scheduals[j].dobule_check != null && (arr[i].scheduals[j].dobule_check.modifier != this.$store.getters.user.admin.id)))))) {
                  arr[i].scheduals.splice(j--, 1)
                }
              } else {
                if (arr[i].scheduals[j].dialysis_order == null || (arr[i].scheduals[j] && arr[i].scheduals[j].dialysis_order != null) ? arr[i].scheduals[j].dialysis_order.start_nurse != this.$store.getters.user.admin.id : false) {
                  arr[i].scheduals.splice(j--, 1)
                }
              }
            }
          }
        }
        console.log('上机', newArr)
        arr3 = arr
      }

      let arr4 = []
      if (this.state_selected == 0) {
        let arr = JSON.parse(JSON.stringify(arr3))
        arr4 = arr
        this.allPatient = arr4
      } else if (this.state_selected == 1) {
        let arr = JSON.parse(JSON.stringify(arr3))
        for (let i = 0; i < arr.length; i++) {
          for (let j = 0; j < arr[i].scheduals.length; j++) {
            if (arr[i].scheduals[j].doctor_advice.length == 0) {
              arr[i].scheduals.splice(j--, 1)
            }
            if (arr[i].scheduals && arr[i].scheduals[j] && arr[i].scheduals[j].doctor_advice) {
              let sign = 0
              arr[i].scheduals[j].doctor_advice.map(item => {
                if (item.check_state == 1) {
                  sign++
                }
              })
              if (sign == arr[i].scheduals[j].doctor_advice.length && arr[i].scheduals[j].doctor_advice.length > 0) {
                arr[i].scheduals.splice(j--, 1)
              }
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      } else if (this.state_selected == 2) {
        let arr = JSON.parse(JSON.stringify(arr3))
        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].treatment_summary != null) {
              arr[i].scheduals.splice(j--, 1)
            }
          }
        }
        arr4 = arr
        this.allPatient = arr4
      }
      let arr5 = JSON.parse(JSON.stringify(this.allPatient))
      arr5.map(item => {
        item.scheduals.map(it => {
          it.bedNumber = parseInt(it.device_number.number)
          it.sort = parseInt(it.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) {
        arr5.map(item => {
          item.scheduals.sort(this.compare('bedNumber'))
        })
      }
      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) {
        arr5.map(item => {
          item.scheduals.sort(this.compare('sort'))
        })
      }

      this.allPatient = arr5
    }

  }
}
</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: 2.84rem;
  // @media only screen and (min-width: 768px) {
  //   top: 163px;
  // }
  // @media only screen and (min-width: 415px) and (max-width: 767px) {
  //   top: 134px;
  // }
  // @media only screen and (min-width: 813px) and (max-width: 1024px) {
  //   top: 130px;
  // }
  // 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-around;
    width: 100%;
    margin: 0 auto;
    li {
      font-size: 0.45rem;
      padding: 0.3rem 0;
      cursor: pointer;
      .iconfont {
        font-size: 0.45rem;
        color: #a8b3ba;
        // margin-left: 0.1rem;
        // @media only screen and (max-width: 768px) {
        //   font-size: 0.45 !important;
        // }
      }
    }
    .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.26rem 0 0 0.6rem;
  // background: #fff;
  flex: 1;
  height: 100%;
  overflow-y: auto;
  .title {
    font-size: 0.34rem;
    font-weight: 600;
    color: $title-color;
    height: 1rem;
    line-height: 0.8rem;
    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;
}

.picker-toolbar {
  height: 60px;
}
.mint-datetime-action {
  line-height: 60px;
  font-size: 0.45rem;
  @media only screen and (max-width: 768px) {
    line-height: 40px !important;
  }
}
.NoData{
  p{
    margin-top: 100px;
    font-size: 18px
  }
}
.stateTxt{
  font-size: 0.34rem;
  font-weight: 600;
  color: #1b2631;
  display: inline-block;
}
</style>
