<template>
  <div id="table_data">


    <div class="cell clearfix" v-if="weekTime == 'thisWeek' || weekTime == 'nextWeek'  || weekTime == 'nextTwoWeek' ">
      <div class="select_list">
<!--        <span>班次：</span>-->
<!--        <el-select-->
<!--            v-model="schedule_type"-->
<!--            placeholder="请选择"-->
<!--            multiple-->
<!--        >-->
<!--          <el-option-->
<!--              v-for="item in options"-->
<!--              :key="item.id"-->
<!--              :label="item.name"-->
<!--              :value="item.id"-->
<!--          >-->
<!--          </el-option>-->
<!--        </el-select>-->

        <span>日期：</span>
        <el-select
            v-model="week_type"
            placeholder="请选择"
            multiple
           @change="changeWeekDay"
        >
          <el-option
              v-for="(item,index) in weeks"
              :key="index"
              :label="item"
              :value="item"
          >
          </el-option>
        </el-select>

        <span>分区：</span>
        <el-select
            v-model="partition_id"
            multiple
            placeholder="请选择"
            @change="changePartiton"
        >
          <el-option
              v-for="item in this.zones"
              :key="item.id"
              :label="item.name"
              :value="item.id"
          >
          </el-option>
        </el-select>


      </div>
      <el-input
          size="small"
          style="width: 200px;margin-left: 20px"
          class="filter-item"
          v-model.trim="keywords"
          placeholder="病人名称/透析号"
          @keyup.enter.native='search'
      />
      <el-button
          size="small"
          class="filter-item"
          type="primary"
          icon="el-icon-search"
          @click="search"

      >搜索</el-button>

    </div>



    <el-dialog :visible.sync="searchTableVisible" width="80%">
      <el-table
        :data="schedulePatients"
        :header-cell-style="{
          backgroundColor: 'rgb(245, 247, 250)',
          color: '#606266'
        }"
        :row-style="{ color: '#303133' }"
        style="width: 100%"
        border
      >
        <el-table-column label="姓名" width="120">
          <template slot-scope="scope">
            {{ scope.row.patient }}
          </template>
        </el-table-column>
        <el-table-column label="透析日期" width="200">
          <template slot-scope="scope">
            {{ getDialysisDate(scope.row) }}
          </template>
        </el-table-column>
        <el-table-column label="分区">
          <template slot-scope="scope">
            {{ scope.row.zone.name }}
          </template>
        </el-table-column>
        <el-table-column label="班次" width="80">
          <template slot-scope="scope">
            {{ getSchedulesType(scope.row.schedule_type,scope.row) }}
          </template>
        </el-table-column>
        <el-table-column label="机号" width="80">
          <template slot-scope="scope">
            {{ scope.row.number.number }}
          </template>
        </el-table-column>
        <el-table-column label="透析模式" width="100">
          <template slot-scope="scope">
            {{ scope.row.mode.name }}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="300">

           <template slot-scope="scope">
            <span v-if="now_time>scope.row.schedule_date">
              <el-button
                size="mini"
                type="primary"
                :disable="true"
              >
                取消排班
              </el-button>
              <el-button
                size="mini"
                type="primary"
                :disable="true"
              >
                调整机号
              </el-button>
              <el-button
                size="mini"
                type="primary"
              :disable="true"
              >
                调整模式
              </el-button>
           </span>
          </template>


          <template slot-scope="scope">
            <span v-if="now_time <=scope.row.schedule_date">
              <el-button
              size="mini"
              type="primary"
              @click="CancelSchedule(scope.row.id)"
            >
              取消排班
            </el-button>
            <el-button
              size="mini"
              type="primary"
              @click="changeMachineNumber(scope.$index, scope.row)"
            >
              调整机号
            </el-button>
            <el-button
              size="mini"
              type="primary"
              @click="changeMode(scope.$index, scope.row)"
            >
              调整模式
            </el-button>
            </span>

          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
   <div class="tableClass">
    <el-table
      :row-style="{ color: '#303133' }"
      :header-cell-style="{
        backgroundColor: 'rgb(245, 247, 250)',
        color: '#606266'
      }"
      :data="scheduleZone"
      :span-method="objectSpanMethod"
      @cell-click="clickThis"
      @cell-mouse-enter="hoverMouse"
      :summary-method="getSummaries"
      show-summary
      :row-class-name="tableRowClassName"
      :cell-class-name="cellClass"
      sum-text="总数"
      :height="tableContainHeight"
      ref="table"
      style="width: 100%;cursor: pointer;"
    >
      <el-table-column
        prop="area"
        label="分区"
        width="100"
        align="center"
        fixed
      ></el-table-column>
      <el-table-column
        prop="cut"
        label="机号"
        width="100"
        align="center"
        fixed
      ></el-table-column>
      <el-table-column
        :label="'周一 (' + weekTitle[0] + ')'"
        width="335"
        v-if="isShowOne"
        align="center"
      >
        <el-table-column prop="Mon_M" label="上" width="110" align="center" v-if="isShowShangWu">
          <schedule-item
            slot-scope="scope"
            :schedule-detail="scope.row.Mon_M"
            :config="config"

          ></schedule-item>
        </el-table-column>
        <el-table-column prop="Mon_A" label="下" width="110" align="center" v-if="isShowXiaWu">
          <schedule-item
            slot-scope="scope"
            :schedule-detail="scope.row.Mon_A"
            :config="config"

          ></schedule-item>
        </el-table-column>
        <el-table-column prop="Mon_N" label="晚" width="110" align="center" v-if="isShowWanShang">
          <schedule-item
            slot-scope="scope"
            :schedule-detail="scope.row.Mon_N"
            :config="config"

          ></schedule-item>
        </el-table-column>
      </el-table-column>
      <el-table-column
        :label="'周二 (' + weekTitle[1] + ')'"
        width="335"
        v-if="isShowTwo"
        align="center"
      >
        <el-table-column prop="Tue_M" label="上" width="110" align="center" v-if="isShowShangWu">
          <schedule-item
            slot-scope="scope"
            :schedule-detail="scope.row.Tue_M"
            :config="config"

          ></schedule-item>
        </el-table-column>
        <el-table-column prop="Tue_A" label="下" width="110" align="center" v-if="isShowXiaWu">
          <schedule-item
            slot-scope="scope"
            :schedule-detail="scope.row.Tue_A"
            :config="config"

          ></schedule-item>
        </el-table-column>
        <el-table-column prop="Tue_N" label="晚" width="110" align="center" v-if="isShowWanShang">
          <schedule-item
            slot-scope="scope"
            :schedule-detail="scope.row.Tue_N"
            :config="config"

          ></schedule-item>
        </el-table-column>
      </el-table-column>
      <el-table-column
        :label="'周三 (' + weekTitle[2] + ')'"
        width="335"
        v-if="isShowThree"

        align="center"
      >
        <el-table-column prop="Wed_M" label="上" width="110" align="center" v-if="isShowShangWu">
          <schedule-item
            slot-scope="scope"
            :schedule-detail="scope.row.Wed_M"
            :config="config"

          ></schedule-item>
        </el-table-column>
        <el-table-column prop="Wed_A" label="下" width="110" align="center" v-if="isShowXiaWu">
          <schedule-item
            slot-scope="scope"
            :schedule-detail="scope.row.Wed_A"
            :config="config"

          ></schedule-item>
        </el-table-column>
        <el-table-column prop="Wed_N" label="晚" width="110" align="center" v-if="isShowWanShang">
          <schedule-item
            slot-scope="scope"
            :config="config"

            :schedule-detail="scope.row.Wed_N"
          ></schedule-item>
        </el-table-column>
      </el-table-column>
      <el-table-column
        :label="'周四 (' + weekTitle[3] + ')'"
        width="335"
        align="center"
        v-if="isShowFour"

      >
        <el-table-column prop="Thurs_M" label="上" width="110" align="center" v-if="isShowShangWu">
          <schedule-item
            slot-scope="scope"
            :config="config"
            :schedule-detail="scope.row.Thurs_M"
          ></schedule-item>
        </el-table-column>
        <el-table-column prop="Thurs_A" label="下" width="110" align="center" v-if="isShowXiaWu">
          <schedule-item
            slot-scope="scope"
            :schedule-detail="scope.row.Thurs_A"
            :config="config"

          ></schedule-item>
        </el-table-column>
        <el-table-column prop="Thurs_N" label="晚" width="110" align="center" v-if="isShowWanShang">
          <schedule-item
            slot-scope="scope"
            :schedule-detail="scope.row.Thurs_N"
            :config="config"

          ></schedule-item>
        </el-table-column>
      </el-table-column>
      <el-table-column
        :label="'周五 (' + weekTitle[4] + ')'"
        width="335"
        align="center"
        v-if="isShowFive"

      >
        <el-table-column prop="Fri_M" label="上" width="110" align="center" v-if="isShowShangWu">
          <schedule-item
            slot-scope="scope"
            :schedule-detail="scope.row.Fri_M"
            :config="config"

          ></schedule-item>
        </el-table-column>
        <el-table-column prop="Fri_A" label="下" width="110" align="center" v-if="isShowXiaWu">
          <schedule-item
            slot-scope="scope"
            :schedule-detail="scope.row.Fri_A"
            :config="config"

          ></schedule-item>
        </el-table-column>
        <el-table-column prop="Fri_N" label="晚" width="110" align="center" v-if="isShowWanShang">
          <schedule-item
            slot-scope="scope"
            :schedule-detail="scope.row.Fri_N"
            :config="config"

          ></schedule-item>
        </el-table-column>
      </el-table-column>
      <el-table-column
        :label="'周六 (' + weekTitle[5] + ')'"
        width="335"
        align="center"
        v-if="isShowSix"

      >
        <el-table-column prop="Sat_M" label="上" width="110" align="center" v-if="isShowShangWu">
          <schedule-item
            slot-scope="scope"
            :schedule-detail="scope.row.Sat_M"
            :config="config"

          ></schedule-item>
        </el-table-column>
        <el-table-column prop="Sat_A" label="下" width="110" align="center" v-if="isShowXiaWu">
          <schedule-item
            slot-scope="scope"
            :schedule-detail="scope.row.Sat_A"
            :config="config"

          ></schedule-item>
        </el-table-column>
        <el-table-column prop="Sat_N" label="晚" width="110" align="center" v-if="isShowWanShang">
          <schedule-item
            slot-scope="scope"
            :schedule-detail="scope.row.Sat_N"
            :config="config"

          ></schedule-item>
        </el-table-column>
      </el-table-column>
      <el-table-column
        :label="'周日 (' + weekTitle[6] + ')'"
        min-width="335"
        align="center"
        v-if="isShowSeven"

      >
        <el-table-column prop="Sun_M" label="上" min-width="110" align="center" v-if="isShowShangWu">
          <schedule-item
            slot-scope="scope"
            :schedule-detail="scope.row.Sun_M"
            :config="config"

          ></schedule-item>
        </el-table-column>
        <el-table-column prop="Sun_A" label="下" min-width="110" align="center" v-if="isShowXiaWu">
          <schedule-item
            slot-scope="scope"
            :schedule-detail="scope.row.Sun_A"
            :config="config"

          ></schedule-item>
        </el-table-column>
        <el-table-column prop="Sun_N" label="晚" min-width="110" align="center" v-if="isShowWanShang">
          <schedule-item
            slot-scope="scope"
            :schedule-detail="scope.row.Sun_N"
            :config="config"

          ></schedule-item>
        </el-table-column>
      </el-table-column>

