<template>
    <div class="page_scheduling">
        <van-sticky>
            <div class="staffManagementTitle">
                <i class="iconfont icon-zuojiantou jiantou" @click="toReturn"></i>
                <span class="titleName">患者排班</span>
                <span @click="toClick">临时排班</span>
                <!-- <span  class="titleName" @click="toInspection">测试2</span> -->
            </div>
        </van-sticky>
        <div class="searchBox">
            <van-search
                class="searchInput"
                v-model="schedulingVal"
                placeholder="搜索患者姓名"
            />
        </div>
        <div class="optionsBox">
            <div class="toolOne" @click="dateShow = true">
                <div style="display: flex;align-items: center;">
                {{ nowDate }}
                <van-icon name="arrow-down" />
                </div>
            </div>
            <div class="optionsOne" @click="typeShow = true">
                <div style="display: flex;align-items: center;">
                {{ type }}
                <van-icon name="arrow-down" />
                </div>
            </div>
            <div class="optionsOne" @click="areaShow = true">
                <div style="display: flex;align-items: center;">
                {{ area }}
                <van-icon name="arrow-down" />
                </div>
            </div>
            <van-switch :value="isOpen" @input="changeIsOpen" />
        </div>
        <div class="schedulingList">
            <div class="schedulingOne"  v-for="(item,index) in this.seheduleCom" :key="index"   @touchstart="gotouchstart($event,index,item)" @touchmove="gotouchmove" @touchend="gotouchend"  @click="item.patient!=undefined&&item.patient.id > 0 ? toEditPatient(item.id,index,item.order.stage) : openPatientList(item,index)" :id="spanIndex.indexOf(index)>-1 ?  'tavActive' : '' " :class="modeColor(item.mode_name)">
                <div v-if="item.patient!=undefined&&item.patient.id > 0 " >
                  {{item.patient.name ? item.patient.name : '未排班'}}
                  （<span v-if="item.schedule_type == 1">上午</span><span v-if="item.schedule_type == 2">下午</span><span v-if="item.schedule_type == 3">晚上</span>
                  {{item.zone_name}}-{{item.number_name}}/{{item.mode_name}}）
                  <span v-if="$store.getters.user.template_info.org_id !=10679">{{item.anticoagulant_name}} </span>
                    {{item.dialysis_machine_name}}
                     
                   <span v-if="item.calcium>0">钙:{{ item.calcium }}</span> 
                  
                </div>
                <div  v-if="item.patient==undefined">
                  （<span v-if="item.schedule_type == 1">上午</span><span v-if="item.schedule_type == 2">下午</span><span v-if="item.schedule_type == 3">晚上</span>
                  {{item.zone_name}}-{{item.number_name}}/{{item.mode_name}}）
                </div>
                <div v-if="item.order!=undefined">
                  <span v-if="item.order.stage == 0">待上机</span>
                  <span v-if="item.order.stage == 1">已上机</span>
                  <span v-if="item.order.stage == 2">已下机</span>
                </div>
                 <span  v-show="show && (item.order!=undefined&&item.order.stage == 0) && (item.patient!=undefined&&item.patient.id > 0)" class="cancel" @click.stop="changeSchedule(item)">调班</span>

                <div v-if="$store.getters.user.template_info.org_id!=10340 && item.patient!=undefined&&item.patient.id > 0">
                   <span   v-show="show && (item.order!=undefined&&item.order.stage == 0) && item.patient.id > 0" class="cancel" @click.stop="DeleteSchedule(item.id,item.order.stage,item.patient.name)">取消排班</span>
                   <span v-show="(showOne || (item.order!=undefined && item.order.stage != 0)) && item.patient.id > 0" @click.stop="DeleteSchedule(item.patient.id,item.order.stage,item.patient.name)"  class="canceltwo">取消排班</span>
                   <span v-show="item.patient.id == 0" class="canceltwo" style="visibility: hidden;">取消排班</span>
                </div>

                 <div  v-if="$store.getters.user.template_info.org_id ==10340 && $store.getters.user.user.user_title!=7&& item.patient!=undefined&&item.patient.id > 0">
                  <span  v-show="show && item.order!=undefined&&item.order.stage == 0 && item.patient.id > 0" class="cancel" @click.stop="DeleteSchedule(item.id,item.order.stage,item.patient.name)">取消排班</span>
                  <span v-show="(showOne || (item.order!=undefined&&item.order.stage != 0)) && item.patient.id > 0" @click.stop="DeleteSchedule(item.patient.id,item.order.stage,item.patient.name)"  class="canceltwo">取消排班</span>
                  <span v-show="item.patient.id == 0" class="canceltwo" style="visibility: hidden;">取消排班</span>
                </div>
            </div>

        </div>

        <div>
          <van-popup v-model="scheduleShow" position="bottom" :style="{ height: '100%' }">
            <div class="patientPopup">
              <div style="display:flex;align-items: center;">
                <van-icon name="arrow-left" size="1.5rem" @click="closePopup" />
                <van-search
                  style="width:100%"
                  v-model="patientVal"
                  placeholder="搜索患者姓名/透析号"
                  @input="searchPatientVal"
                />
              </div>
              <div class="patientContent">
                <div class="patientList">
                  <div :class="activePatient == index ? 'activePatient patientCell' : 'patientCell'" @click="choosePatient(item,index)" v-for="(item,index) in patientList" :key="index + 'no'">
                    <span>{{ item.name }}</span>
                    <span>（{{ item.dialysis_no }}）</span>
                  </div>
                </div>
                <div @click="createSchedule">确定排班</div>
              </div>
            </div>
          </van-popup>

          <van-popup v-model="changeTypeShow" get-container="#app" position="bottom" :style="{ height: '60%' }">
            <van-dropdown-menu>
              <div>
                <van-dropdown-item class="maxheight" v-model="modeValue" :options="modeOptions" @change="changeMode" />
                <!-- <van-dropdown-item class="maxheight" v-model="dialyzerValue" :options="DialyzerOptions" @change="changeDialyzer" />
                <van-dropdown-item class="maxheight" v-model="irrigationValue" :options="irrigationOptions" @change="changeIrrigation" /> -->
                <van-dropdown-item class="maxheight" v-model="classValue" :options="classOptions" @change="changeClass" />
              </div>
            </van-dropdown-menu>
          </van-popup>
            <van-popup v-model="typeShow" position="bottom" :style="{ height: '40%' }">
                <van-picker
                show-toolbar
                :columns="typeColumns"
                @confirm="chooseType"
                @cancel="typeShow = false"
                />
            </van-popup>
            <van-popup v-model="areaShow" position="bottom" :style="{ height: '40%' }">
                <van-picker
                show-toolbar
                :columns="areaColumns"
                @confirm="chooseArea"
                @cancel="areaShow = false"
                />
            </van-popup>
            <van-popup v-model="dateShow" position="bottom" :style="{ height: '40%' }">
                <van-datetime-picker
                v-model="currentDate"
                type="date"
                :min-date="minDate"
                :max-date="maxDate"
                @confirm="getNowDate"
                @cancel="dateShow = false"
                />
            </van-popup>
            <van-popup
              title="调班"
              v-model="showTb"
              class="appPopup"
              get-container="#app"
              :overlay="true"
              :close-on-click-overlay="false"
            >
            <tb-dialog :scheduleAll="scheduleAll" :currentPatient="currentPatient" @getlist="getlist"  @close="closeTbclose">
            </tb-dialog>

            </van-popup>

            <van-popup v-model="changeTypeShowOne" get-container="#app" position="bottom" :style="{ height: '60%' }">
            <van-dropdown-menu>
              <div>
                <van-dropdown-item class="maxheight" v-model="modeValue" :options="modeOptions" @change="changeModeOne" />
                <van-dropdown-item class="maxheight" v-model="classValue" :options="classOptions" @change="changeClassOne" />
                 <van-dropdown-item class="maxheight" v-model="zoneValue" :options="zoneOptions" @change="changeZonOne" />
                <van-dropdown-item class="maxheight" v-model="bedValue" :options="bedOptions" @change="changeBed" />
              </div>
            </van-dropdown-menu>
          </van-popup>
        </div>
    </div>
</template>

