<template>
  <div  >
    <div id="tem_table_data" v-show="schedulingTableVisible">
      <slot></slot>
      <div class="table_contain temtable_contain">
        <div class="left_contain">
          <div
            class="cell clearfix"
          >
            <el-input
              size="small"
              style="width: 200px"
              class="filter-item"
              v-model.trim="keywords"
              placeholder="病人名称/透析号"
              @keyup.enter.native="search_two"
            />
            <el-button
              size="small"
              class="filter-item"
              type="primary"
              icon="el-icon-search"
              @click="search_two"
            >搜索</el-button
            >
          </div>

          <div style="margin-bottom: 10px; display: flex">
            <h3 style="line-height: 45px">
              <span
                style="margin-right: 15px; font-size: 16px; white-space: nowrap"
              >当前选择</span
              >
            </h3>
            <div
              style="line-height: 45px;
                background: rgb(64, 158, 255);
                color: white;
              "
            >
              <div
                draggable="true"
                @dragstart="curInfoDragStart"
                class="item_touz"
                style="font-weight: bolder"
              >
                <span>{{ cur_info.patient_name }}</span>
                &nbsp;&nbsp;
                <span>{{ cur_info.mode_name }}</span>
              </div>
            </div>
          </div>
          <div style="width: 225px">
            <el-row :gutter="10">
              <el-col :span="15">
                <div style="width: 225px; display: flex">
                  <el-table
                    :row-style="{ color: '#303133' }"
                    :header-cell-style="{
                      backgroundColor: 'rgb(245, 247, 250)',
                      color: '#606266',
                    }"
                    :data="patients"
                    height="620"
                    border
                    @row-click="patientClick"
                    :row-class-name="patientclass"
                    ref="patient_table"
                    style="margin-right: 14px"
                  >
                    <el-table-column
                      prop="name"
                      label="患者名称"
                    >
                    </el-table-column>
                  </el-table>
                  <el-table
                    :row-style="{ color: '#303133' }"
                    :header-cell-style="{
                      backgroundColor: 'rgb(245, 247, 250)',
                      color: '#606266',
                    }"
                    :data="modes"
                    height="620"
                    ref="mode_table"
                    @row-click="modeClick"
                    :row-class-name="modeclass"
                    border
                  >
                    <el-table-column
                      prop="name"
                      label="透析模式"

                      align="center"
                    ></el-table-column>
                  </el-table>
                </div>
              </el-col>
            </el-row>
          </div>
        </div>
        <div class="right_contain">
          <el-table
            :fit="true"
            :header-cell-style="{ backgroundColor: 'rgb(245, 247, 250)' }"
            ref="table"
            :data="opera_device_numbers"
            :span-method="spanMethod"
            show-summary
            height="750"
            style="width: 100%; cursor: pointer"
            :cell-class-name="cellClass"
            :row-class-name="rowClass"
            :summary-method="getSummaries"
            @cell-click="itemClick"
            @cell-dblclick="itemdblclick"
            sum-text="总数"
          >
            <el-table-column
              label="分区"
              min-width="50"
              align="center"
              fixed
            >
              <template slot-scope="scope">
                {{ scope.row.zone.name }}
              </template>
            </el-table-column>

            <el-table-column label="机号" min-width="40" align="center" fixed style="text-align: center;" >
              <template slot-scope="scope">
                <div>{{ scope.row.number }}</div>
              </template>
            </el-table-column>

            <el-table-column label="周一"  align="center" >
              <el-table-column prop="1_1" label="上" min-width="40" align="center" style="padding: 0px 0px !important;">
                <template slot-scope="scope">
                  <div class="del_table_btn">
                    <el-button
                      type="danger"
                      size="mini"
                      icon="el-icon-close"
                      circle
                      @click.stop="
                        deletePatientMode(scope.row['1_1'], '1_1', scope.row)"
                        v-show="cur_drag_info.patient_id== 0 ? false : true"
                    ></el-button>
                  </div>
                  <div
                    @drop="
                      drop($event, '1_1', scope.row.index, scope.row, scope.row)
                    "
                    @dragover="allowDrop"
                    @dragover.prevent
                  >
                    <template-table-item
                      :info="scope.row['1_1']"
                      :draggable="true"

                      @mouseover.native="
                      drag(
                        $event,
                        '1_1',
                        scope.row.index,
                        scope.row['1_1'],
                        scope.row
                      )
                    "
                    ></template-table-item>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="1_2" label="下" min-width="40" align="center">
                <template slot-scope="scope">
                  <div class="del_table_btn">
                    <el-button
                      type="danger"
                      size="mini"
                      icon="el-icon-close"
                      circle
                      @click.stop="
                        deletePatientMode(scope.row['1_2'], '1_2', scope.row)
                      "
                      v-show="cur_drag_info.patient_id== 0 ? false : true"
                    ></el-button>
                  </div>
                  <div
                    @drop="
                      drop($event, '1_2', scope.row.index, scope.row, scope.row)
                    "
                    @dragover="allowDrop"
                    @dragover.prevent
                  >
                    <template-table-item
                      :info="scope.row['1_2']"
                      :draggable="true"

                      @mouseover.native="
                      drag(
                        $event,
                        '1_2',
                        scope.row.index,
                        scope.row['1_2'],
                        scope.row
                      )
                    "
                    ></template-table-item>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="1_3" label="晚" min-width="40" align="center">
                <template slot-scope="scope">
                  <div class="del_table_btn">
                    <el-button
                      type="danger"
                      size="mini"
                      icon="el-icon-close"
                      circle
                      @click.stop="
                        deletePatientMode(scope.row['1_3'], '1_3', scope.row)
                      "
                      v-show="cur_drag_info.patient_id== 0 ? false : true"
                    ></el-button>
                  </div>
                  <div
                    @drop="
                      drop($event, '1_3', scope.row.index, scope.row, scope.row)
                    "
                    @dragover="allowDrop"
                    @dragover.prevent
                  >
                    <template-table-item
                      :info="scope.row['1_3']"
                      :draggable="true"

                      @mouseover.native="
                      drag(
                        $event,
                        '1_3',
                        scope.row.index,
                        scope.row['1_3'],
                        scope.row
                      )
                    "
                    ></template-table-item>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>

            <el-table-column label="周二"  align="center">
              <el-table-column prop="2_1" label="上" min-width="40" align="center">
                <template slot-scope="scope">
                  <div class="del_table_btn">
                    <el-button
                      type="danger"
                      size="mini"
                      icon="el-icon-close"
                      circle
                      @click.stop="
                        deletePatientMode(scope.row['2_1'], '2_1', scope.row)
                      "
                      v-show="cur_drag_info.patient_id== 0 ? false : true"
                    ></el-button>
                  </div>
                  <div
                    @drop="
                      drop($event, '2_1', scope.row.index, scope.row, scope.row)
                    "
                    @dragover="allowDrop"
                    @dragover.prevent
                  >
                    <template-table-item
                      :info="scope.row['2_1']"
                      :draggable="true"
                      @mouseover.native="
                      drag(
                        $event,
                        '2_1',
                        scope.row.index,
                        scope.row['2_1'],
                        scope.row
                      )
                    "
                    ></template-table-item>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="2_2" label="下" min-width="40" align="center">
                <template slot-scope="scope">
                  <div class="del_table_btn">
                    <el-button
                      type="danger"
                      size="mini"
                      icon="el-icon-close"
                      circle
                      @click.stop="
                        deletePatientMode(scope.row['2_2'], '2_2', scope.row)
                      "
                      v-show="cur_drag_info.patient_id== 0 ? false : true"
                    ></el-button>
                  </div>
                  <div
                    @drop="
                      drop($event, '2_2', scope.row.index, scope.row, scope.row)
                    "
                    @dragover="allowDrop"
                    @dragover.prevent
                  >
                    <template-table-item
                      :info="scope.row['2_2']"
                      :draggable="true"

                      @mouseover.native="
                      drag(
                        $event,
                        '2_2',
                        scope.row.index,
                        scope.row['2_2'],
                        scope.row
                      )
                    "
                    ></template-table-item>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="2_3" label="晚" min-width="40" align="center">
                <template slot-scope="scope">
                  <div class="del_table_btn">
                    <el-button
                      type="danger"
                      size="mini"
                      icon="el-icon-close"
                      circle
                      @click.stop="
                        deletePatientMode(scope.row['2_3'], '2_3', scope.row)
                      "
                      v-show="cur_drag_info.patient_id== 0 ? false : true"
                    ></el-button>
                  </div>
                  <div
                    @drop="
                      drop($event, '2_3', scope.row.index, scope.row, scope.row)
                    "
                    @dragover="allowDrop"
                    @dragover.prevent
                  >
                    <template-table-item
                      :info="scope.row['2_3']"
                      :draggable="true"

                      @mouseover.native="
                      drag(
                        $event,
                        '2_3',
                        scope.row.index,
                        scope.row['2_3'],
                        scope.row
                      )
                    "
                    ></template-table-item>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>

            <el-table-column label="周三"  align="center">
              <el-table-column prop="3_1" label="上" min-width="40" align="center">
                <template slot-scope="scope">
                  <div class="del_table_btn">
                    <el-button
                      type="danger"
                      size="mini"
                      icon="el-icon-close"
                      circle
                      @click.stop="
                        deletePatientMode(scope.row['3_1'], '3_1', scope.row)
                      "
                      v-show="cur_drag_info.patient_id== 0 ? false : true"
                    ></el-button>
                  </div>
                  <div
                    @drop="
                      drop($event, '3_1', scope.row.index, scope.row, scope.row)
                    "
                    @dragover="allowDrop"
                    @dragover.prevent
                  >
                    <template-table-item
                      :info="scope.row['3_1']"
                      :draggable="true"

                      @mouseover.native="
                      drag(
                        $event,
                        '3_1',
                        scope.row.index,
                        scope.row['3_1'],
                        scope.row
                      )
                    "
                    ></template-table-item>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="3_2" label="下" min-width="40" align="center">
                <template slot-scope="scope">
                  <div class="del_table_btn">
                    <el-button
                      type="danger"
                      size="mini"
                      icon="el-icon-close"
                      circle
                      @click.stop="
                        deletePatientMode(scope.row['3_2'], '3_2', scope.row)
                      "
                      v-show="cur_drag_info.patient_id== 0 ? false : true"
                    ></el-button>
                  </div>
                  <div
                    @drop="
                      drop($event, '3_2', scope.row.index, scope.row, scope.row)
                    "
                    @dragover="allowDrop"
                    @dragover.prevent
                  >
                    <template-table-item
                      :info="scope.row['3_2']"
                      :draggable="true"

                      @mouseover.native="
                      drag(
                        $event,
                        '3_2',
                        scope.row.index,
                        scope.row['3_2'],
                        scope.row
                      )
                    "
                    ></template-table-item>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="3_3" label="晚" min-width="40" align="center">
                <template slot-scope="scope">
                  <div class="del_table_btn">
                    <el-button
                      type="danger"
                      size="mini"
                      icon="el-icon-close"
                      circle
                      @click.stop="
                        deletePatientMode(scope.row['3_3'], '3_3', scope.row)
                      "
                      v-show="cur_drag_info.patient_id== 0 ? false : true"
                    ></el-button>
                  </div>
                  <div
                    @drop="
                      drop($event, '3_3', scope.row.index, scope.row, scope.row)
                    "
                    @dragover="allowDrop"
                    @dragover.prevent
                  >
                    <template-table-item
                      :info="scope.row['3_3']"
                      :draggable="true"

                      @mouseover.native="
                      drag(
                        $event,
                        '3_3',
                        scope.row.index,
                        scope.row['3_3'],
                        scope.row
                      )
                    "
                    ></template-table-item>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>

            <el-table-column label="周四"  align="center">
              <el-table-column prop="4_1" label="上" min-width="40" align="center">
                <template slot-scope="scope">
                  <div class="del_table_btn">
                    <el-button
                      type="danger"
                      size="mini"
                      icon="el-icon-close"
                      circle
                      @click.stop="
                        deletePatientMode(scope.row['4_1'], '4_1', scope.row)
                      "
                      v-show="cur_drag_info.patient_id== 0 ? false : true"
                    ></el-button>
                  </div>
                  <div
                    @drop="
                      drop($event, '4_1', scope.row.index, scope.row, scope.row)
                    "
                    @dragover="allowDrop"
                    @dragover.prevent
                  >
                    <template-table-item
                      :info="scope.row['4_1']"
                      :draggable="true"

                      @mouseover.native="
                      drag(
                        $event,
                        '4_1',
                        scope.row.index,
                        scope.row['4_1'],
                        scope.row
                      )
                    "
                    ></template-table-item>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="4_2" label="下" min-width="40" align="center">
                <template slot-scope="scope">
                  <div class="del_table_btn">
                    <el-button
                      type="danger"
                      size="mini"
                      icon="el-icon-close"
                      circle
                      @click.stop="
                        deletePatientMode(scope.row['4_2'], '4_2', scope.row)
                      "
                      v-show="cur_drag_info.patient_id== 0 ? false : true"
                    ></el-button>
                  </div>
                  <div
                    @drop="
                      drop($event, '4_2', scope.row.index, scope.row, scope.row)
                    "
                    @dragover="allowDrop"
                    @dragover.prevent
                  >
                    <template-table-item
                      :info="scope.row['4_2']"
                      :draggable="true"

                      @mouseover.native="
                      drag(
                        $event,
                        '4_2',
                        scope.row.index,
                        scope.row['4_2'],
                        scope.row
                      )
                    "
                    ></template-table-item>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="4_3" label="晚" min-width="40" align="center">
                <template slot-scope="scope">
                  <div class="del_table_btn">
                    <el-button
                      type="danger"
                      size="mini"
                      icon="el-icon-close"
                      circle
                      @click.stop="
                        deletePatientMode(scope.row['4_3'], '4_3', scope.row)
                      "
                      v-show="cur_drag_info.patient_id== 0 ? false : true"
                    ></el-button>
                  </div>
                  <div
                    @drop="
                      drop($event, '4_3', scope.row.index, scope.row, scope.row)
                    "
                    @dragover="allowDrop"
                    @dragover.prevent
                  >
                    <template-table-item
                      :info="scope.row['4_3']"
                      :draggable="true"

                      @mouseover.native="
                      drag(
                        $event,
                        '4_3',
                        scope.row.index,
                        scope.row['4_3'],
                        scope.row
                      )
                    "
                    ></template-table-item>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>

            <el-table-column label="周五" align="center">
              <el-table-column prop="5_1" label="上" min-width="40" align="center">
                <template slot-scope="scope">
                  <div class="del_table_btn">
                    <el-button
                      type="danger"
                      size="mini"
                      icon="el-icon-close"
                      circle
                      @click.stop="
                        deletePatientMode(scope.row['5_1'], '5_1', scope.row)
                      "
                      v-show="cur_drag_info.patient_id== 0 ? false : true"
                    ></el-button>
                  </div>
                  <div
                    @drop="
                      drop($event, '5_1', scope.row.index, scope.row, scope.row)
                    "
                    @dragover="allowDrop"
                    @dragover.prevent
                  >
                    <template-table-item
                      :info="scope.row['5_1']"
                      :draggable="true"

                      @mouseover.native="
                      drag(
                        $event,
                        '5_1',
                        scope.row.index,
                        scope.row['5_1'],
                        scope.row
                      )
                    "
                    ></template-table-item>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="5_2" label="下" min-width="40" align="center">
                <template slot-scope="scope">
                  <div class="del_table_btn">
                    <el-button
                      type="danger"
                      size="mini"
                      icon="el-icon-close"
                      circle
                      @click.stop="
                        deletePatientMode(scope.row['5_2'], '5_2', scope.row)
                      "
                      v-show="cur_drag_info.patient_id== 0 ? false : true"
                    ></el-button>
                  </div>
                  <div
                    @drop="
                      drop($event, '5_2', scope.row.index, scope.row, scope.row)
                    "
                    @dragover="allowDrop"
                    @dragover.prevent
                  >
                    <template-table-item
                      :info="scope.row['5_2']"
                      :draggable="true"

                      @mouseover.native="
                      drag(
                        $event,
                        '5_2',
                        scope.row.index,
                        scope.row['5_2'],
                        scope.row
                      )
                    "
                    ></template-table-item>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="5_3" label="晚" min-width="40" align="center">
                <template slot-scope="scope">
                  <div class="del_table_btn">
                    <el-button
                      type="danger"
                      size="mini"
                      icon="el-icon-close"
                      circle
                      @click.stop="
                        deletePatientMode(scope.row['5_3'], '5_3', scope.row)
                      "
                      v-show="cur_drag_info.patient_id== 0 ? false : true"
                    ></el-button>
                  </div>
                  <div
                    @drop="
                      drop($event, '5_3', scope.row.index, scope.row, scope.row)
                    "
                    @dragover="allowDrop"
                    @dragover.prevent
                  >
                    <template-table-item
                      :info="scope.row['5_3']"
                      :draggable="true"

                      @mouseover.native="
                      drag(
                        $event,
                        '5_3',
                        scope.row.index,
                        scope.row['5_3'],
                        scope.row
                      )
                    "
                    ></template-table-item>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>

            <el-table-column label="周六"  align="center">
              <el-table-column prop="6_1" label="上" min-width="40" align="center">
                <template slot-scope="scope">
                  <div class="del_table_btn">
                    <el-button
                      type="danger"
                      size="mini"
                      icon="el-icon-close"
                      circle
                      @click.stop="
                        deletePatientMode(scope.row['6_1'], '6_1', scope.row)
                      "
                      v-show="cur_drag_info.patient_id== 0 ? false : true"
                    ></el-button>
                  </div>
                  <div
                    @drop="
                      drop($event, '6_1', scope.row.index, scope.row, scope.row)
                    "
                    @dragover="allowDrop"
                    @dragover.prevent
                  >
                    <template-table-item
                      :info="scope.row['6_1']"
                      :draggable="true"

                      @mouseover.native="
                      drag(
                        $event,
                        '6_1',
                        scope.row.index,
                        scope.row['6_1'],
                        scope.row
                      )
                    "
                    ></template-table-item>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="6_2" label="下" min-width="40" align="center">
                <template slot-scope="scope">
                  <div class="del_table_btn">
                    <el-button
                      type="danger"
                      size="mini"
                      icon="el-icon-close"
                      circle
                      @click.stop="
                        deletePatientMode(scope.row['6_2'], '6_2', scope.row)
                      "
                      v-show="cur_drag_info.patient_id== 0 ? false : true"
                    ></el-button>
                  </div>
                  <div
                    @drop="
                      drop($event, '6_2', scope.row.index, scope.row, scope.row)
                    "
                    @dragover="allowDrop"
                    @dragover.prevent
                  >
                    <template-table-item
                      :info="scope.row['6_2']"
                      :draggable="true"

                      @mouseover.native="
                      drag(
                        $event,
                        '6_2',
                        scope.row.index,
                        scope.row['6_2'],
                        scope.row
                      )
                    "
                    ></template-table-item>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="6_3" label="晚" min-width="40" align="center">
                <template slot-scope="scope">
                  <div class="del_table_btn">
                    <el-button
                      type="danger"
                      size="mini"
                      icon="el-icon-close"
                      circle
                      @click.stop="
                        deletePatientMode(scope.row['6_3'], '6_3', scope.row)
                      "
                      v-show="cur_drag_info.patient_id== 0 ? false : true"
                    ></el-button>
                  </div>
                  <div
                    @drop="
                      drop($event, '6_3', scope.row.index, scope.row, scope.row)
                    "
                    @dragover="allowDrop"
                    @dragover.prevent
                  >
                    <template-table-item
                      :info="scope.row['6_3']"
                      :draggable="true"

                      @mouseover.native="
                      drag(
                        $event,
                        '6_3',
                        scope.row.index,
                        scope.row['6_3'],
                        scope.row
                      )
                    "
                    ></template-table-item>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>

            <el-table-column label="周日" align="center">
              <el-table-column
                prop="7_1"
                label="上"
                min-width="40"
                align="center"
              >
                <template slot-scope="scope">
                  <div class="del_table_btn">
                    <el-button
                      type="danger"
                      size="mini"
                      icon="el-icon-close"
                      circle
                      @click.stop="
                        deletePatientMode(scope.row['7_1'], '7_1', scope.row) "
                        v-show="cur_drag_info.patient_id== 0 ? false : true"
                    ></el-button>
                  </div>
                  <div
                    @drop="
                      drop($event, '7_1', scope.row.index, scope.row, scope.row)
                    "
                    @dragover="allowDrop"
                    @dragover.prevent
                  >
                    <template-table-item
                      :info="scope.row['7_1']"
                      :draggable="true"

                      @mouseover.native="
                      drag(
                        $event,
                        '7_1',
                        scope.row.index,
                        scope.row['7_1'],
                        scope.row
                      )
                    "
                    ></template-table-item>
                  </div>
                </template>
              </el-table-column>
              <el-table-column
                prop="7_2"
                label="下"
                min-width="40"
                align="center"
              >
                <template slot-scope="scope">
                  <div class="del_table_btn">
                    <el-button
                      type="danger"
                      size="mini"
                      icon="el-icon-close"
                      circle
                      @click.stop="
                        deletePatientMode(scope.row['7_2'], '7_2', scope.row) "
                      v-show="cur_drag_info.patient_id== 0 ? false : true"
                    ></el-button>
                  </div>
                  <div
                    @drop="
                      drop($event, '7_2', scope.row.index, scope.row, scope.row)
                    "
                    @dragover="allowDrop"
                    @dragover.prevent
                  >
                    <template-table-item
                      :info="scope.row['7_2']"
                      :draggable="true"

                      @mouseover.native="
                      drag(
                        $event,
                        '7_2',
                        scope.row.index,
                        scope.row['7_2'],
                        scope.row
                      )
                    "
                    ></template-table-item>
                  </div>
                </template>
              </el-table-column>
              <el-table-column
                prop="7_3"
                label="晚"
                min-width="40"
                align="center"
              >
                <template slot-scope="scope">
                  <div class="del_table_btn">
                    <el-button
                      type="danger"
                      size="mini"
                      icon="el-icon-close"
                      circle
                      @click.stop="
                        deletePatientMode(scope.row['7_3'], '7_3', scope.row)"
                      v-show="cur_drag_info.patient_id== 0 ? false : true"
                    ></el-button>
                  </div>
                  <div
                    @drop="
                      drop($event, '7_3', scope.row.index, scope.row, scope.row)
                    "
                    @dragover="allowDrop"
                    @dragover.prevent
                  >
                    <template-table-item
                      :info="scope.row['7_3']"
                      :draggable="true"

                      @mouseover.native="
                      drag(
                        $event,
                        '7_3',
                        scope.row.index,
                        scope.row['7_3'],
                        scope.row
                      )
                    "
                    ></template-table-item>
                  </div>
                </template>
              </el-table-column>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
    <!-- 修改透析模式 -->
    <schedule-selector-dialog
      ref="selector_dialog"
      :patients="patients"
      @did_selected="will_add_schedule_action_three"
      @did_cancel="cancel_schedule_action"
    ></schedule-selector-dialog>

    <template-schedule-dialog
      ref="selector_dialog_two"
      :patients="patients"
      @did_selected="will_add_schedule_action_four"
      @did_cancel="cancel_schedule_action"
    >
    </template-schedule-dialog>

    <!-- 智能排班 -->
    <div class="dialog-wrapper">
      <el-dialog
        class="smartdialog"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        append-to-body
        width="48%"
        :visible.sync="smartVisible"
      >
        <!-- :style="{ background: '#409EFF', color: 'white' }" -->
        <div slot="title" class="header-title">
          <div style="padding: 15px 20px">
            {{
              `智能排班  (姓名：${
                this.cur_smart_patient_name ? this.cur_smart_patient_name : ""
              }  透析号：${
                this.cur_smart_patient_no ? this.cur_smart_patient_no : ""
              })`
            }}
          </div>
        </div>
        <el-autocomplete
          class="checkSearch"
          popper-class="my-autocomplete"
          v-model.trim="smart_keyword"
          :fetch-suggestions="querySearchAsync"
          placeholder="病人透析号/姓名"
          @select="handleSelect"
        >
          <i class="el-icon-search el-input__icon" slot="suffix"></i>
          <template slot-scope="{ item }">
            <div class="name">{{ item.name }}</div>
          </template>
        </el-autocomplete>

        <el-tabs
          v-model="editableTabsValue"
          type="card"
          @tab-click="handleClick"
        >
          <el-tab-pane
            :key="item.name"
            v-for="(item, index) in editableTabs"
            :label="item.title"
            :name="item.name"
          >
            <el-table
              border
              v-loading="handledDataLoading"
              :data="item.tableWeekArrage"
              style="width: 100%"
            >
              <!-- 自定义表结构 -->
              <el-table-column
                label="星期"
                prop="week"
                align="center"
                width="100"
              >
              </el-table-column>
              <el-table-column align="left">
                <template slot="header" slot-scope="scope">
                  <el-checkbox-group
                    v-model="item.checkedWeek"
                    @change="select_week"
                  >
                    <el-checkbox
                      v-for="(i, index) in weeks"
                      :label="i"
                      :key="index"
                      :value="i"
                    >
                      {{ i.name }}
                    </el-checkbox>
                  </el-checkbox-group>
                </template>
                <template slot-scope="scope">
                  <div>
                    <span>模式：</span>
                    <el-select
                      v-model="scope.row.treat_mode"
                      placeholder="请选择"
                      size="mini"
                      class="select_list_arrage"
                    >
                      <el-option
                        v-for="(item, index) in modes"
                        :key="index"
                        :label="item.name"
                        :value="item.id"
                      >
                      </el-option>
                    </el-select>
                    <span>班次：</span>
                    <el-select
                      v-model="scope.row.time_type"
                      placeholder="请选择"
                      @change="changeSch(scope.row)"
                      size="mini"
                      class="select_list_arrage"
                    >
                      <el-option
                        v-for="(item, index) in teem_sel"
                        :key="index"
                        :label="item.name"
                        :value="item.id"
                      >
                      </el-option>
                    </el-select>
                    <span>分区：</span>
                    <el-select
                      v-model="scope.row.zone_id"
                      placeholder="请选择"
                      @change="changeSch(scope.row)"
                      size="mini"
                      class="select_list_arrage"
                    >
                      <el-option
                        v-for="(item, index) in all_zones"
                        :key="index"
                        :label="item.name"
                        :value="item.id"
                      >
                      </el-option>
                    </el-select>
                    <span>机号：</span>
                    <el-select
                      v-model="scope.row.device_number_id"
                      placeholder="请选择"
                      size="mini"
                      @click.native="changeSchMachine(scope.row)"
                      class="select_list_arrage"
                    >
                      <el-option
                        v-for="(item, index) in scope.row.jihaos"
                        :key="index"
                        :label="item.number"
                        :value="item.id"
                      >
                      </el-option>
                    </el-select>
                  </div>
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
        </el-tabs>
        <span slot="footer" class="dialog-footer">
            <el-button @click="smartVisible = false">取 消</el-button>
            <el-button
              type="primary"
              v-loading="smartSaveLoading"
              @click="batchSetSch"
            >保 存</el-button
            >
          </span>
      </el-dialog>
    </div>
    <!-- 替换/交换 -->
    <el-dialog
      title="提示"
      :visible.sync="tipDialogVisible"
      width="300px"
    >
      <div>
        所选位置已有排班,请选择操作
      </div>
      <span slot="footer" class="dialog-footer">
         <el-button
           type="danger"
           @click="tipDialogVisibleTwo = true"
         >替换</el-button>
            <el-button
              type="primary"
              @click="tipDialogVisibleThree = true"
            >交换</el-button>
        <el-button @click="tipDialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 替换弹窗 -->
    <el-dialog
      title="提示"
      :visible.sync="tipDialogVisibleTwo"
      width="300px"
    >
      <div>
        是否将此位置排班替换
      </div>
      <span slot="footer" class="dialog-footer">
         <el-button
           type="primary"
           :loading="changeLoadingOne"
           @click="coverSch()"
         >确定</el-button>

        <el-button @click="tipDialogVisibleTwo = false">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 互换弹窗 -->
    <el-dialog
      title="提示"
      :visible.sync="tipDialogVisibleThree"
      width="300px"
    >
      <div>
        是否将此位置排班互换
      </div>
      <span slot="footer" class="dialog-footer">
         <el-button
           type="primary"
           :loading="changeLoadingTwo"
           @click="changeSchTemplateTwo()"
         >确定</el-button>
        <el-button @click="tipDialogVisibleThree = false">取 消</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