<!--      <el-table-column-->
<!--        prop="total"-->
<!--        label="总数"-->
<!--        width="60"-->
<!--        align="center"-->
<!--        fixed="right"-->
<!--      ></el-table-column>-->
    </el-table>
 </div>
    <el-dialog
      title="排班"
      :visible.sync="dialogTableVisible"
      width="1000px;"
      :v-model="dialog"
      v-loading="creating_schedule"
    >
      <div>
        <div class="cell clearfix">
          <label class="title"><span class="name">当前排班</span> : </label>
          <div class="time ">
            <ul class="">
              <span class="current"
                >日期 : {{ currentData.schedule_date }} &nbsp;&nbsp; 班次 :
                {{ currentData.type_name }} &nbsp;&nbsp; 病房 :
                {{ currentData.zone_name }} &nbsp;&nbsp; 透析机 :
                {{ currentData.bed_name }}
              </span>
            </ul>
          </div>
        </div>

        <div class="cell clearfix">
          <label class="title"><span class="name">患者搜索</span> : </label>
          <div class="time ">
            <ul class="">
              <el-input
                size="medium"
                v-model="searchKey"
                placeholder="请输入搜索的内容"
                style="width:260px"
                @keyup.enter.native='SubmitSearch'
              ></el-input>
              <el-button
                type="primary"
                icon="el-icon-search"
                @click="SubmitSearch"
                >搜索</el-button
              >
            </ul>
          </div>
        </div>
        <div class="cell clearfix">
          <label class="title"><span class="name">排班</span> : </label>
          <div class="time ">
            <ul class="">
              <li
                v-for="item in schedulArr"
                @click="changeSearchSchedule(item.value)"
                :key="item.value"
                :class="patientQuery.schedule == item.value ? 'active' : ''"
              >
                {{ item.label }}
              </li>
            </ul>
          </div>
        </div>
        <!-- <div class="cell clearfix">
          <label class="title"><span class="name">标签</span> : </label>
          <div class="time ">
            <ul class="">
              <li v-for="item in tagArr" :key="item.value" >{{item.label}}</li>
            </ul>
          </div>
        </div> -->
        <div class="cell clearfix">
          <label class="title"><span class="name">传染病</span> : </label>
          <div class="time ">
            <ul class="">
              <li
                v-for="item in diseasesArr"
                @click="changeSearchContagion(item.value)"
                :key="item.value"
                :class="patientQuery.contagion == item.value ? 'active' : ''"
              >
                {{ item.label }}
              </li>
            </ul>
          </div>
        </div>
      </div>
      <el-table
        ref="singleTable"
        :data="patients"
        border
        highlight-current-row
        @current-change="handleCurrentChange"
        :header-cell-style="{ backgroundColor: 'rgb(236, 245, 255)' }"
      >
        <el-table-column
          type="index"
          label="序号"
          width="89"
          align="center"
        ></el-table-column>
        <el-table-column
          property="dialysis_no"
          label="透析号"
          min-width="110"
          align="center"
        ></el-table-column>
        <el-table-column
          property="name"
          label="姓名"
          min-width="110"
          align="center"
        ></el-table-column>
        <el-table-column
          property="schedules"
          label="双周已排"
          min-width="80"
          align="center"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.schedules.length }}次</span>
          </template>
        </el-table-column>
        <el-table-column
          property="solutions"
          label="治疗频率"
          min-width="200"
          align="center"
        >
          <template slot-scope="scope">
            <span v-for="solution in scope.row.solutions" :key="solution.id"
              >{{ solution.name }}({{ solution.period }}{{ solution.times }})
            </span>
          </template>
        </el-table-column>
        <el-table-column
          property="sch_remark"
          label="备注"
          min-width="200"
          align="center"
        >
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="closePatientPanel()">取 消</el-button>
        <el-button
          :disabled="$store.getters.xt_user.subscibe.state == 3 ? true : false"
          type="primary"
          @click="setSchedule"
          >保 存
        </el-button>
      </div>
    </el-dialog>
    <el-dialog title="调整排班" :visible.sync="tzDialogVisible" width="500px">
      <div style="width:100%;margin:0 auto">
        <el-radio-group v-model="tiaoZhengType" :class="tiaozhengclass">
          <el-radio :label="1">取消排班</el-radio>
          <el-radio :label="2">调整机号</el-radio>
          <el-radio :label="3">调整模式</el-radio>
        </el-radio-group>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button
          @click="
            tzDialogVisible = false;
            tiaoZhengType = 1;
          "
          >取 消</el-button
        >
        <el-button
          :disabled="$store.getters.xt_user.subscibe.state == 3 ? true : false"
          type="primary"
          @click="submitTiaoX"
          >
          <span v-if='tiaoZhengType == 1'>保存</span>
          <span v-if='tiaoZhengType == 2'>下一步</span>
          <span v-if='tiaoZhengType == 3'>下一步</span>
          </el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="调整模式"
      :visible.sync="msDialogVisible"
      width="500px"
      v-loading="changing_mode"
    >
      <div>
        <el-form
          :model="changeSchedule"
          ref="changeSchedule"
          :rules="changeRules"
        >
          <el-form-item label="" prop="mode_id">
            <el-select
              v-model="changeSchedule.mode_id"
              placeholder="请选择"
              style="width:100%"
            >
              <el-option
                :disabled="item.id == currentData.mode_id"
                v-for="item in modeOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="msDialogVisible = false">取 消</el-button>
        <el-button
          :disabled="$store.getters.xt_user.subscibe.state == 3 ? true : false"
          type="primary"
          @click="submitMode('changeSchedule')"
          >保 存</el-button
        >
      </span>
    </el-dialog>
    <el-dialog
      title="调整机号"
      :visible.sync="jhDialogVisible"
      width="500px"
      v-loading="changing_bed"
    >
      <div>
        <el-form
          :model="changeSchedule"
          ref="changeSchedule"
          :rules="changeRules"
          label-width="90px"
        >
          <el-form-item label="排班日期: ">
            <el-input v-model="currentData.schedule_date" disabled></el-input>
          </el-form-item>
          <el-form-item label="班次: " prop="schedule_type">
            <el-select
              v-model="changeSchedule.schedule_type"
              placeholder="请选择"
              style="width:100%"
              @change="changeScheduleType"
            >
              <el-option
                v-for="item in scheduleType"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="病房: " prop="partition_id">
            <el-select
              v-model="zone_name"
              placeholder="请选择"
              style="width:100%"
              @change="changePartition"
            >
              <el-option
                v-for="(item, index) in zones"
                :key="index"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="透析机: " prop="bed_id">
            <el-select
              v-model="device_id"
              placeholder="请选择"
              style="width:100%"
            >
              <el-option
                v-for="item in current_devices"
                :key="item.id"
                :label="item.number"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="jhDialogVisible = false">取 消</el-button>
        <el-button
          :disabled="$store.getters.xt_user.subscibe.state == 3 ? true : false"
          type="primary"
          @click="submitTiaoZJH('changeSchedule')"
          >保 存</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { uParseTime } from "@/utils/tools";
import print from 'print-js'
const moment = require('moment')
import {
  CancelSchedule,
  ChangeSchedule,
  CreateSchedule,
  getSchedulePatients,
  getSchedulesOne,
  getSearchResult,
  getUrgentScheduleInitData,
  getWeekPanelsOne,
  getAllZones,
} from "@/api/schedule";
import {
  getSmartDevices
} from "@/api/schedule_template/sch_template";