<script>
import { getPatientScheduleList, GetAllZone, GetAllZonePb, DeleteSchedule, searchPatient, updatePatientSchedule, getAllPatient, createSchedule, updateScheduleInfo, updateScheduleMode, updateScheduleDialysisPrescription, getSolutionSchedule, getAllBedList, changeScheduleModeById, changeScheduleType, changeScheduleBed,toInspection } from '@/api/staff_schedule'
import { Dialog, Toast } from 'vant'
import TbDialog from './TbDialog.vue'
import { sort } from 'semver'
var timeOutEvent = 0
export default {
  components: {
    TbDialog
  },
  data () {
    return {
      schedulingVal: '',
      nowDate: new Date(),
      type: '全部班',
      area: '全部分区',
      dateShow: false,
      typeShow: false,
      areaShow: false,
      showTb: false,
      changeTypeShowOne: false,
      currentDate: new Date(),
      minDate: new Date(1970, 0, 1),
      maxDate: new Date(2025, 10, 1),
      typeColumns: ['全部班', '上午', '下午', '晚上'],
      areaColumns: [],
      currentPatient: {},
      start_time: 0,
      class_type: 0,
      area_type: 0,
      zones: [],
      schedule: [],
      todayDate: 0,
      show: true,
      showOne: false,
      zoneid: 0,
      scheArr: [],
      spanIndex: [],
      changeTypeShow: false,
      modeOptions: [
        { text: '透析模式', value: 0 }
      ],
      bedOptions: [
        {text: '床位号', value: 0}
      ],
      DialyzerOptions: [
        { text: '透析器', value: '' }
      ],
      irrigationOptions: [
        { text: '灌流器', value: '' }
      ],
      classOptions: [
        { text: '更改班次', value: 0 },
        { text: '上午', value: 1 },
        { text: '下午', value: 2 },
        { text: '晚上', value: 3 }
      ],
      zoneOptions: [{text: '分区', value: 0}],
      modeValue: 0,
      bedValue: 0,
      dialyzerValue: '',
      irrigationValue: '',
      classValue: 0,
      zoneValue: 0,
      scheduleShow: false,
      org_id: 0,
      isOpen: false,
      patientQuery: {
        keywords: '',
        schedule: 0,
        contagion: 0
      },
      scheduleAll: {},
      patientList: [],
      patientListMap: [],
      currentData: {
        id: 0,
        schedule_date: '',
        schedule_type: 0,
        bed_id: 0,
        partition_id: 0,
        patient_id: 0,
        schedule_week: 0,
        mode_id: 0,
        type_name: '',
        bed_name: '',

        partition_type: 0,
        contagions: [],
        patient: ''
      },
      activePatient: -1,
      patientIndex: -1,
      patientVal: '',
      patientParams: {
        patient_id: 0,
        mode_id: 0,
        schedule_type: 1,
        start_time: 0,
        dialyzer_perfusion_apparatus: '',
        bed_id: 0
      },
      solutionList: [],
      id: 0,
      patient_id: 0,
      schedule_date: 0,
      bed_id: 0,
      partition_id: 0,
      schedule_week: 0,
      mode_id: 0,
      schedule_type: 0,
      is_open: 0
    }
  },
  computed: {
    seheduleCom: function () {
      var scheduleMap = new Array()
      // console.log("hhhhahhahah",this.isOpen)
      if (this.isOpen == false) {
        if (this.scheduleAll.length > 0) {
          this.scheduleAll.forEach((item, index) => {
            item.device.forEach((device, dindex) => {
              if (device.schedule.length > 0) {
                device.schedule.forEach((schedule, sindex) => {
                  schedule['zone_name'] = item['name']
                  schedule['number_name'] = device['number']
                  schedule['sort'] = device['sort']
                  if (schedule.mode_id == 0) {
                    schedule.mode_name = ''
                  }
                  if (schedule.mode_id == 1) {
                    schedule.mode_name = 'HD'
                  }
                  if (schedule.mode_id == 2) {
                    schedule.mode_name = 'HDF'
                  }
                  if (schedule.mode_id == 3) {
                    schedule.mode_name = 'HD+HP'
                  }
                  if (schedule.mode_id == 4) {
                    schedule.mode_name = 'HP'
                  }
                  if (schedule.mode_id == 5) {
                    schedule.mode_name = 'HF'
                  }
                  if (schedule.mode_id == 6) {
                    schedule.mode_name = 'SCUF'
                  }
                  if (schedule.mode_id == 7) {
                    schedule.mode_name = 'IUF'
                  }
                  if (schedule.mode_id == 8) {
                    schedule.mode_name = 'HFHD'
                  }
                  if (schedule.mode_id == 9) {
                    schedule.mode_name = 'HFHD+HP'
                  }
                  if (schedule.mode_id == 10) {
                    schedule.mode_name = 'PHF'
                  }
                  if (schedule.mode_id == 11) {
                    schedule.mode_name = 'HFR'
                  }
                  if (schedule.mode_id == 12) {
                    schedule.mode_name = 'HDF+HP'
                  }
                  if (schedule.mode_id == 13) {
                    schedule.mode_name = 'CRRT'
                  }
                  if (schedule.mode_id == 14) {
                    schedule.mode_name = '腹水回输'
                  }
                  if (schedule.mode_id == 19) {
                    schedule.mode_name = 'IUF+HD'
                  }
                  if (schedule.mode_id == 20) {
                    schedule.mode_name = 'UF'
                  }
                  if (schedule.mode_id == 21) {
                    schedule.mode_name = 'HD+'
                  }
                  if (schedule.mode_id == 22) {
                    schedule.mode_name = '血浆胆红素吸附+HDF'
                  }
                  if (schedule.mode_id == 24) {
                    schedule.mode_name = 'I-HDF'
                  }
                  if (schedule.mode_id == 25) {
                    schedule.mode_name = 'HD高通'
                  }
                  if (schedule.mode_id == 26) {
                    schedule.mode_name = 'CVVH'
                  }
                  if (schedule.mode_id == 27) {
                    schedule.mode_name = 'CVVHD'
                  }
                  if (schedule.mode_id == 28) {
                    schedule.mode_name = 'CVVHDF'
                  }
                  if (schedule.mode_id == 29) {
                    schedule.mode_name = 'PE'
                  }
                  if (schedule.mode_id == 30) {
                    schedule.mode_name = '血浆胆红素吸附+HP'
                  }

                  if (schedule.mode_id == 31) {
                    schedule.mode_name = 'HPD'
                  }

                  if (schedule.mode_id == 32) {
                    schedule.mode_name = 'HDP'
                  }

                  if (schedule.mode_id == 33) {
                    schedule.mode_name = 'HFD'
                  }

                  if (schedule.mode_id == 34) {
                    schedule.mode_name = 'HDF100'
                  }

                  if (schedule.mode_id == 35) {
                    schedule.mode_name = 'HDF600'
                  }


                  
                  if (schedule.prescription != undefined && schedule.prescription.id > 0) {
                    schedule.anticoagulant = 0
                    schedule.anticoagulant = schedule.prescription.anticoagulant
                  } else {
                    if (schedule.vmsolution != undefined) {
                      schedule.anticoagulant = 0
                      schedule.anticoagulant = schedule.vmsolution.anticoagulant
                    }
                  }

                  if (schedule.prescription != undefined && schedule.prescription.id > 0) {
                    schedule.calcium = 0
                    schedule.calcium = schedule.prescription.calcium
                  } else {
                    if (schedule.vmsolution != undefined) {
                      schedule.calcium = 0
                      schedule.calcium = schedule.vmsolution.calcium
                    }
                  }

                  if (schedule != undefined && schedule.anticoagulant == 0) {
                    schedule.anticoagulant_name = ''
                  }
                  if (schedule != undefined && schedule.anticoagulant == 1) {
                    schedule.anticoagulant_name = '无肝素'
                  }
                  if (schedule != undefined && schedule.anticoagulant == 2) {
                    schedule.anticoagulant_name = '普通肝素'
                  }
                  if (schedule != undefined && schedule.anticoagulant == 3) {
                    schedule.anticoagulant_name = '低分子肝素'
                  }
                  if (schedule != undefined && schedule.anticoagulant == 4) {
                    schedule.anticoagulant_name = '阿加曲班'
                  }
                  if (schedule != undefined && schedule.anticoagulant == 5) {
                    schedule.anticoagulant_name = '枸橼酸钠'
                  }
                  if (schedule != undefined && schedule.anticoagulant == 6) {
                    schedule.anticoagulant_name = '低分子肝素钙'
                  }
                  if (schedule != undefined && schedule.anticoagulant == 7) {
                    schedule.anticoagulant_name = '低分子肝素钠'
                  }
                  if (schedule != undefined && schedule.anticoagulant == 8) {
                    schedule.anticoagulant_name = '依诺肝素'
                  }
                  if (schedule != undefined && schedule.anticoagulant == 9) {
                    schedule.anticoagulant_name = '达肝素'
                  }
                  if (schedule != undefined && schedule.anticoagulant == 10) {
                    schedule.anticoagulant_name = '体外抗凝'
                  }
                  if (schedule != undefined && schedule.anticoagulant == 11) {
                    schedule.anticoagulant_name = '那屈肝素'
                  }
                  if (schedule != undefined && schedule.anticoagulant == 12) {
                    schedule.anticoagulant_name = '无抗凝剂'
                  }
                  if (schedule != undefined && schedule.anticoagulant == 13) {
                    schedule.anticoagulant_name = '那屈肝素钙'
                  }
                  if (this.zoneid == 0 || this.zoneid == item.id) {
                    if (this.class_type == 0 || this.class_type == schedule.schedule_type) {
                      if (this.schedulingVal == '' || 
                          schedule.patient.name.includes(this.schedulingVal) || 
                          schedule.patient.first_letter.includes(this.schedulingVal)) {
                            // console.log('asdasfsasrds',this.schedulingVal);
                        scheduleMap.push(schedule)
                      }
                    }
                  }
                })
              }
            })
          })
        }
      }
     
      if (this.isOpen == true) {
        if (this.scheduleAll != null && this.scheduleAll.length > 0) {
          this.scheduleAll.forEach((item, index) => {
            // console.log('itme0000-----', item)
            item.device.forEach((device, dindex) => {
              if (device.schedule.length > 0) {
                for (let i = 0; i < device.schedule.length; i++) {
                 
                  if (device.schedule.length == 1) {
                    if (device.schedule[i].schedule_type == 1) {
                      var objTwo = {}
                      var objThree = {}
                      objTwo.zone_name = item.name
                      objTwo.number_name = device['number']
                      objTwo.bed_id = device['id']
                      objTwo.zone_id = device['zone_id']
                      objTwo.schedule_type = 2
                      objTwo.mode_id = 1
                      objTwo.sort = device['sort']

                      objThree.zone_name = item.name
                      objThree.number_name = device['number']
                      objThree.bed_id = device['id']
                      objThree.zone_id = device['zone_id']
                      objThree.sort = device['sort']
                      objThree.schedule_type = 3
                      objThree.mode_id = 1
                      device.schedule.push(objTwo)
                      device.schedule.push(objThree)

                      break
                    } else if (device.schedule[i].schedule_type == 2) {
                      var obj2 = {}
                      var objThree2 = {}
                      obj2.zone_name = item.name
                      obj2.number_name = device['number']
                      obj2.bed_id = device['id']
                      obj2.zone_id = device['zone_id']
                      obj2.sort = device['sort']
                      obj2.schedule_type = 1
                      obj2.mode_id = 1

                      objThree2.zone_name = item.name
                      objThree2.number_name = device['number']
                      objThree2.bed_id = device['id']
                      objThree2.zone_id = device['zone_id']
                      objThree2.sort = device['sort']
                      objThree2.schedule_type = 3
                      objThree2.mode_id = 1
                      device.schedule.push(obj2)
                      device.schedule.push(objThree2)
                      break
                    } else if (device.schedule[i].schedule_type == 3) {
                      var obj3 = {}
                      var objTwo3 = {}

                      obj3.zone_name = item.name
                      obj3.number_name = device['number']
                      obj3.bed_id = device['id']
                      obj3.zone_id = device['zone_id']
                      obj3.sort = device['sort']
                      obj3.schedule_type = 1
                      obj3.mode_id = 1

                      objTwo3.zone_name = item.name
                      objTwo3.number_name = device['number']
                      objTwo3.bed_id = device['id']
                      objTwo3.zone_id = device['zone_id']
                      objTwo3.sort = device['sort']
                      objTwo3.schedule_type = 2
                      objTwo3.mode_id = 1

                      device.schedule.push(obj3)
                      device.schedule.push(objTwo3)
                      break
                    }
                  }

                  if (device.schedule.length == 2) {
                    if (device.schedule[0].schedule_type == 1 && device.schedule[1].schedule_type == 2) {
                      var obj5 = {}
                      obj5.zone_name = item.name
                      obj5.number_name = device['number']
                      obj5.bed_id = device['id']
                      obj5.zone_id = device['zone_id']
                      obj5.sort = device['sort']
                      obj5.schedule_type = 3
                      obj5.mode_id = 1
                      device.schedule.push(obj5)
                    }
                    if (device.schedule[0].schedule_type == 1 && device.schedule[1].schedule_type == 3) {
                      var obj6 = {}
                      obj6.zone_name = item.name
                      obj6.number_name = device['number']
                      obj6.bed_id = device['id']
                      obj6.zone_id = device['zone_id']
                      obj6.sort = device['sort']
                      obj6.schedule_type = 2
                      obj6.mode_id = 1
                      device.schedule.push(obj6)
                    }
                    if (device.schedule[0].schedule_type == 2 && device.schedule[1].schedule_type == 1) {
                      var obj7 = {}
                      obj7.zone_name = item.name
                      obj7.number_name = device['number']
                      obj7.bed_id = device['id']
                      obj7.zone_id = device['zone_id']
                      obj7.sort = device['sort']
                      obj7.schedule_type = 3
                      obj7.mode_id = 1
                      device.schedule.push(obj7)
                    }
                    if (device.schedule[0].schedule_type == 2 && device.schedule[1].schedule_type == 3) {
                      var obj8 = {}
                      obj8.zone_name = item.name
                      obj8.number_name = device['number']
                      obj8.bed_id = device['id']
                      obj8.zone_id = device['zone_id']
                      obj8.sort = device['sort']
                      obj8.schedule_type = 1
                      obj8.mode_id = 1
                      device.schedule.push(obj8)
                    }

                    if (device.schedule[0].schedule_type == 3 && device.schedule[1].schedule_type == 1) {
                      var obj9 = {}
                      obj9.zone_name = item.name
                      obj9.number_name = device['number']
                      obj9.bed_id = device['id']
                      obj9.zone_id = device['zone_id']
                      obj9.sort = device['sort']
                      obj9.schedule_type = 2
                      obj9.mode_id = 1
                      device.schedule.push(obj9)
                    }
                    if (device.schedule[0].schedule_type == 3 && device.schedule[1].schedule_type == 2) {
                      var obj10 = {}
                      obj10.zone_name = item.name
                      obj10.number_name = device['number']
                      obj10.bed_id = device['id']
                      obj10.zone_id = device['zone_id']
                      obj10.sort = device['sort']
                      obj10.schedule_type = 1
                      obj10.mode_id = 1
                      device.schedule.push(obj10)
                    }
                  }
                }
              }

              if (device.schedule.length == 0) {
                var obj4 = {}
                var objTwo4 = {}
                var objThree4 = {}
                obj4.zone_name = item.name
                obj4.number_name = device['number']
                obj4.bed_id = device['id']
                obj4.zone_id = device['zone_id']
                obj4.sort = device['sort']
                obj4.schedule_type = 1
                obj4.mode_id = 1

                objTwo4.zone_name = item.name
                objTwo4.number_name = device['number']
                objTwo4.bed_id = device['id']
                objTwo4.zone_id = device['zone_id']
                objTwo4.sort = device['sort']
                objTwo4.schedule_type = 2
                objTwo4.mode_id = 1

                objThree4.zone_name = item.name
                objThree4.number_name = device['number']
                objThree4.bed_id = device['id']
                objThree4.zone_id = device['zone_id']
                objThree4.sort = device['sort']
                objThree4.schedule_type = 3
                objThree4.mode_id = 1

                device.schedule.push(obj4)
                device.schedule.push(objTwo4)
                device.schedule.push(objThree4)
              }
              device.schedule.forEach((schedule, sindex) => {
               
                schedule['zone_name'] = item['name']
                schedule['number_name'] = device['number']
                schedule['sort'] = device['sort']
                if (schedule.mode_id == 0) {
                  schedule.mode_name = ''
                }
                if (schedule.mode_id == 1) {
                  schedule.mode_name = 'HD'
                }
                if (schedule.mode_id == 2) {
                  schedule.mode_name = 'HDF'
                }
                if (schedule.mode_id == 3) {
                  schedule.mode_name = 'HD+HP'
                }
                if (schedule.mode_id == 4) {
                  schedule.mode_name = 'HP'
                }
                if (schedule.mode_id == 5) {
                  schedule.mode_name = 'HF'
                }
                if (schedule.mode_id == 6) {
                  schedule.mode_name = 'SCUF'
                }
                if (schedule.mode_id == 7) {
                  schedule.mode_name = 'IUF'
                }
                if (schedule.mode_id == 8) {
                  schedule.mode_name = 'HFHD'
                }
                if (schedule.mode_id == 9) {
                  schedule.mode_name = 'HFHD+HP'
                }
                if (schedule.mode_id == 10) {
                  schedule.mode_name = 'PHF'
                }
                if (schedule.mode_id == 11) {
                  schedule.mode_name = 'HFR'
                }
                if (schedule.mode_id == 12) {
                  schedule.mode_name = 'HDF+HP'
                }
                if (schedule.mode_id == 13) {
                  schedule.mode_name = 'CRRT'
                }
                if (schedule.mode_id == 14) {
                  schedule.mode_name = '腹水回输'
                }
                if (schedule.mode_id == 19) {
                  schedule.mode_name = 'IUF+HD'
                }
                if (schedule.mode_id == 20) {
                  schedule.mode_name = 'UF'
                }
                if (schedule.mode_id == 21) {
                  schedule.mode_name = 'HD+'
                }
                if (schedule.mode_id == 22) {
                  schedule.mode_name = '血浆胆红素吸附+HDF'
                }
                if (schedule.mode_id == 24) {
                  schedule.mode_name = 'I-HDF'
                }
                if (schedule.mode_id == 25) {
                  schedule.mode_name = 'HD高通'
                }
                if (schedule.mode_id == 26) {
                  schedule.mode_name = 'CVVH'
                }
                if (schedule.mode_id == 27) {
                  schedule.mode_name = 'CVVHD'
                }
                if (schedule.mode_id == 28) {
                  schedule.mode_name = 'CVVHDF'
                }
                if (schedule.mode_id == 29) {
                  schedule.mode_name = 'PE'
                }
                if (schedule.mode_id == 30) {
                  schedule.mode_name = '血浆胆红素吸附+HP'
                }

                if (schedule.prescription != undefined && schedule.prescription.id > 0) {
                  schedule.anticoagulant = 0
                  schedule.anticoagulant = schedule.prescription.anticoagulant
                } else {
                  if (schedule.vmsolution != undefined) {
                    schedule.anticoagulant = 0
                    schedule.anticoagulant = schedule.vmsolution.anticoagulant
                  }
                }

                if (schedule != undefined && schedule.anticoagulant == 0) {
                  schedule.anticoagulant_name = ''
                }
                if (schedule != undefined && schedule.anticoagulant == 1) {
                  schedule.anticoagulant_name = '无肝素'
                }
                if (schedule != undefined && schedule.anticoagulant == 2) {
                  schedule.anticoagulant_name = '普通肝素'
                }
                if (schedule != undefined && schedule.anticoagulant == 3) {
                  schedule.anticoagulant_name = '低分子肝素'
                }
                if (schedule != undefined && schedule.anticoagulant == 4) {
                  schedule.anticoagulant_name = '阿加曲班'
                }
                if (schedule != undefined && schedule.anticoagulant == 5) {
                  schedule.anticoagulant_name = '枸橼酸钠'
                }
                if (schedule != undefined && schedule.anticoagulant == 6) {
                  schedule.anticoagulant_name = '低分子肝素钙'
                }
                if (schedule != undefined && schedule.anticoagulant == 7) {
                  schedule.anticoagulant_name = '低分子肝素钠'
                }
                if (schedule != undefined && schedule.anticoagulant == 8) {
                  schedule.anticoagulant_name = '依诺肝素'
                }
                if (schedule != undefined && schedule.anticoagulant == 9) {
                  schedule.anticoagulant_name = '达肝素'
                }
                if (schedule != undefined && schedule.anticoagulant == 10) {
                  schedule.anticoagulant_name = '体外抗凝'
                }
                if (this.zoneid == 0 || this.zoneid == item.id) {
                  if (this.class_type == 0 || this.class_type == schedule.schedule_type) {
                    if (this.schedulingVal == '' || 
                      (schedule.patient != undefined && schedule.patient.name.includes(this.schedulingVal)) ||
                      (schedule.patient != undefined && schedule.patient.first_letter.includes(this.schedulingVal))) {
                      scheduleMap.push(schedule)
                    }
                  }
                }
              })
            })
          })
        }
      }
      scheduleMap.sort((a, b) => { return a.sort - b.sort })
      return scheduleMap
    }
  },
  created () {
    let treatment_mode = this.$store.getters.treatment_mode
    let modeArr = Object.values(treatment_mode).map(item => {
      let obj = {
        text: item.name,
        value: item.id
      }
      return obj
    })
    this.modeOptions.push(...modeArr)
    this.org_id = this.$store.getters.user.template_info.org_id
    if (this.org_id == 10223) {
      this.isOpen = true
    }
    if (sessionStorage.getItem('isOpenSchedule')) {
      this.isOpen = sessionStorage.getItem('isOpenSchedule') == 1
    }
    // console.log('我的马来西亚', this.isOpen)
    let value = new Date()
    let year = value.getFullYear()
    let month = value.getMonth() + 1
    let day = value.getDate()
    if (month >= 1 && month <= 9) {
      month = `0${month}`
    }
    if (day >= 1 && day <= 9) {
      day = `0${day}`
    }

    this.nowDate = `${year}-${month}-${day}`
    this.start_time = `${year}-${month}-${day}`

    var now = this.formatDate(new Date())
    this.todayDate = this.getTimestamp(now)

    // 获取所有分区
    // this.GetAllZone()

    // 获取患者排班列表
    this.getlist()
    // this.getAllPatient()
    // this.getSolutionSchedule()
  },
  methods: {
    closeTbclose () {
      this.showTb = false
    },
    gotouchstart (event, index, item) {
      let that = this
      clearTimeout(timeOutEvent)// 清除定时器
      timeOutEvent = 0
      timeOutEvent = setTimeout(function () {
        // 执行长按要执行的内容，

        if (item.patient == undefined) {
          Toast.fail('该床位未有患者!')
          return
        }

        that.modeValue = item.mode_id
        that.dialyzerValue = item.prescription.dialysis_dialyszers ? item.prescription.dialysis_dialyszers : ''
        that.irrigationValue = item.prescription.dialysis_irrigation ? item.prescription.dialysis_irrigation : ''
        that.classValue = item.schedule_type

        that.patientParams.index = index
        that.patientParams.id = item.id
        that.patientParams.patient_id = item.patient_id
        that.patientParams.mode_id = item.mode_id
        that.patientParams.schedule_type = item.schedule_type
        that.patientParams.start_time = item.schedule_date
        that.patientParams.bed_id = item.bed_id
        that.patientParams.dialyzer_perfusion_apparatus = item.prescription.dialysis_dialyszers ? item.prescription.dialysis_dialyszers : ''
        that.patientParams.dialysis_irrigation = item.prescription.dialysis_irrigation ? item.prescription.dialysis_irrigation : ''
        that.changeTypeShow = true
      }, 1000)// 这里设置定时
    },
    // 手释放，如果在500毫秒内就释放，则取消长按事件，此时可以执行onclick应该执行的事件
    gotouchend () {
      clearTimeout(timeOutEvent)
      if (timeOutEvent != 0) {
        // 这里写要执行的内容（尤如onclick事件）
      }
    },
    // 如果手指有移动，则取消所有事件，此时说明用户只是要移动而不是长按
    gotouchmove () {
      clearTimeout(timeOutEvent)// 清除定时器
      timeOutEvent = 0
    },
    formatDate (date) {
      var year = date.getFullYear() + '.'
      var month = (date.getMonth() + 1) + '.'
      var day = date.getDate()
      return year + month + day
    },
    getTimestamp (time) { // 把时间日期转成时间戳
      return (new Date(time)).getTime() / 1000
    },
    searchPatient () {
      const params = {
        keyword: this.schedulingVal,
        start_time: this.start_time
      }
      searchPatient(params).then(response => {
        if (response.data.state == 1) {
          var zoneArr = response.data.data.schedule
          let schedule = []
          zoneArr.map(item => {
            let obj = {
              bed_id: item.bed_id,
              id: item.id,
              mode_id: item.mode_id,
              mode_name: this.getModeName(item.mode_id),
              number: item.number.number,
              order: item.order,
              partition_id: 1,
              patient: {name: item.patient, id: item.patient_id},
              patient_id: item.patient_id,
              prescription: item.dialysis_prescription,
              schedule_date: item.schedule_date,
              schedule_type: item.schedule_type,
              schedule_week: item.schedule_week,
              zone: item.number.zone
            }
            schedule.push(obj)
          })
          for (let i = 0; i < schedule.length; i++) {
            if (schedule[i].schedule_date < this.todayDate) {
              this.showOne = true
              this.show = false
            }
            if (schedule[i].schedule_date > this.todayDate) {
              this.show = true
              this.showOne = false
            }
          }
          this.schedule = schedule
        }
      })
    },
    chooseType (value) {
      this.type = value
      this.typeShow = false
      this.areaColumns = []
      this.getlist()
      // this.getSolutionSchedule()
    },
    chooseArea (value) {
      this.zones.forEach((item, index) => {
        if (value == item.name) {
          this.zoneid = item.id
        }
      })
      this.area = ''
      this.area = value
      this.areaShow = false
      this.getlist()
      // this.getSolutionSchedule()
    },
    getNowDate (value) {
      let year = value.getFullYear()
      let month = value.getMonth() + 1
      let day = value.getDate()
      if (month >= 1 && month <= 9) {
        month = `0${month}`
      }
      if (day >= 1 && day <= 9) {
        day = `0${day}`
      }

      this.nowDate = `${year}-${month}-${day}`
      this.start_time = `${year}-${month}-${day}`
      this.dateShow = false
      this.getlist()
      this.getSolutionSchedule()
    },
    toReturn () {
      this.$router.push('/homeIndex')
    },
    toClick () {
      this.$router.push('add_urgent_schedule')
    },
    getlist () {
      if (this.type == '全部班') {
        this.class_type = 0
      }
      if (this.type == '上午') {
        this.class_type = 1
      }
      if (this.type == '下午') {
        this.class_type = 2
      }
      if (this.type == '晚上') {
        this.class_type = 3
      }

      const params = {
        start_time: this.start_time,
        classtype: this.class_type
      }
      GetAllZonePb(params).then(response => {
        if (response.data.state == 1) {
          var resp_data = response.data.data.schedule
          // console.log('resp_date23233223222', resp_data)
          this.scheduleAll = resp_data
          // 设置分区信息
          this.zones = []

          var newArr = []

          if (this.scheduleAll != null) {
            for (let j = 0; j < this.scheduleAll.length; j++) {
              if (this.scheduleAll[j].device != null) {
                for (let i = 0; i < this.scheduleAll[j].device.length; i++) {
                  if (this.scheduleAll[j].device[i].schedule.length > 0) {
                    newArr.push(...this.scheduleAll[j].device[i].schedule)
                  }
                }
              }
            }
          }

          var zoneArrList = []
          if (newArr.length != null && newArr.length > 0) {
            for (let i = 0; i < newArr.length; i++) {
              if (this.class_type == 0) {
                zoneArrList.push(newArr[i])
              }
              if (this.class_type == 1) {
                if (newArr[i].schedule_type == 1) {
                  zoneArrList.push(newArr[i])
                }
              }
              if (this.class_type == 2) {
                if (newArr[i].schedule_type == 2) {
                  zoneArrList.push(newArr[i])
                }
              }
              if (this.class_type == 3) {
                if (newArr[i].schedule_type == 3) {
                  zoneArrList.push(newArr[i])
                }
              }
            }
          }
          var total = 0
          let dataInfo = {}
          var newList = []
          if (zoneArrList != null && zoneArrList.length > 0) {
            total = zoneArrList.length

            zoneArrList.forEach((item, index) => {
              let { partition_id } = item
              if (!dataInfo[partition_id]) {
                dataInfo[partition_id] = {
                  partition_id,
                  child: []

                }
              }
            })
            let arr = Object.values(dataInfo)

            if (arr != null) {
              for (let i = 0; i < zoneArrList.length; i++) {
                for (let j = 0; j < arr.length; j++) {
                  if (zoneArrList[i].partition_id == arr[j].partition_id) {
                    arr[j].child.push(zoneArrList[i])
                  }
                }
              }
            }
            newList = arr
          }
          if (this.area == '全部分区') {
            this.area = ''
            this.area = '全部分区' + '(' + total + ')'
          }

          var obj = {id: 0, name: '全部分区'}

          this.zones.push(obj)
          for (let i = 0; i < resp_data.length; i++) {
            var obj1 = {id: 0, name: '全部分区'}
            obj1.name = resp_data[i].name
            obj1.id = resp_data[i].id
            this.zones.push(obj1)
          }

          for (let i = 0; i < this.zones.length; i++) {
            if (this.zones[i].id == 0) {
              this.zones[i].name = this.zones[i].name + '(' + total + ')'
            }
            this.area = ''
            this.area = '全部分区' + '(' + total + ')'
          }
          if (newList != null) {
            for (let i = 0; i < newList.length; i++) {
              for (let j = 0; j < this.zones.length; j++) {
                if (newList[i].partition_id == this.zones[j].id) {
                  this.zones[j].name = this.zones[j].name + '(' + newList[i].child.length + ')'
                }
              }
            }
          }

          var arr = []
          for (let i = 0; i < this.zones.length; i++) {
            arr.push(this.zones[i].name)
          }

          this.areaColumns = arr
        }
      })
    },
    GetAllZone () {
      GetAllZone().then(response => {
        if (response.data.state == 1) {
          var obj = {id: 0, name: '全部分区'}
          var zone = response.data.data.zone
          for (let i = 0; i < zone.length; i++) {
            zone[i].text = zone[i].name
            zone[i].value = zone[i].id
            this.zoneOptions.push(zone[i])
          }
          this.zones.push(obj)
          this.zones.push(...zone)
          var arr = []
          for (let i = 0; i < this.zones.length; i++) {
            arr.push(this.zones[i].name)
          }
          this.areaColumns = arr
        }
      })
    },
    DeleteSchedule (id, stage, name) {
      if (stage == 1) {
        this.$toast('患者已上机，不能取消排班')
        return false
      }
      if (stage == 2) {
        this.$toast('患者已下机，不能取消排班')
        return false
      }
      Dialog.confirm({
        title: '删除提示!',
        message: '是否确认要删除' + name + '的排班'
      }).then(() => {
        DeleteSchedule(id).then(response => {
          if (response.data.state == 1) {
            var msg = response.data.data.msg
            this.$toast('取消成功!')
            this.getlist()
            this.getSolutionSchedule()
          }else{
            var msg = response.data.msg
            this.$toast(msg)
          }
        })
      })
    },
    modeColor (id) {
      if (id == 'HD') {

      } else if (id == 'HDF') {
        return 'modeRed'
      } else if (id == 'HD+HP') {
        return 'modePurple'
      }
    },
    toEditPatient (id, index, stage) {
      if (stage == 1 || stage == 2) {
        this.$toast('已上机的患者不能调换床位号!')
        return
      }
      this.scheArr.push(id)
      let arrIndex = this.spanIndex.indexOf(index)
      if (arrIndex > -1) {
        this.spanIndex.splice(arrIndex, 1)
      } else {
        this.spanIndex.push(index)
        if (this.spanIndex.length > 2) {
          this.spanIndex.shift()
        }
      }
      // console.log('arrr000000', this.scheArr)
      if (this.scheArr[0] == this.scheArr[1]) {
        this.$toast('请选择不同床位的互换')
        this.scheArr = []
        this.spanIndex = []
        return
      }
      if (this.scheArr.length == 2) {
        Dialog.confirm({
          title: '提示!',
          message: '是否确认要更换位置'
        }).then(() => {
          var ids = this.scheArr.join(',')
          var params = {
            ids: ids
          }
          updatePatientSchedule(params).then(response => {
            if (response.data.state === 1) {
              var msg = response.data.data.msg
              this.getlist()
              this.$toast('保存成功')
              this.scheArr = []
              this.spanIndex = []
            }
          })
        }).catch(() => {
          this.scheArr = []
          this.spanIndex = []
        })
      }
    },
    changeIsOpen (isOpen) {
      let isOpenNum = 1
      if (isOpen) {
        isOpenNum = 1
      } else {
        isOpenNum = 2
      }
      let message = isOpen ? '是否展示空床位？' : '是否隐藏空床位？'
      Dialog.confirm({
        title: '提醒',
        message: message
      }).then(() => {
        this.isOpen = isOpen
        this.getlist()
      }).catch(() => {
        // on cancel
      })
      sessionStorage.setItem('isOpenSchedule', isOpenNum)
    },
    getAllPatient () {
      getAllPatient(this.patientQuery).then(res => {

        this.patientList = res.data.data.patients
        this.patientListMap = res.data.data.patients
      }).catch(() => {})
    },
    openPatientList (row, index) {
      if (this.isOpen == false) {
        this.getAllPatient()
        this.patientIndex = index
        this.currentData.schedule_date = this.nowDate
        this.currentData.schedule_type = row.schedule_type
        this.currentData.bed_id = row.bed_id
        this.currentData.partition_id = row.zone.id
        this.currentData.schedule_week = this.getWeekDay(new Date(this.nowDate))

        switch (row.schedule_type) {
          case 1:
            this.currentData.type_name = '上午'
            break
          case 2:
            this.currentData.type_name = '下午'
            break
          case 3:
            this.currentData.type_name = '晚上'
            break
        }

        this.currentData.zone_name = row.zone.name
        this.currentData.bed_name = row.number
        this.currentData.partition_type = row.zone.type

        this.currentData.id = 0
        this.scheduleShow = true
      }

      if (this.isOpen == true) {
        this.scheduleShow = true
        this.patientIndex = index
        this.currentData.schedule_date = this.nowDate
        this.currentData.schedule_type = row.schedule_type
        this.currentData.bed_id = row.bed_id
        this.currentData.partition_id = row.zone_id
        this.currentData.schedule_week = this.getWeekDay(new Date(this.nowDate))

        switch (row.schedule_type) {
          case 1:
            this.currentData.type_name = '上午'
            break
          case 2:
            this.currentData.type_name = '下午'
            break
          case 3:
            this.currentData.type_name = '晚上'
            break
        }

        // this.currentData.zone_name = row.zone.name
        // this.currentData.bed_name = row.number
        // this.currentData.partition_type = row.zone.type

        this.currentData.id = 0
        this.getAllPatient()
      }
    },
    closePopup () {
      this.activePatient = -1
      this.currentData = {
        id: 0,
        schedule_date: '',
        schedule_type: 0,
        bed_id: 0,
        partition_id: 0,
        patient_id: 0,
        schedule_week: 0,
        mode_id: 0,
        type_name: '',
        bed_name: '',

        partition_type: 0,
        contagions: [],
        patient: ''
      },
      this.scheduleShow = false
    },
    choosePatient (row, index) {
      this.activePatient = index
      this.currentData.mode_id = 1
      this.currentData.patient_id = row.id
      this.currentData.patient = ''
      this.currentData.contagions = row.contagions
    },
    createSchedule () {
      if (this.currentData.patient_id == 0) {
        Toast.fail('请选择需要排班患者')
        return
      }
      // console.log('param23223233223', this.currentData)
      createSchedule(this.currentData.patient_id, this.currentData).then(res => {
        if (res.data.state == 0) {
          Toast.fail(res.data.msg)
        } else {
          this.scheduleShow = false
          Toast.success('排班成功!')
          this.getlist()
        }
      }).catch(() => {})
    },
    getWeekDay (date) {
      var week
      if (date.getDay() == 0) week = 7
      if (date.getDay() == 1) week = 1
      if (date.getDay() == 2) week = 2
      if (date.getDay() == 3) week = 3
      if (date.getDay() == 4) week = 4
      if (date.getDay() == 5) week = 5
      if (date.getDay() == 6) week = 6
      return week
    },
    searchPatientVal (val) {
      if (val.length > 0) {
        var scheduals = []
        for (let index = 0; index < this.patientListMap.length; index++) {
          const schedual = this.patientListMap[index]
          if (schedual.name.indexOf(val) != -1 || schedual.dialysis_no.indexOf(val) != -1) {
            scheduals.push(schedual)
          }
        }
        this.patientList = scheduals
      } else {
        this.getAllPatient()
      }
    },
    changeClass (value) {
      if (value == 0) {
        Toast.fail('请选择正确的排班!')
        return
      }
      let params = {
        patient_id: this.patientParams.patient_id,
        mode_id: this.patientParams.mode_id,
        schedule_type: value,
        start_time: this.patientParams.start_time,
        bed_id: this.patientParams.bed_id
      }
      updateScheduleInfo(params).then(res => {
        if (res.data.data.msgerr == '排班已存在') {
          Toast.fail(res.data.data.msgerr)
        } else {
          this.getlist()
          setTimeout(() => {
            Toast.success('更新成功!')
          }, 100)
        }
      }).catch(() => {})
    },
    changeMode (value) {
      if (value == '') {
        Toast.fail('请选择正确的透析模式!')
        return
      }
      this.patientParams.mode_id = value
      let params = {
        id: this.patientParams.id,
        mode_id: this.patientParams.mode_id
      }
      updateScheduleMode(params).then(res => {
        // console.log(res)
        if (res.data.state == 0) {
          Toast.fail('保存失败!')
        } else {
          Toast.success('保存成功!')
          this.getlist()
          // this.schedule[this.patientParams.index].mode_id = value
          // this.schedule[this.patientParams.index].mode_name = this.getModeName(value)
        }
      })
    },
    changeModeOne (value) {
      var params = {
        id: this.id,
        mode_id: value,
        schedule_date: this.schedule_date,
        patient_id: this.patient_id
      }

      changeScheduleModeById(params).then(response => {
        if (response.data.state == 1) {
          Toast.fail('保存成功!')
          this.changeTypeShowOne = false
          this.getlist()
        } else {
          Toast.fail('保存失败!')
        }
      })
    },
    changeBed (value) {
      var params = {
        schedule_type: this.schedule_type,
        schedule_date: this.schedule_date,
        patient_id: this.patient_id,
        bed_id: value,
        schedule_week: this.schedule_week,
        mode_id: this.mode_id,
        id: this.id
      }
      // console.log('param232323223', params)
      changeScheduleBed(params).then(response => {
        if (response.data.state == 1) {
          Toast.fail('保存成功!')
          this.changeTypeShowOne = false
          this.getlist()
        } else {
          Toast.fail('被调用床位已有患者上机,调用失败!')
        }
      })
    },
    changeClassOne (value) {
      var params = {
        schedule_type: value,
        schedule_date: this.schedule_date,
        patient_id: this.patient_id,
        bed_id: this.bed_id,
        schedule_week: this.schedule_week,
        mode_id: this.mode_id,
        id: this.id
      }
      changeScheduleType(params).then(response => {
        if (response.data.state == 1) {
          Toast.fail('保存成功!')
          this.changeTypeShowOne = false
          this.getlist()
        } else {
          Toast.fail('被调用床位已有患者上机,调班失败!')
        }
      })
    },
    getModeName (mode_id) {
      let mode_name = ''
      if (mode_id == 0) {
        mode_name = ''
      }
      if (mode_id == 1) {
        mode_name = 'HD'
      }
      if (mode_id == 2) {
        mode_name = 'HDF'
      }
      if (mode_id == 3) {
        mode_name = 'HD+HP'
      }
      if (mode_id == 4) {
        mode_name = 'HP'
      }
      if (mode_id == 5) {
        mode_name = 'HF'
      }
      if (mode_id == 6) {
        mode_name = 'SCUF'
      }
      if (mode_id == 7) {
        mode_name = 'IUF'
      }
      if (mode_id == 8) {
        mode_name = 'HFHD'
      }
      if (mode_id == 9) {
        mode_name = 'HFHD+HP'
      }
      if (mode_id == 10) {
        mode_name = 'PHF'
      }
      if (mode_id == 11) {
        mode_name = 'HFR'
      }
      if (mode_id == 12) {
        mode_name = 'HDF+HP'
      }
      if (mode_id == 13) {
        mode_name = 'CRRT'
      }
      if (mode_id == 14) {
        mode_name = '腹水回输'
      }
      if (mode_id == 19) {
        mode_name = 'IUF+HD'
      }
      if (mode_id == 20) {
        mode_name = 'UF'
      }
      if (mode_id == 21) {
        mode_name = 'HD+'
      }
      if (mode_id == 22) {
        mode_name = '血浆胆红素吸附+HDF'
      }
      if (mode_id == 24) {
        mode_name = 'I-HDF'
      }
      if (mode_id == 25) {
        mode_name = 'HD高通'
      }
      if (mode_id == 26) {
        mode_name = 'CVVH'
      }
      if (mode_id == 27) {
        mode_name = 'CVVHD'
      }
      if (mode_id == 28) {
        mode_name = 'CVVHDF'
      }
      return mode_name
    },
    changeDialyzer (value) {
      let params = {
        mode_id: this.schedule[this.patientParams.index].mode_id,
        patient_id: this.patientParams.patient_id,
        start_time: this.patientParams.start_time,
        dialyzer_perfusion_apparatus: value,
        dialysis_irrigation: this.patientParams.dialysis_irrigation
      }

      updateScheduleDialysisPrescription(params).then(res => {
        if (res.data.state == 0) {
          Toast.fail('保存失败!')
        } else {
          this.schedule[this.patientParams.index].prescription.dialysis_dialyszers = value
          this.patientParams.dialyzer_perfusion_apparatus = value
          Toast.success('保存成功!')
        }
      })
    },
    changeIrrigation (value) {
      let params = {
        mode_id: this.schedule[this.patientParams.index].mode_id,
        patient_id: this.patientParams.patient_id,
        start_time: this.patientParams.start_time,
        dialyzer_perfusion_apparatus: this.patientParams.dialyzer_perfusion_apparatus,
        dialysis_irrigation: value
      }
      updateScheduleDialysisPrescription(params).then(res => {
        if (res.data.state == 0) {
          Toast.fail('保存失败!')
        } else {
          this.schedule[this.patientParams.index].prescription.dialysis_irrigation = value
          this.patientParams.dialysis_irrigation = value
          Toast.success('保存成功!')
        }
      })
    },
    getSolutionSchedule () {
      var params = {
        start_time: this.start_time,
        zoneid: this.zoneid,
        classtype: this.class_type
      }
      getSolutionSchedule(params).then(response => {
        if (response.data.state == 1) {
          var schedule = response.data.data.schedule

          for (let i = 0; i < schedule.length; i++) {
            if (schedule[i].vmsolution.mode_id == 1) {
              schedule[i].vmsolution.mode_name = 'HD'
            }
            if (schedule[i].vmsolution.mode_id == 2) {
              schedule[i].vmsolution.mode_name = 'HDF'
            }
            if (schedule[i].vmsolution.mode_id == 3) {
              schedule[i].vmsolution.mode_name = 'HD+HP'
            }
            if (schedule[i].vmsolution.mode_id == 4) {
              schedule[i].vmsolution.mode_name = 'HP'
            }
            if (schedule[i].vmsolution.mode_id == 5) {
              schedule[i].vmsolution.mode_name = 'HF'
            }
            if (schedule[i].vmsolution.mode_id == 6) {
              schedule[i].vmsolution.mode_name = 'SCUF'
            }
            if (schedule[i].vmsolution.mode_id == 7) {
              schedule[i].vmsolution.mode_name = 'IUF'
            }
            if (schedule[i].vmsolution.mode_id == 8) {
              schedule[i].vmsolution.mode_name = 'HFHD'
            }
            if (schedule[i].vmsolution.mode_id == 9) {
              schedule[i].vmsolution.mode_name = 'HFHD+HP'
            }
            if (schedule[i].vmsolution.mode_id == 10) {
              schedule[i].vmsolution.mode_name = 'PHF'
            }
            if (schedule[i].vmsolution.mode_id == 11) {
              schedule[i].vmsolution.mode_name = 'HFR'
            }
            if (schedule[i].vmsolution.mode_id == 12) {
              schedule[i].vmsolution.mode_name = 'HDF+HP'
            }
            if (schedule[i].vmsolution.mode_id == 13) {
              schedule[i].vmsolution.mode_name = 'CRRT'
            }
            if (schedule[i].vmsolution.mode_id == 14) {
              schedule[i].vmsolution.mode_name = '腹水回输'
            }
            if (schedule[i].vmsolution.mode_id == 19) {
              schedule[i].vmsolution.mode_name = 'IUF+HD'
            }
            if (schedule[i].vmsolution.mode_id == 20) {
              schedule[i].vmsolution.mode_name = 'UF'
            }
            if (schedule[i].vmsolution.mode_id == 21) {
              schedule[i].vmsolution.mode_name = 'HD+'
            }
            if (schedule[i].vmsolution.mode_id == 18) {
              schedule[i].vmsolution.mode_name = 'SCUF'
            }
            if (schedule[i].vmsolution.mode_id == 19) {
              schedule[i].vmsolution.mode_name = 'SCUF'
            }
            if (schedule[i].vmsolution.mode_id == 20) {
              schedule[i].vmsolution.mode_name = 'SCUF'
            }
            if (schedule[i].vmsolution.mode_id == 21) {
              schedule[i].vmsolution.mode_name = 'HD+'
            }
            if (schedule[i].vmsolution.mode_id == 22) {
              schedule[i].vmsolution.mode_name = '血浆胆红素吸附+HDF'
            }
            if (schedule[i].vmsolution.mode_id == 23) {
              schedule[i].vmsolution.mode_name = '血浆胆红素吸附'
            }
            if (schedule[i].vmsolution.mode_id == 24) {
              schedule[i].vmsolution.mode_name = 'I-HDF'
            }
            if (schedule[i].vmsolution.mode_id == 25) {
              schedule[i].vmsolution.mode_name = 'HD高通'
            }
            if (schedule[i].vmsolution.mode_id == 26) {
              schedule[i].vmsolution.mode_name = 'CVVH'
            }
            if (schedule[i].vmsolution.mode_id == 27) {
              schedule[i].vmsolution.mode_name = 'CVVH'
            }
            if (schedule[i].vmsolution.mode_id == 28) {
              schedule[i].vmsolution.mode_name = 'CVVHDF'
            }
            if (schedule[i].vmsolution.mode_id == 29) {
              schedule[i].vmsolution.mode_name = 'PE'
            }
            if (schedule[i].vmsolution.solution != undefined) {
              schedule[i].vmsolution.dialysis_dialyszers = schedule[i].vmsolution.solution.dialysis_dialyszers
              schedule[i].vmsolution.dialysis_irrigation = schedule[i].vmsolution.solution.dialysis_irrigation
              schedule[i].vmsolution.dialyzer_perfusion_apparatus = schedule[i].vmsolution.solution.dialyzer_perfusion_apparatus
            }
            if (schedule[i].vmsolution.anticoagulant == 0) {
              schedule[i].vmsolution.anticoagulant = ''
            }
            if (schedule[i].vmsolution.anticoagulant == 1) {
              schedule[i].vmsolution.anticoagulant = '无肝素'
            }
            if (schedule[i].vmsolution.anticoagulant == 2) {
              schedule[i].vmsolution.anticoagulant = '普通肝素'
            }
            if (schedule[i].vmsolution.anticoagulant == 3) {
              schedule[i].vmsolution.anticoagulant = '低分子肝素'
            }
            if (schedule[i].vmsolution.anticoagulant == 4) {
              schedule[i].vmsolution.anticoagulant = '阿加曲班'
            }
            if (schedule[i].vmsolution.anticoagulant == 5) {
              schedule[i].vmsolution.anticoagulant = '枸橼酸钠'
            }
            if (schedule[i].vmsolution.anticoagulant == 6) {
              schedule[i].vmsolution.anticoagulant = '低分子肝素钙'
            }
            if (schedule[i].vmsolution.anticoagulant == 7) {
              schedule[i].vmsolution.anticoagulant = '低分子肝素钠'
            }
            if (schedule[i].vmsolution.anticoagulant == 8) {
              schedule[i].vmsolution.anticoagulant = '依诺肝素'
            }
            if (schedule[i].vmsolution.anticoagulant == 9) {
              schedule[i].vmsolution.anticoagulant = '达肝素'
            }
            if (schedule[i].vmsolution.anticoagulant == 10) {
              schedule[i].vmsolution.anticoagulant = '体外抗凝'
            }
          }

          this.solutionList = schedule
        }
      })
    },
    getPatientSolution (patient_id) {
      var anticoagulant = ''
      for (let i = 0; i < this.solutionList.length; i++) {
        if (patient_id == this.solutionList[i].vmsolution.patient_id) {
          anticoagulant = this.solutionList[i].vmsolution.anticoagulant
        }
      }
      return anticoagulant
    },
    getDiazer (patient_id, mode_id) {
      var diazers = ''
      var irrigation = ''
      for (let i = 0; i < this.solutionList.length; i++) {
        if (patient_id == this.solutionList[i].vmsolution.patient_id && mode_id == this.solutionList[i].vmsolution.mode_id) {
          if (this.solutionList[i].vmsolution.dialyzer_perfusion_apparatus != '') {
            diazers = this.solutionList[i].vmsolution.dialyzer_perfusion_apparatus
            irrigation = this.solutionList[i].vmsolution.dialysis_irrigation
          } else {
            diazers = this.solutionList[i].vmsolution.dialysis_dialyszers
            irrigation = this.solutionList[i].vmsolution.dialysis_irrigation
          }
        }
      }
      if (irrigation != '') {
        return diazers + '/' + irrigation
      } else {
        return diazers
      }
    },
    changeSchedule (item) {
      this.showTb = true
      this.currentPatient = item
    },
    changeZonOne (value) {
      this.bedOptions = []
      var params = {
        partition_id: value
      }
      getAllBedList(params).then(response => {
        if (response.data.state == 1) {
          this.bedOptions = []
          var list = response.data.data.list
          for (let i = 0; i < list.length; i++) {
            list[i].text = list[i].number
            list[i].value = list[i].id
          }
          for (let i = 0; i < list.length; i++) {
            this.bedOptions.push(list[i])
          }
        }
      })
    },
    toInspection(){
     
      toInspection().then(response=>{
        if(response.data.state ==1){

        }
      })
    }

  },
  watch: {
  }
}
</script>