import {
  cancelScheduleTemplate,
  getPatientSmartSchTemplate,
  getTemplateScheduleSearchResult,
  updateSchedules,
  updateEditSchedules,
  getTemplateSmartDevices,
  getSmartDevices,
  CoverSchTemplate,
  ExchangeSchTemplate,
  DeleteAndAddScheduleTemplateTwo
} from "@/api/schedule_template/sch_template";

import TemplateTableItem from "./template_table_item";
import ScheduleSelectorDialog from "./template_schedule_selector_dialog";
import { PostSearchSmartSchTemplatePatient } from "../../../api/schedule_template/sch_template";
import TemplateScheduleDialog from './template_schedule_dialog'

const weekOptions = [
  {
    name: "周一",
    week_type: 1,
    is_edit: true,
  },
  {
    name: "周二",
    week_type: 2,
    is_edit: true,
  },
  {
    name: "周三",
    week_type: 3,
    is_edit: true,
  },
  {
    name: "周四",
    week_type: 4,
    is_edit: true,
  },
  {
    name: "周五",
    week_type: 5,
    is_edit: true,
  },
  {
    name: "周六",
    week_type: 6,
    is_edit: true,
  },
  {
    name: "周日",
    week_type: 7,
    is_edit: true,
  },
];

var rowspanNoControl = -1;
export default {
  name: "TemplateTable",
  components: {
    TemplateScheduleDialog,
    TemplateTableItem,
    ScheduleSelectorDialog,
  },
  data() {
    return {
      schedulingTableVisible:true,//全屏
      changeLoadingOne:false,
      changeLoadingTwo:false,
      tipDialogVisibleTwo:false,
      tipDialogVisibleThree:false,
      tipDialogVisible:false,

      teem_sel: [
        { name: "上午", id: 1 },
        { name: "下午", id: 2 },
        { name: "晚上", id: 3 },
      ],
      smartSaveLoading: false,
      checkedWeek: [], //默认选中那些星期，如不需要可去掉
      editableTabsValue: "",
      handledDataLoading: false,
      smartVisible: false,
      current_patient_data:[],
      isDel:false,
      isEdit:false,
      zones: [],
      weeks: weekOptions,
      patient_id_hover:0,
      smart_keyword: "",
      cur_smart_patient_id: 0,
      cur_smart_patient_name: "",
      cur_smart_patient_no: "",
      all_zones: [],
      devices: [],
      current_all_sch: [],
      editableTabs: [],
      current_all_schtemplate: [],
      cur_drag_obj:1, //當前拖拽對象，用來區分病人列表那的當前選擇和表格内的拖拽對象，1.病人列表，2.表格内的
      // 拖拽数据
      cur_drag_info: {
        patient_name: "",
        patient_id: "",
        mode_name: "",
        mode_id: "",
        schedule_date:"",
        schedule_type:"",
        bed_id:"",
        partition_id:"",
        schedule_week:"",
        type_name:"",
        zone_name:"",
        bed_name:"",
        id:"",
      },
      // 左侧患者数据
      cur_info: {
        patient_name: "",
        mode_name: "",
        mode_id: "",
        patient_id: "",
      },
      cur_temp_info:{
        patient_name: "",
        patient_id: "",
        mode_name: "",
        mode_id: "",
        schedule_date:"",
        schedule_type:"",
        bed_id:"",
        partition_id:"",
        schedule_week:"",
        type_name:"",
        zone_name:"",
        bed_name:"",
        id:"",


      },
      all_patients:[],
      patientList: [],
      keywords: "",
      schedulePatients: [],
      searchTableVisible: false,
      saving: false,
      zone_device_counts: {},
      treat_modes: {},
      // is_editing: false,
      opera_device_numbers: [],
      origin_device_numbers: [],
      opera_device_numbers_two: [],

      partition_id: 0,
      tableHeight: document.documentElement.clientHeight,
      template:null,
      all_template:[],
      active_name:"first",
    };
  },
  props: {
    modes: {
      type: Array,
    },

    template_mode: {
      type: Object,
    },
    data: {
      type: Array,
    },
    editable: {
      type: Boolean,
      default: false,
    },
    is_editing: {
      type: Boolean,
      default: false,
    },
    device_numbers: {
      type: Array,
    },

    patients: {
      type: Array,
    },
  },
  created() {
    this.treat_modes = this.$store.getters.treatment_mode;
    // window.addEventListener('scroll', this.handleScroll)
  },
  watch: {
    // device_numbers: function () {
    //   if(this.isEdit){
    //     this.opera_device_numbers = this.makeDeviceNumbers(this.device_numbers);
    //     this.origin_device_numbers = this.makeDeviceNumbers(this.device_numbers);
    //
    //   }
    //
    //
    // },
    // "template.items": function () {
    //   if(this.isEdit) {
    //
    //     this.$nextTick(() => {
    //       var weekdays = [1, 2, 3, 4, 5, 6, 7]; // 周一-周日
    //       var time_types = [1, 2, 3]; // 上下晚
    //       for (let d_n_i = 0; d_n_i < this.opera_device_numbers.length; d_n_i++) {
    //         const op_d_n = this.opera_device_numbers[d_n_i];
    //         const or_d_n = this.origin_device_numbers[d_n_i];
    //
    //         op_d_n.total = 0;
    //         or_d_n.total = 0;
    //
    //         for (let w_i = 0; w_i < weekdays.length; w_i++) {
    //           const weekday = weekdays[w_i];
    //           for (let t_i = 0; t_i < time_types.length; t_i++) {
    //             const time_type = time_types[t_i];
    //
    //             var item_key = weekday + "_" + time_type;
    //             var op_item = op_d_n[item_key];
    //             var or_item = or_d_n[item_key];
    //
    //             op_item.pid = 0;
    //             op_item.name = "";
    //             op_item.treat_mode_id = 0;
    //             op_item.treat_mode = "";
    //
    //             or_item.pid = 0;
    //             or_item.name = "";
    //             or_item.treat_mode_id = 0;
    //             or_item.treat_mode = "";
    //           }
    //         }
    //       }
    //       console.log("this.template");
    //       console.log(this.template);
    //       for (let index = 0; index < this.template.items.length; index++) {
    //         const template_item = this.template.items[index];
    //         if (template_item.patient == null) {
    //           continue;
    //         }
    //
    //         for (let d_i = 0; d_i < this.opera_device_numbers.length; d_i++) {
    //           const device_number = this.opera_device_numbers[d_i];
    //           if (device_number.id == template_item.device_number_id) {
    //             var weekday = template_item.weekday;
    //             var time_type = template_item.time_type;
    //             var cell_item = device_number[weekday + "_" + time_type];
    //             cell_item.pid = template_item.patient_id;
    //             cell_item.name = template_item.patient.name;
    //             cell_item.treat_mode_id = template_item.treat_mode;
    //             cell_item.treat_mode = template_item.treat_mode
    //               ? this.treat_modes[template_item.treat_mode].name
    //               : "";
    //             device_number.total += 1;
    //
    //             // origin_device_numbers 初始化时数据应该是和 opera_device_numbers 一样的，这里就不再用一个 for 遍历 origin_device_numbers 重复 opera_device_numbers 的操作了
    //             const o_device_number = this.origin_device_numbers[d_i];
    //             var o_cell_item = o_device_number[weekday + "_" + time_type];
    //             o_cell_item.pid = template_item.patient_id;
    //             o_cell_item.name = template_item.patient.name;
    //             o_cell_item.treat_mode_id = template_item.treat_mode;
    //             o_cell_item.treat_mode = template_item.treat_mode
    //               ? this.treat_modes[template_item.treat_mode].name
    //               : "";
    //             o_device_number.total += 1;
    //
    //             break;
    //           }
    //         }
    //       }
    //       let obj = {
    //         id: this.template.id,
    //         data: this.opera_device_numbers,
    //         data2: this.origin_device_numbers,
    //       };
    //       this.data.push(obj);
    //
    //     });
    //     console.log("~~~~~~2222222");
    //     console.log(this.template);
    //     // 先清除所有已有 item
    //   }
    //
    // },
    tableHeight(val) {
      if (!this.timer) {
        this.tableHeight = val;
        this.timer = true;
        const that = this;
        setTimeout(function () {
          that.timer = false;
        }, 400);
      }
    },

  },
  mounted() {
    this.tableContainHeight =
      window.innerHeight - this.$refs.table.$el.offsetTop - 310;

    const that = this;
    window.onresize = () => {
      return (() => {
        window.fullHeight = document.documentElement.clientHeight;
        if (window.fullHeight < 200) {
          that.tableHeight = 200;
        } else {
          that.tableHeight = window.fullHeight - 200;
        }
      })();
    };

    this.$refs.patient_table.setCurrentRow(this.patients[0]);
    this.$refs.mode_table.setCurrentRow(this.modes[0]);
  },
  methods: {
    // 后两周
    GetTemplateTwo(template){
      this.$nextTick(() => {
        var weekdays = [1, 2, 3, 4, 5, 6, 7]; // 周一-周日
        var time_types = [1, 2, 3]; // 上下晚
        for (let d_n_i = 0; d_n_i < this.opera_device_numbers_two.length; d_n_i++) {
          const op_d_n = this.opera_device_numbers_two[d_n_i];
          const or_d_n = this.origin_device_numbers[d_n_i];

          op_d_n.total = 0;
          or_d_n.total = 0;

          for (let w_i = 0; w_i < weekdays.length; w_i++) {
            const weekday = weekdays[w_i];
            for (let t_i = 0; t_i < time_types.length; t_i++) {
              const time_type = time_types[t_i];

              var item_key = weekday + "_" + time_type;
              var op_item = op_d_n[item_key];
              var or_item = or_d_n[item_key];

              op_item.pid = 0;
              op_item.name = "";
              op_item.treat_mode_id = 0;
              op_item.treat_mode = "";

              or_item.pid = 0;
              or_item.name = "";
              or_item.treat_mode_id = 0;
              or_item.treat_mode = "";
            }
          }
        }

        for (let index = 0; index < template.items.length; index++) {
          const template_item = template.items[index];
          if (template_item.patient == null) {
            continue;
          }

          for (let d_i = 0; d_i < this.opera_device_numbers_two.length; d_i++) {
            const device_number = this.opera_device_numbers_two[d_i];
            if (device_number.id == template_item.device_number_id) {
              var weekday = template_item.weekday;
              var time_type = template_item.time_type;
              var cell_item = device_number[weekday + "_" + time_type];
              cell_item.pid = template_item.patient_id;
              cell_item.name = template_item.patient.name;
              cell_item.treat_mode_id = template_item.treat_mode;
              cell_item.treat_mode = template_item.treat_mode
                ? this.treat_modes[template_item.treat_mode].name
                : "";
              device_number.total += 1;

              // origin_device_numbers 初始化时数据应该是和 opera_device_numbers 一样的，这里就不再用一个 for 遍历 origin_device_numbers 重复 opera_device_numbers 的操作了
              const o_device_number = this.origin_device_numbers[d_i];
              var o_cell_item = o_device_number[weekday + "_" + time_type];
              o_cell_item.pid = template_item.patient_id;
              o_cell_item.name = template_item.patient.name;
              o_cell_item.treat_mode_id = template_item.treat_mode;
              o_cell_item.treat_mode = template_item.treat_mode
                ? this.treat_modes[template_item.treat_mode].name
                : "";
              o_device_number.total += 1;

              break;
            }
          }
        }


      })},
      // 下一周
    GetTemplate(template){
      this.$nextTick(() => {
        var weekdays = [1, 2, 3, 4, 5, 6, 7]; // 周一-周日
        var time_types = [1, 2, 3]; // 上下晚
        for (let d_n_i = 0; d_n_i < this.opera_device_numbers.length; d_n_i++) {
          const op_d_n = this.opera_device_numbers[d_n_i];
          const or_d_n = this.origin_device_numbers[d_n_i];

          op_d_n.total = 0;
          or_d_n.total = 0;

          for (let w_i = 0; w_i < weekdays.length; w_i++) {
            const weekday = weekdays[w_i];
            for (let t_i = 0; t_i < time_types.length; t_i++) {
              const time_type = time_types[t_i];

              var item_key = weekday + "_" + time_type;
              var op_item = op_d_n[item_key];
              var or_item = or_d_n[item_key];

              op_item.pid = 0;
              op_item.name = "";
              op_item.treat_mode_id = 0;
              op_item.treat_mode = "";

              or_item.pid = 0;
              or_item.name = "";
              or_item.treat_mode_id = 0;
              or_item.treat_mode = "";
            }
          }
        }
        console.log("this.template");
        console.log(template);
        for (let index = 0; index < template.items.length; index++) {
          const template_item = template.items[index];
          if (template_item.patient == null) {
            continue;
          }

          for (let d_i = 0; d_i < this.opera_device_numbers.length; d_i++) {
            const device_number = this.opera_device_numbers[d_i];
            if (device_number.id == template_item.device_number_id) {
              var weekday = template_item.weekday;
              var time_type = template_item.time_type;
              var cell_item = device_number[weekday + "_" + time_type];
              cell_item.pid = template_item.patient_id;
              cell_item.name = template_item.patient.name;
              cell_item.treat_mode_id = template_item.treat_mode;
              cell_item.treat_mode = template_item.treat_mode
                ? this.treat_modes[template_item.treat_mode].name
                : "";
              device_number.total += 1;

              // origin_device_numbers 初始化时数据应该是和 opera_device_numbers 一样的，这里就不再用一个 for 遍历 origin_device_numbers 重复 opera_device_numbers 的操作了
              const o_device_number = this.origin_device_numbers[d_i];
              var o_cell_item = o_device_number[weekday + "_" + time_type];
              o_cell_item.pid = template_item.patient_id;
              o_cell_item.name = template_item.patient.name;
              o_cell_item.treat_mode_id = template_item.treat_mode;
              o_cell_item.treat_mode = template_item.treat_mode
                ? this.treat_modes[template_item.treat_mode].name
                : "";
              o_device_number.total += 1;

              break;
            }
          }
        }
        let obj = {
          id: template.id,
          data: this.opera_device_numbers,
          data2: this.origin_device_numbers,
        };
        this.data.push(obj);
        this.$emit("changeLoading")

      })},
    changePartiton(val) {
      this.$emit("event1", val);
      // this.partition_id = val;
      // this.getWeekPanels();
      // this.getSchedules();
    },
    // 这周
    handleData() {
      this.$nextTick(() => {
        var weekdays = [1, 2, 3, 4, 5, 6, 7]; // 周一-周日
        var time_types = [1, 2, 3]; // 上下晚
        for (let d_n_i = 0; d_n_i < this.opera_device_numbers.length; d_n_i++) {
          const op_d_n = this.opera_device_numbers[d_n_i];
          const or_d_n = this.origin_device_numbers[d_n_i];

          op_d_n.total = 0;
          or_d_n.total = 0;

          for (let w_i = 0; w_i < weekdays.length; w_i++) {
            const weekday = weekdays[w_i];
            for (let t_i = 0; t_i < time_types.length; t_i++) {
              const time_type = time_types[t_i];

              var item_key = weekday + "_" + time_type;
              var op_item = op_d_n[item_key];
              var or_item = or_d_n[item_key];

              op_item.pid = 0;
              op_item.name = "";
              op_item.treat_mode_id = 0;
              op_item.treat_mode = "";

              or_item.pid = 0;
              or_item.name = "";
              or_item.treat_mode_id = 0;
              or_item.treat_mode = "";
            }
          }
        }
        console.log("this.template");
        console.log(this.template);
        for (let index = 0; index < this.template.items.length; index++) {
          const template_item = this.template.items[index];
          if (template_item.patient == null) {
            continue;
          }

          for (let d_i = 0; d_i < this.opera_device_numbers.length; d_i++) {
            const device_number = this.opera_device_numbers[d_i];
            if (device_number.id == template_item.device_number_id) {
              var weekday = template_item.weekday;
              var time_type = template_item.time_type;
              var cell_item = device_number[weekday + "_" + time_type];
              cell_item.pid = template_item.patient_id;
              cell_item.name = template_item.patient.name;
              cell_item.treat_mode_id = template_item.treat_mode;
              cell_item.treat_mode = template_item.treat_mode
                ? this.treat_modes[template_item.treat_mode].name
                : "";
              device_number.total += 1;

              // origin_device_numbers 初始化时数据应该是和 opera_device_numbers 一样的，这里就不再用一个 for 遍历 origin_device_numbers 重复 opera_device_numbers 的操作了
              const o_device_number = this.origin_device_numbers[d_i];
              var o_cell_item = o_device_number[weekday + "_" + time_type];
              o_cell_item.pid = template_item.patient_id;
              o_cell_item.name = template_item.patient.name;
              o_cell_item.treat_mode_id = template_item.treat_mode;
              o_cell_item.treat_mode = template_item.treat_mode
                ? this.treat_modes[template_item.treat_mode].name
                : "";
              o_device_number.total += 1;

              break;
            }
          }
        }
        let obj = {
          id: this.template.id,
          data: this.opera_device_numbers,
          data2: this.origin_device_numbers,
        };
        this.data.push(obj);
        console.log(this.data);
      });
    },
    // 便利周一到周日
    getWeekByzhongwen(week_str) {
      switch (week_str) {
        case "周一":
          return 1;
          break;
        case "周二":
          return 2;
          break;
        case "周三":
          return 3;
          break;
        case "周四":
          return 4;
          break;
        case "周五":
          return 5;
          break;
        case "周六":
          return 6;
          break;
        case "周日":
          return 7;
          break;
      }
    },
    // 拖拽
    drop(e, day, index, name, row) {
      e.preventDefault();
      console.log('11111111',row)
      for (var key in row) {
        if (key == day) {
          let info = {};
          for (var key in row) {
            if (key == day) {
              info = row[key];
            }
          }
          console.log(info)

          var weekday_timetype = day.split("_");
          var weekday = weekday_timetype[0];
          var time_type = weekday_timetype[1];

          this.cur_temp_info.schedule_week = weekday
          this.cur_temp_info.schedule_type = time_type
          this.cur_temp_info.patient_id = info.pid
          this.cur_temp_info.id = row.id

          if (info.pid > 0 || info.treat_mode_id > 0 ) {
            if (this.cur_drag_obj == 2){

              if(info.pid != this.cur_drag_info.patient_id){
                console.log('1234132412',info.pid,this.cur_drag_info.patient_id);
                this.tipDialogVisible = true
              }
                // this.tipDialogVisible = false
            }else{
              this.$message.error("当前机号已有排班2");
              return;
            }

          } else {
            //當前類型是表格内的拖拽，如果是同一天内的表格拖拽到空床位則先刪除原先排版，后在將排班弄到空床位
            if(this.cur_drag_obj == 2){
              if (this.cur_drag_info.schedule_week == weekday){
                //删除原来的排班，新增一个新的排班
                let params={
                  template_id:this.template.id,
                  week_type_one:this.cur_drag_info.schedule_week,
                  time_type_one:this.cur_drag_info.schedule_type,
                  device_id_one:this.cur_drag_info.id,
                  patient_id_one:this.cur_drag_info.patient_id,


                  week_type_two:this.cur_temp_info.schedule_week,
                  time_type_two:this.cur_temp_info.schedule_type,
                  device_id_two:this.cur_temp_info.id,
                  patient_id_two:this.cur_drag_info.patient_id,
                  mode_id:this.cur_drag_info.mode_id,

                }
                DeleteAndAddScheduleTemplateTwo(params).then((response) => {
                  if (response.data.state == 0) {
                    this.$message.error(response.data.msg);
                    this.tipDialogVisibleThree = false
                  } else {
                    this.all_template = response.data.data.items
                    this.$emit("setTemplate",response.data.data.items)
                    if(this.active_name == 'first'){
                      this.GetTemplate(response.data.data.items[0])
                    }else if(this.active_name == "second"){
                      this.GetTemplate(response.data.data.items[1])
                    }else if(this.active_name == "third"){
                      this.GetTemplate(response.data.data.items[2])
                    }else if(this.active_name == "four"){
                      this.GetTemplate(response.data.data.items[3])
                    }
                  }
                });

              }else{
                this.will_add_schedule_action(
                  this.cur_drag_info.patient_id,
                  this.cur_drag_info.mode_id,
                  weekday,
                  time_type,
                  row.id,
                  0
                );
                this.saveActionTwo();
              }
            }else{
              this.will_add_schedule_action(
                this.cur_info.patient_id,
                this.cur_info.mode_id,
                weekday,
                time_type,
                row.id,
                0
              );
              this.saveActionTwo();
            }
          }
        }
      }
    },
    unique_two(array) {
      // res用来存储结果
      var res = [];
      for (var i = 0, arrayLen = array.length; i < arrayLen; i++) {
        for (var j = 0, resLen = res.length; j < resLen; j++) {
          if (array[i].id === res[j].id) {
            break;
          }
        }
        // 如果array[i]是唯一的，那么执行完循环，j等于resLen
        if (j === resLen) {
          res.push(array[i]);
        }
      }
      return res;
    },

    showSmartDialog() {
      this.smartVisible = true;
      this.smart_keyword = "";
      this.all_zones = this.unique_two(this.all_zones);

      for (let i = 0; i < this.patientList.length; i++) {
        if (this.patientList[i].id == this.cur_info.patient_id) {
          this.cur_smart_patient_name = this.patientList[i].name;
          this.cur_smart_patient_no = this.patientList[i].dialysis_no;
          this.cur_smart_patient_id = this.patientList[i].id;
        }
      }

      let params = {
        patient_id: this.cur_smart_patient_id,
      };

      getPatientSmartSchTemplate(params).then((response) => {
        if (response.data.state == 0) {
          return false;
        }

        if ((response.data.data.status = 1)) {
          var data = [];
          var schedules = response.data.data.schedules_template;
          for (let i = 0; i < this.editableTabs.length; i++) {
            this.editableTabs[i].checkedWeek = [];
            this.editableTabs[i].tableWeekArrage = [];
          }
          for (let i = 0; i < schedules.length; i++) {
            if (i == 0) {
              this.editableTabsValue = schedules[0].id;
            }
            let obj = {
              id: schedules[i].id,
              checkedWeek: [],
              title: schedules[i].week,
              name: schedules[i].id,
              tableWeekArrage: schedules[i].template,
            };
            if (i == 0) {
              obj.title = "一周模版";
            } else if (i == 1) {
              obj.title = "二周模版";
            } else if (i == 2) {
              obj.title = "三周模版";
            } else if (i == 3) {
              obj.title = "四周模版";
            }
            for (let b = 0; b < schedules[i].template.length; b++) {
              let devices = [];
              for (let d = 0; d < this.devices.length; d++) {
                if (
                  this.devices[d].zone.id == schedules[i].template[b].zone_id
                ) {
                  devices.push(this.devices[d]);
                }
              }
              schedules[i].template[b]["jihaos"] = devices;
              schedules[i].template[b]["week"] = this.getWeekDay(
                schedules[i].template[b].weekday
              );
              schedules[i].template[b]["week_type"] = this.getWeekByzhongwen(
                schedules[i].template[b].weekday
              );

              for (let c = 0; c < this.weeks.length; c++) {
                if (
                  schedules[i].template[b].weekday == this.weeks[c].week_type
                ) {
                  obj.checkedWeek.push(this.weeks[c]);
                }
              }
            }
            schedules[i].template.sort(function (a, b) {
              return a.week_type - b.week_type;
            });
            data.push(obj);
          }

          this.editableTabs = data;
          this.current_patient_data = this.deepClone(data);
          this.current_all_schtemplate = data
        } else {
        }
      });


      this.smartVisible = true;
    },
    SetSmartSch(tempData,del_data) {
      this.saveActionThree(tempData,del_data);
    },
    check(tempData) {
      let isJiXu = true;
      //进行校验
      for (let i = 0; i < tempData.length; i++) {
        for (let index = 0; index < this.opera_device_numbers_two.length; index++) {
          const device_number = this.opera_device_numbers_two[index];
          for (let t_y = 1; t_y <= 3; t_y++) {
            if (
              t_y == tempData[i].time_type &&
              tempData[i].jihao_id == device_number.id &&
              device_number[tempData[i].schedule_week + "_" + t_y].pid !=
              tempData[i].patient_id
            ) {
              console.log( device_number[tempData[i].schedule_week + "_" + t_y].pid)
              console.log(tempData[i].patient_id)
              console.log( tempData[i].jihao_id)
              console.log( device_number.id)
              let msg = "";
              let name = "";
              for(let i = 0; i < this.editableTabs.length;i++){
                if(this.editableTabs[i].name == tempData[i].t_id){
                  name = this.editableTabs[i].title
                }
              }
              msg = name + "周" + tempData[i].schedule_week;

              if (tempData[i].time_type == 1) {
                msg = msg + "上午";
              } else if (tempData[i].time_type == 2) {
                msg = msg + "下午";
              } else {
                msg = msg + "晚上";
              }
              isJiXu = false;
              this.smartSaveLoading = false;
              msg =
                msg +
                device_number.zone.name +
                device_number.number +
                "已有排班";
              this.$message.error(msg);
            }
          }
        }
      }
      return isJiXu;
    },
    batchSetSch() {
      this.smartSaveLoading = true;
      var tempData = [];
      var delData = [];
      for (let b = 0; b < this.editableTabs.length; b++) {
        for (let c = 0; c < this.editableTabs[b].tableWeekArrage.length; c++) {
          let obj = {
            time_type: this.editableTabs[b].tableWeekArrage[c].time_type,
            jihao_id: this.editableTabs[b].tableWeekArrage[c].device_number_id,
            schedule_week: this.getWeekByzhongwen(
              this.editableTabs[b].tableWeekArrage[c].week
            ),
            mode_id: this.editableTabs[b].tableWeekArrage[c].treat_mode,
            sch_id: this.editableTabs[b].tableWeekArrage[c].id,
            zone_id: this.editableTabs[b].tableWeekArrage[c].zone_id,
            t_id: this.editableTabs[b].name,
            title:this.editableTabs[b].title,
            patient_id: this.cur_smart_patient_id,
          };
          tempData.push(obj);
        }
      }

      for (let b = 0; b < this.current_patient_data.length; b++) {
        for (let c = 0; c < this.current_patient_data[b].tableWeekArrage.length; c++) {
          let obj = {
            time_type: this.current_patient_data[b].tableWeekArrage[c].time_type,
            jihao_id: this.current_patient_data[b].tableWeekArrage[c].device_number_id,
            schedule_week: this.getWeekByzhongwen(
              this.current_patient_data[b].tableWeekArrage[c].week
            ),
            mode_id: this.current_patient_data[b].tableWeekArrage[c].treat_mode,
            sch_id: this.current_patient_data[b].tableWeekArrage[c].id,
            zone_id: this.current_patient_data[b].tableWeekArrage[c].zone_id,
            t_id: this.current_patient_data[b].name,
            title:this.current_patient_data[b].title,
            patient_id: this.cur_smart_patient_id,
          };
          delData.push(obj);
        }
      }
      if(tempData.length > 0) {
        for (let i = 0; i < delData.length; i++) {
          for (let b = 0; b < tempData.length; b++) {
            if (delData[i] && delData[i].sch_id == tempData[b].sch_id) {
              delData.splice(i, 1)
            }
          }
        }
      }

      for (let i = 0; i < tempData.length; i++) {
        if (tempData[i].jihao_id == "" || tempData[i].zone_id == "") {
          this.$message.error("分区或者床位不能空");
          this.smartSaveLoading = false;

          return;
        }
      }
      this.isEdit = true
      console.log("saveData")
      console.log(tempData)
      this.$emit("saveData", tempData,delData);
    },
    changeJihao(){
      this.$forceUpdate()
    },
    changeSchMachine(row) {
      let params = {
        zone_id: row.zone_id,
        sch_type: row.time_type,
        weekday: this.getWeekByzhongwen(row.week),
        patient_id: this.cur_smart_patient_id,
        template_id:this.editableTabsValue,
      };
      //进行网络请求，获取空排班机位
      getTemplateSmartDevices(params).then((response) => {
        if (response.data.state == 0) {
          return false;
        } else {
          var devices = response.data.data.devices;
          row.jihaos = [];
          // row.jihaos = devices;
          for (let i = 0; i < devices.length; i++){
            this.$set(row.jihaos , i, devices[i])
          }
        }
      });
    },
    changeSch(row) {

      console.log(row)
      let params = {
        zone_id: row.zone_id,
        sch_type: row.time_type,
        weekday: this.getWeekByzhongwen(row.week),
        patient_id: this.cur_smart_patient_id,
        template_id:this.editableTabsValue,
      };
      //进行网络请求，获取空排班机位
      getTemplateSmartDevices(params).then((response) => {
        if (response.data.state == 0) {
          return false;
        } else {
          var devices = response.data.data.devices;
          row.jihaos = [];
          // row.jihaos = devices;
          for (let i = 0; i < devices.length; i++){
            this.$set(row.jihaos , i, devices[i])
          }

          row.device_number_id = "";
        }
      });
    },
    changeArea(row) {


      let params = {
        zone_id: row.zone_id,
        sch_type: row.time_type,
        weekday: this.getWeekByzhongwen(row.week),
        patient_id: this.cur_smart_patient_id,
        template_id:this.editableTabsValue,
      };
      //进行网络请求，获取空排班机位
      getTemplateSmartDevices(params).then((response) => {
        if (response.data.state == 0) {
          return false;
        } else {
          var devices = response.data.data.devices;
          row.jihaos = [];
          row.jihaos = devices;
          row.device_number_id = "";
        }
      });

    },
    // changeJihao(row) {
    //   // let devices = [];
    //   // devices = this.opera_device_numbers_two;
    //   // let cur_key =
    //   //   this.getWeekByzhongwen(row.week).toString() +
    //   //   "_" +
    //   //   row.time_type.toString();
    //   // row.jihaos = [];
    //   // for (let i = 0; i < devices.length; i++) {
    //   //   if (devices[i].zone_id == row.zone_id) {
    //   //     let is_sch = false; //是否有排班
    //   //     for (let key in devices[i]) {
    //   //       if (key == cur_key) {
    //   //         if (
    //   //           devices[i][key].pid > 0 &&
    //   //           devices[i][key].treat_mode_id > 0 &&
    //   //           devices[i][key].pid != this.cur_smart_patient_id
    //   //         ) {
    //   //           is_sch = true;
    //   //         }
    //   //       }
    //   //     }
    //   //     if (!is_sch) {
    //   //       row.jihaos.push(devices[i]);
    //   //     }
    //   //   }
    //   // }
    //   // row.device_number_id = ""
    //   // let params = {
    //   //   zone_id: row.zone_id,
    //   //   sch_type: row.time_type,
    //   //   weekday: row.weekday,
    //   //   patient_id: this.cur_smart_patient_id,
    //   // };
    //   // //进行网络请求，获取空排班机位
    //   // getTemplateSmartDevices(params).then((response) => {
    //   //   if (response.data.state == 0) {
    //   //     return false;
    //   //   } else {
    //   //     var devices = response.data.data.devices;
    //   //     row.ihaos = [];
    //   //     row.jihaos = devices;
    //   //     if (devices && devices.length > 0) {
    //   //       row.jihao_id = devices[0].id;
    //   //     } else {
    //   //       row.jihao_id = "";
    //   //     }
    //   //   }
    //   // });
    // },

    select_week(val) {
      this.handledDataLoading = true;
      let params = {
        patient_id: this.cur_smart_patient_id,
      };

      getPatientSmartSchTemplate(params).then((response) => {
        if (response.data.state == 0) {
          return false;
        }

        if(response.data.data.status = 1) {
          this.handledDataLoading = false;

          var data = [];
          var schedules = response.data.data.schedules_template;

          for (let i = 0; i < schedules.length; i++) {
            let obj = {
              id: schedules[i].id,
              checkedWeek: [],
              title: schedules[i].week,
              name: schedules[i].id,
              tableWeekArrage: schedules[i].template,
            };
            if (i == 0) {
              obj.title = "一周模版";
            } else if (i == 1) {
              obj.title = "二周模版";
            } else if (i == 2) {
              obj.title = "三周模版";
            } else if (i == 3) {
              obj.title = "四周模版";
            }
            for (let b = 0; b < schedules[i].template.length; b++) {
              let devices = [];
              for (let d = 0; d < this.devices.length; d++) {
                if (
                  this.devices[d].zone.id == schedules[i].template[b].zone_id
                ) {
                  devices.push(this.devices[d]);
                }
              }
              schedules[i].template[b]["jihaos"] = devices;
              schedules[i].template[b]["week"] = this.getWeekDay(
                schedules[i].template[b].weekday
              );
              schedules[i].template[b]["week_type"] = this.getWeekByzhongwen(
                schedules[i].template[b].weekday
              );

              for (let c = 0; c < this.weeks.length; c++) {
                if (
                  schedules[i].template[b].weekday == this.weeks[c].week_type
                ) {
                  obj.checkedWeek.push(this.weeks[c]);
                }
              }
            }
            schedules[i].template.sort(function (a, b) {
              return a.week_type - b.week_type;
            });
            data.push(obj);
          }

          this.current_all_schtemplate = this.editableTabs
          var sch = [];
          for (let i = 0; i < this.current_all_schtemplate.length; i++) {
            if (this.current_all_schtemplate[i].name == this.editableTabsValue) {
              sch = this.current_all_schtemplate[i];
            }
          }

          let data2 = [];
          if (val.length == 0) {
            for (let i = 0; i < this.editableTabs.length; i++) {
              if (this.editableTabsValue == this.editableTabs[i].name) {
                this.editableTabs[i].tableWeekArrage = [];
                this.editableTabs[i].checkedWeek = [];
              }
            }
          }

          for (let i = 0; i < val.length; i++) {
            let is_new = true;
            let week_name = val[i].name;

            let obj = {};
            for (let b = 0; b < sch.tableWeekArrage.length; b++) {

              if (week_name == sch.tableWeekArrage[b].week) {
                is_new = false;
                obj = sch.tableWeekArrage[b];
              }
            }
            if (!is_new) {
              data2.push(obj);
            } else {
              data2.push({
                treat_mode: 1,
                week: val[i].name,
                time_type: 1,
                zone_id: "",
                device_number_id: "",
                jihaos: [],
                id: 0,
              });
            }
          }

          for (let i = 0; i < data2.length; i++) {
            data2[i]["week_type"] = this.getWeekByzhongwen(data2[i].week);
          }

          data2.sort(function (a, b) {
            return a.week_type - b.week_type;
          });

          for (let i = 0; i < this.editableTabs.length; i++) {
            if (this.editableTabs[i].name == this.editableTabsValue) {
              this.editableTabs[i].tableWeekArrage = data2;
            }
          }
        } else {
        }
      });


    },
    handleClick() {
      if(this.editableTabsValue == this.all_template[0].id){
        this.GetTemplateTwo(this.all_template[0])

      }else if(this.editableTabsValue == this.all_template[1].id){
        this.GetTemplateTwo(this.all_template[1])


      }else if(this.editableTabsValue == this.all_template[2].id){
        this.GetTemplateTwo(this.all_template[2])


      }else if(this.editableTabsValue == this.all_template[3].id){

        this.GetTemplateTwo(this.all_template[3])

      }

    },
    deepClone(source) {
      if (!source && typeof source !== 'object') {
        throw new Error('error arguments', 'shallowClone')
      }
      const targetObj = source.constructor === Array ? [] : {}
      Object.keys(source).forEach((keys) => {
        if (source[keys] && typeof source[keys] === 'object') {
          targetObj[keys] = this.deepClone(source[keys])
        } else {
          targetObj[keys] = source[keys]
        }
      })
      return targetObj
    },

    handleSelect(val) {
      for (let i = 0; i < this.editableTabs.length; i++) {
        this.editableTabs[i].tableWeekArrage = [];
        this.editableTabs[i].checkedWeek = [];
      }

      this.smart_keyword = val.name;
      this.cur_smart_patient_id = val.id;
      this.cur_smart_patient_name = val.name;
      this.cur_smart_patient_no = val.dialysis_no;

      let params = {
        patient_id: this.cur_smart_patient_id,
      };

      getPatientSmartSchTemplate(params).then((response) => {
        if (response.data.state == 0) {
          return false;
        }

        if ((response.data.data.status = 1)) {
          var data = [];
          var schedules = response.data.data.schedules_template;
          for (let i = 0; i < this.editableTabs.length; i++) {
            this.editableTabs[i].checkedWeek = [];
            this.editableTabs[i].tableWeekArrage = [];
          }
          for (let i = 0; i < schedules.length; i++) {
            if (i == 0) {
              this.editableTabsValue = schedules[0].id;
            }
            let obj = {
              id: schedules[i].id,
              checkedWeek: [],
              title: schedules[i].week,
              name: schedules[i].id,
              tableWeekArrage: schedules[i].template,
            };
            if (i == 0) {
              obj.title = "一周模版";
            } else if (i == 1) {
              obj.title = "二周模版";
            } else if (i == 2) {
              obj.title = "三周模版";
            } else if (i == 3) {
              obj.title = "四周模版";
            }
            for (let b = 0; b < schedules[i].template.length; b++) {
              let devices = [];
              for (let d = 0; d < this.devices.length; d++) {
                if (
                  this.devices[d].zone.id == schedules[i].template[b].zone_id
                ) {
                  devices.push(this.devices[d]);
                }
              }
              schedules[i].template[b]["jihaos"] = devices;
              schedules[i].template[b]["week"] = this.getWeekDay(
                schedules[i].template[b].weekday
              );
              schedules[i].template[b]["week_type"] = this.getWeekByzhongwen(
                schedules[i].template[b].weekday
              );

              for (let c = 0; c < this.weeks.length; c++) {
                if (
                  schedules[i].template[b].weekday == this.weeks[c].week_type
                ) {
                  obj.checkedWeek.push(this.weeks[c]);
                }
              }
            }
            schedules[i].template.sort(function (a, b) {
              return a.week_type - b.week_type;
            });
            data.push(obj);
          }

          this.editableTabs = data;
          this.current_patient_data = this.deepClone(data);
          this.current_all_schtemplate = data
        } else {
        }
      });

      // var schedules = val.XtPatientScheduleTemplateId;
      // var data = [];
      // for (let i = 0; i < schedules.length; i++) {
      //   if (i == 0) {
      //     this.editableTabsValue = schedules[0].id;
      //   }
      //   let obj = {
      //     id: schedules[i].id,
      //     checkedWeek: [],
      //     title: schedules[i].week,
      //     name: schedules[i].id,
      //     tableWeekArrage: schedules[i].template,
      //   };
      //
      //   if (i == 0) {
      //     obj.title = "一周模版";
      //   } else if (i == 1) {
      //     obj.title = "二周模版";
      //   } else if (i == 2) {
      //     obj.title = "三周模版";
      //   } else if (i == 3) {
      //     obj.title = "四周模版";
      //   }
      //   for (let b = 0; b < schedules[i].template.length; b++) {
      //     let devices = [];
      //     for (let d = 0; d < this.devices.length; d++) {
      //       if (this.devices[d].zone.id == schedules[i].template[b].zone_id) {
      //         devices.push(this.devices[d]);
      //       }
      //     }
      //
      //     schedules[i].template[b]["jihaos"] = devices;
      //     schedules[i].template[b]["week"] = this.getWeekDay(
      //       schedules[i].template[b].weekday
      //     );
      //     schedules[i].template[b]["week_type"] = this.getWeekByzhongwen(
      //       schedules[i].template[b].weekday
      //     );
      //
      //     for (let c = 0; c < this.weeks.length; c++) {
      //       if (schedules[i].template[b].weekday == this.weeks[c].week_type) {
      //         obj.checkedWeek.push(this.weeks[c]);
      //       }
      //     }
      //   }
      //   data.push(obj);
      // }
      // this.editableTabs = data;
      // // this.current_patient_data = data;
      // this.current_patient_data = data
      // this.current_all_sch =data;
      // this.current_patient_data = data

    },
    querySearchAsync(keyword, cb) {
      let key = "";
      if (keyword != undefined) {
        key = keyword;
      }
      let searchArray = [];
      let obj = {
        keyword: key,
      };
      PostSearchSmartSchTemplatePatient(obj).then((response) => {
        if (response.data.state == 1) {
          searchArray = response.data.data.patient;
          cb(searchArray);
        } else {
          cb([]);
        }
      });
    },
    getData() {
      return this.opera_device_numbers;
    },
    // 左侧模式点击
    modeClick(row) {
      this.cur_info.mode_name = row.name;
      this.cur_info.mode_id = row.id;
    },
    deletePatientMode(row, key, rows) {
      this.isEdit= true
      var weekday_timetype = key.split("_");
      var weekday = weekday_timetype[0];
      var time_type = weekday_timetype[1];
      this.cancel_schedule_action(weekday, time_type, rows.id);
      this.saveActionTwo();
    },
    setEditData(patients, template, device_numbers,all_template,active_name) {
      this.active_name = active_name
      this.all_template = all_template
      this.all_patients = patients
      this.patientList = patients;
      this.template = template;
      this.device_numbers = device_numbers
      this.cur_info.patient_name = this.patientList[0].name;
      this.cur_info.mode_name = this.modes[0].name;
      this.cur_info.patient_id = this.patientList[0].id;
      this.cur_info.mode_id = this.modes[0].id;
      this.$refs.patient_table.setCurrentRow(this.patientList[0]);
      this.$refs.mode_table.setCurrentRow(this.modes[0]);
      let that = this
      if(that.opera_device_numbers.length == 0 &&that.origin_device_numbers.length == 0){
        that.opera_device_numbers = that.makeDeviceNumbers(device_numbers);
        that.origin_device_numbers = that.makeDeviceNumbers(device_numbers);
        that.opera_device_numbers_two = that.makeDeviceNumbers(device_numbers);
      }
      setTimeout(function (){
        that.GetTemplate(template)
        that.GetTemplateTwo(template)

      }, 1000);

    },
    // 左侧拖拽
    curInfoDragStart(){
      this.cur_drag_obj = 1
      this.cur_drag_info.patient_id = this.cur_info.patient_id
      this.cur_drag_info.patient_name = this.cur_info.patient_name
      this.cur_drag_info.mode_id = this.cur_info.mode_id
      this.cur_drag_info.mode_name = this.cur_info.mode_name
    },
    // 左侧患者点击
    patientClick(row) {
      console.log(row);
      this.cur_info.patient_name = row.name;
      this.cur_info.patient_id = row.id;
      this.patient_id_hover = row.id
      console.log('this.patient_id_hover',this.patient_id_hover);
      console.log('patientClick的数据',row);
    },
    dragstartTwo(event) {
      console.log("start的索引");
    },
    dragendTwo(event) {
      console.log("dragend");
    },
    // 鼠标移入
    drag(e, day, index, name,row) {
      e.preventDefault();
      let info = {};
      for (var key in row) {
        if (key == day) {
          info = row[key];
        }
      }
      var weekday_timetype = day.split("_");
      var weekday = weekday_timetype[0];
      var time_type = weekday_timetype[1];

      console.log(info)
      console.log(row)
      if(info.pid > 0 ) {
        this.cur_drag_obj = 2
        this.cur_drag_info.schedule_type =time_type;
        this.cur_drag_info.partition_id = row.zone_id;
        this.cur_drag_info.schedule_week = weekday;
        this.cur_drag_info.mode_id = info.treat_mode_id;
        this.cur_drag_info.mode_name = info.treat_mode;
        this.cur_drag_info.patient_name = info.name;
        this.cur_drag_info.patient_id = info.pid;
        this.cur_drag_info.id = row.id;
      }else{
        this.cur_drag_obj = 2
        this.cur_drag_info.schedule_type ='';
        this.cur_drag_info.partition_id = '';
        this.cur_drag_info.schedule_week = '';
        this.cur_drag_info.mode_id = '';
        this.cur_drag_info.mode_name = '';
        this.cur_drag_info.patient_name = '';
        this.cur_drag_info.patient_id = 0;
        this.cur_drag_info.id = 0;

      }

        console.log('this.cur_drag_info的数据',this.cur_drag_info);
      },
    allowDrop(e) {
      e.preventDefault();
    },
    //        ----------------------------------
    //        | !在html里面的chedule-item里绑定的|
    //        |  "：draggable"可控制该表格能否拖 |
    //        | 动，根据实际情况进行修改          |
    //        |                                 |
    //        -----------------------------------
    // drop(e, day, index, name,row) {
    //   e.preventDefault();
    //   for(var key in row){
    //     if(key == day){
    //       var week = this.weekDay(day);
    //
    //
    //       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(this.currentData.schedule_date)
    //       //TODO 比较当前拖动到的日期和当天比较，如果小于今天则无法添加
    //
    //       if( row[key].patient.length > 0 ||  row[key].mode_name.length > 0 || row[key].mode_id > 0 ||  row[key].patient_id > 0){
    //         this.$message.error("当前机号已有排班");
    //         return
    //       }else{ //接口提交排班数据
    //
    //
    //
    //         this.currentData.mode_id = this.cur_info.mode_id;
    //         this.currentData.id = 0;
    //         this.currentData.contagions = [];
    //         this.currentData.patient_id = this.cur_info.patient_id;
    //         this.currentData.patient = this.cur_info.patient_name;
    //         this.setSchedule()
    //       }
    //     }
    //   }
    //
    // },

    // 左边栏选中名字和模式拖动结束后
    taskDraggerEnd(e) {
      console.log(e.to);
      console.log(e.form);
    },

    //move回调方法
    onMove(e, originalEvent) {
      return true;
    },

    compare(p) {
      //这是比较函数
      return function (m, n) {
        var a = m[p];
        var b = n[p];
        return a - b; //升序
      };
    },
    // 周一到周日
    getWeekDay: function (week) {
      let week_name = "";
      switch (week) {
        case 1:
          week_name = "周一";
          break;
        case 2:
          week_name = "周二";
          break;
        case 3:
          week_name = "周三";
          break;
        case 4:
          week_name = "周四";
          break;
        case 5:
          week_name = "周五";
          break;
        case 6:
          week_name = "周六";
          break;
        case 7:
          week_name = "周日";
          break;
      }
      return week_name;
    },
    // 早中晚
    getSchedulesType: function (type) {
      let type_name = "";
      switch (type) {
        case 1:
          type_name = "上午";
          break;
        case 2:
          type_name = "下午";

          break;
        case 3:
          type_name = "晚上";
          break;
      }
      return type_name;
    },
    getModeName: function (mode) {
      if (this.$store.getters.treatment_mode[mode] != undefined) {
        return this.$store.getters.treatment_mode[mode].name;
      }
      return "";
    },

    makeDeviceNumbers: function (device_numbers) {
      this.all_zones = [];
      this.devices = [];
      console.log("device_numbers", device_numbers);
      var arr = [];
      for (let i = 0; i < device_numbers.length; i++) {
        arr.push(device_numbers[i]);
      }
      arr.sort(this.arraySort("sort"));
      console.log("Arr2332232332", arr);
      var maked_device_numbers = [];
      var weekdays = [1, 2, 3, 4, 5, 6, 7]; // 周一-周日
      var time_types = [1, 2, 3]; // 上下晚
      for (let index = 0; index < arr.length; index++) {
        const device_number = arr[index];
        if (device_number.zone != null) {
          var zone = {
            id: device_number.zone.id,
            name: device_number.zone.name,
            type: device_number.zone.type,
            sort: device_number.sort,
          };
          this.all_zones.push(zone);
          var device = {
            id: device_number.id,
            number: device_number.number,
            group_id: device_number.group_id,
            zone_id: device_number.zone_id,
            zone: zone,
            sort: device_number.sort,
          };
          this.devices.push(device);
        }

        // 以 weekday_timetype 为 key，{pid: 0, name: "", treat_mode_id: 0, treat_mode: ""} 为 value，加入到 maked_device_numbers 中
        for (let w_i = 0; w_i < weekdays.length; w_i++) {
          const weekday = weekdays[w_i];
          for (let t_i = 0; t_i < time_types.length; t_i++) {
            const time_type = time_types[t_i];
            var defaultValue = {};
            this.$set(defaultValue, "pid", 0);
            this.$set(defaultValue, "name", "");
            this.$set(defaultValue, "treat_mode_id", 0);
            this.$set(defaultValue, "treat_mode", "");
            this.$set(device, weekday + "_" + time_type, defaultValue);
          }
        }
        this.$set(device, "total", 0); // 每个床位号每周的排班总数

        maked_device_numbers.push(device);
      }

      this.all_zones = this.unique_two(this.all_zones);

      return maked_device_numbers;
    },
    // 替换
    coverSch(){
      let params={
        template_id:this.template.id,
        week_type_one:this.cur_drag_info.schedule_week,
        time_type_one:this.cur_drag_info.schedule_type,
        device_id_one:this.cur_drag_info.id,
        patient_id_one:this.cur_drag_info.patient_id,

        week_type_two:this.cur_temp_info.schedule_week,
        time_type_two:this.cur_temp_info.schedule_type,
        device_id_two:this.cur_temp_info.id,
        patient_id_two:this.cur_temp_info.patient_id,

      }
      this.changeLoadingOne = true
      CoverSchTemplate(params).then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg);
          this.tipDialogVisibleTwo = false
          this.changeLoadingOne = false

        } else {
          this.$message.success("替换成功");
          this.tipDialogVisible = false
          this.tipDialogVisibleTwo = false
          this.changeLoadingOne = false

          // this.getSchedules();
          this.all_template = response.data.data.items
          console.log('替换数据',response.data.data);
          this.$emit("setTemplate",response.data.data.items)
          if(this.active_name == 'first'){
            this.GetTemplate(response.data.data.items[0])
          }else if(this.active_name == "second"){
            this.GetTemplate(response.data.data.items[1])
          }else if(this.active_name == "third"){
            this.GetTemplate(response.data.data.items[2])
          }else if(this.active_name == "four"){
            this.GetTemplate(response.data.data.items[3])
          }
        }
      });
    },
    // 交换
    changeSchTemplateTwo(){
      let params={
        template_id:this.template.id,
        week_type_one:this.cur_drag_info.schedule_week,
        time_type_one:this.cur_drag_info.schedule_type,
        device_id_one:this.cur_drag_info.id,
        patient_id_one:this.cur_drag_info.patient_id,


        week_type_two:this.cur_temp_info.schedule_week,
        time_type_two:this.cur_temp_info.schedule_type,
        device_id_two:this.cur_temp_info.id,
        patient_id_two:this.cur_temp_info.patient_id,


      }
      this.changeLoadingTwo = true
      ExchangeSchTemplate(params).then((response) => {
        if (response.data.state == 0) {
          this.$message.error(response.data.msg);
          this.tipDialogVisibleThree = false
          this.changeLoadingTwo = false

        } else {
          this.$message.success("交换成功");
          this.tipDialogVisible = false
          this.tipDialogVisibleThree = false
          this.changeLoadingTwo = false

          // this.getSchedules();
          this.all_template = response.data.data.items
          this.$emit("setTemplate",response.data.data.items)
          if(this.active_name == 'first'){
            this.GetTemplate(response.data.data.items[0])
          }else if(this.active_name == "second"){
            this.GetTemplate(response.data.data.items[1])
          }else if(this.active_name == "third"){
            this.GetTemplate(response.data.data.items[2])
          }else if(this.active_name == "four"){
            this.GetTemplate(response.data.data.items[3])
          }

        }
      });
    },
    // 合并行或列的计算方法
    spanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex == 0) {
        if (rowIndex == 0) {
          rowspanNoControl = -1;
        }
        var spanRowCount = this.zone_device_counts[row.zone_id];
        var isFirstRowInGroup = false;
        if (spanRowCount == undefined) {
          var count = 0;
          for (
            let index = 0;
            index < this.opera_device_numbers.length;
            index++
          ) {
            const number = this.opera_device_numbers[index];
            if (number.zone_id == row.zone_id) {
              count++;
            }
          }
          this.zone_device_counts[row.zone_id] = count;
          spanRowCount = count + 0;
          isFirstRowInGroup = true;
        } else {
          isFirstRowInGroup = rowIndex == rowspanNoControl + 1;
          if (rowspanNoControl + spanRowCount == rowIndex) {
            rowspanNoControl = rowIndex;
          }
        }

        if (isFirstRowInGroup) {
          return {
            rowspan: spanRowCount,
            colspan: 1,
          };
        } else
        {
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      }
    },
    search_two: function () {
      if (this.keywords.length == 0) {
        this.patients = this.all_patients;
      } else {
        this.patients = [];
        for (let i = 0; i < this.all_patients.length; i++) {
          if (
            this.all_patients[i].name.indexOf(this.keywords) != -1 ||
            this.all_patients[i].dialysis_no.indexOf(this.keywords) != -1
          ) {
            this.patients.push(this.all_patients[i]);
          }
        }

        if (this.patients.length > 0) {
          this.cur_info.patient_name = this.patients[0].name;
          this.cur_info.mode_name = this.modes[0].name;
          this.cur_info.patient_id = this.patients[0].id;
          this.cur_info.mode_id = this.modes[0].id;
          this.$refs.patient_table.setCurrentRow(this.patients[0]);
          this.$refs.mode_table.setCurrentRow(this.modes[0]);
        }
      }
    },
    search: function () {
      const params = {
        keywords: this.keywords,
        template_id: this.template.id,
      };
      getTemplateScheduleSearchResult(params).then((response) => {
        if (response.data.state == 1) {
          this.schedulePatients = response.data.data.schdules;
          console.log(this.schedulePatients);
          this.searchTableVisible = true;
        }
      });
    },
    //单击
    itemClick: function (row, column, cell, event) {
      console.log('itemClick的数据',row[column.property]);
      if(row[column.property].pid >0 ){
            this.cur_info.patient_id=row[column.property].pid
            this.cur_info.mode_id=row[column.property].treat_mode_id
            this.patient_id_hover = this.cur_info.patient_id;
            this.cur_info.patient_name = row[column.property].name
            this.cur_info.mode_name = row[column.property].treat_mode
            console.log('this.patient_id_hover的数据',this.patient_id_hover);
      }else{
        var item = row[column.property]
        var weekday_timetype = column.property.split('_')
        var weekday = weekday_timetype[0]
        var time_type = weekday_timetype[1]
        var device_number_id = row.id
        if (item.pid == 0) {
          this.$refs.selector_dialog_two.show(weekday, time_type, device_number_id,this.patients)
        } else {
          this.$refs.selector_dialog_two.showWith(item.pid, item.treat_mode_id, weekday, time_type, device_number_id,this.patients)
        }

      }
    },
    // 双击
    itemdblclick (row, column, cell, event){
      if (
        column.property == undefined ||
        /^[1-7]_[1-3]$/.test(column.property) == false
      ) {
        return;
      }
      if (row[column.property] == undefined) {
        return;
      }
      var item = row[column.property];
      var weekday_timetype = column.property.split("_");
      var weekday = weekday_timetype[0];
      var time_type = weekday_timetype[1];
      var device_number_id = row.id;
      if (item.pid != 0) {
        // this.$refs.selector_dialog.show(weekday, time_type, device_number_id)
        this.$refs.selector_dialog.showWith(
          item.pid,
          item.treat_mode_id,
          weekday,
          time_type,
          device_number_id
        );
      }
    },
    will_add_schedule_actionTwo: function (
      patient_id,
      treat_mode,
      weekday,
      time_type,
      device_number_id,
      t_id
    ) {
      var patient = null;
      console.log(patient_id);
      for (let index = 0; index < this.patientList.length; index++) {
        const p = this.patientList[index];
        console.log(p);
        if (p.id == patient_id) {
          console.log(patient_id);
          console.log(p);
          patient = p;
          break;
        }
      }
      console.log(patient);

      if (patient == null) {
        this.smartSaveLoading = false;
        this.$message.error("患者不存在");
        return;
      }

      for (let index = 0; index < this.opera_device_numbers.length; index++) {
        const device_number = this.opera_device_numbers[index];
        for (let t_y = 1; t_y <= 3; t_y++) {
          if (device_number[weekday + "_" + t_y].pid == patient_id) {
            // this.$message.error('一天不能存在多个排班')
            // return
            console.log("~~~~~~");
            this.cancel_schedule_action(weekday, t_y, device_number.id);
          }
        }
      }

      for (let index = 0; index < this.opera_device_numbers.length; index++) {
        const device_number = this.opera_device_numbers[index];
        if (device_number.id == device_number_id) {
          var isDiseaseSame = false;
          var havePatientDisease = patient.contagions.length > 0;
          if (patient.contagions.length > 0 || device_number.zone.type != 1) {
            if (device_number.zone.type != 1) {
              for (let c_i = 0; c_i < patient.contagions.length; c_i++) {
                const contagion = patient.contagions[c_i];
                if (contagion.disease_id == device_number.zone.type) {
                  isDiseaseSame = true;
                }
              }
            }
          } else {
            isDiseaseSame = true;
          }
          // if (isDiseaseSame == false) {
          //   // 此患者没有传染病，与此透析机不匹配，确定在此排班吗?
          //   // 此患者有传染病，与此透析机不匹配，确定在此排班吗?
          //   var msg = havePatientDisease ? '此患者有传染病，与此透析机不匹配，确定在此排班吗?' : '此患者没有传染病，与此透析机不匹配，确定在此排班吗?'
          //   this.$confirm(msg, '提示', { confirmButtonText: '确 定', cancelButtonText: '取 消', type: 'warning' })
          //     .then(() => {
          //       this.add_schedule(patient, device_number, treat_mode, weekday, time_type)
          //     })
          // } else {
          // console.log("33333333")
          this.add_scheduleTwo(
            patient,
            device_number,
            treat_mode,
            weekday,
            time_type,
            t_id
          );
          // }
          return;
        }
      }

      this.$message.error("设备不存在");
    }, 
     will_add_schedule_action_four: function(patient_id, treat_mode, weekday, time_type, device_number_id) {
      var patient = null
      for (let index = 0; index < this.patients.length; index++) {
        const p = this.patients[index]
        if (p.id == patient_id) {
          patient = p
          break
        }
      }
      if (patient == null) {
        this.$message.error('患者不存在')
        return
      }

      for (let index = 0; index < this.opera_device_numbers.length; index++) {
        const device_number = this.opera_device_numbers[index]
        console.log(device_number)
        for (let t_y = 1; t_y <= 3; t_y++) {
          if (t_y == time_type && device_number_id == device_number.id) {
            continue
          }
          if (device_number[weekday + '_' + t_y].pid == patient_id) {
            this.$message.error('同位患者一天内不可有两次排班')
            return
          }
        }
      }

      for (let index = 0; index < this.opera_device_numbers.length; index++) {
        const device_number = this.opera_device_numbers[index]
        if (device_number.id == device_number_id) {
          var isDiseaseSame = false
          var havePatientDisease = patient.contagions.length > 0
          if (patient.contagions.length > 0 || device_number.zone.type != 1) {
            if (device_number.zone.type != 1) {
              for (let c_i = 0; c_i < patient.contagions.length; c_i++) {
                const contagion = patient.contagions[c_i]
                if (contagion.disease_id == device_number.zone.type) {
                  isDiseaseSame = true
                }
              }
            }
          } else {
            isDiseaseSame = true
          }
          if (isDiseaseSame == false) {
            // 此患者没有传染病，与此透析机不匹配，确定在此排班吗?
            // 此患者有传染病，与此透析机不匹配，确定在此排班吗?
            var msg = havePatientDisease ? '此患者有传染病，与此透析机不匹配，确定在此排班吗?' : '此患者没有传染病，与此透析机不匹配，确定在此排班吗?'
            this.$confirm(msg, '提示', { confirmButtonText: '确 定', cancelButtonText: '取 消', type: 'warning' })
              .then(() => {
                // this.add_scheduleTwo(patient, device_number, treat_mode, weekday, time_type)

                this.will_add_schedule_action(
                  patient.id,
                  treat_mode,
                  weekday,
                  time_type,
                  device_number.id,
                  0
                );
                this.saveActionTwo();
              })
          } else {
            // this.add_scheduleTwo(patient, device_number, treat_mode, weekday, time_type)
            this.will_add_schedule_action(
              patient.id,
              treat_mode,
              weekday,
              time_type,
              device_number.id,
              0
            );
            this.saveActionTwo();
          }
          // this.saveActionTwo()
          this.$refs.selector_dialog_two.hide()
          return
        }
      }

      this.$message.error('设备不存在')
    },
    will_add_schedule_action_three: function (
      patient_id,
      treat_mode,
      weekday,
      time_type,
      device_number_id,
      t_id
    ) {
      console.log("111111");
      var patient = null;
      for (let index = 0; index < this.patientList.length; index++) {
        const p = this.patientList[index];
        if (p.id == patient_id) {
          patient = p;
          break;
        }
      }
      if (patient == null) {
        this.$message.error("患者不存在");
        return;
      }
      this.isEdit = true
      for (let index = 0; index < this.opera_device_numbers.length; index++) {
        const device_number = this.opera_device_numbers[index];
        if (device_number.id == device_number_id) {
          var isDiseaseSame = false;
          var havePatientDisease = patient.contagions.length > 0;
          if (patient.contagions.length > 0 || device_number.zone.type != 1) {
            if (device_number.zone.type != 1) {
              for (let c_i = 0; c_i < patient.contagions.length; c_i++) {
                const contagion = patient.contagions[c_i];
                if (contagion.disease_id == device_number.zone.type) {
                  isDiseaseSame = true;
                }
              }
            }
          } else {
            isDiseaseSame = true;
          }
          // if (isDiseaseSame == false) {
          //   // 此患者没有传染病，与此透析机不匹配，确定在此排班吗?
          //   // 此患者有传染病，与此透析机不匹配，确定在此排班吗?
          //   var msg = havePatientDisease ? '此患者有传染病，与此透析机不匹配，确定在此排班吗?' : '此患者没有传染病，与此透析机不匹配，确定在此排班吗?'
          //   this.$confirm(msg, '提示', { confirmButtonText: '确 定', cancelButtonText: '取 消', type: 'warning' })
          //     .then(() => {
          //       this.add_schedule(patient, device_number, treat_mode, weekday, time_type)
          //     })
          // } else {
          // console.log("33333333")
          this.add_scheduleTwo(
            patient,
            device_number,
            treat_mode,
            weekday,
            time_type,
            t_id
          );
          this.saveActionTwo()
          // }
          return;
        }
      }

      this.$message.error("设备不存在");
    },

    will_add_schedule_action: function (
      patient_id,
      treat_mode,
      weekday,
      time_type,
      device_number_id,
      t_id
    ) {
      console.log("111111");

      var patient = null;
      for (let index = 0; index < this.patientList.length; index++) {
        const p = this.patientList[index];
        if (p.id == patient_id) {
          patient = p;
          break;
        }
      }
      if (patient == null) {
        this.$message.error("患者不存在");
        return;
      }
      console.log("22222222");

      for (let index = 0; index < this.opera_device_numbers.length; index++) {
        const device_number = this.opera_device_numbers[index];
        for (let t_y = 1; t_y <= 3; t_y++) {
          if (t_y == time_type && device_number_id == device_number.id) {
            continue;
          }
          if (device_number[weekday + "_" + t_y].pid == patient_id) {
            this.$message.error("同位患者一天内不可有两次排班");
            return;
          }
        }
      }

      for (let index = 0; index < this.opera_device_numbers.length; index++) {
        const device_number = this.opera_device_numbers[index];
        if (device_number.id == device_number_id) {
          var isDiseaseSame = false;
          var havePatientDisease = patient.contagions.length > 0;
          if (patient.contagions.length > 0 || device_number.zone.type != 1) {
            if (device_number.zone.type != 1) {
              for (let c_i = 0; c_i < patient.contagions.length; c_i++) {
                const contagion = patient.contagions[c_i];
                if (contagion.disease_id == device_number.zone.type) {
                  isDiseaseSame = true;
                }
              }
            }
          } else {
            isDiseaseSame = true;
          }
          // if (isDiseaseSame == false) {
          //   // 此患者没有传染病，与此透析机不匹配，确定在此排班吗?
          //   // 此患者有传染病，与此透析机不匹配，确定在此排班吗?
          //   var msg = havePatientDisease ? '此患者有传染病，与此透析机不匹配，确定在此排班吗?' : '此患者没有传染病，与此透析机不匹配，确定在此排班吗?'
          //   this.$confirm(msg, '提示', { confirmButtonText: '确 定', cancelButtonText: '取 消', type: 'warning' })
          //     .then(() => {
          //       this.add_schedule(patient, device_number, treat_mode, weekday, time_type)
          //     })
          // } else {
          // console.log("33333333")
          this.add_schedule(
            patient,
            device_number,
            treat_mode,
            weekday,
            time_type,
            t_id
          );
          // }
          return;
        }
      }

      this.$message.error("设备不存在");
    },
    cancel_schedule_action: function (weekday, time_type, device_number_id) {


      for (let index = 0; index < this.opera_device_numbers.length; index++) {
        const device_number = this.opera_device_numbers[index];
        if (device_number.id == device_number_id) {
          console.log("````````")
          var item = device_number[weekday + "_" + time_type];
          item.pid = 0;
          item.name = "";
          item.treat_mode_id = 0;
          item.treat_mode = "";
        }
      }

      let obj = {
        id: this.template.id,
        data: [],
        data2: [],
      };
      obj.data = this.opera_device_numbers;
      obj.data2 = this.origin_device_numbers;
      this.data.push(obj);
    },
    cancel_schedule_action_two: function (row) {
      let params = {
        id: row.id,
      };
      cancelScheduleTemplate(params).then((response) => {
        if (response.data.state == 1) {
          for (let index = 0; index < this.schedulePatients.length; index++) {
            const sch = this.schedulePatients[index];
            if (sch.id == row.id) {
              this.schedulePatients.splice(index, 1);
            }
          }

          for (
            let index = 0;
            index < this.opera_device_numbers.length;
            index++
          ) {
            const device_number = this.opera_device_numbers[index];
            if (device_number.id == row.device_number_id) {
              var item = device_number[row.weekday + "_" + row.time_type];
              item.pid = 0;
              item.name = "";
              item.treat_mode_id = 0;
              item.treat_mode = "";
            }
          }

          // this.$emit('cancel_sch')
        }
      });
    },
    add_scheduleTwo: function (
      patient,
      device_number,
      treat_mode,
      weekday,
      time_type,
      t_id
    ) {
      var item = device_number[weekday + "_" + time_type];
      var isNew = item.pid == 0;
      item.pid = patient.id;
      item.name = patient.name;
      item.treat_mode_id = treat_mode;
      item.treat_mode = this.treat_modes[treat_mode].name;

      if (isNew) {
        device_number.total += 1;
      }
      if (t_id == 0) {
        let obj = {
          id: this.template.id,
          data: [],
          data2: [],
        };
        obj.data = this.opera_device_numbers;
        obj.data2 = this.origin_device_numbers;
        this.data.push(obj);
      } else {
        let obj = {
          id: t_id,
          data: [],
          data2: [],
        };
        obj.data = this.opera_device_numbers;
        obj.data2 = this.origin_device_numbers;
        this.data.push(obj);
        this.$refs.selector_dialog.hide();
      }
    },

    add_schedule: function (
      patient,
      device_number,
      treat_mode,
      weekday,
      time_type,
      t_id
    ) {
      var item = device_number[weekday + "_" + time_type];
      var isNew = item.pid == 0;
      item.pid = patient.id;
      item.name = patient.name;
      item.treat_mode_id = treat_mode;
      item.treat_mode = this.treat_modes[treat_mode].name;

      if (isNew) {
        device_number.total += 1;
      }
      if (t_id == 0) {
        let obj = {
          id: this.template.id,
          data: [],
          data2: [],
        };
        obj.data = this.opera_device_numbers;
        obj.data2 = this.origin_device_numbers;
        this.data.push(obj);
      } else {
        let obj = {
          id: t_id,
          data: [],
          data2: [],
        };
        obj.data = this.opera_device_numbers;
        obj.data2 = this.origin_device_numbers;
        this.data.push(obj);
        this.$refs.selector_dialog.hide();
      }
    },
    saveActionFour: function () {
      var add_items = [];
      var del_items = [];
      var change_items = [];
      var weekdays = [1, 2, 3, 4, 5, 6, 7]; // 周一-周日
      var time_types = [1, 2, 3]; // 上下晚
      for (let d_n_i = 0; d_n_i < this.opera_device_numbers.length; d_n_i++) {
        const op_d_n = this.opera_device_numbers[d_n_i];
        const or_d_n = this.origin_device_numbers[d_n_i];

        for (let w_i = 0; w_i < weekdays.length; w_i++) {
          const weekday = weekdays[w_i];
          for (let t_i = 0; t_i < time_types.length; t_i++) {
            const time_type = time_types[t_i];

            var item_key = weekday + "_" + time_type;
            var op_item = op_d_n[item_key];
            var or_item = or_d_n[item_key];
            if (op_item.pid == 0 && or_item.pid == 0) {
              continue;
            }
            if (
              op_item.pid == or_item.pid &&
              op_item.treat_mode_id == or_item.treat_mode_id
            ) {
              continue;
            }
            if (op_item.pid == 0) {
              del_items.push({
                device_number_id: op_d_n.id,
                weekday: weekday,
                time_type: time_type,
              });

            } else if (or_item.pid == 0) {
              console.log(op_item.pid);
              add_items.push({
                device_number_id: op_d_n.id,
                patient_id: op_item.pid,
                mode: op_item.treat_mode_id,
                weekday: weekday,
                time_type: time_type,
              });


            } else {
              if (
                op_item.pid != or_item.pid ||
                op_item.treat_mode_id != or_item.treat_mode_id
              ) {
                change_items.push({
                  device_number_id: op_d_n.id,
                  patient_id: op_item.pid,
                  mode: op_item.treat_mode_id,
                  weekday: weekday,
                  time_type: time_type,
                });
              }
            }
          }
        }
      }
      if (
        add_items.length == 0 &&
        del_items.length == 0 &&
        change_items.length == 0
      ) {

      } else {
        var res = [];
        for (var i = 0, arrayLen = add_items.length; i < arrayLen; i++) {
          for (var j = 0, resLen = res.length; j < resLen; j++) {
            if (
              add_items[i].weekday === res[j].weekday &&
              add_items[i].patient_id === res[j].patient_id
            ) {
              break;
            }
          }
          // 如果array[i]是唯一的，那么执行完循环，j等于resLen
          if (j === resLen) {
            res.push(add_items[i]);
          }
        }

        updateSchedules(
          this.template.id,
          JSON.stringify(res),
          JSON.stringify(del_items),
          JSON.stringify(change_items)
        ).then((rs) => {
          var resp = rs.data;
          if (resp.state == 1) {
            // this.opera_device_numbers = this.origin_device_numbers
            this.all_template = resp.data.items
            this.$emit("setTemplate",resp.data.items)
            this.smartSaveLoading = false;
          } else {
            this.$message.error(resp.msg);
          }
        });
      }
    },
    saveActionTwo: function () {
      var add_items = [];
      var del_items = [];
      var change_items = [];
      var weekdays = [1, 2, 3, 4, 5, 6, 7]; // 周一-周日
      var time_types = [1, 2, 3]; // 上下晚
      for (let d_n_i = 0; d_n_i < this.opera_device_numbers.length; d_n_i++) {
        const op_d_n = this.opera_device_numbers[d_n_i];
        const or_d_n = this.origin_device_numbers[d_n_i];

        for (let w_i = 0; w_i < weekdays.length; w_i++) {
          const weekday = weekdays[w_i];
          for (let t_i = 0; t_i < time_types.length; t_i++) {
            const time_type = time_types[t_i];

            var item_key = weekday + "_" + time_type;
            var op_item = op_d_n[item_key];
            var or_item = or_d_n[item_key];
            if (op_item.pid == 0 && or_item.pid == 0) {
              continue;
            }
            if (
              op_item.pid == or_item.pid &&
              op_item.treat_mode_id == or_item.treat_mode_id
            ) {
              continue;
            }
            if (op_item.pid == 0) {
              del_items.push({
                device_number_id: op_d_n.id,
                weekday: weekday,
                time_type: time_type,
              });

            } else if (or_item.pid == 0) {
              console.log(op_item.pid);
              add_items.push({
                device_number_id: op_d_n.id,
                patient_id: op_item.pid,
                mode: op_item.treat_mode_id,
                weekday: weekday,
                time_type: time_type,
              });


            } else {
              if (
                op_item.pid != or_item.pid ||
                op_item.treat_mode_id != or_item.treat_mode_id
              ) {
                change_items.push({
                  device_number_id: op_d_n.id,
                  patient_id: op_item.pid,
                  mode: op_item.treat_mode_id,
                  weekday: weekday,
                  time_type: time_type,
                });
              }
            }
          }
        }
      }
      if (
        add_items.length == 0 &&
        del_items.length == 0 &&
        change_items.length == 0
      ) {

      } else {
        var res = [];
        for (var i = 0, arrayLen = add_items.length; i < arrayLen; i++) {
          for (var j = 0, resLen = res.length; j < resLen; j++) {
            if (
              add_items[i].weekday === res[j].weekday &&
              add_items[i].patient_id === res[j].patient_id
            ) {
              break;
            }
          }
          // 如果array[i]是唯一的，那么执行完循环，j等于resLen
          if (j === resLen) {
            res.push(add_items[i]);
          }
        }

        updateSchedules(
          this.template.id,
          JSON.stringify(res),
          JSON.stringify(del_items),
          JSON.stringify(change_items)
        ).then((rs) => {
          var resp = rs.data;
          if (resp.state == 1) {
            // this.opera_device_numbers = this.origin_device_numbers
            this.all_template = resp.data.items
            this.$emit("setTemplate",resp.data.items)
            this.smartSaveLoading = false;
          } else {
            this.$message.error(resp.msg);
          }
        });
      }
    },
    saveActionThree: function (val,del_data) {
      updateEditSchedules(
        JSON.stringify(val),
        JSON.stringify(del_data),
      ).then((rs) => {
        var resp = rs.data;
        if (resp.state == 1) {
          this.all_template = resp.data.items
          this.$emit("setTemplate",resp.data.items)
          if(this.active_name == 'first'){
            this.GetTemplate(resp.data.items[0])
          }else if(this.active_name == "second"){
            this.GetTemplate(resp.data.items[1])
          }else if(this.active_name == "third"){
            this.GetTemplate(resp.data.items[2])
          }else if(this.active_name == "four"){
            this.GetTemplate(resp.data.items[3])
          }
          this.smartSaveLoading = false;
          this.smartVisible = false;
        } else {
          this.smartSaveLoading = false;
          this.$message.error(resp.msg);
        }
      });
    },
    saveAction: function () {
      var add_items = [];
      var del_items = [];
      var change_items = [];
      var weekdays = [1, 2, 3, 4, 5, 6, 7]; // 周一-周日
      var time_types = [1, 2, 3]; // 上下晚
      for (let d_n_i = 0; d_n_i < this.opera_device_numbers.length; d_n_i++) {
        const op_d_n = this.opera_device_numbers[d_n_i];
        const or_d_n = this.origin_device_numbers[d_n_i];

        for (let w_i = 0; w_i < weekdays.length; w_i++) {
          const weekday = weekdays[w_i];
          for (let t_i = 0; t_i < time_types.length; t_i++) {
            const time_type = time_types[t_i];

            var item_key = weekday + "_" + time_type;
            var op_item = op_d_n[item_key];
            var or_item = or_d_n[item_key];
            if (op_item.pid == 0 && or_item.pid == 0) {
              continue;
            }
            if (
              op_item.pid == or_item.pid &&
              op_item.treat_mode_id == or_item.treat_mode_id
            ) {
              continue;
            }
            if (op_item.pid == 0) {
              del_items.push({
                device_number_id: op_d_n.id,
                weekday: weekday,
                time_type: time_type,
              });

            } else if (or_item.pid == 0) {
              console.log(op_item.pid);
              add_items.push({
                device_number_id: op_d_n.id,
                patient_id: op_item.pid,
                mode: op_item.treat_mode_id,
                weekday: weekday,
                time_type: time_type,
              });

            } else {
              if (
                op_item.pid != or_item.pid ||
                op_item.treat_mode_id != or_item.treat_mode_id
              ) {
                change_items.push({
                  device_number_id: op_d_n.id,
                  patient_id: op_item.pid,
                  mode: op_item.treat_mode_id,
                  weekday: weekday,
                  time_type: time_type,
                });
              }
            }
          }
        }
      }

      var res = [];
      for (var i = 0, arrayLen = add_items.length; i < arrayLen; i++) {
        for (var j = 0, resLen = res.length; j < resLen; j++) {
          if (
            add_items[i].weekday === res[j].weekday &&
            add_items[i].patient_id === res[j].patient_id
          ) {
            break;
          }
        }
        // 如果array[i]是唯一的，那么执行完循环，j等于resLen
        if (j === resLen) {
          res.push(add_items[i]);
        }
      }

      updateSchedules(
        this.template.id,
        JSON.stringify(res),
        JSON.stringify(del_items),
        JSON.stringify(change_items)
      ).then((rs) => {
        var resp = rs.data;
        if (resp.state == 1) {
          // this.$message({
          //   message: '保存成功',
          //   type: 'success'
          // })
          // this.$emit("saveSuccess")
        } else {
          this.$message.error(resp.msg);
        }
        this.saving = false;
        this.is_editing = false;
      });
    },
    // 计算总数
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0 || index === 25) {
          sums[index] = "总数";
          return;
        }
        if (index === 1 || index === 24) {
          sums[index] = data.length;
          return;
        }

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

        if (index === 23) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index];
          return;
        }

        sums[index] = values.reduce((prev, curr) => {
          if (typeof curr["treat_mode_id"] === "undefined") {
            return prev;
          }
          const value = Number(curr["treat_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){
          //表格某列全部数据
        var Mon_M = []
        var Mon_A = []
        var Mon_N = []

        var Tue_M =[]
        var Tue_A = []
        var Tue_N = []

        var Wed_M = []
        var Wed_A = []
        var Wed_N = []

        var Thurs_M = []
        var Thurs_A = []
        var Thurs_N = []

        var Fri_M = []
        var Fri_A = []
        var Fri_N = []

        var Sat_M = []
        var Sat_A = []
        var Sat_N = []

        var Sun_M = []
        var Sun_A = []
        var Sun_N = []

        // 操作后数据
        var Mon_M_One= []
        var Mon_A_One = []
        var Mon_N_One = []

        var Tue_M_One =[]
        var Tue_A_One = []
        var Tue_N_One = []

        var Wed_M_One = []
        var Wed_A_One = []
        var Wed_N_One = []

        var Thurs_M_One = []
        var Thurs_A_One = []
        var Thurs_N_One = []

        var Fri_M_One = []
        var Fri_A_One = []
        var Fri_N_One = []

        var Sat_M_One = []
        var Sat_A_One = []
        var Sat_N_One = []

        var Sun_M_One = []
        var Sun_A_One = []
        var Sun_N_One = []
        for(let j in data){
        if(data[j].hasOwnProperty ('1_1') == true){
          Mon_M.push(data[j]['1_1'].treat_mode)
          Mon_M=Mon_M.filter(item=> item && item.trim())//去掉空字符串
          var countNum =Mon_M.reduce((obj,name)=>{
            if(name in obj){
              obj[name]++
            }else{
              obj[name]=1
            }
            return obj
          },{})
        }

      }
      for(let x in countNum){
        Mon_M_One.push(x + ':' + countNum[x]+"\n")
      }
      var result = [];
      for (var i = 0,len = Mon_M_One.length; i < len; i+=29) {
          var strObjcet = Mon_M_One.slice(i, i+29);
          var str = strObjcet.toString();
          str = str.replace(/,/g, " "); //将所有的逗号 替换成空格
          result.push(str);
      }
      sums[2]="总人数:"+ sums[2] +"\n"+result

      for(let j in data){
        if(data[j].hasOwnProperty ('1_2') == true){
          Mon_A.push(data[j]['1_2'].treat_mode)
          Mon_A=Mon_A.filter(item=> item && item.trim())//去掉空字符串
          var countNum =Mon_A.reduce((obj,name)=>{
            if(name in obj){
              obj[name]++
            }else{
              obj[name]=1
            }
            return obj
          },{})
        }
      }
      for(let x in countNum){
        Mon_A_One.push(x + ':' + countNum[x]+"\n")
      }
      var result = [];
      for (var i = 0,len = Mon_A_One.length; i < len; i+=29) {
          var strObjcet = Mon_A_One.slice(i, i+29);
          var str = strObjcet.toString();
          str = str.replace(/,/g, " "); //将所有的逗号 替换成空格
          result.push(str);
      }
      sums[3]="总人数:"+ sums[3] +"\n"+result

      for(let j in data){
        if(data[j].hasOwnProperty ('1_3') == true){
          Mon_N.push(data[j]['1_3'].treat_mode)
          Mon_N=Mon_N.filter(item=> item && item.trim())
          var countNum =Mon_N.reduce((obj,name)=>{
            if(name in obj){
              obj[name]++
            }else{
              obj[name]=1
            }
            return obj
          },{})
        }
      }
      for(let x in countNum){
        Mon_N_One.push(x + ':' + countNum[x]+"\n")
      }
      var result = [];
      for (var i = 0,len = Mon_N_One.length; i < len; i+=29) {
          var strObjcet = Mon_N_One.slice(i, i+29);
          var str = strObjcet.toString();
          str = str.replace(/,/g, " "); //将所有的逗号 替换成空格
          result.push(str);
      }
      sums[4]="总人数:"+ sums[4] +"\n"+result
      // 星期二
      for(let j in data){
        if(data[j].hasOwnProperty ('2_1') == true){
          Tue_M.push(data[j]['2_1'].treat_mode)
          Tue_M=Tue_M.filter(item=> item && item.trim())
          var countNum =Tue_M.reduce((obj,name)=>{
            if(name in obj){
              obj[name]++
            }else{
              obj[name]=1
            }
            return obj
          },{})
        }
      }
      for(let x in countNum){
        Tue_M_One.push(x + ':' + countNum[x]+"\n")
      }
      var result = [];
      for (var i = 0,len = Tue_M_One.length; i < len; i+=29) {
          var strObjcet = Tue_M_One.slice(i, i+29);
          var str = strObjcet.toString();
          str = str.replace(/,/g, " "); //将所有的逗号 替换成空格
          result.push(str);
      }
      sums[5]="总人数:"+ sums[5] +"\n"+result
      // var newTue_A
      for(let j in data){
        if(data[j].hasOwnProperty ('2_2') == true){
          Tue_A.push(data[j]['2_2'].treat_mode)
          Tue_A=Tue_A.filter(item=> item && item.trim())
          var countNum =Tue_A.reduce((obj,name)=>{
            if(name in obj){
              obj[name]++
            }else{
              obj[name]=1
            }
            return obj
          },{})
        }
      }
      for(let x in countNum){
        Tue_A_One.push(x + ':' + countNum[x]+"\n")
      }
      var result = [];
      for (var i = 0,len = Tue_A_One.length; i < len; i+=29) {
          var strObjcet = Tue_A_One.slice(i, i+29);
          var str = strObjcet.toString();
          str = str.replace(/,/g, " "); //将所有的逗号 替换成空格
          result.push(str);
      }
      sums[6]="总人数:"+ sums[6] +"\n"+result

      for(let j in data){
        if(data[j].hasOwnProperty ('2_3') == true){
          Tue_N.push(data[j]['2_2'].treat_mode)
          Tue_N=Tue_N.filter(item=> item && item.trim())
          var countNum =Tue_N.reduce((obj,name)=>{
            if(name in obj){
              obj[name]++
            }else{
              obj[name]=1
            }
            return obj
          },{})
        }
      }
      for(let x in countNum){
        Tue_N_One.push(x + ':' + countNum[x]+"\n")
      }
      var result = [];
      for (var i = 0,len = Tue_N_One.length; i < len; i+=29) {
          var strObjcet = Tue_N_One.slice(i, i+29);
          var str = strObjcet.toString();
          str = str.replace(/,/g, " "); //将所有的逗号 替换成空格
          result.push(str);
      }
      sums[7]="总人数:"+ sums[7] +"\n"+result
      // 星期三
      for(let j in data){
        if(data[j].hasOwnProperty ('3_1') == true){
          Wed_M.push(data[j]['3_1'].treat_mode)
          Wed_M=Wed_M.filter(item=> item && item.trim())
          var countNum =Wed_M.reduce((obj,name)=>{
            if(name in obj){
              obj[name]++
            }else{
              obj[name]=1
            }
            return obj
          },{})
        }
      }
      for(let x in countNum){
        Wed_M_One.push(x + ':' + countNum[x]+"\n")
      }
      var result = [];
      for (var i = 0,len = Wed_M_One.length; i < len; i+=29) {
          var strObjcet = Wed_M_One.slice(i, i+29);
          var str = strObjcet.toString();
          str = str.replace(/,/g, " "); //将所有的逗号 替换成空格
          result.push(str);
      }
      sums[8]="总人数:"+ sums[8] +"\n"+result

      for(let j in data){
        if(data[j].hasOwnProperty ('3_2') == true){
          Wed_A.push(data[j]['3_2'].treat_mode)
          Wed_A=Wed_A.filter(item=> item && item.trim())
          var countNum =Wed_A.reduce((obj,name)=>{
            if(name in obj){
              obj[name]++
            }else{
              obj[name]=1
            }
            return obj
          },{})
        }
      }
      for(let x in countNum){
        Wed_A_One.push(x + ':' + countNum[x]+"\n")
      }
      var result = [];
      for (var i = 0,len = Wed_A_One.length; i < len; i+=29) {
          var strObjcet = Wed_A_One.slice(i, i+29);
          var str = strObjcet.toString();
          str = str.replace(/,/g, " "); //将所有的逗号 替换成空格
          result.push(str);
      }
      sums[9]="总人数:"+ sums[9]  +"\n"+result

      for(let j in data){
        if(data[j].hasOwnProperty ('3_3') == true){
          Wed_N.push(data[j]['3_3'].treat_mode)
          Wed_N=Wed_N.filter(item=> item && item.trim())
          var countNum =Wed_N.reduce((obj,name)=>{
            if(name in obj){
              obj[name]++
            }else{
              obj[name]=1
            }
            return obj
          },{})
        }
      }
      for(let x in countNum){

        Wed_N_One.push(x + ':' + countNum[x]+"\n")
      }
      var result = [];
      for (var i = 0,len = Wed_N_One.length; i < len; i+=29) {
          var strObjcet = Wed_N_One.slice(i, i+29);
          var str = strObjcet.toString();
          str = str.replace(/,/g, " "); //将所有的逗号 替换成空格
          result.push(str);
      }
      sums[10]="总人数:"+ sums[10] +"\n"+result
       // 星期四
       for(let j in data){
        if(data[j].hasOwnProperty ('4_1') == true){
          Thurs_M.push(data[j]['4_1'].treat_mode)
          Thurs_M=Thurs_M.filter(item=> item && item.trim())
          var countNum =Thurs_M.reduce((obj,name)=>{
            if(name in obj){
              obj[name]++
            }else{
              obj[name]=1
            }
            return obj
          },{})
        }
      }
      for(let x in countNum){
        Thurs_M_One.push(x + ':' + countNum[x]+"\n")
      }
      var result = [];
      for (var i = 0,len = Thurs_M_One.length; i < len; i+=29) {
          var strObjcet = Thurs_M_One.slice(i, i+29);
          var str = strObjcet.toString();
          str = str.replace(/,/g, " "); //将所有的逗号 替换成空格
          result.push(str);
      }
      sums[11]="总人数:"+ sums[11] +"\n"+result

      for(let j in data){
        if(data[j].hasOwnProperty ('4_2') == true){
          Thurs_A.push(data[j]['4_2'].treat_mode)
          Thurs_A=Thurs_A.filter(item=> item && item.trim())
          var countNum =Thurs_A.reduce((obj,name)=>{
            if(name in obj){
              obj[name]++
            }else{
              obj[name]=1
            }
            return obj
          },{})
        }
      }
      for(let x in countNum){
        Thurs_A_One.push(x + ':' + countNum[x]+"\n")
      }
      var result = [];
      for (var i = 0,len = Thurs_A_One.length; i < len; i+=29) {
          var strObjcet = Thurs_A_One.slice(i, i+29);
          var str = strObjcet.toString();
          str = str.replace(/,/g, " "); //将所有的逗号 替换成空格
          result.push(str);
      }
      sums[12]="总人数:"+ sums[12] +"\n"+result

      for(let j in data){
        if(data[j].hasOwnProperty ('4_3') == true){
          Thurs_N.push(data[j]['4_3'].treat_mode)
          Thurs_N=Thurs_N.filter(item=> item && item.trim())
          var countNum =Thurs_N.reduce((obj,name)=>{
            if(name in obj){
              obj[name]++
            }else{
              obj[name]=1
            }
            return obj
          },{})
        }
      }
      for(let x in countNum){

        Thurs_N_One.push(x + ':' + countNum[x]+"\n")
      }
      var result = [];
      for (var i = 0,len = Thurs_N_One.length; i < len; i+=29) {
          var strObjcet = Thurs_N_One.slice(i, i+29);
          var str = strObjcet.toString();
          str = str.replace(/,/g, " "); //将所有的逗号 替换成空格
          result.push(str);
      }
      sums[13]="总人数:"+ sums[13] +"\n"+result
      // 星期五
      for(let j in data){
        if(data[j].hasOwnProperty ('5_1') == true){
          Fri_M.push(data[j]['5_1'].treat_mode)
          Fri_M=Fri_M.filter(item=> item && item.trim())
          var countNum =Fri_M.reduce((obj,name)=>{
            if(name in obj){
              obj[name]++
            }else{
              obj[name]=1
            }
            return obj
          },{})
        }
      }
      for(let x in countNum){
        Fri_M_One.push(x + ':' + countNum[x]+"\n")
      }
      var result = [];
      for (var i = 0,len = Fri_M_One.length; i < len; i+=29) {
          var strObjcet = Fri_M_One.slice(i, i+29);
          var str = strObjcet.toString();
          str = str.replace(/,/g, " "); //将所有的逗号 替换成空格
          result.push(str);
      }
      sums[14]="总人数:"+ sums[14] +"\n"+result

      for(let j in data){
        if(data[j].hasOwnProperty ('5_2') == true){
          Fri_A.push(data[j]['5_2'].treat_mode)
          Fri_A=Fri_A.filter(item=> item && item.trim())
          var countNum =Fri_A.reduce((obj,name)=>{
            if(name in obj){
              obj[name]++
            }else{
              obj[name]=1
            }
            return obj
          },{})
        }
      }
      for(let x in countNum){

        Fri_A_One.push(x + ':' + countNum[x]+"\n")
      }
      var result = [];
      for (var i = 0,len = Fri_A_One.length; i < len; i+=29) {
          var strObjcet = Fri_A_One.slice(i, i+29);
          var str = strObjcet.toString();
          str = str.replace(/,/g, " "); //将所有的逗号 替换成空格
          result.push(str);
      }
      sums[15]="总人数:"+ sums[15] +"\n"+result

      for(let j in data){
        if(data[j].hasOwnProperty ('5_3') == true){
          Fri_N.push(data[j]['5_3'].treat_mode)
          Fri_N=Fri_N.filter(item=> item && item.trim())
          var countNum =Fri_N.reduce((obj,name)=>{
            if(name in obj){
              obj[name]++
            }else{
              obj[name]=1
            }
            return obj
          },{})
        }
      }
      for(let x in countNum){

        Fri_N_One.push(x + ':' + countNum[x]+"\n")
      }
      var result = [];
      for (var i = 0,len = Fri_N_One.length; i < len; i+=29) {
          var strObjcet = Fri_N_One.slice(i, i+29);
          var str = strObjcet.toString();
          str = str.replace(/,/g, " "); //将所有的逗号 替换成空格
          result.push(str);
      }
      sums[16]="总人数:"+ sums[16] +"\n"+result
      // 星期六
      for(let j in data){
        if(data[j].hasOwnProperty ('6_1') == true){
          Sat_M.push(data[j]['6_1'].treat_mode)
          Sat_M=Sat_M.filter(item=> item && item.trim())
          var countNum =Sat_M.reduce((obj,name)=>{
            if(name in obj){
              obj[name]++
            }else{
              obj[name]=1
            }
            return obj
          },{})
        }
      }
      for(let x in countNum){
        Sat_M_One.push(x + ':' + countNum[x]+"\n")
      }
      var result = [];
      for (var i = 0,len = Sat_M_One.length; i < len; i+=29) {
          var strObjcet = Sat_M_One.slice(i, i+29);
          var str = strObjcet.toString();
          str = str.replace(/,/g, " "); //将所有的逗号 替换成空格
          result.push(str);
      }
      sums[17]="总人数:"+ sums[17] +"\n"+result

      for(let j in data){
        if(data[j].hasOwnProperty ('6_2') == true){
          Sat_A.push(data[j]['6_2'].treat_mode)
          Sat_A=Sat_A.filter(item=> item && item.trim())
          var countNum =Sat_A.reduce((obj,name)=>{
            if(name in obj){
              obj[name]++
            }else{
              obj[name]=1
            }
            return obj
          },{})
        }
      }
      for(let x in countNum){

        Sat_A_One.push(x + ':' + countNum[x]+"\n")
      }
      var result = [];
      for (var i = 0,len = Sat_A_One.length; i < len; i+=29) {
          var strObjcet = Sat_A_One.slice(i, i+29);
          var str = strObjcet.toString();
          str = str.replace(/,/g, " "); //将所有的逗号 替换成空格
          result.push(str);
      }
      sums[18]="总人数:"+ sums[18] +"\n"+result

      for(let j in data){
        if(data[j].hasOwnProperty ('6_3') == true){
          Sat_N.push(data[j]['6_3'].treat_mode)
          Sat_N=Sat_N.filter(item=> item && item.trim())
          var countNum =Sat_N.reduce((obj,name)=>{
            if(name in obj){
              obj[name]++
            }else{
              obj[name]=1
            }
            return obj
          },{})
        }
      }
      for(let x in countNum){
        Sat_N_One.push(x + ':' + countNum[x]+"\n")
      }
      var result = [];
      for (var i = 0,len = Sat_N_One.length; i < len; i+=29) {
          var strObjcet = Sat_N_One.slice(i, i+29);
          var str = strObjcet.toString();
          str = str.replace(/,/g, " "); //将所有的逗号 替换成空格
          result.push(str);
      }
      sums[19]="总人数:"+ sums[19]  +"\n"+result
       // 星期天
       for(let j in data){
        if(data[j].hasOwnProperty ('7_1') == true){
          Sun_M.push(data[j]['7_1'].treat_mode)
          Sun_M=Sun_M.filter(item=> item && item.trim())
          var countNum =Sun_M.reduce((obj,name)=>{
            if(name in obj){
              obj[name]++
            }else{
              obj[name]=1
            }
            return obj
          },{})
        }
      }
      for(let x in countNum){
        Sun_M_One.push(x + ':' + countNum[x]+"\n")
      }
      var result = [];
      for (var i = 0,len = Sun_M_One.length; i < len; i+=29) {
          var strObjcet = Sun_M_One.slice(i, i+29);
          var str = strObjcet.toString();
          str = str.replace(/,/g, " "); //将所有的逗号 替换成空格
          result.push(str);
      }
      sums[20]="总人数:"+ sums[20] +"\n"+result

      for(let j in data){
        if(data[j].hasOwnProperty ('7_2') == true){
          Sun_A.push(data[j]['7_2'].treat_mode)
          Sun_A=Sun_A.filter(item=> item && item.trim())
          var countNum =Sun_A.reduce((obj,name)=>{
            if(name in obj){
              obj[name]++
            }else{
              obj[name]=1
            }
            return obj
          },{})
        }
      }
      for(let x in countNum){

        Sun_A_One.push(x + ':' + countNum[x]+"\n")
      }
      var result = [];
      for (var i = 0,len = Sun_A_One.length; i < len; i+=29) {
          var strObjcet = Sun_A_One.slice(i, i+29);
          var str = strObjcet.toString();
          str = str.replace(/,/g, " "); //将所有的逗号 替换成空格
          result.push(str);
      }
      sums[21]="总人数:"+ sums[21] +"\n"+result

      for(let j in data){
        if(data[j].hasOwnProperty ('7_3') == true){
          Sun_N.push(data[j]['7_3'].treat_mode)
          Sun_N=Sun_N.filter(item=> item && item.trim())
          var countNum =Sun_N.reduce((obj,name)=>{
            if(name in obj){
              obj[name]++
            }else{
              obj[name]=1
            }
            return obj
          },{})
        }
      }
      for(let x in countNum){

        Sun_N_One.push(x + ':' + countNum[x]+"\n")
      }
      var result = [];
      for (var i = 0,len = Sun_N_One.length; i < len; i+=29) {
          var strObjcet = Sun_N_One.slice(i, i+29);
          var str = strObjcet.toString();
          str = str.replace(/,/g, " "); //将所有的逗号 替换成空格
          result.push(str);
      }
      sums[22]="总人数:"+ sums[22] +"\n"+result
      // }

      return sums;
    },
    // 右侧表格的列回调
    cellClass({row,column, rowIndex, columnIndex}){
      // console.log('cellClass数据',row);
      if(columnIndex==1&&row.zone.type!=1){
        //
        return "table-row-new-class schedule-table-row Infectious_disease";
      }
      if(columnIndex==0 ||columnIndex==1){
        return ''
      }else{
          if(row[column.property].pid >0 &&
          row[column.property].pid == this.patient_id_hover){
            return 'hover-td'
          }
      }
    },
    // 右侧表格的行回调
    rowClass({row,column, rowIndex, columnIndex}){
      if (row.zone.type == 1) {
        return "table-row-new-class schedule-table-row ";
      } else {
        return "table-row-new-class schedule-table-row infectious";
      };
    },
    // 左侧表格的患者回调
    patientclass({row,column, rowIndex, columnIndex}){
      if(this.cur_info.patient_id == row.id){
        return 'highlight';
      }
    },
    // 左侧表格的透析回调
    modeclass({row,column, rowIndex, columnIndex}){
      if(this.cur_info.mode_id == row.id){
        return 'highlight';
      }
    },
    arraySort(property) {
      return function (a, b) {
        var value1 = a[property];
        var value2 = b[property];
        return value1 - value2;
      };
    },
    unique_id(array) {
      // res用来存储结果
      var res = [];
      for (var i = 0, arrayLen = array.length; i < arrayLen; i++) {
        for (var j = 0, resLen = res.length; j < resLen; j++) {
          if (array[i] === res[j]) {
            break;
          }
        }
        // 如果array[i]是唯一的，那么执行完循环，j等于resLen
        if (j === resLen) {
          res.push(array[i]);
        }
      }
      return res;
    },
  },
};
</script>

<style lang="scss">
.table_contain {
  display: flex;
  
.left_contain {
  width: 14%;
  margin-right: 50px;
  .highlight{
    background-color: #ecf5ff !important;
    color: #3a8ee6 !important;
  }
  .item_touz{
    width: 115px;
    padding: 6px 5px;
    margin: 0px 5px ;
    // border: solid 1px #eee;
    text-align: left;
  }
}

.right_contain {
  width: 83%;
  .el-table td .cell{
    text-align: center !important;
    white-space: pre-wrap;
    padding: 0 0px !important;
  }
  .Infectious_disease{
  background-color: red !important;
  color: white;
}
  .el-table--medium td, .el-table--medium th {
    padding: 5px 0 !important;
}
  .del_table_btn{
    position: absolute;
    right: 0px;
    top: -3px;
    visibility: hidden;
    .el-button {
      width: 15px;
      height: 15px;
      padding: 0px;
    }
  }
}

// .el-table th .cell, .el-table td .cell {
//     margin: 0;
//     padding: 0 0px;
// }
// .el-table--medium td, .el-table--medium th {
//     padding: 5px 0 !important;
// }
}
.temtable_contain{
  margin-top: 30px !important;
}
.infectious{
  color: red !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: normal !important;
}

#tem_table_data {
  /*min-height: calc(100vh - 350px);*/
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: auto;
  margin: 0;
  background: #fff;
  padding: 20px;
  z-index:2000;
  height: 100%;
}

#tem_table_data ::-webkit-scrollbar {
  height: 15px;
}

#tem_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;

.del_table_btn {
  visibility: visible;
}
}
.el-table__body tr .hover-td {
  background-color: #409eff !important;
  color: #fff;
}
}

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

#tem_table_data ::-webkit-scrollbar {
  height: 15px;
}

// .del_table_btn {
//   position: absolute;
//   right: 0px;
//   top: -3px;
//   z-index: 999;
//   visibility: hidden;

// .el-button {
//   width: 15px;
//   height: 15px;
//   padding: 0px;
// }
// }

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

#tem_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;
}

.select_list_arrage {
  width: 105px !important;
}

.checkSearch {
  position: absolute;
  top: 25px;
  right: 120px;
}

.el-dialog__wrapper {
.el-dialog {
/deep/ .el-dialog__header {
  background: #3a8ee6;
  padding: 0px;
  padding: 0 !important;
}
}
}

// .el-dialog__header {
//   padding: 0 !important;
// }
</style>