import ScheduleItem from "./ScheduleItem";
const weekOptions = ['周一','周二','周三','周四','周五','周六','周日'];
let rowNumber = 0;
export default {
  name: "tableData",
  props: {
    is_edit:{
      type: Boolean,
      default: false,

    },
    weekTime: {
      type: String,
      default: "thisWeek"
    },
    scheduleZoneRowProp: {
      type: Array,
      dafault: []
    },
    // scheduleZoneProp: {
    //   type: Array,
    //   dafault: []
    // },
    partitionsProp: {
      type: Object,
      dafault: {}
    }, config: {
      type: Object,
      dafault: {}
    },

  },
  data() {
    return {
      // tableContainHeight:400,
      // tableHeight:'window.innerHeight - 0',
      // rowClass: "table-row-new-class schedule-table-row",
      weeks:weekOptions,
      searchKey: "",
      tiaoZhengType: 1,
      modeOptions: null,
      keywords: "",
      schedulePatients: [],
      searchTableVisible: false,
      dialog: {
        tag: ""
      },
      patients: [],
      toDay: "",
      schedulArr: [
        { value: 0, label: "不限" },
        { value: 2, label: "未排班" },
        { value: 1, label: "已排班" }
      ],
      tagArr: [
        { value: 1, label: "不限" },
        { value: 2, label: "透析记录" },
        { value: 3, label: "传染病" }
      ],
      diseasesArr: [{ value: 0, label: "不限" }],
      scheduleType: [
        { id: 1, name: "上午" },
        { id: 2, name: "下午" },
        { id: 3, name: "晚上" }
      ],
      dialogTableVisible: false,
      tzDialogVisible: false,
      msDialogVisible: false,
      jhDialogVisible: false,
     // scheduleZone: this.scheduleZoneProp,
      scheduleZoneRow: -1,
      partitions: [],
      jihaos: [],
      weekTitle: ["", "", "", "", "", "", ""],
      weekList: ["", "", "", "", "", "", ""],
      weekDays: ["", "", "", "", "", "", ""],
      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: ""
      },
      changeSchedule: {
        mode_id: "",
        schedule_type: "",
        partition_id: "",
        bed_id: "",
        schedule_week: "",
        partition_type: ""
      },
      patientQuery: {
        keywords: "",
        schedule: 0,
        contagion: 0
      },

      tiaozhengclass: "tiaozhengclass",
      changeRules: {
        mode_id: [{ required: true, message: "请选择模式", trigger: "blur" }],
        schedule_type: [
          { required: true, message: "请选择班次", trigger: "blur" }
        ],
        partition_id: [
          { required: true, message: "请选择病房", trigger: "blur" }
        ],
        bed_id: [{ required: true, message: "请选择透析机", trigger: "blur" }]
      },

      weekday: 0,

      creating_schedule: false,
      changing_mode: false,
      changing_bed: false,

      tableHeight: document.documentElement.clientHeight,

      origin_schedules: [],
      origin_device_numbers: [],
      zone_device_map: {},
      device_id: 0,
      zone_name: "",
      current_devices: [],
      zone_names: [],
      zone_device_options: [],
      options:[
        {id:1,name:"上午"},
        {id:2,name:"下午"},
        {id:3,name:"晚上"},
      ],
      partition_id:0,
      schedule_type:[],
      week_type:[],
      zones:[],
      theType:"",
      scheduleZone:[],
      source_scheduleZone:[],
      theWeek: {
        lastWeek: 0,
        thisWeek: 0,
        nextWeek: 0,
        nextTwoWeek: 0
      },
      zoneIdList:[],
      strArr:"",
      patient_id_hover:0,
      now_time:"",
      isShowOne:true,
      isShowTwo:true,
      isShowThree:true,
      isShowFour:true,
      isShowFive:true,
      isShowSix:true,
      isShowSeven:true,
      isShowShangWu:true,
      isShowXiaWu:true,
      isShowWanShang:true,
      schedulesGroup:[]

    };
  },

  watch: {
    schedule_type:function (){
      this.isShowShangWu = false
      this.isShowXiaWu = false
      this.isShowWanShang = false
      if(this.schedule_type.length > 0) {
        for (let i = 0; i < this.schedule_type.length; i++) {
          if (this.schedule_type[i] == 1) {
            this.isShowShangWu = true
          } else if (this.schedule_type[i] == 2) {
            this.isShowXiaWu = true
          } else if (this.schedule_type[i] == 3) {
            this.isShowWanShang = true
          }
        }
      }else{
        this.isShowShangWu = true
        this.isShowXiaWu = true
        this.isShowWanShang = true
      }
      // console.log(this.source_scheduleZone)
      //删除对应数据
      var list = this.source_scheduleZone
      var list1 = this.source_scheduleZone
      var list2 = this.source_scheduleZone

      //
      // if(this.isShowShangWu){
      //   for(let i = 0; i < list.length; i++){
      //      for(var key in list[i]){
      //        if(key.indexOf("_A") != -1 || key.indexOf("_N") != -1 ){
      //          delete  list[i][key]
      //        }
      //      }
      //   }
      // }
      //
      // if(this.isShowXiaWu){
      //   for(let i = 0; list1.length; i++){
      //     for(var key in list1[i]){
      //       if(key.indexOf("_M") != -1 || key.indexOf("_N") != -1 ){
      //         delete  list1[i][key]
      //       }
      //     }
      //   }
      // }
      //
      // if(this.isShowWanShang){
      //   for(let i = 0; list2.length; i++){
      //     for(var key in list2[i]){
      //       if(key.indexOf("_A") != -1 || key.indexOf("_M") != -1 ){
      //         delete  list2[i][key]
      //       }
      //     }
      //   }
      //
      // }



      // if(this.week_type.length > 0){
      //   if(this.week_type.indexOf("周一") != -1){
      //
      //   }
      //   if(this.week_type.indexOf("周二") != -1){
      //
      //
      //   }
      //   if(this.week_type.indexOf("周三") != -1){
      //
      //
      //   }
      //   if(this.week_type.indexOf("周四") != -1){
      //
      //
      //   }
      //   if(this.week_type.indexOf("周五") != -1){
      //
      //
      //   }
      //   if(this.week_type.indexOf("周六") != -1){
      //
      //
      //   }
      //   if(this.week_type.indexOf("周日") != -1){
      //
      //
      //   }
      //
      // }


    }, week_type:function () {
      // console.log(this.week_type)
      // console.log(this.schedule_type)
      // console.log(this.scheduleZone)

      this.isShowOne = false
      this.isShowTwo = false
      this.isShowThree = false
      this.isShowFour = false
      this.isShowFive = false
      this.isShowSix = false
      this.isShowSeven = false
      if(this.week_type.length > 0) {
        for (let i = 0; i < this.week_type.length; i++) {
          if (this.week_type[i] == "周一") {
            this.isShowOne = true
          } else if (this.week_type[i] == "周二") {
            this.isShowTwo = true
          } else if (this.week_type[i] == "周三") {
            this.isShowThree = true
          } else if (this.week_type[i] == "周四") {
            this.isShowFour = true
          } else if (this.week_type[i] == "周五") {
            this.isShowFive = true
          } else if (this.week_type[i] == "周六") {
            this.isShowSix = true
          } else if (this.week_type[i] == "周日") {
            this.isShowSeven = true
          }
        }
      }else{
        this.isShowOne = true
        this.isShowTwo = true
        this.isShowThree = true
        this.isShowFour = true
        this.isShowFive = true
        this.isShowSix = true
        this.isShowSeven = true
      }



    },
    weekTime: function() {
      var theType = this.weekType(this.weekTime);
      // console.log("999999999",theType)
      this.theType = theType
      this.getSchedules();
    },
    scheduleZoneRow: function() {
      var theType = this.weekType(this.weekTime);
      this.theType = theType
      this.getSchedules();
    },
    tableHeight(val) {
      if (!this.timer) {
        this.tableHeight = val;
        this.timer = true;
        const that = this;
        setTimeout(function() {
          that.timer = false;
        }, 400);
      }
    }
  },
  methods: {
    getData(){
      return this.scheduleZone
    },
    compare(p){ //这是比较函数
      return function(m,n){
          var a = m[p];
          var b = n[p];
          return a - b; //升序
      }
     },
     getWeekPanels() {
         this.scheduleZone=[]
         var partionStr = this.partition_id
         var arr = this.zoneIdList.join(',')

         var str = ""
         if(partionStr == 0){
            str = arr
         }
         if(partionStr != 0){
            str = partionStr.join(',')
         }


        getWeekPanelsOne(1,str).then(response => {
          if (response.data.state == 0) {
            return false
          }
          var partitions = response.data.data.partitions
          console.log("partitions",partitions)
          this.theWeek.thisWeek = response.data.data.theWeek

          this.theWeek.lastWeek = this.theWeek.thisWeek - 1
          this.theWeek.nextWeek = this.theWeek.thisWeek + 1
          this.theWeek.nextTwoWeek = this.theWeek.thisWeek + 2
          var that = this
          if (partitions.length > 0) {
            partitions.forEach(function(partition) {
              if (partition.jihaos.length == 0) {
                return false
              }
              that.scheduleZoneRow.push(partition.jihaos.length)

              that.partitions[partition.id] = partition

              partition.jihaos.forEach(function(jihao) {
                var thisPa = {
                  area: partition.name,
                  zone_id: partition.id,
                  zone_type: partition.type,
                  cut: jihao.number,
                  jihao_id: jihao.id,
                  sort:jihao.sort,

                  Mon_M: {
                    schedule_id: 0,
                    mode_id: 0,
                    mode_name: '',
                    patient_id: 0,
                    patient: '',
                    dialysis_machine_name:'',
                    schedule_date:"",
                    Count:0,
                  },
                  Mon_A: {
                    schedule_id: 0,
                    mode_id: 0,
                    mode_name: '',
                    patient_id: 0,
                    patient: '',
                    dialysis_machine_name:'',
                    schedule_date:"",
                    Count:0,
                  },
                  Mon_N: {
                    schedule_id: 0,
                    mode_id: 0,
                    mode_name: '',
                    patient_id: 0,
                    patient: '',
                    dialysis_machine_name:'',
                    schedule_date:"",
                    Count:0,
                  },
                  Tue_M: {
                    schedule_id: 0,
                    mode_id: 0,
                    mode_name: '',
                    patient_id: 0,
                    patient: '',
                    dialysis_machine_name:'',
                    schedule_date:"",
                    Count:0,
                  },
                  Tue_A: {
                    schedule_id: 0,
                    mode_id: 0,
                    mode_name: '',
                    patient_id: 0,
                    patient: '',
                    dialysis_machine_name:'',
                    schedule_date:"",
                    Count:0,
                  },
                  Tue_N: {
                    schedule_id: 0,
                    mode_id: 0,
                    mode_name: '',
                    patient_id: 0,
                    patient: '',
                    dialysis_machine_name:'',
                    schedule_date:"",
                    Count:0,
                  },
                  Wed_M: {
                    schedule_id: 0,
                    mode_id: 0,
                    mode_name: '',
                    patient_id: 0,
                    patient: '',
                    dialysis_machine_name:'',
                    schedule_date:"",
                    Count:0,
                  },
                  Wed_A: {
                    schedule_id: 0,
                    mode_id: 0,
                    mode_name: '',
                    patient_id: 0,
                    patient: '',
                    dialysis_machine_name:'',
                    schedule_date:"",
                    Count:0,
                  },
                  Wed_N: {
                    schedule_id: 0,
                    mode_id: 0,
                    mode_name: '',
                    patient_id: 0,
                    patient: '',
                    dialysis_machine_name:'',
                    schedule_date:"",
                    Count:0,
                  },
                  Thurs_M: {
                    schedule_id: 0,
                    mode_id: 0,
                    mode_name: '',
                    patient_id: 0,
                    patient: '',
                    dialysis_machine_name:'',
                    schedule_date:"",
                    Count:0,
                  },
                  Thurs_A: {
                    schedule_id: 0,
                    mode_id: 0,
                    mode_name: '',
                    patient_id: 0,
                    patient: '',
                    dialysis_machine_name:'',
                    schedule_date:"",
                    Count:0,
                  },
                  Thurs_N: {
                    schedule_id: 0,
                    mode_id: 0,
                    mode_name: '',
                    patient_id: 0,
                    patient: '',
                    dialysis_machine_name:'',
                    schedule_date:"",
                    Count:0,
                  },
                  Fri_M: {
                    schedule_id: 0,
                    mode_id: 0,
                    mode_name: '',
                    patient_id: 0,
                    patient: '',
                    dialysis_machine_name:'',
                    schedule_date:"",
                    Count:0,
                  },
                  Fri_A: {
                    schedule_id: 0,
                    mode_id: 0,
                    mode_name: '',
                    patient_id: 0,
                    patient: '',
                    dialysis_machine_name:'',
                    schedule_date:"",
                    Count:0,
                  },
                  Fri_N: {
                    schedule_id: 0,
                    mode_id: 0,
                    mode_name: '',
                    patient_id: 0,
                    patient: '',
                    dialysis_machine_name:'',
                    schedule_date:"",
                    Count:0,
                  },
                  Sat_M: {
                    schedule_id: 0,
                    mode_id: 0,
                    mode_name: '',
                    patient_id: 0,
                    patient: '',
                    dialysis_machine_name:'',
                    schedule_date:"",
                    Count:0,
                  },
                  Sat_A: {
                    schedule_id: 0,
                    mode_id: 0,
                    mode_name: '',
                    patient_id: 0,
                    patient: '',
                    dialysis_machine_name:'',
                    schedule_date:"",
                    Count:0,
                  },
                  Sat_N: {
                    schedule_id: 0,
                    mode_id: 0,
                    mode_name: '',
                    patient_id: 0,
                    patient: '',
                    dialysis_machine_name:'',
                    schedule_date:"",
                    Count:0,
                  },
                  Sun_A: {
                    schedule_id: 0,
                    mode_id: 0,
                    mode_name: '',
                    patient_id: 0,
                    patient: '',
                    dialysis_machine_name:'',
                    schedule_date:"",
                    Count:0,
                  },
                  Sun_N: {
                    schedule_id: 0,
                    mode_id: 0,
                    mode_name: '',
                    patient_id: 0,
                    patient: '',
                    dialysis_machine_name:'',
                    schedule_date:"",
                    Count:0,
                  },
                  Sun_M: {
                    schedule_id: 0,
                    mode_id: 0,
                    mode_name: '',
                    patient_id: 0,
                    patient: '',
                    dialysis_machine_name:'',
                    schedule_date:"",
                    Count:0,
                  },
                  total: 0
                }

                that.scheduleZone.push(thisPa)

              })
            })
          }

          this.scheduleZone.sort(this.compare('sort'))
          this.source_scheduleZone = this.scheduleZone
          console.log("34455555566666",this.source_scheduleZone)
        })
     },

    cellClass({ row, column, rowIndex, columnIndex }) {
      if (columnIndex == 0 || columnIndex == 1 || columnIndex == 23) {
        return "";
      } else {
        if (this.weekTime == "lastWeek") {
          if(row[column.property].patient_id > 0 && row[column.property].patient_id == this.patient_id_hover){
            return 'hover-td schedule-table-cell-disable'
          }else {
            return 'schedule-table-cell-disable'
          }
          // return "schedule-table-cell-disable";
        } else if (this.weekTime == "thisWeek") {
          var weekday = Math.floor((columnIndex - 2) / 3 + 1);
          if (weekday < this.weekday) {
            if(row[column.property].patient_id > 0 && row[column.property].patient_id == this.patient_id_hover){
              return 'hover-td schedule-table-cell-disable'
            }else {
              return 'schedule-table-cell-disable'
            }
            // return "schedule-table-cell-disable";
          }else {
            if(row[column.property].patient_id > 0 && row[column.property].patient_id == this.patient_id_hover){
              return 'hover-td'
            }else {
              return ''
            }
          }
        }
      }
      return "";
    },
    SubmitSearch() {
      this.patientQuery.keywords = this.searchKey;
      this.getSchedulePatients();
    },
    changeSearchContagion(id) {
      this.patientQuery.contagion = id;
      this.getSchedulePatients();
    },
    changeSearchSchedule(id) {
      this.patientQuery.schedule = id;
      this.getSchedulePatients();
    },
    getSummaries(param) {


      const { columns, data } = param;
      const sums = [];

      columns.forEach((column, index) => {

        if (index === 0 ) {
          sums[index] = "总数";
          return;
        }
        if (index === 1 ) {
          sums[index] = data.length;
          return;
        }

        const values = data.map(item => item[column.property]);

        sums[index] = values.reduce((prev, curr) => {
          if (typeof curr["mode_id"] === "undefined") {
            return prev;
          }
          const value = Number(curr["mode_id"]);
          if (!isNaN(value) && value > 0) {
            return prev + 1;
          } else {
            return prev;
          }
        }, 0);
        sums[index];
      });
      this.$nextTick(() => {
        this.$refs.table.doLayout();
      });
    if(this.$store.getters.xt_user.template_info.org_id == 9671 || this.$store.getters.xt_user.template_info.org_id == 0 || this.$store.getters.xt_user.template_info.org_id == 3877 || this.$store.getters.xt_user.template_info.org_id == 10340){

      //灌流 HD+HP
      var Mon_M = 0
      var Mon_A = 0
      var Mon_N = 0

      var Tue_M =0
      var Tue_A = 0
      var Tue_N = 0

      var Wed_M = 0
      var Wed_A = 0
      var Wed_N = 0

      var Thurs_M = 0
      var Thurs_A = 0
      var Thurs_N = 0

      var Fri_M = 0
      var Fri_A = 0
      var Fri_N = 0

      var Sat_M = 0
      var Sat_A = 0
      var Sat_N = 0

      var Sun_M = 0
      var Sun_A = 0
      var Sun_N = 0

      //血滤 HDF
      var Mon_M_One = 0
      var Mon_A_One = 0
      var Mon_N_One = 0

      var Tue_M_One =0
      var Tue_A_One = 0
      var Tue_N_One = 0

      var Wed_M_One = 0
      var Wed_A_One = 0
      var Wed_N_One = 0

      var Thurs_M_One = 0
      var Thurs_A_One = 0
      var Thurs_N_One = 0

      var Fri_M_One = 0
      var Fri_A_One = 0
      var Fri_N_One = 0

      var Sat_M_One = 0
      var Sat_A_One = 0
      var Sat_N_One = 0

      var Sun_M_One = 0
      var Sun_A_One = 0
      var Sun_N_One= 0

      if(this.schedulesGroup!=null && this.schedulesGroup.length >0){

        for(let i=0;i<this.schedulesGroup.length;i++){
          //灌流
          //礼拜一上午
          if(this.schedulesGroup[i].schedule_week == 1 && this.schedulesGroup[i].schedule_type == 1 && this.schedulesGroup[i].mode_id == 3){
            Mon_M = this.schedulesGroup[i].Count
          }
           //礼拜一下午
           if(this.schedulesGroup[i].schedule_week == 1 && this.schedulesGroup[i].schedule_type == 2 && this.schedulesGroup[i].mode_id == 3){
            Mon_A = this.schedulesGroup[i].Count
          }
           //礼拜一晚上
           if(this.schedulesGroup[i].schedule_week == 1 && this.schedulesGroup[i].schedule_type == 3 && this.schedulesGroup[i].mode_id == 3){
            Mon_N = this.schedulesGroup[i].Count
          }

           //礼拜二上午
           if(this.schedulesGroup[i].schedule_week == 2 && this.schedulesGroup[i].schedule_type == 1 && this.schedulesGroup[i].mode_id == 3){
            Tue_M = this.schedulesGroup[i].Count
          }
           //礼拜二下午
           if(this.schedulesGroup[i].schedule_week == 2 && this.schedulesGroup[i].schedule_type == 2&& this.schedulesGroup[i].mode_id == 3){
            Tue_A = this.schedulesGroup[i].Count
          }
           //礼拜二晚上
           if(this.schedulesGroup[i].schedule_week == 2 && this.schedulesGroup[i].schedule_type == 3 && this.schedulesGroup[i].mode_id == 3){
            Tue_N = this.schedulesGroup[i].Count
          }


          //礼拜三上午
          if(this.schedulesGroup[i].schedule_week == 3 && this.schedulesGroup[i].schedule_type == 1 && this.schedulesGroup[i].mode_id == 3){
            Wed_M = this.schedulesGroup[i].Count
          }
           //礼拜三下午
           if(this.schedulesGroup[i].schedule_week == 3 && this.schedulesGroup[i].schedule_type == 2 && this.schedulesGroup[i].mode_id == 3){
            Wed_A = this.schedulesGroup[i].Count
          }
           //礼拜三晚上
           if(this.schedulesGroup[i].schedule_week == 3 && this.schedulesGroup[i].schedule_type == 3 && this.schedulesGroup[i].mode_id == 3){
            Wed_N = this.schedulesGroup[i].Count
          }

           //礼拜四上午
          if(this.schedulesGroup[i].schedule_week == 4 && this.schedulesGroup[i].schedule_type == 1 && this.schedulesGroup[i].mode_id == 3){
            Thurs_M = this.schedulesGroup[i].Count
          }
           //礼拜四下午
           if(this.schedulesGroup[i].schedule_week == 4 && this.schedulesGroup[i].schedule_type == 2 && this.schedulesGroup[i].mode_id == 3){
            Thurs_A = this.schedulesGroup[i].Count
          }
           //礼拜四晚上
           if(this.schedulesGroup[i].schedule_week == 4 && this.schedulesGroup[i].schedule_type == 3 && this.schedulesGroup[i].mode_id == 3){
            Thurs_N = this.schedulesGroup[i].Count
          }

           //礼拜五上午
          if(this.schedulesGroup[i].schedule_week == 5 && this.schedulesGroup[i].schedule_type == 1 && this.schedulesGroup[i].mode_id == 3){
            Fri_M = this.schedulesGroup[i].Count
          }
           //礼拜五下午
           if(this.schedulesGroup[i].schedule_week == 5 && this.schedulesGroup[i].schedule_type == 2 && this.schedulesGroup[i].mode_id == 3){
            Fri_A = this.schedulesGroup[i].Count
          }
           //礼拜五晚上
           if(this.schedulesGroup[i].schedule_week == 5 && this.schedulesGroup[i].schedule_type == 3 && this.schedulesGroup[i].mode_id == 3){
            Fri_N = this.schedulesGroup[i].Count
          }


          //礼拜六上午
           if(this.schedulesGroup[i].schedule_week == 6 && this.schedulesGroup[i].schedule_type == 1  && this.schedulesGroup[i].mode_id == 3){
            Sat_M = this.schedulesGroup[i].Count
          }
           //礼拜六下午
           if(this.schedulesGroup[i].schedule_week == 6 && this.schedulesGroup[i].schedule_type == 2  && this.schedulesGroup[i].mode_id == 3){
            Sat_A = this.schedulesGroup[i].Count
          }
           //礼拜六晚上
           if(this.schedulesGroup[i].schedule_week == 6 && this.schedulesGroup[i].schedule_type == 3  && this.schedulesGroup[i].mode_id == 3){
            Sat_N = this.schedulesGroup[i].Count
          }

           //礼拜日上午
          if(this.schedulesGroup[i].schedule_week == 7 && this.schedulesGroup[i].schedule_type == 1  && this.schedulesGroup[i].mode_id == 3){
            Sun_M = this.schedulesGroup[i].Count
          }
           //礼拜日下午
           if(this.schedulesGroup[i].schedule_week == 7 && this.schedulesGroup[i].schedule_type == 2  && this.schedulesGroup[i].mode_id == 3){
            Sun_A = this.schedulesGroup[i].Count
          }
           //礼拜日晚上
           if(this.schedulesGroup[i].schedule_week == 7 && this.schedulesGroup[i].schedule_type == 3  && this.schedulesGroup[i].mode_id == 3){
            Sun_N = this.schedulesGroup[i].Count
          }


           //血滤
            //礼拜一上午
          if(this.schedulesGroup[i].schedule_week == 1 && this.schedulesGroup[i].schedule_type == 1 && this.schedulesGroup[i].mode_id == 2){
            Mon_M_One = this.schedulesGroup[i].Count
          }
           //礼拜一下午
           if(this.schedulesGroup[i].schedule_week == 1 && this.schedulesGroup[i].schedule_type == 2 && this.schedulesGroup[i].mode_id == 2){
            Mon_A_One = this.schedulesGroup[i].Count
          }
           //礼拜一晚上
           if(this.schedulesGroup[i].schedule_week == 1 && this.schedulesGroup[i].schedule_type == 3 && this.schedulesGroup[i].mode_id == 2){
            Mon_N_One = this.schedulesGroup[i].Count
          }

           //礼拜二上午
           if(this.schedulesGroup[i].schedule_week == 2 && this.schedulesGroup[i].schedule_type == 1 && this.schedulesGroup[i].mode_id == 2){
            Tue_M_One = this.schedulesGroup[i].Count
          }
           //礼拜二下午
           if(this.schedulesGroup[i].schedule_week == 2 && this.schedulesGroup[i].schedule_type == 2&& this.schedulesGroup[i].mode_id == 2){
            Tue_A_One = this.schedulesGroup[i].Count
          }
           //礼拜二晚上
           if(this.schedulesGroup[i].schedule_week == 2 && this.schedulesGroup[i].schedule_type == 3 && this.schedulesGroup[i].mode_id == 2){
            Tue_N_One = this.schedulesGroup[i].Count
          }


          //礼拜三上午
          if(this.schedulesGroup[i].schedule_week == 3 && this.schedulesGroup[i].schedule_type == 1 && this.schedulesGroup[i].mode_id == 2){
            Wed_M_One = this.schedulesGroup[i].Count
          }
           //礼拜三下午
           if(this.schedulesGroup[i].schedule_week == 3 && this.schedulesGroup[i].schedule_type == 2 && this.schedulesGroup[i].mode_id == 2){
            Wed_A_One = this.schedulesGroup[i].Count
          }
           //礼拜三晚上
           if(this.schedulesGroup[i].schedule_week == 3 && this.schedulesGroup[i].schedule_type == 3 && this.schedulesGroup[i].mode_id == 2){
            Wed_N_One = this.schedulesGroup[i].Count
          }

           //礼拜四上午
          if(this.schedulesGroup[i].schedule_week == 4 && this.schedulesGroup[i].schedule_type == 1 && this.schedulesGroup[i].mode_id == 2){
            Thurs_M_One = this.schedulesGroup[i].Count

          }
           //礼拜四下午
           if(this.schedulesGroup[i].schedule_week == 4 && this.schedulesGroup[i].schedule_type == 2 && this.schedulesGroup[i].mode_id == 2){
            Thurs_A_One = this.schedulesGroup[i].Count
          }
           //礼拜四晚上
           if(this.schedulesGroup[i].schedule_week == 4 && this.schedulesGroup[i].schedule_type == 3 && this.schedulesGroup[i].mode_id == 2){
            Thurs_N_One = this.schedulesGroup[i].Count
          }

           //礼拜五上午
          if(this.schedulesGroup[i].schedule_week == 5 && this.schedulesGroup[i].schedule_type == 1 && this.schedulesGroup[i].mode_id == 2){
            Fri_M_One = this.schedulesGroup[i].Count
          }
           //礼拜五下午
           if(this.schedulesGroup[i].schedule_week == 5 && this.schedulesGroup[i].schedule_type == 2 && this.schedulesGroup[i].mode_id == 2){
            Fri_A_One = this.schedulesGroup[i].Count
          }
           //礼拜五晚上
           if(this.schedulesGroup[i].schedule_week == 5 && this.schedulesGroup[i].schedule_type == 3 && this.schedulesGroup[i].mode_id == 2){
            Fri_N_One = this.schedulesGroup[i].Count
          }


          //礼拜六上午
           if(this.schedulesGroup[i].schedule_week == 6 && this.schedulesGroup[i].schedule_type == 1 && this.schedulesGroup[i].mode_id == 2){
            Sat_M_One = this.schedulesGroup[i].Count
          }
           //礼拜六下午
           if(this.schedulesGroup[i].schedule_week == 6 && this.schedulesGroup[i].schedule_type == 2 && this.schedulesGroup[i].mode_id == 2){
            Sat_A_One = this.schedulesGroup[i].Count
          }
           //礼拜六晚上
           if(this.schedulesGroup[i].schedule_week == 6 && this.schedulesGroup[i].schedule_type == 3 && this.schedulesGroup[i].mode_id == 2){
            Sat_N_One = this.schedulesGroup[i].Count
          }

           //礼拜日上午
          if(this.schedulesGroup[i].schedule_week == 7 && this.schedulesGroup[i].schedule_type == 1 && this.schedulesGroup[i].mode_id == 2){
            Sun_M_One = this.schedulesGroup[i].Count
          }
           //礼拜日下午
           if(this.schedulesGroup[i].schedule_week == 7 && this.schedulesGroup[i].schedule_type == 2 && this.schedulesGroup[i].mode_id == 2){
            Sun_A_One = this.schedulesGroup[i].Count
          }
           //礼拜日晚上
           if(this.schedulesGroup[i].schedule_week == 7 && this.schedulesGroup[i].schedule_type == 3 && this.schedulesGroup[i].mode_id == 2){
            Sun_N_One = this.schedulesGroup[i].Count
          }

        }
      }

      sums[2] = ("总人数:"+ sums[2]+"人").replace(/\\r\\n/g, '<br/>')+""+ "\n" + "HD+HP:"+Mon_M +"人" +"\n"+ "HDF:" + Mon_M_One +"人"
      sums[3] = ("总人数:"+ sums[3]+"人").replace(/\\r\\n/g, '<br/>')+" "+"\n"+ "HD+HP:"+Mon_A +"人" +"\n"+ "HDF:" + Mon_A_One +"人"
      sums[4] = ("总人数:"+ sums[4]+"人").replace(/\\r\\n/g, '<br/>')+" "+"\n"+ "HD+HP:"+Mon_N +"人" +"\n"+ "HDF:" + Mon_N_One +"人"

      sums[5] = "总人数:"+ sums[5]  +"人"+ " " + "\n"+ "HD+HP:"+Tue_M +"人" +" "+ "HDF:" + Tue_M_One +"人"
      sums[6] = "总人数:"+ sums[6]  +"人"+ " " +'\n' + "HD+HP:"+Tue_A +"人" +" "+ "HDF:" + Tue_A_One +"人"
      sums[7] = "总人数:"+ sums[7]  +"人"+ " " +'\n' + "HD+HP:"+Tue_N +"人" +" "+ "HDF:" + Tue_N_One +"人"

      sums[8] = "总人数:"+ sums[8]  +"人"+ " " + '\n'+ "HD+HP:"+Wed_M +"人" +" "+ "HDF:" + Wed_M_One +"人"
      sums[9] = "总人数:"+ sums[9]  +"人"+ " " +'\n' + "HD+HP:"+ Wed_A +"人" +" "+ "HDF:" + Wed_A_One +"人"
      sums[10] = "总人数:"+ sums[10]  +"人"+ " " +'\n'+"HD+HP:"+Wed_N +"人" +" "+ "HDF:" +Wed_N_One +"人"

      sums[11] = "总人数:"+ sums[11]  +"人"+ " " +'\n' + "HD+HP:"+Thurs_M +"人" +" "+ "HDF:" + Thurs_M_One +"人"
      sums[12] = "总人数:"+ sums[12]  +"人"+ " " +'\n' + "HD+HP:"+Thurs_A +"人" +" "+ "HDF:" + Thurs_A_One +"人"
      sums[13] = "总人数:"+ sums[13]  +"人"+ " " +'\n' + "HD+HP:"+Thurs_N +"人" +" "+ "HDF:" + Thurs_N_One +"人"

      sums[14] = "总人数:"+ sums[14]  +"人"+ " " +'\n' + "HD+HP:"+Fri_M +"人" +" "+ "HDF:" + Fri_M_One +"人"
      sums[15] = "总人数:"+ sums[15]  +"人"+ " " + '\n' +"HD+HP:"+Fri_A +"人" +" "+ "HDF:" + Fri_A_One +"人"
      sums[16] = "总人数:"+ sums[16]  +"人"+ " " +'\n' + "HD+HP:"+Fri_N +"人" +" "+ "HDF:" + Fri_N_One +"人"

      sums[17] = "总人数:"+ sums[17]  +"人"+ " " +'\n' + "HD+HP:"+Sat_M +"人" +" "+ "HDF:" + Sat_M_One +"人"
      sums[18] = "总人数:"+ sums[18]  +"人"+ " " + '\n' +"HD+HP:"+Sat_A +"人" +" "+ "HDF:" + Sat_A_One +"人"
      sums[19] = "总人数:"+ sums[19]  +"人"+ " " +'\n' + "HD+HP:"+Sat_N +"人" +" "+ "HDF:" + Sat_N_One +"人"

      sums[20] = "总人数:"+ sums[20]  +"人"+ " " +'\n' + "HD+HP:"+Sun_M +"人" +" "+ "HDF:" + Sun_M_One +"人"
      sums[21] = "总人数:"+ sums[21]  +"人"+ " " + '\n'+"HD+HP:"+Sun_A +"人" +" "+ "HDF:" + Sun_A_One +"人"
      sums[22] = "总人数:"+ sums[22]  +"人"+ " " + '\n'+"HD+HP:"+Sun_N +"人" +" "+ "HDF:" + Sun_N_One +"人"
      return sums;

      }

      if(this.$store.getters.xt_user.template_info.org_id != 9671 && this.$store.getters.xt_user.template_info.org_id != 0 && this.$store.getters.xt_user.template_info.org_id != 3877&& this.$store.getters.xt_user.template_info.org_id != 10340){
        return sums;
      }
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {

      var that = this;
      var rowNum = 0;
      rowNumber = 0;
      var rutrnData = {};
      if (columnIndex === 0) {
        var rowLen = this.scheduleZoneRow.length;
        if (rowLen > 0) {
          for (let index = 0; index < rowLen; index++) {
            rowNum = this.scheduleZoneRow[index];
            rowNumber += rowNum;
            var f = rowNumber - rowNum;
            if (f == rowIndex) {
              rutrnData = {
                rowspan: rowNum,
                colspan: 1
              };
              break;
            } else if (rowIndex < rowNumber) {
              rutrnData = {
                rowspan: 0,
                colspan: 0
              };
              break;
            }
          }
          return rutrnData;
        }
      }
    },
    handleCurrentChange(row) {
      if (typeof row === "undefined" || row == null) {
        this.currentData.patient_id = 0;
        this.currentData.contagions = [];
      } else {
        this.currentData.patient_id = row.id;
        this.currentData.contagions = row.contagions;
      }
    },
    closePatientPanel(row) {
      this.dialogTableVisible = false;
      this.$refs.singleTable.setCurrentRow(row);
      this.currentData.patient_id = 0;
    },
    getSchedules() {
         var partionStr = this.partition_id
         var arr = this.zoneIdList.join(',')
         var str = ""
         if(partionStr == 0){
            str = arr
         }
         if(partionStr != 0){
            str = partionStr.join(',')
         }
        const params = {
          weekTime:this.theType,
          patitionid:str,
          schedule_type:this.schedule_type,
        }

      getSchedulesOne(params).then(response => {
        if (response.data.state == 1) {
          this.weekTitle = response.data.data.weekTitle;

          this.weekDays = response.data.data.days;
          this.toDay = response.data.data.today;
          var theSchedules = response.data.data.schdules;

          var schedulesGroup = response.data.data.schedulesGroup
          this.schedulesGroup = schedulesGroup




          var that = this;

          this.scheduleZone.forEach(function(zone, index) {

            that.scheduleZone[index].Mon_M = {
              mode_id: 0,
              mode_name: "",
              patient_id: 0,
              patient: "",
              dialysis_machine_name:"",
              schedule_date:"",
              Count:0,
            };
            that.scheduleZone[index].Mon_A = {
              mode_id: 0,
              mode_name: "",
              patient_id: 0,
              patient: "",
              dialysis_machine_name:"",
              schedule_date:"",
              Count:0,
            };
            that.scheduleZone[index].Mon_N = {
              mode_id: 0,
              mode_name: "",
              patient_id: 0,
              patient: "",
              dialysis_machine_name:"",
              schedule_date:"",
              Count:0,
            };
            that.scheduleZone[index].Tue_M = {
              mode_id: 0,
              mode_name: "",
              patient_id: 0,
              patient: "",
              dialysis_machine_name:"",
              schedule_date:"",
              Count:0,
            };
            that.scheduleZone[index].Tue_A = {
              mode_id: 0,
              mode_name: "",
              patient_id: 0,
              patient: "",
              dialysis_machine_name:"",
              schedule_date:"",
              Count:0,
            };
            that.scheduleZone[index].Tue_N = {
              mode_id: 0,
              mode_name: "",
              patient_id: 0,
              patient: "",
              dialysis_machine_name:"",
              schedule_date:"",
              Count:0,
            };
            that.scheduleZone[index].Wed_M = {
              mode_id: 0,
              mode_name: "",
              patient_id: 0,
              patient: "",
              dialysis_machine_name:"",
              schedule_date:"",
              Count:0,
            };
            that.scheduleZone[index].Wed_A = {
              mode_id: 0,
              mode_name: "",
              patient_id: 0,
              patient: "",
              dialysis_machine_name:"",
              schedule_date:"",
              Count:0,
            };
            that.scheduleZone[index].Wed_N = {
              mode_id: 0,
              mode_name: "",
              patient_id: 0,
              patient: "",
              dialysis_machine_name:"",
              schedule_date:"",
              Count:0,

            };
            that.scheduleZone[index].Thurs_M = {
              mode_id: 0,
              mode_name: "",
              patient_id: 0,
              patient: "",
              dialysis_machine_name:"",
              schedule_date:"",
              Count:0,
            };
            that.scheduleZone[index].Thurs_A = {
              mode_id: 0,
              mode_name: "",
              patient_id: 0,
              patient: "",
              dialysis_machine_name:"",
              schedule_date:"",
              Count:0,
            };
            that.scheduleZone[index].Thurs_N = {
              mode_id: 0,
              mode_name: "",
              patient_id: 0,
              patient: "",
              dialysis_machine_name:"",
              schedule_date:"",
              Count:0,
            };
            that.scheduleZone[index].Fri_M = {
              mode_id: 0,
              mode_name: "",
              patient_id: 0,
              patient: "",
              dialysis_machine_name:"",
              schedule_date:"",
              Count:0,
            };
            that.scheduleZone[index].Fri_A = {
              mode_id: 0,
              mode_name: "",
              patient_id: 0,
              patient: "",
              dialysis_machine_name:"",
              schedule_date:"",
              Count:0,
            };
            that.scheduleZone[index].Fri_N = {
              mode_id: 0,
              mode_name: "",
              patient_id: 0,
              patient: "",
              dialysis_machine_name:"",
              schedule_date:"",
              Count:0,
            };
            that.scheduleZone[index].Sat_M = {
              mode_id: 0,
              mode_name: "",
              patient_id: 0,
              patient: "",
              dialysis_machine_name:"",
              schedule_date:"",
              Count:0,
            };
            that.scheduleZone[index].Sat_A = {
              mode_id: 0,
              mode_name: "",
              patient_id: 0,
              patient: "",
              dialysis_machine_name:"",
              schedule_date:"",
              Count:0,
            };
            that.scheduleZone[index].Sat_N = {
              mode_id: 0,
              mode_name: "",
              patient_id: 0,
              patient: "",
              dialysis_machine_name:"",
              schedule_date:"",
              Count:0,
            };
            that.scheduleZone[index].Sun_A = {
              mode_id: 0,
              mode_name: "",
              patient_id: 0,
              patient: "",
              dialysis_machine_name:"",
              schedule_date:"",
              Count:0,
            };
            that.scheduleZone[index].Sun_N = {
              mode_id: 0,
              mode_name: "",
              patient_id: 0,
              patient: "",
              dialysis_machine_name:"",
              schedule_date:"",
              Count:0,
            };
            that.scheduleZone[index].Sun_M = {
              mode_id: 0,
              mode_name: "",
              patient_id: 0,
              patient: "",
              dialysis_machine_name:"",
              schedule_date:"",
              Count:0,
            };





            that.scheduleZone[index].total = 0;

            if (response.data.data.schdules.length > 0) {
              theSchedules.forEach(function(schedule, sindex) {

                if (zone.jihao_id == schedule.bed_id) {

                  var weekPath = that.weekPath(
                    schedule.schedule_week,
                    schedule.schedule_type
                  );

                  if (weekPath.length == 2) {


                    var weekPathKey = weekPath[0] + "_" + weekPath[1];
                    that.scheduleZone[index][weekPathKey] = {
                      schedule_id: schedule.id,
                      mode_id: schedule.mode_id,
                      patient_id: schedule.patient_id,
                      patient: schedule.patient,
                      dialysis_machine_name:schedule.dialysis_machine_name,
                      patient_contagions: schedule.patient_contagions,
                      schedule_date:schedule.schedule_date,
                      mode_name: typeof that.modeOptions[schedule.mode_id] ==="undefined"? "": that.modeOptions[schedule.mode_id].name
                    };
                    that.scheduleZone[index].total += 1;

                  }
                }
              });
            }

          });

          this.source_scheduleZone = this.scheduleZone
          console.log("------------aaaa",this.source_scheduleZone)
        } else {
          this.$message.error("网络错误");
          return false;
        }
      });
    },
    getSchedulePatients() {
      getSchedulePatients(this.patientQuery).then(response => {
        if (response.data.state == 1) {
          this.patients = response.data.data.patients;
        }
      });
    },
    CancelSchedule(id) {
      this.$confirm("确定要取消当前排班?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          CancelSchedule(id).then(response => {
            if (response.data.state == 0) {
              this.$message.error(response.data.msg);
            } else {
              this.$message({
                type: "success",
                message: "排班已取消!"
              });
              var that = this;
              var schedule = response.data.data.schedule;
              this.scheduleZone.forEach(function(zone, index) {
                if (
                  zone.zone_id == schedule.partition_id &&
                  zone.jihao_id == schedule.bed_id
                ) {
                  var weekPath = that.weekPath(
                    schedule.schedule_week,
                    schedule.schedule_type
                  );
                  if (weekPath.length == 2) {
                    var weekPathKey = weekPath[0] + "_" + weekPath[1];
                    that.scheduleZone[index][weekPathKey] = {
                      schedule_id: 0,
                      mode_id: 0,
                      patient_id: 0,
                      patient: "",
                      mode_name: "",
                      dialysis_machine_name:'',
                    };

                    that.scheduleZone[index].total -= 1;
                  }
                }
              });
              this.tzDialogVisible = false;
              this.searchTableVisible = false;
            }
          });
        })
        .catch(() => {});
    },
    changeScheduleActon(formName) {
      this.changing_bed = true;
      ChangeSchedule(this.currentData.id, this.changeSchedule)
        .then(response => {
          if (response.data.state == 0) {
            this.$message.error(response.data.msg);
          } else {
            this.$message({
              type: "success",
              message: "修改成功!"
            });
            var that = this;
            var schedule = response.data.data.schedule;
            this.scheduleZone.forEach(function(zone, index) {
              if (
                zone.zone_id == schedule.partition_id &&
                zone.jihao_id == schedule.bed_id
              ) {
                var weekPath = that.weekPath(
                  schedule.schedule_week,
                  schedule.schedule_type
                );
                if (weekPath.length == 2) {
                  var weekPathKey = weekPath[0] + "_" + weekPath[1];
                  that.scheduleZone[index][weekPathKey] = {
                    schedule_id: schedule.id,
                    mode_id: schedule.mode_id,
                    patient_id: schedule.patient_id,
                    patient: that.currentData.patient,


                    dialysis_machine_name:schedule.dialysis_machine_name,

                    patient_contagions: that.currentData.contagions,
                    mode_name:
                      typeof that.modeOptions[schedule.mode_id] === "undefined"
                        ? ""
                        : that.modeOptions[schedule.mode_id].name
                  };

                  that.scheduleZone[index].total += 1;
                }
              }
              if (
                zone.zone_id == that.currentData.partition_id &&
                zone.jihao_id == that.currentData.bed_id
              ) {
                var weekPath = that.weekPath(
                  that.currentData.schedule_week,
                  that.currentData.schedule_type
                );
                if (weekPath.length == 2) {
                  var weekPathKey = weekPath[0] + "_" + weekPath[1];
                  that.scheduleZone[index][weekPathKey] = {
                    schedule_id: 0,
                    mode_id: 0,
                    patient_id: 0,
                    patient: "",
                    mode_name: "",
                    dialysis_machine_name:"",
                    patient_contagions: []
                  };

                  that.scheduleZone[index].total -= 1;
                }
              }
            });
            this.$refs[formName].resetFields();
            this.jhDialogVisible = false;
          }
          this.changing_bed = false;
        })
        .catch(err => {
          this.$message.error(err);
          this.changing_bed = false;
        });
    },
    CreateSchedule(id, data) {
      this.creating_schedule = true;
      CreateSchedule(id, data)
        .then(response => {
          if (response.data.state == 0) {
            this.$message.error(response.data.msg);
          } else {
            this.$message({
              type: "success",
              message: "排班成功!"
            });
            var that = this;
            var schedule = response.data.data.schedule;
            this.scheduleZone.forEach(function(zone, index) {
              if (
                zone.zone_id == schedule.partition_id &&
                zone.jihao_id == schedule.bed_id
              ) {
                var weekPath = that.weekPath(
                  schedule.schedule_week,
                  schedule.schedule_type
                );
                if (weekPath.length == 2) {
                  var weekPathKey = weekPath[0] + "_" + weekPath[1];
                  that.scheduleZone[index][weekPathKey] = {
                    schedule_id: schedule.id,
                    mode_id: schedule.mode_id,
                    patient_id: schedule.patient_id,
                    patient: schedule.patient,
                    dialysis_machine_name:schedule.dialysis_machine_name,
                    patient_contagions: that.currentData.contagions,
                    mode_name:
                      typeof that.modeOptions[schedule.mode_id] === "undefined"
                        ? ""
                        : that.modeOptions[schedule.mode_id].name
                  };
                  that.scheduleZone[index].total += 1;
                }
              }
            });
            this.closePatientPanel();
          }
          this.creating_schedule = false;
        })
        .catch(err => {
          this.$message.error(err);
          this.creating_schedule = false;
        });
    },
    hoverMouse(row, column, cell, event){
      if (row[column.property].schedule_id > 0) {
        let patient_id = row[column.property].patient_id
        this.patient_id_hover = patient_id
      } else {
        this.patient_id_hover = -1
      }
    },
    clickThis(row, column, cell, event) {
      if(!this.is_edit){
        this.$message.error("当前页面不可编辑");
        return
      }
      // debugger
      var week = this.weekDay(column.property);

      if (week[0] == -1 || week[1] == -1) {
        return false;
      }
      if (this.toDay > this.weekDays[week[0] - 1]) {
        return false;
      }

      this.currentData.schedule_date = this.weekDays[week[0] - 1];
      this.currentData.schedule_type = week[1];
      this.currentData.bed_id = row.jihao_id;
      this.currentData.partition_id = row.zone_id;
      this.currentData.schedule_week = week[0];

      this.currentData.type_name = this.dayType(week[1]);
      this.currentData.zone_name = row.area;

      this.currentData.bed_name = row.cut;
      this.currentData.partition_type = row.zone_type;



      if (row[column.property].schedule_id > 0) {
        this.currentData.mode_id = row[column.property].mode_id;
        this.currentData.id = row[column.property].schedule_id;
        this.currentData.patient_id = row[column.property].patient_id;
        this.currentData.patient = row[column.property].patient;
        this.currentData.contagions = row[column.property].patient_contagions;
        this.tiaoZhengType = 1;
        this.tzDialogVisible = true;
      } else {
        this.currentData.mode_id = 1;
        this.currentData.id = 0;
        this.currentData.patient_id = 0;
        this.currentData.patient = "";
        this.currentData.contagions = [];
        this.getSchedulePatients();
        this.dialogTableVisible = true;
      }
    },
    submitTiaoZJH(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          var weekPath = this.weekPath(
            this.changeSchedule.schedule_week,
            this.changeSchedule.schedule_type
          );
          if (weekPath.length != 2) {
            this.$message.error("数据异常");
            return false;
          }

          this.changeSchedule.bed_id = this.device_id;
          for (let i = 0; i < this.origin_device_numbers.length; i++) {
            if (this.origin_device_numbers[i].id == this.device_id) {
              this.changeSchedule.partition_id = this.origin_device_numbers[
                i
              ].zone_id;
            }
          }
          this.changeSchedule.partition_id = this.zone_name
          this.changeSchedule.change_action = "change_device";
          this.changeScheduleActon(formName);

          // this.changeSchedule.spartition_type = this.scheduleZone[index].zone_type
          // var weekPathKey = weekPath[0] + '_' + weekPath[1]
          // for (var index in this.scheduleZone) {
          //   if (this.scheduleZone[index].jihao_id == this.changeSchedule.bed_id) {
          //     if (this.scheduleZone[index][weekPathKey].mode_id > 0) {
          //       this.$message.error('选中的区域已经存在排班，不能再排班！')
          //       return false
          //     }
          //     break
          //   }
          // }

          // 可能
          // 患者有传染病，与选择的机器类型（传染病）不匹配
          // 患者没有传染病，但机器是某个传染病的专用透析器
          // 机器的透析模式与患者不匹配

          // if (this.currentData.contagions.length > 0) {
          //   var cflag = false
          //   for (var index in this.currentData.contagions) {
          //     if (this.currentData.contagions[index].disease_id == this.changeSchedule.partition_type) {
          //       cflag = true
          //     }
          //   }
          //   if (!cflag) {
          //     this.$confirm('此患者有传染病，与此透析机不匹配，确定在此排班吗?', '提示', { confirmButtonText: '确 定', cancelButtonText: '取 消', type: 'warning' })
          //       .then(() => {
          //
          //       }).catch(() => {
          //       })
          //   } else {
          //     this.changeSchedule.change_action = 'change_device'
          //     this.changeScheduleActon(formName)
          //   }
          // } else if (this.changeSchedule.partition_type > 1) {
          //   this.$confirm('此患者没有传染病，与此透析机不匹配，确定在此排班吗?', '提示', { confirmButtonText: '确 定', cancelButtonText: '取 消', type: 'warning' })
          //     .then(() => {
          //       this.changeSchedule.change_action = 'change_device'
          //       this.changeScheduleActon(formName)
          //     }).catch(() => {
          //     })
          // } else {
          //   this.changeSchedule.change_action = 'change_device'
          //   this.changeScheduleActon(formName)
          // }
        }
      });
    },
    submitMode(formName) {
      this.changing_mode = true;
      this.changeSchedule.change_action = "change_mode";
      ChangeSchedule(this.currentData.id, this.changeSchedule)
        .then(response => {
          if (response.data.state == 0) {
            this.$message.error(response.data.msg);
          } else {
            this.$message({
              type: "success",
              message: "修改成功!"
            });
            var that = this;
            var schedule = response.data.data.schedule;
            this.scheduleZone.forEach(function(zone, index) {
              if (
                zone.zone_id == schedule.partition_id &&
                zone.jihao_id == schedule.bed_id
              ) {
                var weekPath = that.weekPath(
                  schedule.schedule_week,
                  schedule.schedule_type
                );
                if (weekPath.length == 2) {
                  var weekPathKey = weekPath[0] + "_" + weekPath[1];
                  that.scheduleZone[index][weekPathKey].mode_id =
                    schedule.mode_id;
                  that.scheduleZone[index][weekPathKey].mode_name =
                    typeof that.modeOptions[schedule.mode_id] === "undefined"
                      ? ""
                      : that.modeOptions[schedule.mode_id].name;
                }
              }
            });
            this.msDialogVisible = false;
          }
          this.changing_mode = false;
        })
        .catch(err => {
          this.$message.error(err);
          this.changing_mode = false;
        });
    },

    submitTiaoZMS(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.changing_mode = true;
          this.changeSchedule.change_action = "change_mode";
          ChangeSchedule(this.currentData.id, this.changeSchedule)
            .then(response => {
              if (response.data.state == 0) {
                this.$message.error(response.data.msg);
              } else {
                this.$message({
                  type: "success",
                  message: "修改成功!"
                });
                var that = this;
                var schedule = response.data.data.schedule;
                this.scheduleZone.forEach(function(zone, index) {
                  if (
                    zone.zone_id == schedule.partition_id &&
                    zone.jihao_id == schedule.bed_id
                  ) {
                    var weekPath = that.weekPath(
                      schedule.schedule_week,
                      schedule.schedule_type
                    );
                    if (weekPath.length == 2) {
                      var weekPathKey = weekPath[0] + "_" + weekPath[1];
                      that.scheduleZone[index][weekPathKey].mode_id =
                        schedule.mode_id;
                      that.scheduleZone[index][weekPathKey].mode_name =
                        typeof that.modeOptions[schedule.mode_id] ===
                        "undefined"
                          ? ""
                          : that.modeOptions[schedule.mode_id].name;
                    }
                  }
                });
                this.$refs[formName].resetFields();
                this.msDialogVisible = false;
              }
              this.changing_mode = false;
            })
            .catch(err => {
              this.$message.error(err);
              this.changing_mode = false;
            });
        }
      });
    },

    changePartition(value) {
      let params = {
        zone_id:  value,
        sch_type: this.currentData.schedule_type,
        schedule_date:  this.currentData.schedule_date,
        patient_id: this.currentData.patient_id,
      };
      //进行网络请求，获取空排班机位
      getSmartDevices(params).then((response) => {
        if (response.data.state == 0) {
          return false;
        } else {
          var devices = response.data.data.devices;
          this.current_devices = [];
          this.current_devices = devices;
          this.device_id = devices[0].id
        }
      });
    },
    changeScheduleType(schedule_type) {
      this.currentData.schedule_type = schedule_type
      let params = {
        zone_id:  this.currentData.partition_id,
        sch_type: schedule_type,
        schedule_date:  this.currentData.schedule_date,
        patient_id: this.currentData.patient_id,
      };
      //进行网络请求，获取空排班机位
      getSmartDevices(params).then((response) => {
        if (response.data.state == 0) {
          return false;
        } else {
          var devices = response.data.data.devices;
          this.current_devices = [];
          this.current_devices = devices;
          this.device_id = ""
        }
      });
      // const params = {
      //   type: schedule_type,
      //   date: this.currentData.schedule_date
      // };
      // getUrgentScheduleInitData(params)
      //   .then(rs => {
      //     if (rs.data.state == 1) {
      //       this.origin_schedules = rs.data.data.schedules;
      //       this.origin_device_numbers = rs.data.data.device_numbers;
      //
      //       var zone_device_map = {};
      //       for (
      //         let index = 0;
      //         index < this.origin_device_numbers.length;
      //         index++
      //       ) {
      //         const device_number = this.origin_device_numbers[index];
      //         if (
      //           zone_device_map[device_number.zone_name] == null ||
      //           zone_device_map[device_number.zone_name] == undefined
      //         ) {
      //           zone_device_map[device_number.zone_name] = [];
      //         }
      //         zone_device_map[device_number.zone_name].push(device_number);
      //       }
      //       this.zone_device_map = zone_device_map;
      //
      //       this.zone_names = Object.keys(this.zone_device_map);
      //       // console.log('8989898989898989',this.zone_names)
      //
      //       // console.log(this.current_devices);
      //
      //       if (this.zone_names.length > 0) {
      //         this.zone_name = this.zone_names[0];
      //         this.current_devices = this.zone_device_map[this.zone_name];
      //         this.device_id = this.current_devices[0].id;
      //       }
      //
      //
      //       this.zone_device_options = [
      //         { values: this.zone_names },
      //         // { values: this.getDeviceNumberNames(this.current_devices) },
      //         { values: this.current_devices }
      //       ];
      //
      //     } else {
      //     }
      //   })
      //   .catch(err => {
      //     this.loading = false;
      //   });
    },
    submitTiaoX() {
      // if (this.tiaoZhengType==1) {
      //     this.$confirm('确定要取消当前排班?', '提示', {
      //       confirmButtonText: '确定',
      //       cancelButtonText: '取消',
      //       type: 'warning'
      //     }).then(() => {
      //        this.CancelSchedule(this.currentData.id);
      //     }).catch(() => {});
      // }

      switch (this.tiaoZhengType) {
        case 1:
          this.CancelSchedule(this.currentData.id);
          break;
        case 2:
          this.changeSchedule = {
            mode_id: this.currentData.mode_id,
            schedule_type: this.currentData.schedule_type,
            partition_id: this.currentData.partition_id,
            bed_id: this.currentData.bed_id,
            schedule_week: this.currentData.schedule_week,
            partition_type: ""
          };

          if (
            typeof this.partitions[this.currentData.partition_id].jihaos !==
            "undefined"
          ) {
            this.jihaos = this.partitions[this.currentData.partition_id].jihaos;
          } else {
            this.jihaos = [];
          }

          const params = {
            type: this.currentData.schedule_type,
            date: this.currentData.schedule_date
          };
          getUrgentScheduleInitData(params)
            .then(response => {
              if (response.data.state == 0) {
                this.$message.error(response.data.msg);
              } else {
                if (response.data.state == 1) {
                  this.origin_schedules = response.data.data.schedules;
                  this.origin_device_numbers =
                    response.data.data.device_numbers;

                  var zone_device_map = {};
                  for (
                    let index = 0;
                    index < this.origin_device_numbers.length;
                    index++
                  ) {
                    const device_number = this.origin_device_numbers[index];
                    if (
                      zone_device_map[device_number.zone_name] == null ||
                      zone_device_map[device_number.zone_name] == undefined
                    ) {
                      zone_device_map[device_number.zone_name] = [];
                    }
                    zone_device_map[device_number.zone_name].push(
                      device_number
                    );
                  }
                  this.zone_device_map = zone_device_map;
                  this.zone_names = Object.keys(this.zone_device_map);
                  if (this.zone_names.length > 0) {
                    this.zone_name = this.zone_names[0];
                    this.current_devices = this.zone_device_map[this.zone_name];
                    this.device_id = this.current_devices[0].id;
                  }
                  this.zone_device_options = [
                    { values: this.zone_names },
                    // { values: this.getDeviceNumberNames(this.current_devices) },
                    { values: this.current_devices }
                  ];

                  //
                  // for (let i = this.origin_schedules.length - 1; i >= 0; i--) {
                  //   for (let y = this.origin_device_numbers.length - 1; y >= 0; y--) {
                  //     if (this.origin_device_numbers[y].id == this.origin_schedules[i].bed_id) {
                  //       this.origin_device_numbers.splice(y, 1)
                  //     }
                  //   }
                  // }
                  // // debugger
                  // var zone_device_map = {}
                  // for (let index = 0; index < this.origin_device_numbers.length; index++) {
                  //   const device_number = this.origin_device_numbers[index]
                  //   if (zone_device_map[device_number.zone.name] == null || zone_device_map[device_number.zone.name] == undefined) {
                  //     zone_device_map[device_number.zone.name] = []
                  //   }
                  //   zone_device_map[device_number.zone.name].push(device_number)
                  // }
                  // this.zone_device_map = zone_device_map
                  //
                  // this.zone_names = Object.keys(this.zone_device_map)
                  // if (this.zone_names.length > 0) {
                  //   this.zone_name = this.zone_names[0]
                  //   this.current_devices = this.zone_device_map[this.zone_name]
                  //   this.device_id = this.current_devices[0].id
                  // }
                  //
                  // this.zone_device_options = [
                  //   { values: this.zone_names },
                  //   // { values: this.getDeviceNumberNames(this.current_devices) },
                  //   { values: this.current_devices }
                  // ]
                } else {
                }
              }
            })
            .catch(err => {
              this.$message.error(err);
            });

          this.tzDialogVisible = false;
          this.jhDialogVisible = true;
          break;
        case 3:
          this.changeSchedule = {
            mode_id: "",
            schedule_type: "",
            partition_id: "",
            bed_id: "",
            schedule_week: "",
            partition_type: ""
          };
          this.tzDialogVisible = false;
          this.msDialogVisible = true;
          break;

        default:
          break;
      }
    },
    setSchedule() {
      var that = this;
      var submitFlag = true;
      if (this.currentData.patient_id <= 0) {
        this.$message.error("请先选择患者");
        return false;
      }

      if (
        this.currentData.schedule_date.length == 0 ||
        this.currentData.schedule_type < 1 ||
        this.currentData.schedule_type > 3 ||
        this.currentData.bed_id < 1 ||
        this.currentData.partition_id < 1 ||
        this.currentData.schedule_week < 1 ||
        this.currentData.schedule_week > 7
      ) {
        this.$message.error("请先选择排班时间或机号");
        return false;
      }

      // 可能
      // 患者有传染病，与选择的机器类型（传染病）不匹配
      // 患者没有传染病，但机器是某个传染病的专用透析器
      // 机器的透析模式与患者不匹配

      if (this.currentData.contagions.length > 0) {
        var cflag = false;
        this.currentData.contagions.forEach(function(contagion) {
          if (contagion.disease_id == that.currentData.partition_type) {
            cflag = true;
          }
        });
        if (!cflag) {
          this.$confirm(
            "此患者有传染病，与此透析机不匹配，确定在此排班吗?",
            "提示",
            {
              confirmButtonText: "确 定",
              cancelButtonText: "取 消",
              type: "warning"
            }
          )
            .then(() => {
              this.CreateSchedule(
                this.currentData.patient_id,
                this.currentData
              );
            })
            .catch(() => {});
        } else {
          this.CreateSchedule(this.currentData.patient_id, this.currentData);
        }
      } else if (that.currentData.partition_type > 1) {
        this.$confirm(
          "此患者没有传染病，与此透析机不匹配，确定在此排班吗?",
          "提示",
          {
            confirmButtonText: "确 定",
            cancelButtonText: "取 消",
            type: "warning"
          }
        )
          .then(() => {
            this.CreateSchedule(this.currentData.patient_id, this.currentData);
          })
          .catch(() => {});
      } else {
        this.CreateSchedule(this.currentData.patient_id, this.currentData);
      }
    },
    weekType(weekTime) {
      var theType = 2;
      switch (weekTime) {
        case "lastWeek":
          theType = 1;
          break;
        case "thisWeek":
          theType = 2;
          break;
        case "nextWeek":
          theType = 3;
          break;
        case "nextTwoWeek":
          theType = 4;
          break;
        default:
          theType = 2;
          break;
      }
      return theType;
    },
    dayType(theType) {
      var jType = "";
      switch (theType) {
        case 1:
          jType = "上午";
          break;
        case 2:
          jType = "下午";
          break;
        case 3:
          jType = "晚上";
          break;

        default:
          break;
      }
      return jType;
    },
    weekPath(week, schedule_type) {
      var weekArr = {
        1: "Mon",
        2: "Tue",
        3: "Wed",
        4: "Thurs",
        5: "Fri",
        6: "Sat",
        7: "Sun"
      };
      var typeArr = { 1: "M", 2: "A", 3: "N" };
      if (
        typeof weekArr[week] === "undefined" ||
        typeof typeArr[schedule_type] === "undefined"
      ) {
        return [];
      }
      return [weekArr[week], typeArr[schedule_type]];
    },
    weekDay(prop) {
      var week = prop.split("_");
      if (week.length != 2) {
        return [-1, -1];
      }
      var w = -1;
      var n = -1;
      switch (week[0]) {
        case "Mon":
          w = 1;
          break;
        case "Tue":
          w = 2;
          break;
        case "Wed":
          w = 3;
          break;
        case "Thurs":
          w = 4;
          break;
        case "Fri":
          w = 5;
          break;
        case "Sat":
          w = 6;
          break;
        case "Sun":
          w = 7;
          break;
        default:
          w = -1;
          break;
      }
      switch (week[1]) {
        case "M":
          n = 1;
          break;
        case "A":
          n = 2;
          break;
        case "N":
          n = 3;
          break;
        default:
          n = -1;
          break;
      }
      if (w == -1 || n == -1) {
        return [-1, -1];
      }
      return [w, n];
    },
    search: function() {
      let week_type = 0
      var weeklist = moment().format('E');//计算今天是这周第几天
      var first_monday = moment().subtract(weeklist-1, 'days').format('YYYY-MM-DD');//周一日期
      var end_monday = moment().add(7-weeklist, 'days').format('YYYY-MM-DD')
      if (this.weekTime == 'thisWeek'){
        week_type = 1
      }else if(this.weekTime == 'nextWeek'){
        week_type = 2
      }else if(this.weekTime == 'nextTwoWeek'){
        week_type = 3
      }

      const params = {
        keywords: this.keywords,
        week_type: week_type,
        start_sch:first_monday,
        end_sch:end_monday,
      };
      // console.log("params",params)
      getSearchResult(params).then(response => {
        if (response.data.state == 1) {
          this.schedulePatients = response.data.data.schdules;
          this.searchTableVisible = true;
        }
      });
    },
    changeMachineNumber: function(index, row) {
      this.currentData.schedule_type = row.schedule_type;
      this.currentData.bed_id = row.bed_id;
      this.currentData.partition_id = row.partition_id;
      this.currentData.schedule_week = row.schedule_week;

      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.number;
      this.currentData.partition_type = row.zone.type;

      this.currentData.mode_id = row.mode_id;
      this.currentData.patient_id = row.patient_id;
      this.currentData.patient = row.patient;
      this.currentData.contagions = row.patient_contagions;

      this.currentData.id = row.id;
      this.currentData.schedule_date = uParseTime(
        row.schedule_date,
        "{y}-{m}-{d}"
      );


      this.zone_name = row.partition_id;
      this.device_id = row.bed_id;
      // this.current_devices = this.partitions[row.partition_id].jihaos

      let params = {
        zone_id:  row.partition_id,
        sch_type: row.schedule_type,
        schedule_date:  this.currentData.schedule_date,
        patient_id: this.currentData.patient_id,
      };
      //进行网络请求，获取空排班机位
      getSmartDevices(params).then((response) => {
        if (response.data.state == 0) {
          return false;
        } else {
          var devices = response.data.data.devices;
          this.current_devices = [];
          this.current_devices = devices;
          this.device_id = devices[0].id
        }
      });

      this.changeSchedule = {
        mode_id: row.mode_id,
        schedule_type: row.schedule_type,
        partition_id: row.partition_id,
        bed_id: row.bed_id,
        schedule_week: row.schedule_week,
        partition_type: ""
      };

      if (typeof this.partitions[row.partition_id].jihaos !== "undefined") {
        this.jihaos = this.partitions[row.partition_id].jihaos;
      } else {
        this.jihaos = [];
      }

      this.searchTableVisible = false;
      this.jhDialogVisible = true;
    },
    getDialysisDate: function(row) {
      let week = "";
      switch (row.schedule_week) {
        case 7:
          week = "周日";
          break;
        case 1:
          week = "周一";
          break;
        case 2:
          week = "周二";

          break;
        case 3:
          week = "周三";

          break;
        case 4:
          week = "周四";

          break;
        case 5:
          week = "周五";
          break;
        case 6:
          week = "周六";
          break;
      }

      return week + "(" + uParseTime(row.schedule_date, "{y}-{m}-{d}") + ")";
    },
    getSchedulesType: function(type,row) {
      let type_name = "";
      switch (type) {
        case 1:
          type_name = "上午";
          break;
        case 2:
          type_name = "下午";

          break;
        case 3:
          type_name = "晚上";
          break;
      }

      return type_name;
    },
    changeMode: function(index, row) {
      this.changeSchedule = {
        mode_id: "",
        schedule_type: "",
        partition_id: "",
        bed_id: "",
        schedule_week: "",
        partition_type: ""
      };
      this.currentData.id = row.id;
      this.searchTableVisible = false;
      this.msDialogVisible = true;
    },
    tableRowClassName({row, rowIndex}) {
      if(row.zone_type == 1){
        return 'table-row-new-class schedule-table-row'
      }else {
        return 'table-row-new-class schedule-table-row backPurple'
      }
    },
    getAllZones(){
      getAllZones().then(response=>{
         if(response.data.state == 1){
           var zones = response.data.data.zones
           for(let i=0;i<zones.length;i++){
              this.zoneIdList.push(zones[i].id)
           }
          this.zones.push(...zones)
          var strArr =  this.zoneIdList.join(",")

          this.strArr = strArr
          this.getWeekPanels()
         }
      })
    },
    changePartiton(val){
     this.$emit('event1', val)
      this.partition_id = val
      this.getWeekPanels()
      this.getSchedules()

    },
    changeSchedule_type(val){
     this.$emit('event2', val)
     this.schedule_type = val
     this.getSchedules()
    },
    changeWeekDay(val){
      this.$emit('event3', val)
    }
  },
  components: {
    ScheduleItem
  },
  mounted() {

    this.tableContainHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 120;

    // var theType = this.weekType(this.weekTime);
    // this.getSchedules(theType);
    const that = this;
    window.onresize = () => {
      return (() => {
        window.fullHeight = document.documentElement.clientHeight;
        if (window.fullHeight < 200) {
          that.tableHeight = 200;
        } else {
          that.tableHeight = window.fullHeight - 160;
        }
      })();
    };
  },
  // mounted:function(){
  //    this.tableContainHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 160
  // },
  created() {
    var date = new Date()
    this.time = date
    var year = date.getFullYear()
    var month = date.getMonth() + 1
    if (month < 10) {
      month = "0" + month
    }
    var day = date.getDate()
    if (day < 10) {
      day = "0" + day
    }
    var nowDate = year + "-" + month + "-" + day
    var date = new Date(nowDate + " 00:00:00")

    this.now_time = date.getTime()/1000
    this.getAllZones()

    this.changeScheduleType(1)
    rowNumber = 0;
    this.modeOptions = this.$store.getters.treatment_mode;

    this.partitions = this.partitionsProp;


    var contagions = this.$store.getters.contagions;
    if (contagions.length > 0) {
      var that = this;
      contagions.forEach(function(citem) {
        if (citem.type == 2) {
          that.diseasesArr.push({ value: citem.id, label: citem.name });
        }
      });
    }

    this.scheduleZoneRow = this.scheduleZoneRowProp;


    this.weekday = new Date().getDay();
    if (this.weekday == 0) {
      this.weekday = 7;
    }

  }
};
</script>

