<template>
  <div class="main-contain">
    <div class="position">
      <bread-crumb :crumbs="crumbs" style="flex:1;"></bread-crumb>
    </div>
    <div class="app-container" style="background-color: white">
      <div id="print_content">
        <div style="margin: 20px 0;">
          <div class="content_top">日期：
            <el-date-picker
              @change="date_picker"
              v-model="date"
              type="date"
              placeholder="选择日期">
            </el-date-picker>
          </div>
          <div class="content_top">排班班次：
            <el-select v-model="classes" placeholder="请选择" @change="banci_select">
              <el-option
                v-for="item in schedulArr"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </div>
          <div class="content_top">病区选择：
            <el-select v-model="bingqu" placeholder="请选择" @change="bingqu_select">
              <el-option
                v-for="item in partitionArr"
                :key="item.value"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </div>
          <div class="content_top">隐藏备注：
            <el-switch
              v-model="hidder"
              active-color="#13ce66"
              inactive-color="#ff4949"
              active-text="ON"
              inactive-text="OFF">
            </el-switch>
          </div>
        </div>
        <div class="table_panel"  v-for="(item, index) in tableData" :key="index">
          <table class="table">
            <thead>
              <tr>
                <td :width="td_1_width">分区</td>
                <td :width="td_3_width">病人姓名</td>
              </tr>
            </thead>
            <tbody>
              <tr v-for="(ite,index) in item.zones" :key="index">
                <td style="text-align: center;">{{ getZoneName(ite.partition_id) }}</td>
                <td>
                  <div v-for="(it,index) in numberlist" style="display: inline-block;position: relative;" >
                    <div  v-if="ite.partition_id==it.zone_id" class="huanzhekuais" :style="{'height':hidder ? '30px': '110px','line-height':hidder ? '30px':''}" @dblclick="db_click($event,it)" @drop="drop($event,item,it.number)" @dragstart="curInfoDragStart($event,item)" draggable="true"   @dragover="allowDrop"> 
                      <div class="huanzhekuai">
                        <div v-for="(item2) in item.list"   draggable="true" >
                          <template >
                            <div v-if="it.id==item2.bed_id" style="display: inline-block;">
                              <div>
                                <span>{{nameSplit(item2.name) }}({{ getmode(item2.mode_id) }})</span><br>
                                <span v-if="!hidder" >
                                  <span style="font-size: 14px;margin-bottom: 5px;">{{item2.order.DeviceNumber.zone.name}}-{{item2.order.DeviceNumber.number}}</span><br>
                                  <span style="font-size: 14px;margin-bottom: 5px;">{{getBloodAccess(item2.order.blood_access_id)}}</span><br>
                                  <span style="font-size: 13px;;margin-bottom: 5px;">{{item2.order.schedule_remark}}</span>
                                </span> 
                              </div>
                            </div>
                          </template> 
                        </div>
                      </div> 
                                        
                    </div>
                    <div v-if="ite.partition_id==it.zone_id" style="display: inline-block;width: 125px;text-align: center;">
                      {{ it.number }}
                    </div>
                  </div>
                </td>
              </tr>
            </tbody>
          </table>
          
        </div>
        <!-- 双击弹窗 -->
        <el-dialog
          title="提示"
          :visible.sync="centerDialogVisible"
          width="30%"
          center>
          <div>
            <div style="display: flex;">
              <div style="width:150px;margin-right: 10px;">
                <div style="margin: 10px 0;">分区
                  <el-select v-model="fenqu_dialog" placeholder="请选择" @change="dialogfenqu">
                    <el-option
                      v-for="item in partitionArr"
                      :key="item.value"
                      :label="item.name"
                      :value="item.id">
                    </el-option>
                  </el-select>
                </div>
                <div>床位
                  <el-select v-model="chuangwei" placeholder="请选择" @change="dialogchuangwei">
                    <el-option
                      v-for="item in subzone"
                      :key="item.value"
                      :label="item.number"
                      :value="item.id">
                    </el-option>
                  </el-select>
                </div>
              </div>
              <div style="width:350px">
                <div style="display: flex;">
                  <div>
                    <div style="margin: 10px 30px 10px 10px;background: rgb(74 211 235 / 51%);height: 110px;width: 125px;text-align: center;">
                      <span >{{ huanzhe.name}}({{getmode(huanzhe.mode_id)}})</span><br>
                      <span style="font-size: 14px;margin-bottom: 5px;">
                        {{ huanzhe.zeng_fenqu }}-{{ huanzhe.zeng_chuang }}
                      </span><br>
                      <span style="font-size: 14px;margin-bottom: 5px;">{{getBloodAccess(huanzhe.boolen_id)}}</span><br>
                      <span style="font-size: 13px;margin-bottom: 5px;">{{huanzhe.schedule_remark}}</span> 
                    </div>
                     <div style="margin-left: 10px;">{{getZoneName(xian_fenqu.zone_id)}}-{{xian_fenqu.number}}</div>
                  </div>
                  
                  <div>
                    <div style="margin: 10px 30px 10px 10px;background: rgb(74 197 235);height: 110px;width: 125px;text-align: center;">
                      <span >{{genghuan.name}}</span><span v-if="genghuan.mode_id !=''">({{genghuan.mode_id}})</span><br>
                      <span style="font-size: 14px;margin-bottom: 5px;">
                        {{ genghuan.genghuan_fenqu }}-{{ genghuan.genghuan_chuang }}
                        <!-- A1区-6号床 -->
                      </span><br>
                      <span style="font-size: 14px;margin-bottom: 5px;"></span>{{getBloodAccess(genghuan.g_boolen_id)}}<br>
                      <span style="font-size: 13px;margin-bottom: 5px;">{{genghuan.genghuan_remark}}</span>
                    </div>
                    <div style="margin-left: 10px;">{{getZoneName(g_xian_fenqu.zone_id)}}-{{g_xian_fenqu.number}}</div>
                  </div>
                </div>
               
              </div>
            </div>
          </div>
          <span slot="footer" class="dialog-footer">
            <el-button @click="centerDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="verify_dialog">确 定</el-button>
          </span>
        </el-dialog>
          <!-- 排班替换/交换提示弹窗 -->
        <el-dialog
          title="提示"
          :visible.sync="tipDialogVisible"
          width="300px"
          :modal-append-to-body='false'
          :close-on-click-modal="false"
        >
          <div>
            所选位置已有排班,请选择操作
          </div>
          <span slot="footer" class="dialog-footer">
            <el-button
              type="danger"
              @click="tipDialogVisibleTwo = true"
            >替换</el-button>
                <el-button
                  type="primary"
                  @click="tipDialogVisibleThree = true"
                >交换</el-button>
            <el-button @click="tipDialogVisible = false">取 消</el-button>
          </span>
        </el-dialog>
        <!-- 排班替换   -->
        <el-dialog
          title="提示"
          :visible.sync="tipDialogVisibleTwo"
          width="300px"
          class="replace"
          :modal-append-to-body='false'
          :close-on-click-modal="false"
        >
          <div>
            是否将此位置排班替换
          </div>
          <span slot="footer" class="dialog-footer">
            <el-button
              type="primary"
              @click="coverSch()"
            >确定</el-button>

            <el-button @click="tipDialogVisibleTwo = false">取 消</el-button>
          </span>
        </el-dialog>
        <!-- 将此位置排班互换  -->
        <el-dialog
          title="提示"
          :visible.sync="tipDialogVisibleThree"
          width="300px"
          class="exchange"
          :modal-append-to-body='false'
          :close-on-click-modal="false"
        >
          <div>
            是否将此位置排班互换
          </div>
          <span slot="footer" class="dialog-footer">
            <el-button
              type="primary"
              @click="changeSchTwo()"
            >确定</el-button>
            <el-button @click="tipDialogVisibleThree = false">取 消</el-button>
          </span>
        </el-dialog>
      </div>
    </div>
  </div>