<style lang="scss" scoped>

  ::v-deep .appPopup {
    .Dialog {
      .van-collapse {
        .van-collapse-item {
          .van-cell {
            padding: 0.25rem 0.5rem !important;
            font-size: 0.5rem !important;
            .van-cell__right-icon {
              font-size: 0.5rem;
            }
          }
          .van-collapse-item__wrapper {
            .van-collapse-item__content {
              padding: 0.25rem 0.5rem;
              font-size: 0.5rem;
            }
          }
        }
      }
    }
  }
  .page_scheduling {
    height: 100%;
    overflow-y: auto;
    background: #fafafa;
  .staffManagementTitle {
    background: #fff;
    padding: 0 1.125rem;
    height: 3.125rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    span{
      -webkit-touch-callout:none;
      -webkit-user-select:none;
      -khtml-user-select:none;
      -moz-user-select:none;
      -ms-user-select:none;
      user-select:none;
    }
  }
  .jiantou {
    font-size: 1.5rem;
    font-weight: 600;
    -webkit-touch-callout:none;
    -webkit-user-select:none;
    -khtml-user-select:none;
    -moz-user-select:none;
    -ms-user-select:none;
    user-select:none;
    // margin-right: 6.5rem;
  }
  .titleName {
    font-size: 1.125rem;
    font-weight: 600;
    -webkit-touch-callout:none;
    -webkit-user-select:none;
    -khtml-user-select:none;
    -moz-user-select:none;
    -ms-user-select:none;
    user-select:none;
  }
  .searchInput{
    -webkit-touch-callout:none;
    -webkit-user-select:none;
    -khtml-user-select:none;
    -moz-user-select:none;
    -ms-user-select:none;
    user-select:none;
  }
  .optionsBox {
    display: flex;
  // height: 3.125rem;
    padding-bottom: 0.625rem;
    align-items: center;
    width: 100%;
    background: #fff;
    min-height: 0;
    .optionsOne {
      //   max-width: 8.75rem;
      //   min-width: 6.25rem;
      padding: 0 0.75rem;
      height: 1.875rem;
      background: rgba(246, 246, 246, 1);
      border-radius: 5px;
      text-align: center;
      font-size: 0.8125rem;
      color: #8d8d8d;
      display: flex;
      align-items: center;
      justify-content: space-around;
      margin-left: 0.8125rem;
      -webkit-touch-callout:none;
      -webkit-user-select:none;
      -khtml-user-select:none;
      -moz-user-select:none;
      -ms-user-select:none;
      user-select:none;
    }
    .toolOne {
      width: 6.25rem;
      height: 1.875rem;
      background: rgba(246, 246, 246, 1);
      border-radius: 5px;
      text-align: center;
      font-size: 0.8125rem;
      color: #8d8d8d;
      display: flex;
      align-items: center;
      justify-content: space-around;
      margin-left: 0.8125rem;
      -webkit-touch-callout:none;
      -webkit-user-select:none;
      -khtml-user-select:none;
      -moz-user-select:none;
      -ms-user-select:none;
      user-select:none;
    }
  }
  .schedulingList{
      font-size: 0.875rem;
      background: #fff;
    .schedulingOne{
        display: flex;
        align-items: center;
        height: 4.125rem;
        justify-content: space-between;
        padding: 0 .625rem;
        border-top: 1px solid #e5e5e5;
        -webkit-touch-callout:none;
        -webkit-user-select:none;
        -khtml-user-select:none;
        -moz-user-select:none;
        -ms-user-select:none;
        user-select:none;
        >div:first-child{
            width: 50%;
        }
        .cancel{
            padding: 0.3125rem 0.625rem;
            background: #258ffc;
            border-radius: .3125rem;
            color:#fff;
            font-size: 0.875rem;
        }
        .canceltwo{
            padding: 0.3125rem 0.625rem;
            background: #ccc;
            border-radius: .3125rem;
            color:#fff;
            font-size: 0.875rem;
        }
    }

  }
  }
  .modeRed{
    color:#ed5555;
  }
  .modePurple{
    color: #53b86e;
  }
  .patientPopup{
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
  }
  .patientContent{
    flex: 1;
    overflow-y: auto;
    height: 100%;
    display: flex;
    flex-direction: column;
  >:last-child{
    height: 3.125rem;
    text-align: center;
    line-height: 3.125rem;
    background: #258ffc;
    color: #fff;
  }
  }
  .activePatient{
    background: #badcff !important;
  }
  .patientList{
    flex: 1;
    overflow-y: auto;
    height: 100%;
  .patientCell{
    display: flex;
    align-items: center;
    height: 3.125rem;
  // justify-content: space-between;
    padding: 0 .625rem;
    border-top: 1px solid #e5e5e5;
  }
  }
</style>

<style lang="scss">
.page_scheduling{
    .searchBox {
        .van-search__content {
        border-radius: 1.875rem;
        }
        .van-cell__value {
        display: flex;
        align-items: center;
        }
        .van-field__body {
        width: 100%;
        }
    }
    #tavActive{
      background:#b3d8ff;
    }

}
#app{
  .van-dropdown-menu{
    display: flex;
    height: 100%;
    flex-direction: column;
    >div:last-child{
      flex: 1;
    }
  }
  .van-dropdown-menu__bar .van-dropdown-menu__bar--opened{
    width: 100%;
  }
  .van-dropdown-item{
    position: absolute !important;
    top: 3rem !important;
  }
  .maxheight{
    .van-dropdown-item{
      z-index: 6000 !important;
    }
    .van-dropdown-item__content{
      max-height: 100%;
      z-index: 7000 !important;
    }
  }
}
</style>