<style rel="stylesheet/css" lang="scss">
.tiaozhengclass {
  display: block;
  margin: 0 auto;
}

// .el-table tr {
//   background-color: #111 !important;
// }

.schedule-table-row {
  background: #fff !important;
}

.schedule-table-row:hover {
  background: #fff !important;
}

.schedule-table-row td:hover {
  background: rgb(88, 162, 236) !important;
}

.schedule-table-row td .cell {
  font-size: 12px;
  white-space: nowrap !important;
}

.schedule-table-cell-disable {
  background-color: rgb(245, 245, 245) !important;
}

#table_data {
  min-height: calc(100vh - 350px);
}

#table_data ::-webkit-scrollbar {
  height: 15px;
}
.el-table td,
.el-table th.is-leaf,
.el-table--border,
.el-table--group {
  border-color: #d0d3da;
}
.el-table--border::after,
.el-table--group::after,
.el-table::before {
  background-color: #d0d3da;
}
.el-table--border th {
  border-color: #d0d3da;
}
.el-table--border td {
  border-color: #d0d3da;
}
.el-table td {
  border-color: #d0d3da;
}
// .hover-td{
//   color: red;
// }

// .el-table__body tr.current-row > td {
//   background-color: #409eff !important;
//   color: #fff;
// }
// .el-table__body tr > td:hover {
//   background-color: #409eff !important;
// }
#table_data {
  .el-table__body tr.current-row > td {
    background-color: #ecf5ff !important;
    color: #3a8ee6;
  }
  .el-table__body tr > td:hover {
    background-color: #409eff !important;
    color: #fff;
  }
  .el-table__body tr .hover-td {
    background-color: #409eff !important;
    color: #fff;
  }

}
.backPurple{
  color: #08c3df !important;
}

.tableClass{
  .el-table .cell{
   white-space: pre-wrap;
 }
}
</style>