</template>

<script>
import { GetAllZone, getSchedualPrintList } from '@/api/dialysis'
import { parseTime } from '@/utils'
import { uParseTime } from '@/utils/tools'
import { getDataConfig } from '@/utils/data'
import {CreateScheduleTwo} from '@/api/schedule'
import {CoverSch,ExchangeSch,} from "@/api/schedule_template/sch_template";
import BreadCrumb from '@/xt_pages/components/bread-crumb'
import print from 'print-js'
const moment = require('moment')
// import {getAllZones} from "@/api/schedule"
export default {
  name: 'SchedulePrint',
  data() {
    return {
      crumbs: [
        { path: false, name: '排班管理' },
        { path: false, name: '患者调班' }
      ],
      tipDialogVisible:false,
      tipDialogVisibleTwo:false,
      tipDialogVisibleThree:false,
      hidder: true,
      td_1_width: '8%',
      td_3_width: '90%',
      date:'',
      classes:1,
      bingqu:0,
      fenqu_dialog:0,
      chuangwei:519,
      options:[],
      centerDialogVisible:false,
      cur_drag_info:{
        id:'',
        name:'',
        quhao:'',
        chaung:'',
        patient_id:'',
      },
      currentData:{
        currentData_id:'',
        currentData_name:'',
        currentData_quhao:'',
        currentData_chaung:'',
        patient_id:'',
        bed_id:'',
        mode_id:'',
        partition_id:'',
        schedule_date:'',
        schedule_type:'',
        schedule_week: '',
      },
      // 交换空白时数据
      schedule:{
        schedule_date:'',
        schedule_type:'',
        bed_id:'',
        partition_id:'',
        schedule_week:'',
        mode_id:'',
        bed_name:'',
        contagions:'',
        id:0,
        partition_type:'',
        patient:'',
        patient_id:'',
        type_name:'',
        zone_name:''
      },
      schedulArr: [
        { value: 1, label: "上午" },
        { value: 2, label: "下午" },
        { value: 3, label: "晚上" }
      ],
      zones:[],
      schedules: [
        {
          day: 1,
          weekday: '星期一',
          all: {
            am: {
              /* zone_name: [ schedule, ... ] */
            },
            pm: {
              /* zone_name: [ schedule, ... ] */
            },
            evening: {
              /* zone_name: [ schedule, ... ] */
            }
          },
          hdf: [
            /* schedule, ... */
          ],
          hd_hp: [
            /* schedule, ... */
          ],

          new_hdf: {
            am: {
              /* zone_name: [ schedule, ... ] */
            },
            pm: {
              /* zone_name: [ schedule, ... ] */
            },
            evening: {
              /* zone_name: [ schedule, ... ] */
            }
          },
          new_hd_hp: {
            am: {
              /* zone_name: [ schedule, ... ] */
            },
            pm: {
              /* zone_name: [ schedule, ... ] */
            },
            evening: {
              /* zone_name: [ schedule, ... ] */
            }
          }
        },
        {
          day: 2,
          weekday: '星期二',
          all: {
            am: {
              /* zone_name: [ schedule, ... ] */
            },
            pm: {
              /* zone_name: [ schedule, ... ] */
            },
            evening: {
              /* zone_name: [ schedule, ... ] */
            }
          },
          hdf: [
            /* schedule, ... */
          ],
          hd_hp: [
            /* schedule, ... */
          ],
          new_hdf: {
            am: {
              /* zone_name: [ schedule, ... ] */
            },
            pm: {
              /* zone_name: [ schedule, ... ] */
            },
            evening: {
              /* zone_name: [ schedule, ... ] */
            }
          },
          new_hd_hp: {
            am: {
              /* zone_name: [ schedule, ... ] */
            },
            pm: {
              /* zone_name: [ schedule, ... ] */
            },
            evening: {
              /* zone_name: [ schedule, ... ] */
            }
          }
        },
        {
          day: 3,
          weekday: '星期三',
          all: {
            am: {
              /* zone_name: [ schedule, ... ] */
            },
            pm: {
              /* zone_name: [ schedule, ... ] */
            },
            evening: {
              /* zone_name: [ schedule, ... ] */
            }
          },
          hdf: [
            /* schedule, ... */
          ],
          hd_hp: [
            /* schedule, ... */
          ],
          new_hdf: {
            am: {
              /* zone_name: [ schedule, ... ] */
            },
            pm: {
              /* zone_name: [ schedule, ... ] */
            },
            evening: {
              /* zone_name: [ schedule, ... ] */
            }
          },
          new_hd_hp: {
            am: {
              /* zone_name: [ schedule, ... ] */
            },
            pm: {
              /* zone_name: [ schedule, ... ] */
            },
            evening: {
              /* zone_name: [ schedule, ... ] */
            }
          }
        },
        {
          day: 4,
          weekday: '星期四',
          all: {
            am: {
              /* zone_name: [ schedule, ... ] */
            },
            pm: {
              /* zone_name: [ schedule, ... ] */
            },
            evening: {
              /* zone_name: [ schedule, ... ] */
            }
          },
          hdf: [
            /* schedule, ... */
          ],
          hd_hp: [
            /* schedule, ... */
          ],
          new_hdf: {
            am: {
              /* zone_name: [ schedule, ... ] */
            },
            pm: {
              /* zone_name: [ schedule, ... ] */
            },
            evening: {
              /* zone_name: [ schedule, ... ] */
            }
          },
          new_hd_hp: {
            am: {
              /* zone_name: [ schedule, ... ] */
            },
            pm: {
              /* zone_name: [ schedule, ... ] */
            },
            evening: {
              /* zone_name: [ schedule, ... ] */
            }
          }
        },
        {
          day: 5,
          weekday: '星期五',
          all: {
            am: {
              /* zone_name: [ schedule, ... ] */
            },
            pm: {
              /* zone_name: [ schedule, ... ] */
            },
            evening: {
              /* zone_name: [ schedule, ... ] */
            }
          },
          hdf: [
            /* schedule, ... */
          ],
          hd_hp: [
            /* schedule, ... */
          ],
          new_hdf: {
            am: {
              /* zone_name: [ schedule, ... ] */
            },
            pm: {
              /* zone_name: [ schedule, ... ] */
            },
            evening: {
              /* zone_name: [ schedule, ... ] */
            }
          },
          new_hd_hp: {
            am: {
              /* zone_name: [ schedule, ... ] */
            },
            pm: {
              /* zone_name: [ schedule, ... ] */
            },
            evening: {
              /* zone_name: [ schedule, ... ] */
            }
          }
        },
        {
          day: 6,
          weekday: '星期六',
          all: {
            am: {
              /* zone_name: [ schedule, ... ] */
            },
            pm: {
              /* zone_name: [ schedule, ... ] */
            },
            evening: {
              /* zone_name: [ schedule, ... ] */
            }
          },
          hdf: [
            /* schedule, ... */
          ],
          hd_hp: [
            /* schedule, ... */
          ],
          new_hdf: {
            am: {
              /* zone_name: [ schedule, ... ] */
            },
            pm: {
              /* zone_name: [ schedule, ... ] */
            },
            evening: {
              /* zone_name: [ schedule, ... ] */
            }
          },
          new_hd_hp: {
            am: {
              /* zone_name: [ schedule, ... ] */
            },
            pm: {
              /* zone_name: [ schedule, ... ] */
            },
            evening: {
              /* zone_name: [ schedule, ... ] */
            }
          }
        },
        {
          day: 7,
          weekday: '星期日',
          all: {
            am: {
              /* zone_name: [ schedule, ... ] */
            },
            pm: {
              /* zone_name: [ schedule, ... ] */
            },
            evening: {
              /* zone_name: [ schedule, ... ] */
            }
          },
          hdf: [
            /* schedule, ... */
          ],
          hd_hp: [
            /* schedule, ... */
          ],
          new_hdf: {
            am: {
              /* zone_name: [ schedule, ... ] */
            },
            pm: {
              /* zone_name: [ schedule, ... ] */
            },
            evening: {
              /* zone_name: [ schedule, ... ] */
            }
          },
          new_hd_hp: {
            am: {
              /* zone_name: [ schedule, ... ] */
            },
            pm: {
              /* zone_name: [ schedule, ... ] */
            },
            evening: {
              /* zone_name: [ schedule, ... ] */
            }
          }
        }
      ],
      total: [],
      list: [],
      loading: false,
      tableData: [],
      numberlist: [],
      partitionArr: [],
      listname:[],
      mode:[{id:1,name:'HD'},{id:2,name:'HDF'},{id:3,name:'HD+HP'},{id:4,name:'HP'},{id:5,name:'HF'},{id:6,name:'SCUF'},{id:7,name:'IUF'},{id:8,name:'HFHD'},
      {id:9,name:'HFHD+HP'},{id:10,name:'PHF'},{id:11,name:'HFR'},{id:12,name:'HDF+HP'},{id:13,name:'CRRT'},{id:14,name:'腹水回输'},{id:15,name:'IUF+HD'},{id:16,name:'UF'},
      {id:17,name:'HD+'},{id:18,name:'血浆胆红素吸附+HDF'},{id:19,name:'血浆胆红素吸附'},{id:20,name:'I-HDF'},{id:21,name:'HD高通'},{id:22,name:'CVVH'},{id:23,name:'CVVHD'},
      {id:24,name:'CVVHDF'},{id:25,name:'PE'},{id:26,name:'血浆胆红素吸附+HP'},{id:27,name:'HPD'},{id:28,name:'HDP'}],
      subzone:[],
      huanzhe:{
        id:null,
        name:'',
        mode_id:'',
        zeng_fenqu:'',
        zeng_chuang:'',
        boolen_id:'',
        schedule_remark:'',
        patient_id:'',
        partition_id:'',
        schedule_week: '',
      },
      xian_fenqu:'',
      g_xian_fenqu:'',
      genghuan:{
        id:null,
        name:'',
        mode_id:'',
        genghuan_fenqu:'',
        genghuan_chuang:'',
        g_boolen_id:'',
        genghuan_remark:'',
        patient_id:'',
      },
    }
  },
  components: {
    BreadCrumb
  },
  created() {
   this.date= moment(new Date()).format("YYYY-MM-DD");
   console.log('dsafas',this.date);
    this.getAllZones()
    this.getlist()
  },
  mounted(){
    // console.log('8888',this.huanzhe.order.DeviceNumber.zone.name);
  },
  methods:{
   
    drop(e,val,value){
      this.allowDrop(e)
      var bedid = ''
      var bedname=''
      var zonename=''
      var zoneid=''
      console.log('kkkkk',e.target.innerText);
      const inntext= e.target.innerText.split('(')[0]
      for(let i=0;i<val.list.length;i++){
        if(inntext == val.list[i].name){
          console.log('6666',val,value);
          console.log('7777',this.numberlist);
          this.tipDialogVisible=true
          this.currentData={
            currentData_id:val.list[i].id,
            currentData_name:val.list[i].name,
            currentData_quhao:val.list[i].order.DeviceNumber.zone.name,
            currentData_chaung:val.list[i].order.DeviceNumber.number,
            patient_id:val.list[i].patient_id
          }
        }
      }
      for(let x=0;x<this.numberlist.length;x++){
        if(value==this.numberlist[x].number){
          bedid = this.numberlist[x].id
          bedname=this.numberlist[x].number
          zoneid =this.numberlist[x].zone_id
        }
      }
      for(let y=0;y<this.partitionArr.length;y++){
        if(zoneid == this.partitionArr[y].id){
          zonename = this.partitionArr[y].name
        }
      }
      
      if(e.target.innerText == ''){
        console.log('3333',e.target.innerText);
        this.schedule={
          schedule_date:this.date,
          schedule_type:this.classes,
          bed_id:bedid,
          partition_id:zoneid,
          schedule_week:this.cur_drag_info.schedule_week,
          mode_id:this.cur_drag_info.mode_id,
          bed_name:bedname,
          contagions:'',
          id:0,
          partition_type:'',
          patient:this.cur_drag_info.name,
          patient_id:this.cur_drag_info.patient_id,
          type_name:'',
          zone_name:zonename
        }
        this.currentData={
          currentData_id:0,
          currentData_name:this.cur_drag_info.name,
          currentData_quhao:this.cur_drag_info.quhao,
          currentData_chaung:this.cur_drag_info.chaung,
          patient_id:this.cur_drag_info.patient_id,
          
        }
        console.log('8888',this.currentData.currentData_id);
        this.setScheduleTwo(this.cur_drag_info.id)
        // var params={
        //   patient_id:this.currentData.patient_id,
        //   id_two:this.currentData.currentData_id
        // }
        // CreateScheduleTwo(this.currentData.patient_id,this.currentData.currentData_id).then((response)=>{
        //   if (response.data.state == 0) {
        //     this.$message.error(response.data.msg);
        //   } else {
        //     var schedule = response.data.data.schedule;
            
        //     this.getlist()
        //   }
        // })
        // this.CreateScheduleTwo(this.currentData.patient_id,this.currentData,this.currentData.currentData_id)
      }
      
      // for(let i=0;i<this.numberlist.length;i++){
      //   for(let j=0;j<val.list.length;j++){
      //     if(this.numberlist[i].id==val.list[y].bed_id){

      //     }
      //   }
      // }
      // this.currentData={
      //   currentData_id:val.id,
      //   currentData_name:val.name,
      //   currentData_quhao:val.order.DeviceNumber.zone.name,
      //   currentData_chaung:val.order.DeviceNumber.number,
      // },
     
      // this.currentData={
      //   currentData_id:this.cur_drag_info.id,
      //   currentData_name:this.cur_drag_info.name,
      //   currentData_quhao:this.cur_drag_info.quhao,
      //   currentData_chaung:this.cur_drag_info.chaung,
      // },

      
    },
    allowDrop(e) {
      e.preventDefault();
    },
     // 替换
     coverSch(){
      this.tipDialogVisible=false
      let params={
        id_one:this.cur_drag_info.id,
        id_two:this.currentData.currentData_id
      }
        CoverSch(params).then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg);
          this.tipDialogVisibleTwo = false
        } else {
          console.log('888888888888',response.data);
          this.$message.success("替换成功");
          this.tipDialogVisible = false
          this.tipDialogVisibleTwo = false
          this.getlist();
        }
      });
    },
    // 交换
    changeSchTwo(){
      this.tipDialogVisible=false
      let params={
        id_one:this.cur_drag_info.id,
        id_two:this.currentData.currentData_id

      }
      ExchangeSch(params).then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg);
          this.tipDialogVisibleThree = false
        } else {
          console.log('22222222',response.data);
          this.$message.success("交换成功");
          this.tipDialogVisible = false
          this.tipDialogVisibleThree = false
          this.getlist();
        }
      });
    },
    // 交换空白
    setScheduleTwo(id_two){
      this.CreateScheduleTwo(this.currentData.patient_id, this.schedule,id_two);
    },
    // 双击弹窗交换空白
    setSchedulethree(id_two){
      this.CreateScheduleTwo(this.huanzhe.patient_id, this.schedule,id_two);
    },
    async CreateScheduleTwo(id, data,id_two) {
      let response =await CreateScheduleTwo(id, data,id_two)

      if (response.data.state == 0) {
        this.$message.error(response.data.msg);
      } else {
        var schedule = response.data.data.schedule;
        this.getlist()
      }
    },
    // 需要拖动的
    curInfoDragStart(e,val){
      const inntext2= e.target.innerText.split('(')[0]
      for(let i=0;i<val.list.length;i++){
        if(inntext2 == val.list[i].name){
          this.cur_drag_info={
            id:val.list[i].id,
            name:val.list[i].name,
            quhao:val.list[i].order.DeviceNumber.zone.name,
            chaung:val.list[i].order.DeviceNumber.number,
            patient_id:val.list[i].patient_id,
            bed_id:val.list[i].bed_id,
            mode_id:val.list[i].mode_id,
            partition_id:val.list[i].partition_id,
            schedule_date:this.date,
            schedule_type:this.classes,
            schedule_week: val.list[i].schedule_week,
          }
        }
      }
     
      console.log('bbbb',e.target.innerText);
      console.log('4444',val);
      console.log('5555',this.cur_drag_info);
    },
     // 选中日期
     date_picker(e){
      var time=moment(e).format("YYYY-MM-DD");
      console.log('sfddas',time);
      this.date=time
      this.getlist()
    },
    // 选择班次
    banci_select(e){
      console.log(e);
      for(let i=0;i<this.schedulArr.length;i++){
        if(e==this.schedulArr[i].value){
          this.classes = e
        }
        this.getlist()
      }
    },
    // 选择分区
    bingqu_select(e){
      console.log('1234546',e);
      for (let i = 0; i < this.partitionArr.length; i++) {
        if(e==this.partitionArr[i].id){
          this.bingqu=e
        }
      }
      this.getlist()
    },
    // 分区
    getAllZones() {
      GetAllZone().then(response => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg);
          return false;
        } else {
          this.partitionArr = response.data.data.zone;
          this.partitionArr.unshift({ id: 0, name: "全部" });
          console.log('asfasdfsadfa',response.data.data);
        }
      });
    },
    getlist() {

      var params = {
        schedule_date: this.date,
        schedule_type: this.classes,
        partition_type: this.bingqu,
        keywords: '',
        page: 1,
        limit: 5000
      }
      this.loading = true
      this.tableData = []
      console.log('111111111',params);
      getSchedualPrintList(params).then((response) => {
        if (response.data.state == 1) {
          this.loading = false
          console.log('111111',response.data.data);
          var list = response.data.data.list
          this.list = list
          var listOne = response.data.data.listOne
          this.zones =listOne
          var numberlist=response.data.data.numberList
          this.numberlist= numberlist
          this.subzone = numberlist
          if (list != null && list.length > 0) {
            const dataInfo = {}
            list.forEach((item, index) => {
              const { schedule_type } = item
              if (!dataInfo[schedule_type]) {
                dataInfo[schedule_type] = {
                  schedule_type: item.schedule_type,
                  schedule_date: item.schedule_date,
                  zones: [],
                  list:[],
                  
                }
              }
            })
            const arr = Object.values(dataInfo)
            // console.log('arr222', arr)

            if (arr != null && arr.length > 0) {
              for (let i = 0; i < arr.length; i++) {
                for (let j = 0; j < listOne.length; j++) {
                  if (arr[i].schedule_type == listOne[j].schedule_type) {
                    arr[i].zones.push(listOne[j])
                  }
                }
                for(let x=0;x<list.length;x++){
                  arr[i].list.push(list[x])
                }
              }
            }
            // console.log('排班数据------------------', arr)

            this.tableData = arr
            console.log('22222222',this.tableData);
          }

          this.numberList = response.data.data.numberList
          // console.log('list2332233232wo', list)
          // console.log('numberList', this.numberList)
        }
      })
    },
    
    getTimeOne(val) {
      if (val == '') {
        return ''
      } else {
        return uParseTime(val, '{y}-{m}-{d}')
      }
    },
   
    // getPatientName(schedule_type, partition_id) {
    //   var str = ''
    //   var arr = []
    //   if (this.list != null && this.list.length > 0) {
    //     for (let i = 0; i < this.list.length; i++) {
    //       if (this.list[i].schedule_type == schedule_type && this.list[i].partition_id == partition_id) {
    //         arr.push(this.list[i])
    //       }
    //     }
    //   }
    //   if (arr.length > 0) {
    //     for (let i = 0; i < arr.length; i++) {
    //       arr[i].name = this.nameSplit(arr[i].name)
    //       console.log('666666',arr[i].name);
    //       if (this.hiddenFlag) {
    //         str+= arr[i].name + '&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp '
    //       } else {
    //         str+=arr[i].name
    //       }
    //     }
    //   }
    //   // console.log(str, 'strstrstr')
    //   return str
    // },
    // 透析模式
    getmode(id){
      for(let i=0;i<this.mode.length;i++){
        if(id=this.mode[i].id){
          return this.mode[i].name
        }
      }
    },
    // 切割患者姓名
    nameSplit(val) {
      var reg = /[\u4e00-\u9fa5]/g
      let name = val
      name = name.substr(-4)
      var names = name.match(reg)
      name = names.join('')
      if (name.includes('区')) {
        name = name.replace('区', '')
      }
      if (name.includes('号')) {
        name = name.replace('号', '')
      }
      return name
    },
    // 分区
    getZoneName(id) {
      var name = ''
      for (let i = 0; i < this.partitionArr.length; i++) {
        if (id == this.partitionArr[i].id) {
          name = this.partitionArr[i].name
        }
      }

      return name
    },
    // 血管通路
    getBloodAccess(id) {
      var name = ''
      var list = getDataConfig(
        'hemodialysis',
        'vascular_access_desc'
      )
      for (let i = 0; i < list.length; i++) {
        if (id == list[i].id) {
          name = list[i].name
        }
      }
      return name
    },
    // 双击打开弹窗
    db_click(e,val){
      if(e.target.innerText !=''){
        this.centerDialogVisible=true
        this.xian_fenqu=val
        console.log('qqqqq',this.chuangwei,'val',val);
        for(let i=0;i<this.list.length;i++){
          // 双击弹窗的右侧第一个数据
          if(val.id==this.list[i].bed_id){
            console.log('zzzzz',this.list[i]);
            this.huanzhe.id=this.list[i].id
            this.huanzhe.name=this.list[i].name
            this.huanzhe.mode_id=this.list[i].mode_id
            this.huanzhe.zeng_fenqu=this.list[i].order.DeviceNumber.zone.name
            this.huanzhe.zeng_chuang = this.list[i].order.DeviceNumber.number
            this.huanzhe.boolen_id = this.list[i].order.blood_access_id
            this.huanzhe.schedule_remark = this.list[i].order.schedule_remark
            this.huanzhe.patient_id = this.list[i].patient_id
            this.huanzhe.partition_id = this.list[i].partition_id
            this.huanzhe.schedule_week= this.list[i].schedule_week
            // return this.huanzhe
          //   console.log('55555',this.huanzhe);
          }     
          // 双击弹窗的右侧第二个默认数据
          if(this.chuangwei==this.list[i].bed_id){
            console.log('xxxxx',this.chuangwei);
            this.genghuan.id = this.list[i].id
            this.genghuan.name=this.list[i].name
            this.genghuan.mode_id=this.list[i].mode_id
            this.genghuan.genghuan_fenqu=this.list[i].order.DeviceNumber.zone.name
            this.genghuan.genghuan_chuang = this.list[i].order.DeviceNumber.number
            this.genghuan.g_boolen_id = this.list[i].order.blood_access_id
            this.genghuan.genghuan_remark = this.list[i].order.schedule_remark
            this.genghuan.patient_id = this.list[i].patient_id
            // console.log('99999',this.genghuan);
            // console.log('000000',this.list[i].bed_id);
            // return this.genghuan
          }
        // // 第二的床位
        // for(let y=0;y<this.numberlist.length;y++){
        //   if(this.chuangwei==this.numberlist[y].id){
        //     this.g_xian_fenqu=this.numberlist[y]
        //   }
        }
        // 第二的床位
        for(let y=0;y<this.numberlist.length;y++){
          if(this.chuangwei==this.numberlist[y].id){
            this.g_xian_fenqu=this.numberlist[y]
          }
        }
        return this.genghuan
      }else{
        this.centerDialogVisible=false
      }
      
      // console.log('双击弹窗',this.zeng_fenqu);
      // console.log('双击弹窗33',e);
      // console.log('双击弹窗333',value);
    },
    // 双击弹窗分区
    dialogfenqu(e){
      for (let i = 0; i < this.partitionArr.length; i++) {
        if(e==this.partitionArr[i].id){
          this.fenqu_dialog=e
        }
      }
      var params = {
        schedule_date: this.date,
        schedule_type: this.classes,
        partition_type: this.fenqu_dialog,
        keywords: '',
        page: 1,
        limit: 5000
      }
      getSchedualPrintList(params).then((response)=>{
        if (response.data.state == 1) {
          var list = response.data.data.list
          this.list = list
          var listOne = response.data.data.listOne
          this.zones =listOne
          var numberlist=response.data.data.numberList
          console.log('00000',this.list);
          this.subzone=[]
          for(let i=0;i<numberlist.length;i++){
            if(this.fenqu_dialog==0){
              this.subzone = numberlist
              this.chuangwei = numberlist[0].id//默认被交换的床位
              this.g_xian_fenqu = numberlist[0]//被交换的分区床位对象
            }
            if(this.fenqu_dialog==numberlist[i].zone_id){
              const obj={id:null,number:'',zone_id:null}
              obj.id=numberlist[i].id
              obj.number=numberlist[i].number
              obj.zone_id=numberlist[i].zone_id
              this.subzone.push(obj)
              this.chuangwei = this.subzone[0].id 
              this.g_xian_fenqu=this.subzone[0]
            }
          }
          console.log('22222',this.g_xian_fenqu);
          // 默认的患者
          for(let i=0;i<this.list.length;i++){
            if(this.chuangwei==this.list[i].bed_id){
              this.genghuan.name=this.list[i].name
              this.genghuan.mode_id=this.list[i].mode_id
              this.genghuan.genghuan_fenqu=this.list[i].order.DeviceNumber.zone.name
              this.genghuan.genghuan_chuang = this.list[i].order.DeviceNumber.number
              this.genghuan.g_boolen_id =this.list[i].order.blood_access_id
              this.genghuan.genghuan_remark = this.list[i].order.schedule_remark
              console.log('99999',this.genghuan);
              console.log('000000',this.list[i].bed_id);
              return this.genghuan
            }else{
              console.log('eeeeee');
              this.genghuan.name=''
              this.genghuan.mode_id=''
              this.genghuan.genghuan_fenqu=''
              this.genghuan.genghuan_chuang = ''
              this.genghuan.g_boolen_id = ''
              this.genghuan.genghuan_remark =''
              // return this.genghuan
              // console.log('qqqqqq',this.list[i].bed_id);
            }
            
          }
          // this.numberlist= numberlist
        }
      })
      // console.log('77777',this.chuangwei);
      // for(let i=0;i<list.length;i++){
      //   if(this.chuangwei==list[i].bed_id){
      //     this.genghuan.name=list[i].name
      //     this.genghuan.mode_id=list[i].mode_id
      //     this.genghuan.genghuan_fenqu=list[i].order.DeviceNumber.zone.name
      //     this.genghuan.genghuan_chuang = list[i].order.DeviceNumber.number
      //     this.genghuan.g_boolen_id =list[i].order.blood_access_id
      //     this.genghuan.genghuan_remark = list[i].order.schedule_remark
      //     console.log('99999',this.genghuan);
      //     console.log('000000',list[i].bed_id);
      //     return this.genghuan
      //   }else{
      //     console.log('eeeeee');
      //     this.genghuan.name=''
      //     this.genghuan.mode_id=''
      //     this.genghuan.genghuan_fenqu=''
      //     this.genghuan.genghuan_chuang = ''
      //     this.genghuan.g_boolen_id = ''
      //     this.genghuan.genghuan_remark =''
      //     // return this.genghuan
      //     // console.log('qqqqqq',this.list[i].bed_id);
      //   }
        
      // }
    },
    // 双击弹窗床位
    dialogchuangwei(e){
      console.log('333333',e);
      for (let i = 0; i < this.subzone.length; i++) {
        if(e==this.subzone[i].id){
          this.chuangwei=e
        }
      }
      for(let i=0;i<this.list.length;i++){
        if(this.chuangwei==this.list[i].bed_id){
          this.genghuan.id = this.list[i].id
          this.genghuan.name=this.list[i].name
          this.genghuan.mode_id=this.list[i].mode_id
          this.genghuan.genghuan_fenqu=this.list[i].order.DeviceNumber.zone.name
          this.genghuan.genghuan_chuang = this.list[i].order.DeviceNumber.number
          this.genghuan.g_boolen_id = this.list[i].order.blood_access_id
          this.genghuan.genghuan_remark = this.list[i].order.schedule_remark

          for(let y=0;y<this.subzone.length;y++){
            if(this.chuangwei==this.subzone[y].id){
              this.g_xian_fenqu=this.subzone[y]
              console.log('cccc',this.g_xian_fenqu);
            }
          }
          console.log('99999',this.genghuan);
          console.log('000000',this.list[i].bed_id);
          return this.genghuan
        }
        if(this.chuangwei!=this.list[i].bed_id){
          console.log('eeeeee');
          this.genghuan.id = null
          this.genghuan.name=''
          this.genghuan.mode_id=''
          this.genghuan.genghuan_fenqu=''
          this.genghuan.genghuan_chuang = ''
          this.genghuan.g_boolen_id = ''
          this.genghuan.genghuan_remark =''
          // return this.genghuan
          // console.log('qqqqqq',this.list[i].bed_id);
        }
      }
      // 更换的床位置
      for(let y=0;y<this.subzone.length;y++){
        if(this.chuangwei==this.subzone[y].id){
          this.g_xian_fenqu=this.subzone[y]
          console.log('cccc',this.g_xian_fenqu);
        }
      }
    },
    // 双击弹窗确定
    verify_dialog(){
      this.centerDialogVisible=false
      console.log('mmmmm',this.genghuan.id);
      if(this.genghuan.id != ''){
        for(let i=0;i<this.list.length;i++){
          if(this.chuangwei==this.list[i].bed_id){
            console.log('hhhhh',this.chuangwei);
            let params={
              id_one:this.huanzhe.id,
              id_two:this.genghuan.id

            }
            ExchangeSch(params).then((response) => {
              if (response.data.state == 0) {
                this.$message.error(response.data.msg);
                this.tipDialogVisibleThree = false
              } else {
                console.log('22222222',response.data);
                this.$message.success("交换成功");
                this.tipDialogVisible = false
                this.tipDialogVisibleThree = false
                this.getlist();
              }
            });
            return this.genghuan
          }
      //     // else{
      //     //   var zonename=''
      //     //   var bedname=''
      //     //   var zoneid=''
      //     //   console.log('6666',this.chuangwei);
      //     //   for(let y=0;y<this.subzone.length;y++){
      //     //     if(this.chuangwei == this.subzone[y].id){
      //     //       bedname=this.subzone[y].number
      //     //       zoneid=this.subzone[y].zone_id
      //     //       console.log('aaaa',this.chuangwei,this.subzone[y].id,this.subzone[y].number);
      //     //       this.schedule={
      //     //         schedule_date:this.date,
      //     //         schedule_type:this.classes,
      //     //         bed_id:this.chuangwei,
      //     //         partition_id:zoneid,
      //     //         schedule_week:this.huanzhe.schedule_week,
      //     //         mode_id:this.huanzhe.mode_id,
      //     //         bed_name:bedname,
      //     //         contagions:'',
      //     //         id:0,
      //     //         partition_type:'',
      //     //         patient:this.huanzhe.name,
      //     //         patient_id:this.huanzhe.patient_id,
      //     //         type_name:'',
      //     //         zone_name:zonename
      //     //       }
      //     //       this.setSchedulethree(this.huanzhe.id)
      //     //       return ''
      //     //     }
      //     //   }
      //     // }
        }
      }
      // else if(this.genghuan.id == 'null'){
        var zonename=''
        var bedname=''
        var zoneid=''
        console.log('6666',this.chuangwei);
        for(let y=0;y<this.subzone.length;y++){
          if(this.chuangwei == this.subzone[y].id){
            bedname=this.subzone[y].number
            zoneid=this.subzone[y].zone_id
            console.log('aaaa',this.chuangwei,this.subzone[y].id,this.subzone[y].number);
            this.schedule={
              schedule_date:this.date,
              schedule_type:this.classes,
              bed_id:this.chuangwei,
              partition_id:zoneid,
              schedule_week:this.huanzhe.schedule_week,
              mode_id:this.huanzhe.mode_id,
              bed_name:bedname,
              contagions:'',
              id:0,
              partition_type:'',
              patient:this.huanzhe.name,
              patient_id:this.huanzhe.patient_id,
              type_name:'',
              zone_name:zonename
            }
            this.setSchedulethree(this.huanzhe.id)
            return ''
          }
        }
      // }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
#print_content {
  background-color: white;
  padding: 0 0 20px 0;
  .content_top{
    display: inline-block;
  }
  .order_title_panl {
    text-align: center;

    .main_title {
      font-size: 18px;
      line-height: 40px;
      font-weight: 500;
    }
  }
  .table_panel {
    .table {
      width: 100%;
      border: 1px solid;
      border-collapse: collapse;
      padding: 2px;

      thead {
        tr {
          td {
            border: 1px solid;
            text-align: center;
            font-size: 20px;
            padding: 15px 5px;
          }
        }
      }
      tbody {
        tr {
          td {
            border: 1px solid;
            // text-align: center;
            font-size: 18px;
            padding: 5px 5px;

           .huanzhekuai{
            width: 125px;
            display: inline-block;
            text-align: center;
            // margin:0 10px;
           }
           .huanzhekuais{
            width: 125px;
            // display: inline-block;
            text-align: center;
            margin:0 10px;
            // line-height: 110px;
            background: #30b8e394;
           }
           
          }
        }
      }
    }
  }
}
</style>

