<template>
  <div class="main-contain">

    <el-dialog
        title="提示"
        :visible.sync="exportVisible"
        width="40%"
    >

      <div>
        您提交的排班信息已上传成功，系统正在执行导入，请稍候点击当前页面右上角“下载日志”查看导入结果
      </div>

      <span slot="footer" class="dialog-footer">
    <el-button @click="exportVisible = false">取 消</el-button>
    <el-button type="primary" @click="exportVisible = false">确 定</el-button>
  </span>
    </el-dialog>


    <el-dialog
        title="提示"
        :visible.sync="exportLogVisible"
        width="40%"
    >

      <div v-for="(item,index) in logs" :key="index">
        <span> {{ item.export_time | parseTime('{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        <br/>
        <br/>
        <span>{{ getContent(item) }}</span>
        <span>点击</span>
        <span style="color:blue" @click="generateTxt(item)">查看详情</span>
        <br/>
        <br/>
      </div>

      <span slot="footer" class="dialog-footer">
    <el-button @click="exportLogVisible = false">取 消</el-button>
    <el-button type="primary" @click="exportLogVisible = false">确 定</el-button>
  </span>
    </el-dialog>

    <el-dialog
        title="提示"
        :visible.sync="dialogVisible"
        width="40%"
    >
      <span>您提交的文档不是系统标准导入模板，请检查您的文档或重新下载文档</span>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
  </span>
    </el-dialog>


    <el-dialog
        title="提示"
        :visible.sync="msgTipVisible"
        width="40%"
    >
      <span>如果导入成功,会将当前已有的排版会被全部清除,是否继续导入排版数据</span>
      <span slot="footer" class="dialog-footer">
    <el-button @click="msgTipVisible = false">取 消</el-button>
    <el-button type="primary" @click="export_file()">确 定</el-button>
  </span>
    </el-dialog>


    <el-dialog
        title="提示"
        :visible.sync="isExistRepeatVisible"
        width="40%"
    >
      <span>检查到文档中同一天同个人存在多个排班,请检查并修改您的文档,重新导入</span>
      <span slot="footer" class="dialog-footer">
    <el-button @click="isExistRepeatVisible = false">取 消</el-button>
    <el-button type="primary" @click="isExistRepeatVisible = false">确 定</el-button>
  </span>
    </el-dialog>


    <div class="position">
      <bread-crumb :crumbs="crumbs"></bread-crumb>
      <div style="display:flex;align-items:center">

        <!--<upload-excel style="float:right;" :on-success='handleSuccess' :before-upload="beforeUpload"></upload-excel>-->
        <schedule-template-upload-excel style="margin-right:10px;"
                                        :on-success='handleSuccess'></schedule-template-upload-excel>

        <!-- <el-col :span="3" style="text-align: right;"> -->
        <el-button v-loading="downloadLoading" v-if="template_mode"
                   size="small" icon="el-icon-setting" type="primary" @click="import_file()">下载模版
        </el-button>
        <el-button size="small" icon="el-icon-setting" type="primary" @click="setData" v-if="template_mode.mode>0">同步数据</el-button>
        <el-button size="small" icon="el-icon-setting" type="primary" @click="setScheduleTemplateAction">设置</el-button>

        <el-button size="small" icon="el-icon-setting" type="primary" @click="editClick">智能排班</el-button>
        <el-button size="small" icon="el-icon-setting" type="primary" @click="saveClick">保存并退出</el-button>

        <el-button
            @click="generateLog()"
            class="filter-item"
            type="primary"
            size="small"
            v-loading="generateLoading"
        >下载日志
        </el-button>


      </div>
      <!-- </el-col> -->
    </div>
    <div class="app-container">
      <el-tabs v-model="activeName" tab-position="top" @tab-click="handleClick">
<!--        <el-tab-pane name="schedules">-->
<!--          <span slot="label"> 排班信息 </span>-->
<!--          <template-table :editable="false" :device_numbers="device_numbers" :template="this_week_schedules" :is_editing="false"-->
<!--                          :patients="patients" :data="data"></template-table>-->
<!--        </el-tab-pane>-->
        <el-tab-pane name="first" :disabled="template_mode.mode == 0" :label=" first_template.week?'一周模版'+ first_template.week+'周':'一周模版'">
<!--          <span slot="label">-->
<!--          </span>-->

        </el-tab-pane>

        <el-tab-pane :label="  second_template.week?'二周模版' + second_template.week+'周':'二周模版'" name="second" :disabled="template_mode.mode != 2 && template_mode.mode != 3 && template_mode.mode  != 4">
<!--          <template-table   ref="table_two"  :is_editing="is_editing" :editable="true" :device_numbers="device_numbers" :template="first_template"-->
<!--                           :modes="modes"  :patients="patients" @cancel_sch="refresh" :data="data"  :template_mode="template_mode"  @cur_info="cur_info" @saveData="saveData" @event1="changeZone" @saveSuccessTwo="refresh"></template-table>-->

        </el-tab-pane>



        <el-tab-pane :label="  third_template.week? '三周模版' + third_template.week+'周':'三周模版'" name="third" :disabled="template_mode.mode != 3 && template_mode.mode  != 4">
<!--          <span slot="label">三周模版{{ third_template.week?third_template.week+'周':" "}}-->
<!--             <span v-if="schedule.execute_times%2==0">(下一周)</span>-->
<!--             <span v-if="schedule.execute_times%2!=0">(本周)</span>-->
<!--                  <span v-if="schedule.execute_times%4==0">(本周)</span>-->
<!--             <span v-if="schedule.execute_times%4==1">(下一周)</span>-->
<!--            <span v-if="schedule.execute_times%4==2">(下二周)</span>-->
<!--             <span v-if="schedule.execute_times%4==3">(下三周)</span>-->
<!--           </span>-->
<!--          <template-table  ref="table_three"  :is_editing="is_editing" :editable="true" :device_numbers="device_numbers" :template="first_template"-->
<!--                           :modes="modes"  :patients="patients" @cancel_sch="refresh" :data="data"  :template_mode="template_mode"  @cur_info="cur_info" @saveData="saveData" @event1="changeZone" @saveSuccessTwo="refresh"></template-table>-->
        </el-tab-pane>

      <el-tab-pane :label="four_template.week?'四周模版'+four_template.week+'周':'四周模版'" name="four" :disabled="template_mode.mode  != 4 ">
<!--          <span slot="label"> 四周模版 {{ four_template.week?four_template.week+'周':""}}-->
<!--             <span v-if="schedule.execute_times%2==0">(下一周)</span>-->
<!--             <span v-if="schedule.execute_times%2!=0">(本周)</span>-->
<!--            <span v-if="schedule.execute_times%4==0">(本周)</span>-->
<!--             <span v-if="schedule.execute_times%4==1">(下一周)</span>-->
<!--            <span v-if="schedule.execute_times%4==2">(下二周)</span>-->
<!--             <span v-if="schedule.execute_times%4==3">(下三周)</span>-->
<!--           </span>-->
<!--        <template-table   ref="table_four"  :is_editing="is_editing" :editable="true" :device_numbers="device_numbers" :template="first_template"-->
<!--                         :modes="modes"  :patients="patients" @cancel_sch="refresh" :data="data"  :template_mode="template_mode"  @cur_info="cur_info" @saveData="saveData" @event1="changeZone" @saveSuccessTwo="refresh"></template-table>-->

        </el-tab-pane>


<!--        <template-table-two   v-show="activeName =='second'"  ref="table_two"  :is_editing="is_editing" :editable="true" :device_numbers="device_numbers" :template="second_template"-->
<!--                             :modes="modes"  :patients="patients" @cancel_sch="refresh" :data="data"  :template_mode="template_mode"  @cur_info="cur_info" @saveData="saveData"  @saveSuccessTwo="refresh"></template-table-two>-->
<!--        <template-table-three  v-show="activeName =='third'"  ref="table_three" :editable="true" :device_numbers="device_numbers" :template="third_template" :is_editing="is_editing"-->
<!--                                :modes="modes"    :patients="patients" :data="data" @cancel_sch="refresh"  :template_mode="template_mode" @cur_info="cur_info" @saveData="saveData"  @saveSuccessTwo="refresh" ></template-table-three>-->
<!--        <template-table-four  v-show="activeName =='four'" ref="table_four" :editable="true" :device_numbers="device_numbers" :template="four_template" :is_editing="is_editing"-->
<!--                               :modes="modes"    :patients="patients" :data="data" @cancel_sch="refresh"  :template_mode="template_mode" @saveSuccess="refresh" @cur_info="cur_info" @saveData="saveData"   @saveSuccessTwo="refresh"></template-table-four>-->


      </el-tabs>
      <template-table  v-loading="dataloading"  ref="table"  :is_editing="is_editing" :editable="true" :device_numbers="device_numbers" :template="template"
                        :modes="modes"  :patients="patients" @cancel_sch="refresh" :data="data"  :template_mode="template_mode"  @cur_info="cur_info" @saveData="saveData" @event1="changeZone" @saveSuccessTwo="refresh" @setTemplate="setTemplate" @changeLoading="changeLoading"></template-table>


<!--      <template-table  ref="table" :editable="true" :device_numbers="device_numbers" :template="tar_template" :is_editing="is_editing"-->
<!--                      :modes="modes"   :patients="patients" @cancel_sch="refresh" :data="data" :template_mode="template_mode" @saveSuccess="refresh" @cur_info="cur_info" @saveData="saveData" ></template-table>-->







    </div>

    <set-up-template-dialog ref="setup_dialog" :template_mode="template_mode" :origin_mode="origin_mode"
                            @chenge_mode="didChangeTemplateMode"></set-up-template-dialog>
    <el-dialog title="同步排班" width="600px" :visible.sync="newVisible">
      <el-form :model="form" ref="form" label-width="90px" :rules="rules">
        <el-form-item label="同步模板:" v-if="template_mode.mode == 1">
          <el-radio v-model="form.firstWeek" label="1">模板一</el-radio>
        </el-form-item>
        <el-form-item label="同步模板:" v-if="template_mode.mode == 2">
          <el-radio v-model="form.firstWeek" label="1">模板一</el-radio>
          <el-radio v-model="form.firstWeek" label="2">模板二</el-radio>
        </el-form-item>

        <el-form-item label="同步模板:" v-if="template_mode.mode == 3">
          <el-radio v-model="form.firstWeek" label="1">模板一</el-radio>
          <el-radio v-model="form.firstWeek" label="2">模板二</el-radio>
          <el-radio v-model="form.firstWeek" label="3">模板三</el-radio>
        </el-form-item>

        <el-form-item label="同步模板:" v-if="template_mode.mode == 4">
          <el-radio v-model="form.firstWeek" label="1">模板一</el-radio>
          <el-radio v-model="form.firstWeek" label="2">模板二</el-radio>
          <el-radio v-model="form.firstWeek" label="3">模板三</el-radio>
          <el-radio v-model="form.firstWeek" label="4">模板四</el-radio>

        </el-form-item>


        <el-form-item label="同步到 :">
          <el-select v-model="form.copyWeek" placeholder="请选择" required prop="copyWeek">
            <el-option
                v-for="item in typeOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="newVisible=false">取 消</el-button>
        <el-button type="primary" @click="submitAction('form')">保 存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import SetUpTemplateDialog from './components/setup_template_dialog'
import TemplateTable from './components/template_table'
import {getTemplateInitData} from '@/api/schedule_template/sch_template'
import {getTemplateInitDataTwo} from '@/api/schedule_template/sch_template'

import BreadCrumb from '@/xt_pages/components/bread-crumb'
import {
  exportScheduleTemplate,
  getPatientScheduleTemplate,
  getWeekPanels,
  initDate,
  synchroSchedule
} from '@/api/schedule'
import ScheduleTemplateUploadExcel from './components/scheduleTemplateUploadExcel/index'
import {generateLog} from '@/api/config'
import TemplateTableTwo from "./components/template_table_two";
import TemplateTableThree from "./components/template_table_three";
import TemplateTableFour from "./components/template_table_four";

export default {
  name: 'WorkforceTemplate',
  components: {
    TemplateTableFour,
    TemplateTableThree,
    TemplateTableTwo,
    ScheduleTemplateUploadExcel,
    SetUpTemplateDialog,
    TemplateTable,
    BreadCrumb
  },
  data: function () {
    return {
      dataloading:true,
      is_editing:true,
      editable:false,
      data:[],
      crumbs: [
        {path: false, name: '排班管理'},
        {path: 'workforce/template', name: '排班模版'}
      ],
      isTrue:0,
      partitions: {},
      scheduleZone: [],
      activeName: 'first',
      downloadLoading: false,
      isExistRepeatVisible: false,
      exportLogVisible: false,
      exportVisible: false,
      logs: [],
      generateLoading: false,

      days: [],
      msgTipVisible: false,
      dialogVisible: false,
      template_mode: {
        id: 0,
        mode: 0
      },
      cur_info:{
        patient_id:0,
        patient_name:"",
        mode_name:"",
        mode_id:0,


      },
      origin_mode: 0,
      device_numbers: [],
      patients: [],
      modes:[],
      tar_template:{},
      first_template: {
        id: 1,
        items: []
      },
      second_template: {
        id: 2,
        items: []
      },
      third_template:{
        id: 3,
        items: []
      },
      four_template:{
        id: 3,
        items: []
      },
      this_week_schedules: {
        id: 0,
        items: []
      },
      firstWeekData: [],
      secondWeekData: [],
      thirdWeekData:[],
      fourWeekData:[],
      tableList: [],
      newVisible: false,
      weekList: [],
      currentFirstDate1: '',
      weekNum: '',
      weekDayArr: [],
      todayDate: '',
      clen: 7,
      nowYear: new Date().getFullYear(),
      schedule_week: 0,
      newDay: [],
      typeOptions: [],
      timeOptions: [],
      templates:[],
      form: {
        firstWeek: "1",
        secondWeek: "",
        copyWeek: ''

      },
      rules: {
        copyWeek: [{required: true, message: "请选择同步时间段", trigger: "blur"}],
      },
      schedule: {},
    }
  },
  created() {
    this.getPatientScheduleTemplate()
    let year = new Date().getFullYear()
    let month = new Date().getMonth() + 1
    let date = new Date().getDate()
    this.weekNum = this.getYearWeek(year, month, date)
    this.todayDate = this.formatDate(new Date())
    this.setDate(new Date(new Date().setDate((new Date().getDate() - 7))))

    for (var i = 0; i <= 9; i++) {
      this.setDate1(this.addDate(this.currentDate, 7))
    }
    let newNum = 0
    for (let i = 0; i < this.weekList.length; i++) {
      if (this.weekNum + i + 1 <= 53) {
        let num = this.weekNum + i
        let str = this.weekList[i][0] + '~' + this.weekList[i][6]
        this.typeOptions.push({value: i, label: str})
        let stt = this.weekList[i][0] + "~" + this.weekList[i][6]
        this.timeOptions.push({value: i, label: stt})
      } else {

        newNum++
        let str = this.weekList[i][0] + '~' + this.weekList[i][6]
        this.typeOptions.push({value: i, label: str})
        let stt = this.weekList[i][0] + "~" + this.weekList[i][6]
        this.timeOptions.push({value: i, label: stt})
      }

    }
    this.getWeekPanels("")
    this.getInitDate()

    for(let key in this.$store.getters.treatment_mode){
      let obj = {
        id:this.$store.getters.treatment_mode[key].id,
        name:this.$store.getters.treatment_mode[key].name,
      }
      this.modes.push(obj)

    }

  },
  mounted(){
    let params = {
      patitionid:""
    }
    getTemplateInitData(params).then(rs => {
      var resp = rs.data
      if (resp.state == 1) {
        var mode = resp.data.template_mode
        var device_numbers = resp.data.device_numbers
        var templates = resp.data.templates
        this.templates = templates
        if(templates.length > 0){
          this.firstWeekData = templates[0].items
          this.first_template = templates[0]
        }
        if(templates.length > 1){
          this.secondWeekData = templates[1].items
          this.second_template = templates[1]

        }
        if(templates.length > 2){
          this.thirdWeekData = templates[2].items
          this.third_template = templates[2]

        }
        if(templates.length > 3){
          this.fourWeekData = templates[3].items
          this.four_template = templates[3]

        }

        var patients = resp.data.patients
        this.template_mode = mode
        this.origin_mode = mode.mode
        this.device_numbers = device_numbers
        this.patients = patients
        this.tar_template = this.first_template
        this.$refs.table.setEditData(this.patients,this.first_template,this.device_numbers,this.templates,  this.activeName)

        var fakeTemplateItems = []

        this.this_week_schedules.items = fakeTemplateItems

      } else {
        this.$message(resp.msg)
      }
    })


  },
  methods: {
    changeLoading(){
      this.dataloading = false
    },
    setTemplate(items){
      if(this.template_mode.mode == 1){
        this.first_template = items[0]
      }else   if(this.template_mode.mode == 2){
        this.first_template = items[0]
        this.second_template = items[1]
      }else   if(this.template_mode.mode == 3){
        this.first_template = items[0]
        this.second_template = items[1]
        this.third_template = items[2]
      }else   if(this.template_mode.mode == 4){
        this.first_template = items[0]
        this.second_template = items[1]
        this.third_template = items[2]
        this.four_template = items[3]
      }
    },
    handleClick(val){
      this.dataloading = true
      if(this.activeName == "first"){
        this.activeName = "first"
        // this.tar_template = this.first_template

        this.$refs.table.setEditData(this.patients,this.first_template,this.device_numbers,this.templates,  this.activeName)
      }else if(this.activeName == "second"){
        this.activeName = "second"
        // this.tar_template = this.second_template

        this.$refs.table.setEditData(this.patients,this.second_template,this.device_numbers,this.templates,  this.activeName)
      }else if(this.activeName == "third"){
        this.activeName = "third"
        // this.tar_template = this.third_template

        this.$refs.table.setEditData(this.patients,this.third_template,this.device_numbers,this.templates,  this.activeName)
      }else {
        this.activeName = "four"
        // this.tar_template = this.four_template

        this.$refs.table.setEditData(this.patients, this.four_template,this.device_numbers,this.templates,  this.activeName)
      }

    },
    getYearWeek(year, month, date) {
      /*
          dateNow是当前日期
          dateFirst是当年第一天
          dataNumber是当前日期是今年第多少天
          用dataNumber + 当前年的第一天的周差距的和在除以7就是本年第几周
      */
      let dateNow = new Date(year, parseInt(month) - 1, date);
      let dateFirst = new Date(year, 0, 1);
      let dataNumber = Math.round((dateNow.valueOf() - dateFirst.valueOf()) / 86400000);

      return Math.ceil((dataNumber + ((dateFirst.getDay() + 1) - 1)) / 7);
    },
    getTimestamp(time) { //把时间日期转成时间戳
      return (new Date(time)).getTime() / 1000
    },

    formatDate(date) {
      var year = date.getFullYear() + '.'
      var month = (date.getMonth() + 1) + '.';
      var day = date.getDate();
      return year + month + day
    },
    formatDateTwo(date) {
      var year = date.getFullYear() + '.'
      var month = (date.getMonth() + 1) + '.';
      var day = date.getDate();
      return year + month + day
    },
    addDate(date, n) {
      date.setDate(date.getDate() + n);
      return date;
    },
    //
    setDate(date) {
      var week = date.getDay() - 1;
      date = this.addDate(date, week * -1);
      this.currentFirstDate = new Date(date);
      this.currentDate = new Date(date)
      for (var i = 0; i < this.clen; i++) {
        this.weekDayArr.push(this.formatDate(i == 0 ? date : this.addDate(date, 1)))
      }
    },
    setDate1(date) {
      var week = date.getDay() - 1

      date = this.addDate(date, week * -1)

      this.currentDate = new Date(date)
      let arr1 = []
      for (var i = 0; i < this.clen; i++) {
        arr1.push(this.formatDate(i == 0 ? date : this.addDate(date, 1)))
      }
      this.weekList.push(arr1)

      let num = this.weekNum
      this.currentFirstDate1 = num + 1
    },
    getTimestamp(time) { //把时间日期转成时间戳
      return (new Date(time)).getTime() / 1000
    },
    refresh() {
      // this.isTrue.push(1)
      let params = {
        patitionid:""
      }
      getTemplateInitData(params).then(rs => {
        var resp = rs.data
        if (resp.state == 1) {
          var mode = resp.data.template_mode
          var device_numbers = resp.data.device_numbers
          var templates = resp.data.templates
          this.templates = templates
          if(templates.length > 0){
            this.firstWeekData = templates[0].items
            this.first_template = templates[0]
          }
          if(templates.length > 1){
            this.secondWeekData = templates[1].items
            this.second_template = templates[1]

          }
          if(templates.length > 2){
            this.thirdWeekData = templates[2].items
            this.third_template = templates[2]

          }
          if(templates.length > 3){
            this.fourWeekData = templates[3].items
            this.four_template = templates[3]

          }



          var patients = resp.data.patients
          // var schedules = resp.data.schedules

          this.template_mode = mode
          this.origin_mode = mode.mode
          this.device_numbers = device_numbers

          this.patients = patients




          var fakeTemplateItems = []
          this.this_week_schedules.items = fakeTemplateItems

        } else {
          this.$message(resp.msg)
        }
      })


    },
    generateTxt: function (log) {
      var content = ''
      var errlog = log.err_logs
      content = this.getContent(log)
      for (let i = 0; i < errlog.length; i++) {
        if (content.length == 0) {
          content = errlog[i].err_msg
        } else {
          content = content + "\n" + errlog[i].err_msg
        }
      }

      var url = new Blob(['\ufeff' + content], {type: 'text/txt,charset=UTF-8'})
      if (typeof url === 'object' && url instanceof Blob) {
        url = URL.createObjectURL(url) // 创建blob地址
      }
      const aLink = document.createElement('a')
      aLink.href = url
      aLink.download = this.timestampToTime(log.export_time) + '排班模板导入日志.txt'
      aLink.click()

    },
    timestampToTime(timestamp) {
      var date = new Date(timestamp * 1000)//时间戳为10位需*1000，时间戳为13位的话不需乘1000
      var Y = date.getFullYear() + '年'
      var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月'
      var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + '日 '
      var h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + '时'
      var m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + '分'
      var s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds()) + '秒'
      return Y + M + D + h + m + s
    },
    getContent(log) {
      return '您导入的文档共' + log.total_num + '条患者数据' + '，' + '已成功导入' + log.success_num + '条，导入失败' + log.fail_num + '条,'
    },
    generateLog() {
      this.generateLoading = true
      let params = {
        'log_type': 3
      }
      generateLog(params).then(
          response => {
            if (response.data.state === 1) {
              this.generateLoading = false

              this.logs = response.data.data.logs
              this.exportLogVisible = true
            } else {
              this.$message.error(response.data.msg)
              this.generateLoading = false

            }
          }
      ).catch(error => {
        this.generateLoading = false
      })

    },
    getInitDate() {
      initDate().then(response => {
        if (response.data.state == 0) {
          return false
        }

        this.days = response.data.data.days

      })
    },
    handleSuccess({results, header}) {

      let headers = []
      for (let key in results[0]) {
        headers.push(key)
      }
      console.log("hhh2332323232", this.template_mode.mode)
      console.log("result233232233223232323", results)
      console.log("result233232233223232323", headers)

      if (this.template_mode.mode == 1) {
        if (results.length > 0) {

          var isHas_1 = headers.includes('区号')
          console.log(isHas_1)
          var isHas_2 = headers.includes('机号')
          console.log(isHas_2)

          var isHas_3 = headers.includes('周一')
          console.log(isHas_3)

          var isHas_4 = headers.includes('')
          console.log(isHas_4)

          var isHas_5 = headers.includes('_1')
          console.log(isHas_5)

          var isHas_6 = headers.includes('周二')
          console.log(isHas_6)

          var isHas_7 = headers.includes('_2')
          console.log(isHas_7)

          var isHas_8 = headers.includes('_3')
          console.log(isHas_8)

          var isHas_9 = headers.includes('周三')
          console.log(isHas_9)

          var isHas_10 = headers.includes('_4')
          console.log(isHas_1)

          var isHas_11 = headers.includes('_5')
          console.log(isHas_1)

          var isHas_12 = headers.includes('周四')
          console.log(isHas_1)

          var isHas_13 = headers.includes('_6')
          console.log(isHas_1)

          var isHas_14 = headers.includes('_7')
          console.log(isHas_1)

          var isHas_15 = headers.includes('周五')
          console.log(isHas_1)

          var isHas_16 = headers.includes('_8')
          console.log(isHas_1)

          var isHas_17 = headers.includes('_9')
          console.log(isHas_1)

          var isHas_18 = headers.includes('周六')
          console.log(isHas_1)

          var isHas_19 = headers.includes('_10')
          console.log(isHas_1)

          var isHas_20 = headers.includes('_11')
          console.log(isHas_1)

          var isHas_21 = headers.includes('周日')
          console.log(isHas_1)

          var isHas_22 = headers.includes('_12')
          console.log(isHas_1)

          var isHas_23 = headers.includes('_13')
          console.log(isHas_1)

          if (!(isHas_1 && isHas_2 && isHas_3 && isHas_4 && isHas_5 &&
              isHas_6 && isHas_7 && isHas_8 && isHas_9 && isHas_10 &&
              isHas_11 && isHas_12 && isHas_13 && isHas_14 && isHas_15 &&
              isHas_16 && isHas_17 && isHas_18 && isHas_19 && isHas_20 &&
              isHas_21 && isHas_22 && isHas_23)) {

            this.dialogVisible = true
            return
          }
        } else {
          this.dialogVisible = true
          return
        }

      } else if (this.template_mode.mode == 2) {

        if (results.length > 0) {

          var isHas_1 = headers.includes('区号')
          console.log("区号", isHas_1)
          var isHas_2 = headers.includes('机号')
          console.log("机号", isHas_2)

          var isHas_3 = headers.includes('周一')
          console.log(isHas_3)

          var isHas_4 = headers.includes('')
          console.log(isHas_4)

          var isHas_5 = headers.includes('_1')
          console.log(isHas_5)

          var isHas_6 = headers.includes('周二')
          console.log(isHas_6)

          var isHas_7 = headers.includes('_2')
          console.log(isHas_7)

          var isHas_8 = headers.includes('_3')
          console.log(isHas_8)

          var isHas_9 = headers.includes('周三')
          console.log(isHas_9)

          var isHas_10 = headers.includes('_4')
          console.log(isHas_10)

          var isHas_11 = headers.includes('_5')
          console.log(isHas_11)

          var isHas_12 = headers.includes('周四')
          console.log(isHas_12)

          var isHas_13 = headers.includes('_6')
          console.log(isHas_13)

          var isHas_14 = headers.includes('_7')
          console.log(isHas_14)

          var isHas_15 = headers.includes('周五')
          console.log(isHas_15)

          var isHas_16 = headers.includes('_8')
          console.log(isHas_16)

          var isHas_17 = headers.includes('_9')
          console.log(isHas_17)

          var isHas_18 = headers.includes('周六')
          console.log(isHas_18)

          var isHas_19 = headers.includes('_10')
          console.log(isHas_19)

          var isHas_20 = headers.includes('_11')
          console.log(isHas_20)

          var isHas_21 = headers.includes('周日')
          console.log(isHas_21)

          var isHas_22 = headers.includes('_12')
          console.log(isHas_22)

          var isHas_23 = headers.includes('_13')
          console.log(isHas_23)

          var isHas_24 = headers.includes('周一_1')
          console.log(isHas_24)

          var isHas_25 = headers.includes('_14')
          console.log(isHas_25)

          var isHas_26 = headers.includes('_15')
          console.log(isHas_26)

          var isHas_27 = headers.includes('周二_1')
          console.log(isHas_27)

          var isHas_28 = headers.includes('_16')
          console.log(isHas_28)

          var isHas_29 = headers.includes('_17')
          console.log(isHas_29)

          var isHas_30 = headers.includes('周三_1')
          console.log(isHas_30)

          var isHas_31 = headers.includes('_18')
          console.log(isHas_31)

          var isHas_32 = headers.includes('_19')
          console.log(isHas_32)

          var isHas_33 = headers.includes('周四_1')
          console.log(isHas_33)

          var isHas_34 = headers.includes('_20')
          console.log(isHas_34)

          var isHas_35 = headers.includes('_21')
          console.log(isHas_35)

          var isHas_36 = headers.includes('周五_1')
          console.log(isHas_36)

          var isHas_37 = headers.includes('_22')
          console.log(isHas_37)

          var isHas_38 = headers.includes('_23')
          console.log(isHas_38)

          var isHas_39 = headers.includes('周六_1')
          console.log(isHas_39)

          var isHas_40 = headers.includes('_24')
          console.log(isHas_40)

          var isHas_41 = headers.includes('_25')
          console.log(isHas_41)

          var isHas_42 = headers.includes('周日_1')
          console.log(isHas_42)

          var isHas_43 = headers.includes('_26')
          console.log(isHas_43)

          var isHas_44 = headers.includes('_27')
          console.log(isHas_44)


          if (!(isHas_1 && isHas_2 && isHas_3 && isHas_4 && isHas_5 &&
              isHas_6 && isHas_7 && isHas_8 && isHas_9 && isHas_10 &&
              isHas_11 && isHas_12 && isHas_13 && isHas_14 && isHas_15 &&
              isHas_16 && isHas_17 && isHas_18 && isHas_19 && isHas_20 &&
              isHas_21 && isHas_22 && isHas_23 && isHas_24 && isHas_25 &&
              isHas_26 && isHas_27 && isHas_28 && isHas_29 && isHas_30 &&
              isHas_31 && isHas_32 && isHas_33 && isHas_34 && isHas_35 &&
              isHas_36 && isHas_37 && isHas_38 && isHas_39 && isHas_40 &&
              isHas_41 && isHas_42 && isHas_43 && isHas_44)) {
            console.log("~~~~~~~")
            this.dialogVisible = true
            return
          }
        } else {
          console.log("---------")

          this.dialogVisible = true
          return
        }

      } else if (this.template_mode.mode == 3) {

        if (results.length > 0) {

          var isHas_1 = headers.includes('区号')
          console.log("区号", isHas_1)
          var isHas_2 = headers.includes('机号')
          console.log("机号", isHas_2)

          var isHas_3 = headers.includes('周一')
          console.log(isHas_3)

          var isHas_4 = headers.includes('')
          console.log(isHas_4)

          var isHas_5 = headers.includes('_1')
          console.log(isHas_5)

          var isHas_6 = headers.includes('周二')
          console.log(isHas_6)

          var isHas_7 = headers.includes('_2')
          console.log(isHas_7)

          var isHas_8 = headers.includes('_3')
          console.log(isHas_8)

          var isHas_9 = headers.includes('周三')
          console.log(isHas_9)

          var isHas_10 = headers.includes('_4')
          console.log(isHas_1)

          var isHas_11 = headers.includes('_5')
          console.log(isHas_1)

          var isHas_12 = headers.includes('周四')
          console.log(isHas_1)

          var isHas_13 = headers.includes('_6')
          console.log(isHas_1)

          var isHas_14 = headers.includes('_7')
          console.log(isHas_1)

          var isHas_15 = headers.includes('周五')
          console.log(isHas_1)

          var isHas_16 = headers.includes('_8')
          console.log(isHas_1)

          var isHas_17 = headers.includes('_9')
          console.log(isHas_1)

          var isHas_18 = headers.includes('周六')
          console.log(isHas_1)

          var isHas_19 = headers.includes('_10')
          console.log(isHas_1)

          var isHas_20 = headers.includes('_11')
          console.log(isHas_1)

          var isHas_21 = headers.includes('周日')
          console.log(isHas_1)

          var isHas_22 = headers.includes('_12')
          console.log(isHas_1)

          var isHas_23 = headers.includes('_13')
          console.log(isHas_1)

          var isHas_24 = headers.includes('周一_1')
          var isHas_25 = headers.includes('_14')
          var isHas_26 = headers.includes('_15')
          var isHas_27 = headers.includes('周二_1')
          var isHas_28 = headers.includes('_16')
          var isHas_29 = headers.includes('_17')
          var isHas_30 = headers.includes('周三_1')
          var isHas_31 = headers.includes('_18')
          var isHas_32 = headers.includes('_19')
          var isHas_33 = headers.includes('周四_1')
          var isHas_34 = headers.includes('_20')
          var isHas_35 = headers.includes('_21')
          var isHas_36 = headers.includes('周五_1')
          var isHas_37 = headers.includes('_22')
          var isHas_38 = headers.includes('_23')
          var isHas_39 = headers.includes('周六_1')
          var isHas_40 = headers.includes('_24')
          var isHas_41 = headers.includes('_25')
          var isHas_42 = headers.includes('周日_1')
          var isHas_43 = headers.includes('_26')
          var isHas_44 = headers.includes('_27')


          var isHas_45 = headers.includes('周一_2')
          var isHas_46 = headers.includes('_28')
          var isHas_47 = headers.includes('_29')
          var isHas_48 = headers.includes('周二_2')
          var isHas_49 = headers.includes('_30')
          var isHas_50 = headers.includes('_31')
          var isHas_51 = headers.includes('周三_2')
          var isHas_52 = headers.includes('_32')
          var isHas_53 = headers.includes('_33')
          var isHas_54 = headers.includes('周四_2')
          var isHas_55 = headers.includes('_34')
          var isHas_56 = headers.includes('_35')
          var isHas_57 = headers.includes('周五_2')
          var isHas_58 = headers.includes('_36')
          var isHas_59 = headers.includes('_37')
          var isHas_60 = headers.includes('周六_2')
          var isHas_61 = headers.includes('_38')
          var isHas_62 = headers.includes('_39')
          var isHas_63 = headers.includes('周日_2')
          var isHas_64 = headers.includes('_40')
          var isHas_65 = headers.includes('_41')




          if (!(isHas_1 && isHas_2 && isHas_3 && isHas_4 && isHas_5 &&
              isHas_6 && isHas_7 && isHas_8 && isHas_9 && isHas_10 &&
              isHas_11 && isHas_12 && isHas_13 && isHas_14 && isHas_15 &&
              isHas_16 && isHas_17 && isHas_18 && isHas_19 && isHas_20 &&
              isHas_21 && isHas_22 && isHas_23 && isHas_24 && isHas_25 &&
              isHas_26 && isHas_27 && isHas_28 && isHas_29 && isHas_30 &&
              isHas_31 && isHas_32 && isHas_33 && isHas_34 && isHas_35 &&
              isHas_36 && isHas_37 && isHas_38 && isHas_39 && isHas_40 &&
              isHas_41 && isHas_42 && isHas_43 && isHas_44 && isHas_45 &&
              isHas_46 && isHas_47 && isHas_48 && isHas_49 && isHas_50 &&
              isHas_51 && isHas_52 && isHas_53 && isHas_54 && isHas_55 &&
              isHas_56 && isHas_57 && isHas_58 && isHas_59 && isHas_60 &&
              isHas_61 && isHas_62 && isHas_63 && isHas_64 && isHas_65)) {
            this.dialogVisible = true
            return
          }
        } else {
          this.dialogVisible = true
          return
        }

      }else if (this.template_mode.mode == 4) {
        if (results.length > 0) {

          var isHas_1 = headers.includes('区号')
          console.log("区号", isHas_1)
          var isHas_2 = headers.includes('机号')
          console.log("机号", isHas_2)

          var isHas_3 = headers.includes('周一')
          console.log(isHas_3)

          var isHas_4 = headers.includes('')
          console.log(isHas_4)

          var isHas_5 = headers.includes('_1')
          console.log(isHas_5)

          var isHas_6 = headers.includes('周二')
          console.log(isHas_6)

          var isHas_7 = headers.includes('_2')
          console.log(isHas_7)

          var isHas_8 = headers.includes('_3')
          console.log(isHas_8)

          var isHas_9 = headers.includes('周三')
          console.log(isHas_9)

          var isHas_10 = headers.includes('_4')
          console.log(isHas_1)

          var isHas_11 = headers.includes('_5')
          console.log(isHas_1)

          var isHas_12 = headers.includes('周四')
          console.log(isHas_1)

          var isHas_13 = headers.includes('_6')
          console.log(isHas_1)

          var isHas_14 = headers.includes('_7')
          console.log(isHas_1)

          var isHas_15 = headers.includes('周五')
          console.log(isHas_1)

          var isHas_16 = headers.includes('_8')
          console.log(isHas_1)

          var isHas_17 = headers.includes('_9')
          console.log(isHas_1)

          var isHas_18 = headers.includes('周六')
          console.log(isHas_1)

          var isHas_19 = headers.includes('_10')
          console.log(isHas_1)

          var isHas_20 = headers.includes('_11')
          console.log(isHas_1)

          var isHas_21 = headers.includes('周日')
          console.log(isHas_1)

          var isHas_22 = headers.includes('_12')
          console.log(isHas_1)

          var isHas_23 = headers.includes('_13')
          console.log(isHas_1)

          var isHas_24 = headers.includes('周一_1')
          var isHas_25 = headers.includes('_14')
          var isHas_26 = headers.includes('_15')
          var isHas_27 = headers.includes('周二_1')
          var isHas_28 = headers.includes('_16')
          var isHas_29 = headers.includes('_17')
          var isHas_30 = headers.includes('周三_1')
          var isHas_31 = headers.includes('_18')
          var isHas_32 = headers.includes('_19')
          var isHas_33 = headers.includes('周四_1')
          var isHas_34 = headers.includes('_20')
          var isHas_35 = headers.includes('_21')
          var isHas_36 = headers.includes('周五_1')
          var isHas_37 = headers.includes('_22')
          var isHas_38 = headers.includes('_23')
          var isHas_39 = headers.includes('周六_1')
          var isHas_40 = headers.includes('_24')
          var isHas_41 = headers.includes('_25')
          var isHas_42 = headers.includes('周日_1')
          var isHas_43 = headers.includes('_26')
          var isHas_44 = headers.includes('_27')


          var isHas_45 = headers.includes('周一_2')
          var isHas_46 = headers.includes('_28')
          var isHas_47 = headers.includes('_29')
          var isHas_48 = headers.includes('周二_2')
          var isHas_49 = headers.includes('_30')
          var isHas_50 = headers.includes('_31')
          var isHas_51 = headers.includes('周三_2')
          var isHas_52 = headers.includes('_32')
          var isHas_53 = headers.includes('_33')
          var isHas_54 = headers.includes('周四_2')
          var isHas_55 = headers.includes('_34')
          var isHas_56 = headers.includes('_35')
          var isHas_57 = headers.includes('周五_2')
          var isHas_58 = headers.includes('_36')
          var isHas_59 = headers.includes('_37')
          var isHas_60 = headers.includes('周六_2')
          var isHas_61 = headers.includes('_38')
          var isHas_62 = headers.includes('_39')
          var isHas_63 = headers.includes('周日_2')
          var isHas_64 = headers.includes('_40')
          var isHas_65 = headers.includes('_41')



          var isHas_66 = headers.includes('周一_3')
          var isHas_67 = headers.includes('_42')
          var isHas_68 = headers.includes('_43')
          var isHas_69 = headers.includes('周二_3')
          var isHas_70 = headers.includes('_44')
          var isHas_71 = headers.includes('_45')
          var isHas_72 = headers.includes('周三_3')
          var isHas_73 = headers.includes('_46')
          var isHas_74 = headers.includes('_47')
          var isHas_75 = headers.includes('周四_3')
          var isHas_76 = headers.includes('_48')
          var isHas_77 = headers.includes('_49')
          var isHas_78 = headers.includes('周五_3')
          var isHas_79 = headers.includes('_50')
          var isHas_80 = headers.includes('_51')
          var isHas_81 = headers.includes('周六_3')
          var isHas_82 = headers.includes('_52')
          var isHas_83 = headers.includes('_53')
          var isHas_84 = headers.includes('周日_3')
          var isHas_85 = headers.includes('_54')




          if (!(isHas_1 && isHas_2 && isHas_3 && isHas_4 && isHas_5 &&
              isHas_6 && isHas_7 && isHas_8 && isHas_9 && isHas_10 &&
              isHas_11 && isHas_12 && isHas_13 && isHas_14 && isHas_15 &&
              isHas_16 && isHas_17 && isHas_18 && isHas_19 && isHas_20 &&
              isHas_21 && isHas_22 && isHas_23 && isHas_24 && isHas_25 &&
              isHas_26 && isHas_27 && isHas_28 && isHas_29 && isHas_30 &&
              isHas_31 && isHas_32 && isHas_33 && isHas_34 && isHas_35 &&
              isHas_36 && isHas_37 && isHas_38 && isHas_39 && isHas_40 &&
              isHas_41 && isHas_42 && isHas_43 && isHas_44 && isHas_45 &&
              isHas_46 && isHas_47 && isHas_48 && isHas_49 && isHas_50 &&
              isHas_51 && isHas_52 && isHas_53 && isHas_54 && isHas_55 &&
              isHas_56 && isHas_57 && isHas_58 && isHas_59 && isHas_60 &&
              isHas_61 && isHas_62 && isHas_63 && isHas_64 && isHas_65 && isHas_66 && isHas_67 &&
              isHas_68 && isHas_69 && isHas_70 && isHas_71 && isHas_72 &&
              isHas_73 && isHas_74 && isHas_75 && isHas_76 && isHas_77&&
              isHas_78 && isHas_79 && isHas_80 && isHas_81 && isHas_82 &&
              isHas_83 && isHas_84 && isHas_85 )) {
            this.dialogVisible = true
            return
          }
        } else {
          this.dialogVisible = true
          return
        }

      }else {
        this.dialogVisible = true
        return
      }

      let is_system_zone = true
      let is_device_number = true
      let zones = []
      let deviceNumber = []

      for (let i = 0; i < results.length; i++) {
        if (results[i + 1]) {
          zones.push(results[i + 1]['区号'])
        }
        if (results[i + 1]) {
          deviceNumber.push(results[i + 1]['机号'])
        }

      }

      const obj = {}
      zones = zones.reduce((cur, next) => {
        obj[next] ? '' : obj[next] = true && cur.push(next)
        return cur
      }, []) // 设置cur默认类型为数组，并且初始值为空的数组

      const obj2 = {}
      deviceNumber = deviceNumber.reduce((cur, next) => {
        obj2[next] ? '' : obj2[next] = true && cur.push(next)
        return cur
      }, []) // 设置cur默认类型为数组，并且初始值为空的数组

      var total_zones = []
      var total_device_number = []

      for (let key in this.partitions) {
        total_zones.push(this.partitions[key].name)
      }

      for (let key in this.partitions) {
        var jihaos = this.partitions[key].jihaos
        for (let i = 0; i < jihaos.length; i++) {
          total_device_number.push(jihaos[i].number)
        }
      }

      for (let i = 0; i < zones.length; i++) {
        if (!total_zones.includes(zones[i])) {
          is_system_zone = false
        }
      }

      for (let i = 0; i < deviceNumber.length; i++) {
        if (!total_device_number.includes(deviceNumber[i])) {
          is_device_number = false
        }
      }

      let tempObj = null
      if (results.length > 0) {
        tempObj = results[0]
      }

      let datas = []
      for (let i = 0; i < results.length; i++) {
        for (let key in results[i + 1]) {

          let tempObjTwo = {partition_name: '', device_number_name: ''}
          //去除空的
          if (key != '区号' && key != '机号' && results[i + 1][key] != "") {
            let obj = {}
            let result = results[i + 1][key].replace(/\s/g, "")
            console.log(result)
            let result_arr = result.split('-')

            obj['name'] =result_arr[0]
            obj['treat_mode'] = this.getModeId(result_arr[1])
            if (tempObj[key] == '上午') {
              obj['schedule_type'] = 1
            } else if (tempObj[key] == '下午') {
              obj['schedule_type'] = 2
            } else if (tempObj[key] == '晚上') {
              obj['schedule_type'] = 3
            } else {

              obj['schedule_type'] = 0

            }
            obj['schedule_week'] = this.getWeekByResultsStr(key)
            obj['schedule_date'] = this.getDateByResultsStr(key)
            obj['template_id'] = this.getTemplateByWeek(key)
            obj['row'] = this.getRow(key)
            tempObjTwo = obj
          }

          tempObjTwo['partition_name'] = results[i + 1]['区号']
          tempObjTwo['device_number_name'] = results[i + 1]['机号']
          tempObjTwo['index'] = i + 3
          console.log(tempObjTwo['name'])
          console.log(tempObjTwo['schedule_week'])
          console.log(tempObjTwo['schedule_type'])
          console.log(tempObjTwo['schedule_date'])

          if (tempObjTwo['schedule_week'] != undefined && tempObjTwo['name'] != undefined && tempObjTwo['schedule_type'] != undefined && tempObjTwo['schedule_date'] != undefined) {
            var current_date = new Date()
            var m_year = current_date.getFullYear()
            var m_month = current_date.getMonth() + 1
            m_month = m_month < 10 ? '0' + m_month.toString() : m_month.toString()
            var m_date = current_date.getDate() < 10 ? '0' + current_date.getDate().toString() : current_date.getDate().toString()
            var current_date_two = new Date(m_year + '-' + m_month + '-' + m_date)
            console.log(tempObjTwo)
            datas.push(tempObjTwo)

          }

        }

      }
      console.log(datas)

      let date_arr = []
      //校验文档是否规范
      for (let i = 0; i < datas.length; i++) {
        if (datas[i].schedule_date !== '0') {
          date_arr.push(datas[i].schedule_date)
        }

        if (datas[i].device_number_name == undefined) {
          is_device_number = false

        }

        if (datas[i].partition_name == undefined) {
          is_system_zone = false

        }

        if (datas[i].schedule_date === '0') {
          is_system_zone = false

        }

        if (datas[i].schedule_week === '0') {
          is_system_zone = false

        }

        if (datas[i].schedule_type === 0) {
          is_system_zone = false

        }
      }

      //校验文档中同一天同个人是否存在多个排班
      let is_exist_repeat = false
      const obj3 = {}
      date_arr = date_arr.reduce((cur, next) => {
        obj3[next] ? '' : obj3[next] = true && cur.push(next)
        return cur
      }, []) // 设置cur默认类型为数组，并且初始值为空的数组

      let tempObjArr = []
      for (let i = 0; i < date_arr.length; i++) {
        let obj = {}
        let key = date_arr[i]
        let value = []

        for (let b = 0; b < datas.length; b++) {
          if (key == datas[b].schedule_date) {
            value.push(datas[b].name)
          }
        }
        obj[key] = value
        tempObjArr.push(obj)
      }

      for (let i = 0; i < tempObjArr.length; i++) {
        for (let key in tempObjArr[i]) {
          let arr = tempObjArr[i][key]
          const obj = {}
          arr = arr.reduce((cur, next) => {
            obj[next] ? '' : obj[next] = true && cur.push(next)
            return cur
          }, []) // 设置cur默认类型为数组，并且初始值为空的数组

          //这个地方
          console.log(tempObjArr[i][key])
          console.log(arr)

          if (tempObjArr[i][key].length > arr.length) {    //比对原数组和去重后的原数组总数，不同的话则存在重复元素
            is_exist_repeat = true

          }
        }
      }

      let isHeader = true

      if (this.template_mode.mode == 1) {
        if (headers.length > 23) {
          isHeader = false
        }

      } else if (this.template_mode.mode == 2) {
        if (headers.length > 44) {
          isHeader = false
        }

      }else if (this.template_mode.mode == 3) {
        if (headers.length > 65) {
          isHeader = false
        }

      }else if (this.template_mode.mode == 4) {
        if (headers.length > 86) {
          isHeader = false
        }

      }
      console.log(isHeader)
      console.log(is_system_zone)
      console.log(is_device_number)

      if (!is_system_zone || !is_device_number) {
        console.log("123123123123")
        this.dialogVisible = true

      } else {


        if (is_exist_repeat) {
          this.isExistRepeatVisible = true

        } else {

          this.$alert('您提交的排班信息已上传成功，系统正在执行导入，请稍候点击当前页面右上角“下载日志”查看导入结果', '上传成功', {
            confirmButtonText: '确定',
            callback: action => {

            }
          });

          let params = {
            schedule: datas
          }

          //今天的时间
          var day2 = new Date()
          day2.setTime(day2.getTime())
          var month = day2.getMonth() + 1 < 10 ? '0' + (day2.getMonth() + 1).toString() : (day2.getMonth() + 1).toString()
          var day = day2.getDate() < 10 ? '0' + (day2.getDate()).toString() : (day2.getMonth() + 1).toString()

          exportScheduleTemplate(params).then(response => {
            if (response.data.state == 0) {
              return false
            }
            this.$message.success("导入成功")
            // this.getWeekPanels("")
            this.getInitData()

          })
        }

      }

    },getInitData(){
      let params = {
        patitionid:""
      }
      getTemplateInitData(params).then(rs => {
        var resp = rs.data
        if (resp.state == 1) {
          var mode = resp.data.template_mode
          var device_numbers = resp.data.device_numbers
          var templates = resp.data.templates
          var patients = resp.data.patients
          var schedules = resp.data.schedules

          this.template_mode = mode
          this.origin_mode = mode.mode
          this.device_numbers = device_numbers

          this.patients = patients

          this.first_template = templates[0]
          this.second_template = templates[1]
          this.templates = templates
          this.third_template = templates[2]
          this.four_template = templates[3]
          if(this.activeName == "first"){
            this.$refs.table.setEditData(this.patients,this.first_template,this.device_numbers,this.templates,  this.activeName)


          }else if(this.activeName == "second"){

            this.$refs.table.setEditData(this.patients,this.second_template,this.device_numbers,this.templates,  this.activeName)


          }else if(this.activeName == "third"){

            this.$refs.table.setEditData(this.patients,this.third_template,this.device_numbers,this.templates,  this.activeName)


          }else if(this.activeName == "four"){

            this.$refs.table.setEditData(this.patients,this.four_template,this.device_numbers,this.templates,  this.activeName)


          }


          // var fakeTemplateItems = []
          // for (let index = 0; index < schedules.length; index++) {
          //   const schedule = schedules[index]
          //   var item = {}
          //   this.$set(item, 'id', schedule.id)
          //   this.$set(item, 'template_id', 0)
          //   this.$set(item, 'device_number_id', schedule.bed_id)
          //   this.$set(item, 'treat_mode', schedule.mode_id)
          //   this.$set(item, 'weekday', schedule.schedule_week)
          //   this.$set(item, 'time_type', schedule.schedule_type)
          //   var patient = {}
          //   this.$set(patient, 'id', schedule.patient_id)
          //   this.$set(patient, 'name', schedule.patient)
          //   this.$set(item, 'patient', patient)
          //
          //   fakeTemplateItems.push(item)
          // }
          // this.this_week_schedules.items = fakeTemplateItems

        } else {
          this.$message(resp.msg)
        }
      })

    }, getTemplateByWeek(key) {

      switch (key) {
        case '周一' : //本周一
          return this.first_template.id
          break
        case  '': //本周一
          return this.first_template.id
          break
        case  '_1': //本周一
          return this.first_template.id
          break
        case '周一_1': //下周一
          return this.second_template.id
          break
        case '_14': //下周一
          return this.second_template.id
          break
        case   '_15': //下周一
          return this.second_template.id
          break

        case '周一_2': //下周一
          return this.third_template.id
          break
        case '_28': //下周一
          return this.third_template.id
          break
        case   '_29': //下周一
          return this.third_template.id
          break

        case '周一_3': //下周一
          return this.four_template.id
          break
        case '_42': //下周一
          return this.four_template.id
          break
        case   '_43': //下周一
          return this.four_template.id
          break




        case '周二' : //本周二
          return this.first_template.id

          break

        case  '_2': //本周二
          return this.first_template.id

          break

        case '_3': //本周二
          return this.first_template.id

          break

        case '周二_1'://下周二
          return this.second_template.id

          break

        case  '_16' ://下周二
          return this.second_template.id

          break

        case  '_17'://下周二
          return this.second_template.id

          break

        case '周二_2'://下周二
          return this.third_template.id
          break

        case  '_30' ://下周二
          return this.third_template.id
          break

        case  '_31'://下周二
          return this.third_template.id
          break

        case '周二_3'://下周二
          return this.four_template.id
          break

        case  '_44' ://下周二
          return this.four_template.id
          break

        case  '_45'://下周二
          return this.four_template.id
          break


        case '周三' : //本周三
          return this.first_template.id
          break

        case  '_4': //本周三
          return this.first_template.id
          break

        case '_5': //本周三
          return this.first_template.id
          break

        case '周三_1': //下周三
          return this.second_template.id
          break

        case  '_18' : //下周三
          return this.second_template.id
          break

        case '_19': //下周三
          return this.second_template.id
          break

        case '周三_2': //下周三
          return this.third_template.id
          break

        case  '_32' : //下周三
          return this.third_template.id
          break

        case '_33': //下周三
          return this.third_template.id
          break


        case '周三_3': //下周三
          return this.four_template.id
          break

        case  '_46' : //下周三
          return this.four_template.id
          break

        case '_47': //下周三
          return this.four_template.id
          break



        case '周四':
          return this.first_template.id

          break

        case '_6' :
          return this.first_template.id

          break

        case  '_7':
          return this.first_template.id

          break

        case '周四_1':

          return this.second_template.id

          break

        case '_20' :

          return this.second_template.id

          break

        case  '_21':

          return this.second_template.id

          break


        case '周四_2':

          return this.third_template.id

          break

        case '_34' :

          return this.third_template.id

          break

        case  '_35':

          return this.third_template.id

          break


        case '周四_3':

          return this.four_template.id

          break

        case '_48' :

          return this.four_template.id

          break

        case  '_49':

          return this.four_template.id

          break






        case '周五':
          return this.first_template.id

          break

        case  '_8':
          return this.first_template.id

          break

        case  '_9':
          return this.first_template.id

          break
        case '周五_1' :
          return this.second_template.id

          break

        case '_22' :
          return this.second_template.id

          break

        case  '_23':
          return this.second_template.id

          break

        case '周五_2' :
          return this.third_template.id

          break

        case '_36' :
          return this.third_template.id

          break

        case  '_37':
          return this.third_template.id

          break

        case '周五_3' :
          return this.four_template.id

          break

        case '_50' :
          return this.four_template.id

          break

        case  '_51':
          return this.four_template.id

          break


        case '周六' :
          return this.first_template.id

          break

        case  '_10' :
          return this.first_template.id

          break

        case '_11':
          return this.first_template.id

          break
        case '周六_1' :
          return this.second_template.id

          break

        case  '_24' :
          return this.second_template.id

          break

        case  '_25':
          return this.second_template.id

          break

        case '周六_2' :
          return this.third_template.id

          break

        case  '_38' :
          return this.third_template.id

          break

        case  '_39':
          return this.third_template.id

          break


        case '周六_3' :
          return this.four_template.id

          break

        case  '_52' :
          return this.four_template.id

          break

        case  '_53':
          return this.four_template.id

          break


        case '周日' :
          return this.first_template.id

          break

        case  '_12' :
          return this.first_template.id

          break

        case  '_13':
          return this.first_template.id

          break
        case '周日_1' :
          return this.second_template.id
          break

        case  '_26' :
          return this.second_template.id
          break

        case  '_27':
          return this.second_template.id
          break


        case '周日_2' :
          return this.third_template.id
          break

        case  '_40' :
          return this.third_template.id
          break

        case  '_41':
          return this.third_template.id
          break

        case '周日_3' :
          return this.four_template.id
          break

        case  '_54' :
          return this.four_template.id
          break

        case  '_55':
          return this.four_template.id
          break

      }

    },
    getWeekByResultsStr(key) {

      switch (key) {
        case '周一':
          return '1'
          break
        case  '周一_1':
          return '1'
          break

        case   '周一_2':
          return '1'
          break
        case   '周一_3':
          return '1'
          break

        case   '':
          return '1'
          break

        case    '_1':
          return '1'
          break

        case   '_14':
          return '1'
          break

        case   '_15':
          return '1'
          break

        case    '_28':
          return '1'
          break

        case   '_29':
          return '1'
          break
        case    '_42':
          return '1'
          break

        case   '_43':
          return '1'
          break

        case '周二' :
          return '2'
          break
        case '周二_1':
          return '2'
          break
        case '周二_2' :
          return '2'
          break
        case '周二_3' :
          return '2'
          break

        case '_2':
          return '2'
          break

        case '_3':
          return '2'
          break

        case  '_16' :
          return '2'
          break

        case '_17' :
          return '2'
          break

        case '_30':
          return '2'
          break

        case  '_31':
          return '2'
          break
        case '_44':
          return '2'
          break

        case  '_45':
          return '2'
          break

        case '周三':
          return '3'
          break
        case '周三_1':
          return '3'
          break
        case  '周三_2':
          return '3'
          break
        case  '周三_3':
          return '3'
          break
        case  '_4' :
          return '3'
          break
        case '_5'  :
          return '3'
          break
        case  '_18'  :
          return '3'
          break
        case  '_19' :
          return '3'
          break
        case  '_32' :
          return '3'
          break
        case  '_33' :
          return '3'
          break
        case  '_46' :
          return '3'
          break
        case  '_47' :
          return '3'
          break

        case '周四':
          return '4'
          break

        case '周四_1' :
          return '4'
          break
        case'周四_2' :
          return '4'
          break
        case'周四_3' :
          return '4'
          break
        case  '_6' :
          return '4'
          break

        case  '_7':
          return '4'
          break
        case   '_20':
          return '4'
          break
        case  '_21':
          return '4'
          break
        case   '_34':
          return '4'
          break
        case   '_35':
          return '4'
          break
        case   '_48':
          return '4'
          break
        case   '_49':
          return '4'
          break

        case '周五' :
          return '5'
          break

        case  '周五_1':
          return '5'
          break
        case  '周五_2' :
          return '5'
          break
        case  '周五_3' :
          return '5'
          break
        case '_8':
          return '5'
          break
        case '_9' :
          return '5'
          break
        case '_22' :
          return '5'
          break
        case '_23':
          return '5'
          break
        case  '_36':
          return '5'
          break
        case  '_37':
          return '5'
          break
        case  '_50':
          return '5'
          break
        case  '_51':
          return '5'
          break

        case '周六':
          return '6'
          break
        case  '周六_1':
          return '6'
          break
        case  '周六_2' :
          return '6'
          break
        case  '周六_3' :
          return '6'
          break
        case  '_10' :
          return '6'
          break
        case  '_11':
          return '6'
          break
        case  '_24' :
          return '6'
          break
        case '_25' :
          return '6'
          break
        case  '_38' :
          return '6'
          break
        case  '_39':
          return '6'
          break

        case  '_52' :
          return '6'
          break
        case  '_53':
          return '6'
          break


        case '周日':
          return '7'
          break
        case  '周日_1' :
          return '7'
          break
        case '周日_2' :
          return '7'
          break
        case '周日_3' :
          return '7'
          break
        case '_12' :
          return '7'
          break
        case '_13' :
          return '7'
          break
        case  '_26':
          return '7'
          break
        case '_27':
          return '7'
          break
        case '_40' :
          return '7'
          break
        case  '_41':
          return '7'
          break

        case '_54' :
          return '7'
          break
        case  '_55':
          return '7'
          break

        default:
          return '0'
          break

      }

    },
    getRow(key) {
      switch (key) {
        case '周一' : //本周一
          return 'C'
          break

        case  '': //本周一
          return 'D'
          break

        case  '_1': //本周一
          return 'E'
          break

        case '周一_1': //下周一

          return 'X'

          break

        case '_14': //下周一

          return 'Y'
          break

        case   '_15': //下周一
          return 'Z'
          break

        case '周一_2' : //下下周一

          return 'AS'
          break

        case  '_28': //下下周一

          return 'AT'
          break

        case '_29': //下下周一

          return 'AU'
          break


        case '周一_3' : //下下下周一

          return 'BN'
          break

        case  '_42': //下下下周一

          return 'BO'
          break

        case '_43': //下下下周一

          return 'BP'
          break





        case '周二' : //本周二
          return 'F'
          break

        case  '_2': //本周二
          return 'G'
          break

        case '_3': //本周二
          return 'H'
          break

        case '周二_1'://下周二
          return 'AA'

          break

        case  '_16' ://下周二
          return 'AB'

          break

        case  '_17'://下周二
          return 'AC'

          break

        case '周二_2' ://下下周二
          return 'AV'

          break

        case '_30' ://下下周二
          return 'AW'

          break

        case '_31'://下下周二
          return 'AX'
          break

        case '周二_3' ://下xia下周二
          return 'BQ'

          break

        case '_44' ://下xia下周二
          return 'BR'

          break

        case '_45'://下xia下周二
          return 'BS'
          break

        case '周三' : //本周三
          return 'I'

          break

        case  '_4': //本周三
          return 'J'
          break

        case '_5': //本周三
          return 'K'
          break

        case '周三_1': //下周三
          return 'AD'

          break

        case  '_18' : //下周三
          return 'AE'

          break

        case '_19': //下周三
          return 'AF'

          break

        case '周三_2' : //下下周三
          return 'AY'

          break

        case '_32' : //下下周三
          return 'AZ'

          break

        case  '_33': //下下周三
          return 'BA'

          break

        case '周三_3' : //下下周三
          return 'BT'

          break

        case '_46' : //下下周三
          return 'BU'

          break

        case  '_47': //下下周三
          return 'BV'

          break

        case '周四':
          return 'L'

          break

        case '_6' :
          return 'M'

          break

        case  '_7':
          return 'N'

          break

        case '周四_1':
          return 'AG'

          break

        case '_20' :
          return 'AH'

          break

        case  '_21':

          return 'AI'

          break

        case '周四_2' :

          return 'BB'

          break

        case '_34':

          return 'BC'

          break

        case  '_35':

          return 'BD'

          break

        case '周四_3' :

          return 'BW'

          break

        case '_48':

          return 'BX'

          break

        case  '_49':

          return 'BY'

          break


        case '周五':
          return 'O'

          break

        case  '_8':
          return 'P'

          break

        case  '_9':
          return 'Q'
          break
        case '周五_1' :
          return 'AJ'
          break

        case '_22' :
          return 'AK'

          break

        case  '_23':
          return 'AL'

          break
        case '周五_2' :
          return 'BE'

          break

        case '_36':
          return 'BF'

          break

        case  '_37':
          return 'BG'

          break

        case '周五_3' :
          return 'BZ'

          break

        case '_50':
          return 'CA'

          break

        case  '_51':
          return 'CB'

          break

        case '周六' :
          return 'R'

          break

        case  '_10' :
          return 'S'

          break

        case '_11':
          return 'T'

          break
        case '周六_1' :
          return 'AM'

          break

        case  '_24' :
          return 'AN'

          break

        case  '_25':
          return 'AO'

          break

        case '周六_2' :
          return 'BH'

          break

        case '_38' :
          return 'BI'

          break

        case '_39':
          return 'BJ'

          break

        case '周六_3' :
          return 'CC'

          break

        case '_52' :
          return 'CD'

          break

        case '_53':
          return 'CE'

          break
        case '周日' :
          return 'U'

          break

        case  '_12' :
          return 'V'

          break

        case  '_13':
          return 'W'

          break
        case '周日_1' :
          return 'AP'

          break

        case  '_26' :
          return 'AQ'

          break

        case  '_27':
          return 'AR'

          break
        case '周日_2':
          return 'BK'

          break

        case '_40':
          return 'BL'

          break

        case '_41':
          return 'BM'
          break
        case '周日_3':
          return 'CF'

          break

        case '_54':
          return 'CG'

          break

        case '_55':
          return 'CH'
          break
      }

    },
    getDateByResultsStr(key) {

      switch (key) {
        case '周一' : //本周一

          return this.days[0]
          break

        case  '': //本周一
          return this.days[0]

          break

        case  '_1': //本周一
          return this.days[0]
          break

        case '周一_1': //下周一
          return this.days[7]

          break

        case '_14': //下周一

          return this.days[7]

          break

        case   '_15': //下周一

          return this.days[7]

          break

        case '周一_2' : //下下周一

          return this.days[14]

          break

        case  '_28': //下下周一

          return this.days[14]

          break

        case '_29': //下下周一

          return this.days[14]

          break

        case '周一_3' : //下下下周一

          return this.days[21]

          break

        case  '_42': //下下下周一

          return this.days[21]

          break

        case '_43': //下下下周一

          return this.days[21]

          break





        case '周二' : //本周二
          return this.days[1]

          break

        case  '_2': //本周二
          return this.days[1]

          break

        case '_3': //本周二
          return this.days[1]

          break

        case '周二_1'://下周二
          return this.days[8]

          break

        case  '_16' ://下周二
          return this.days[8]

          break

        case  '_17'://下周二
          return this.days[8]

          break

        case '周二_2' ://下下周二
          return this.days[15]

          break

        case '_30' ://下下周二
          return this.days[15]

          break

        case '_31'://下下周二
          return this.days[15]

          break

        case '周二_3' ://下下下周二
          return this.days[22]

          break

        case '_44' ://下下下周二
          return this.days[22]

          break

        case '_45'://下下下周二
          return this.days[22]

          break

        case '周三' : //本周三
          return this.days[2]

          break

        case  '_4': //本周三
          return this.days[2]

          break

        case '_5': //本周三
          return this.days[2]

          break

        case '周三_1': //下周三
          return this.days[9]

          break

        case  '_18' : //下周三
          return this.days[9]

          break

        case '_19': //下周三
          return this.days[9]

          break

        case '周三_2' : //下下周三
          return this.days[16]

          break

        case '_32' : //下下周三
          return this.days[16]

          break

        case  '_33': //下下周三
          return this.days[16]

          break
        case '周三_3' : //下下下周三
          return this.days[23]

          break

        case '_46' : //下下下周三
          return this.days[23]

          break

        case  '_47': //下下下周三
          return this.days[23]

          break

        case '周四':
          return this.days[3]

          break

        case '_6' :
          return this.days[3]

          break

        case  '_7':
          return this.days[3]

          break

        case '周四_1':

          return this.days[10]

          break

        case '_20' :

          return this.days[10]

          break

        case  '_21':

          return this.days[10]

          break

        case '周四_2' :

          return this.days[17]

          break

        case '_34':

          return this.days[17]

          break

        case  '_35':

          return this.days[17]

          break
        case '周四_3' :

          return this.days[24]

          break

        case '_48':

          return this.days[24]

          break

        case  '_49':

          return this.days[24]

          break
        case '周五':
          return this.days[4]

          break

        case  '_8':
          return this.days[4]

          break

        case  '_9':
          return this.days[4]

          break
        case '周五_1' :
          return this.days[11]

          break

        case '_22' :
          return this.days[11]

          break

        case  '_23':
          return this.days[11]

          break
        case '周五_2' :
          return this.days[18]

          break

        case '_36':
          return this.days[18]

          break

        case  '_37':
          return this.days[18]

          break
        case '周五_3' :
          return this.days[25]

          break

        case '_50':
          return this.days[25]

          break

        case  '_51':
          return this.days[25]

          break

        case '周六' :
          return this.days[5]

          break

        case  '_10' :
          return this.days[5]

          break

        case '_11':
          return this.days[5]

          break
        case '周六_1' :
          return this.days[12]

          break

        case  '_24' :
          return this.days[12]

          break

        case  '_25':
          return this.days[12]

          break

        case '周六_2' :
          return this.days[19]

          break

        case '_38' :
          return this.days[19]

          break

        case '_39':
          return this.days[19]

          break
        case '周六_3' :
          return this.days[26]

          break

        case '_52' :
          return this.days[26]

          break

        case '_53':
          return this.days[26]

          break
        case '周日' :
          return this.days[6]

          break

        case  '_12' :
          return this.days[6]

          break

        case  '_13':
          return this.days[6]
          break
        case '周日_1' :
          return this.days[13]

          break

        case  '_26' :
          return this.days[13]

          break

        case  '_27':
          return this.days[13]

          break
        case '周日_2':
          return this.days[20]

          break

        case '_40':
          return this.days[20]

          break

        case '_41':
          return this.days[20]
          break
        case '周日_3':
          return this.days[27]

          break

        case '_54':
          return this.days[27]

          break

        case '_55':
          return this.days[27]
          break
        default:
          return '0'
          break

      }

    },changeZone(val){
      this.getWeekPanels(val)
      let params = {
        patitionid:val
      }
      console.log(params)
      getTemplateInitDataTwo(params).then(rs => {
        var resp = rs.data
        if (resp.state == 1) {
          var mode = resp.data.template_mode
          var device_numbers = resp.data.device_numbers
          var templates = resp.data.templates
          this.templates = templates
          if(templates.length > 0){
            this.firstWeekData = templates[0].items
            this.first_template = templates[0]
          }
          if(templates.length > 1){
            this.secondWeekData = templates[1].items
            this.second_template = templates[1]

          }
          if(templates.length > 2){
            this.thirdWeekData = templates[2].items
            this.third_template = templates[2]

          }
          if(templates.length > 3){
            this.fourWeekData = templates[3].items
            this.four_template = templates[3]

          }



          var patients = resp.data.patients
          // var schedules = resp.data.schedules

          this.template_mode = mode
          this.origin_mode = mode.mode
          this.device_numbers = device_numbers
          this.patients = patients



          this.$refs.table.setEditData(this.patients,this.first_template,this.device_numbers,this.templates,this.activeName)
          // this.$refs.table_two.setEditData(this.patients,this.second_template,this.device_numbers)
          // this.$refs.table_three.setEditData(this.patients,this.third_template,this.device_numbers)
          // this.$refs.table_four.setEditData(this.patients,this.four_template,this.device_numbers)


          var fakeTemplateItems = []
          // for (let index = 0; index < schedules.length; index++) {
          //   const schedule = schedules[index]
          //   var item = {}
          //   this.$set(item, 'id', schedule.id)
          //   this.$set(item, 'template_id', 0)
          //   this.$set(item, 'device_number_id', schedule.bed_id)
          //   this.$set(item, 'treat_mode', schedule.mode_id)
          //   this.$set(item, 'weekday', schedule.schedule_week)
          //   this.$set(item, 'time_type', schedule.schedule_type)
          //   var patient = {}
          //   this.$set(patient, 'id', schedule.patient_id)
          //   this.$set(patient, 'name', schedule.patient)
          //   this.$set(item, 'patient', patient)
          //
          //   fakeTemplateItems.push(item)
          // }
          this.this_week_schedules.items = fakeTemplateItems

        } else {
          this.$message(resp.msg)
        }
      })


    },saveData(val){
      var tempDataOne = []
      for(let i = 0; i < val.length; i++){
          tempDataOne.push(val[i])
      }
      this.$refs.table.SetSmartSch(tempDataOne)
    },
    getWeekPanels(val) {
      getWeekPanels(1,val).then(response => {
        if (response.data.state == 0) {
          return false
        }
        var partitions = response.data.data.partitions
        var that = this
        if (partitions.length > 0) {
          partitions.forEach(function (partition) {
            if (partition.jihaos.length == 0) {
              return false
            }
            that.partitions[partition.id] = partition
            partition.jihaos.forEach(function (jihao) {
              var thisPa = {
                area: partition.name,
                zone_id: partition.id,
                zone_type: partition.type,
                cut: jihao.number,
                jihao_id: jihao.id,
                Mon_M: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  patient: ''
                },
                Mon_A: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  patient: ''
                },
                Mon_N: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  patient: ''
                },
                Tue_M: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  patient: ''
                },
                Tue_A: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  patient: ''
                },
                Tue_N: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  patient: ''
                },
                Wed_M: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  patient: ''
                },
                Wed_A: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  patient: ''
                },
                Wed_N: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  patient: ''
                },
                Thurs_M: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  patient: ''
                },
                Thurs_A: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  patient: ''
                },
                Thurs_N: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  patient: ''
                },
                Fri_M: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  patient: ''
                },
                Fri_A: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  patient: ''
                },
                Fri_N: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  patient: ''
                },
                Sat_M: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  patient: ''
                },
                Sat_A: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  patient: ''
                },
                Sat_N: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  patient: ''
                },
                Sun_A: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  patient: ''
                },
                Sun_N: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  patient: ''
                },
                Sun_M: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  patient: ''
                },
                total: 0
              }
            })
          })
        }
      })
    },editClick:function (){
      this.$nextTick(function() {
        if(this.activeName == "first"){
          this.activeName = "first"
          this.$refs.table.showSmartDialog()
        }else if(this.activeName == "second"){
          this.activeName = "second"
          this.$refs.table.showSmartDialog()
        }else if(this.activeName == "third"){
          this.activeName = "third"
          this.$refs.table.showSmartDialog()
        }else {
          this.activeName = "four"
          this.$refs.table.showSmartDialog()
        }
      })

    },saveClick:function (){
      if(this.template_mode.mode == 0){
        // this.$router.go(-1)
        this.$router.back()

      }else{
        this.$message.success("保存成功")
        this.$router.back()

      }

    },
    setScheduleTemplateAction: function () {
      this.$refs.setup_dialog.show()
    },
    didChangeTemplateMode: function (mode) {
      if (this.origin_mode != mode) {
        if (this.origin_mode == 0) { // 0 -> 1 或 0 -> 2
          // 不处理模板 item
        } else if (mode == 0) { // 1 -> 0 或 2 -> 0 清除所有模板的 item
          this.first_template.items.splice(0, this.first_template.items.length)
          this.second_template.items.splice(0, this.second_template.items.length)
          this.third_template.items.splice(0, this.third_template.items.length)
          this.four_template.items.splice(0, this.four_template.items.length)

        } else if (this.origin_mode == 1 && mode == 2) { // 1 -> 2
          // 不处理模板 item
        }else if (this.origin_mode == 1 && mode == 3) { // 1 -> 2
          // 不处理模板 item
        }else if (this.origin_mode == 1 && mode == 4) { // 1 -> 2
          // 不处理模板 item
        } else if (this.origin_mode == 2 && mode == 1) { // 2 -> 1 清除第二个模板的 item
          this.second_template.items.splice(0, this.second_template.items.length)

        }else if (this.origin_mode == 3 && mode == 1) { // 2 -> 1 清除第二个模板的 item
          this.second_template.items.splice(0, this.second_template.items.length)
          this.third_template.items.splice(0, this.third_template.items.length)
        }else if (this.origin_mode == 3 && mode == 2){
          this.third_template.items.splice(0, this.third_template.items.length)
        }else if (this.origin_mode == 4 && mode == 1) {
          this.second_template.items.splice(0, this.second_template.items.length)
          this.third_template.items.splice(0, this.third_template.items.length)
          this.four_template.items.splice(0, this.four_template.items.length)
        }else if (this.origin_mode == 4 && mode == 2) {
          this.third_template.items.splice(0, this.third_template.items.length)
          this.four_template.items.splice(0, this.four_template.items.length)
        }else if (this.origin_mode == 4 && mode == 3) {
          this.four_template.items.splice(0, this.four_template.items.length)
        }
        this.origin_mode = mode
        let params = {
          patitionid:""
        }
        getTemplateInitData(params).then(rs => {
          var resp = rs.data
          if (resp.state == 1) {
            var mode = resp.data.template_mode
            var device_numbers = resp.data.device_numbers
            var templates = resp.data.templates
            this.templates = templates
            if(templates.length > 0){
              this.firstWeekData = templates[0].items
              this.first_template = templates[0]
            }
            if(templates.length > 1){
              this.secondWeekData = templates[1].items
              this.second_template = templates[1]

            }
            if(templates.length > 2){
              this.thirdWeekData = templates[2].items
              this.third_template = templates[2]

            }
            if(templates.length > 3){
              this.fourWeekData = templates[3].items
              this.four_template = templates[3]

            }



            var patients = resp.data.patients
            // var schedules = resp.data.schedules

            this.template_mode = mode
            this.origin_mode = mode.mode
            this.device_numbers = device_numbers
            this.patients = patients



            this.$refs.table.setEditData(this.patients,this.first_template,this.device_numbers,this.templates,  this.activeName)
            // this.$refs.table_two.setEditData(this.patients,this.second_template,this.device_numbers)
            // this.$refs.table_three.setEditData(this.patients,this.third_template,this.device_numbers)
            // this.$refs.table_four.setEditData(this.patients,this.four_template,this.device_numbers)


            var fakeTemplateItems = []
            // for (let index = 0; index < schedules.length; index++) {
            //   const schedule = schedules[index]
            //   var item = {}
            //   this.$set(item, 'id', schedule.id)
            //   this.$set(item, 'template_id', 0)
            //   this.$set(item, 'device_number_id', schedule.bed_id)
            //   this.$set(item, 'treat_mode', schedule.mode_id)
            //   this.$set(item, 'weekday', schedule.schedule_week)
            //   this.$set(item, 'time_type', schedule.schedule_type)
            //   var patient = {}
            //   this.$set(patient, 'id', schedule.patient_id)
            //   this.$set(patient, 'name', schedule.patient)
            //   this.$set(item, 'patient', patient)
            //
            //   fakeTemplateItems.push(item)
            // }
            this.this_week_schedules.items = fakeTemplateItems

          } else {
            this.$message(resp.msg)
          }
        })


      }
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v =>
          filterVal.map(j => {
            return v[j]

          })
      )
    },
    import_file: function () {

      this.downloadLoading = true
      import('@/vendor/Export2Excel').then(excel => {
        const filterVal = [
          '区号',
          '机号'
        ]
        const multiHeaderForModeOne = [['区号', '机号', '周一', '', '', '周二', '', '', '周三', '', '', '周四', '', '', '周五', '', '', '周六', '', '', '周日', '', '']]
        const multiHeaderForModeTwo = [['区号', '机号', '周一', '', '', '周二', '', '', '周三', '', '', '周四', '', '', '周五', '', '', '周六', '', '', '周日', '', '', '周一', '', '', '周二', '', '', '周三', '', '', '周四', '', '', '周五', '', '', '周六', '', '', '周日', '', '']]
        const multiHeaderForModeThree = [['区号', '机号', '周一', '', '', '周二', '', '', '周三', '', '', '周四', '', '', '周五', '', '', '周六', '', '', '周日', '', '', '周一', '', '', '周二', '', '', '周三', '', '', '周四', '', '', '周五', '', '', '周六', '', '', '周日', '', '', '周一', '', '', '周二', '', '', '周三', '', '', '周四', '', '', '周五', '', '', '周六', '', '', '周日', '', '']]
        const multiHeaderForModeFour = [['区号', '机号', '周一', '', '', '周二', '', '', '周三', '', '', '周四', '', '', '周五', '', '', '周六', '', '', '周日', '', '', '周一', '', '', '周二', '', '', '周三', '', '', '周四', '', '', '周五', '', '', '周六', '', '', '周日', '', '','周一', '', '', '周二', '', '', '周三', '', '', '周四', '', '', '周五', '', '', '周六', '', '', '周日', '', '','周一', '', '', '周二', '', '', '周三', '', '', '周四', '', '', '周五', '', '', '周六', '', '', '周日', '', '']]

        const headerForModeOne = ['', '', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上']
        const headerForModeTwo = ['', '', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上']
        const headerForModeThree = ['', '', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上']
        const headerForModeFour = ['', '', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上','上午', '下午', '晚上','上午', '下午', '晚上','上午', '下午', '晚上','上午', '下午', '晚上','上午', '下午', '晚上','上午', '下午', '晚上','上午', '下午', '晚上','上午', '下午', '晚上','上午', '下午', '晚上','上午', '下午', '晚上','上午', '下午', '晚上','上午', '下午', '晚上','上午', '下午', '晚上','上午', '下午', '晚上']

        const merges = ['A1:A2', 'B1:B2', 'C1:E1', 'F1:H1', 'I1:K1', 'L1:N1', 'O1:Q1', 'R1:T1', 'U1:W1']
        const mergesTwo = ['A1:A2', 'B1:B2', 'C1:E1', 'F1:H1', 'I1:K1', 'L1:N1', 'O1:Q1', 'R1:T1', 'U1:W1', 'X1:Z1', 'AA1:AC1', 'AD1:AF1', 'AG1:AI1', 'AJ1:AL1', 'AM1:AO1', 'AP1:AR1']
        const mergesThree = ['A1:A2', 'B1:B2', 'C1:E1', 'F1:H1', 'I1:K1', 'L1:N1', 'O1:Q1', 'R1:T1', 'U1:W1', 'X1:Z1', 'AA1:AC1', 'AD1:AF1', 'AG1:AI1', 'AJ1:AL1', 'AM1:AO1', 'AP1:AR1','AS1:AU1','AV1:AX1','AY1:BA1','BB1:BD1','BE1:BG1','BH1:BJ1','BK1:BM1']
        const mergesFour = ['A1:A2', 'B1:B2', 'C1:E1', 'F1:H1', 'I1:K1', 'L1:N1', 'O1:Q1', 'R1:T1', 'U1:W1', 'X1:Z1', 'AA1:AC1', 'AD1:AF1', 'AG1:AI1', 'AJ1:AL1', 'AM1:AO1', 'AP1:AR1','AS1:AU1','AV1:AX1','AY1:BA1','BB1:BD1','BE1:BG1','BH1:BJ1','BK1:BM1','BN1:BP1','BQ1:BS1','BT1:BV1','BW1:BY1','BZ1:CB1','CC1:CE1','CF1:CH1']

        var list = []

        let i = 0
        for (let key in this.partitions) {
          var tempValue
          var jihaos = this.partitions[key].jihaos

            if (i == 0) {
              let m = 'A3' + ':' + 'A' + (2 + jihaos.length)
              tempValue = (2 + jihaos.length)
              mergesFour.push(m)
            } else {
              let m = 'A' + (tempValue + 1) + ':' + 'A' + ((tempValue + 1) + jihaos.length - 1)
              tempValue = ((tempValue + 1) + jihaos.length - 1)
              mergesFour.push(m)
            }


          for (let b = 0; b < jihaos.length; b++) {
            let obj = {}
            obj['区号'] = this.partitions[key].name
            obj['机号'] = jihaos[b].number.toString()
            obj['shangwu'] = ''
            obj['xiawu'] = ''
            obj['wanshang'] = ''

            obj['shangwu1'] = ''
            obj['xiawu1'] = ''
            obj['wanshang1'] = ''

            obj['shangwu2'] = ''
            obj['xiawu2'] = ''
            obj['wanshang2'] = ''

            obj['shangwu3'] = ''
            obj['xiawu3'] = ''
            obj['wanshang3'] = ''

            obj['shangwu4'] = ''
            obj['xiawu4'] = ''
            obj['wanshang4'] = ''

            obj['shangwu5'] = ''
            obj['xiawu5'] = ''
            obj['wanshang5'] = ''

            obj['shangwu6'] = ''
            obj['xiawu6'] = ''
            obj['wanshang6'] = ''

            obj['shangwu7'] = ''
            obj['xiawu7'] = ''
            obj['wanshang7'] = ''

            obj['shangwu8'] = ''
            obj['xiawu8'] = ''
            obj['wanshang8'] = ''

            obj['shangwu9'] = ''
            obj['xiawu9'] = ''
            obj['wanshang9'] = ''

            obj['shangwu10'] = ''
            obj['xiawu10'] = ''
            obj['wanshang10'] = ''

            obj['shangwu11'] = ''
            obj['xiawu11'] = ''
            obj['wanshang11'] = ''

            obj['shangwu12'] = ''
            obj['xiawu12'] = ''
            obj['wanshang12'] = ''

            obj['shangwu13'] = ''
            obj['xiawu13'] = ''
            obj['wanshang13'] = ''

            obj['shangwu14'] = ''
            obj['xiawu14'] = ''
            obj['wanshang14'] = ''

            obj['shangwu15'] = ''
            obj['xiawu15'] = ''
            obj['wanshang15'] = ''

            obj['shangwu16'] = ''
            obj['xiawu16'] = ''
            obj['wanshang16'] = ''

            obj['shangwu17'] = ''
            obj['xiawu17'] = ''
            obj['wanshang17'] = ''

            obj['shangwu18'] = ''
            obj['xiawu18'] = ''
            obj['wanshang18'] = ''

            obj['shangwu19'] = ''
            obj['xiawu19'] = ''
            obj['wanshang19'] = ''

            obj['shangwu20'] = ''
            obj['xiawu20'] = ''
            obj['wanshang20'] = ''


            obj['shangwu21'] = ''
            obj['xiawu21'] = ''
            obj['wanshang21'] = ''

            obj['shangwu22'] = ''
            obj['xiawu22'] = ''
            obj['wanshang22'] = ''

            obj['shangwu23'] = ''
            obj['xiawu23'] = ''
            obj['wanshang23'] = ''

            obj['shangwu24'] = ''
            obj['xiawu24'] = ''
            obj['wanshang24'] = ''

            obj['shangwu25'] = ''
            obj['xiawu25'] = ''
            obj['wanshang25'] = ''

            obj['shangwu26'] = ''
            obj['xiawu26'] = ''
            obj['wanshang26'] = ''

            obj['shangwu27'] = ''
            obj['xiawu27'] = ''
            obj['wanshang27'] = ''


            list.push(obj)
          }
          i++
        }

        for (let i = 0; i < this.firstWeekData.length; i++) {
          this.firstWeekData[i].name = ""
          this.firstWeekData[i].number_name = ""
        }
        for (let i = 0; i < this.secondWeekData.length; i++) {
          this.secondWeekData[i].name = ""
          this.secondWeekData[i].number_name = ""
        }

        for (let i = 0; i < this.thirdWeekData.length; i++) {
          this.thirdWeekData[i].name = ""
          this.thirdWeekData[i].number_name = ""
        }

        for (let i = 0; i < this.fourWeekData.length; i++) {
          this.fourWeekData[i].name = ""
          this.fourWeekData[i].number_name = ""
        }

        console.log(this.firstWeekData)
        console.log(this.device_numbers)

        for (let i = 0; i < this.firstWeekData.length; i++) {
          for (let j = 0; j < this.device_numbers.length; j++) {
            if (this.firstWeekData[i].device_number_id == this.device_numbers[j].id) {
              this.firstWeekData[i].number_name = this.device_numbers[j].number
            }
          }
        }

        for (let i = 0; i < this.secondWeekData.length; i++) {
          for (let j = 0; j < this.device_numbers.length; j++) {
            if (this.secondWeekData[i].device_number_id == this.device_numbers[j].id) {
              this.secondWeekData[i].number_name = this.device_numbers[j].number
            }
          }
        }

        for (let i = 0; i < this.thirdWeekData.length; i++) {
          for (let j = 0; j < this.device_numbers.length; j++) {
            if (this.thirdWeekData[i].device_number_id == this.device_numbers[j].id) {
              this.thirdWeekData[i].number_name = this.device_numbers[j].number
            }
          }
        }


        for (let i = 0; i < this.fourWeekData.length; i++) {
          for (let j = 0; j < this.device_numbers.length; j++) {
            if (this.fourWeekData[i].device_number_id == this.device_numbers[j].id) {
              this.fourWeekData[i].number_name = this.device_numbers[j].number
            }
          }
        }


        for (let i = 0; i < this.firstWeekData.length; i++) {
          for (let j = 0; j < this.patients.length; j++) {
            if (this.firstWeekData[i].patient_id == this.patients[j].id) {
              this.firstWeekData[i].name = this.patients[j].name
              if(this.firstWeekData.length > 0){
                this.firstWeekData[i].name = this.firstWeekData[i].name +"-" + this.getMode(this.firstWeekData[i].treat_mode)
              }
            }
          }
        }

        for (let i = 0; i < this.secondWeekData.length; i++) {
          for (let j = 0; j < this.patients.length; j++) {
            if (this.secondWeekData[i].patient_id == this.patients[j].id) {
              this.secondWeekData[i].name = this.patients[j].name
              if(this.secondWeekData.length > 0){
                this.secondWeekData[i].name = this.secondWeekData[i].name +"-" + this.getMode(this.secondWeekData[i].treat_mode)
              }
            }
          }
        }

        for (let i = 0; i < this.thirdWeekData.length; i++) {
          for (let j = 0; j < this.patients.length; j++) {
            if (this.thirdWeekData[i].patient_id == this.patients[j].id) {
              this.thirdWeekData[i].name = this.patients[j].name
              if(this.thirdWeekData.length > 0){
                this.thirdWeekData[i].name = this.thirdWeekData[i].name +"-" + this.getMode(this.thirdWeekData[i].treat_mode)
              }
            }
          }
        }

        for (let i = 0; i < this.fourWeekData.length; i++) {
          for (let j = 0; j < this.patients.length; j++) {
            if (this.fourWeekData[i].patient_id == this.patients[j].id) {
              this.fourWeekData[i].name = this.patients[j].name
              if(this.fourWeekData.length > 0){
                this.fourWeekData[i].name = this.fourWeekData[i].name +"-" + this.getMode(this.fourWeekData[i].treat_mode)
              }
            }
          }
        }




          for (let i = 0; i < this.firstWeekData.length; i++) {
            for (let j = 0; j < list.length; j++) {
              if (this.firstWeekData[i].number_name == list[j].机号 && this.firstWeekData[i].devices.zone.name == list[j].区号) {
                //第一周周一上午
                if (this.firstWeekData[i].weekday == 1 && this.firstWeekData[i].time_type == 1) {
                  list[j].shangwu = this.firstWeekData[i].name
                }
                //第一周周一下午
                if (this.firstWeekData[i].weekday == 1 && this.firstWeekData[i].time_type == 2) {
                  list[j].xiawu = this.firstWeekData[i].name
                }
                //第一周晚上
                if (this.firstWeekData[i].weekday == 1 && this.firstWeekData[i].time_type == 3) {
                  list[j].wanshang = this.firstWeekData[i].name
                }

                //第一周周二上午
                if (this.firstWeekData[i].weekday == 2 && this.firstWeekData[i].time_type == 1) {
                  list[j].shangwu1 = this.firstWeekData[i].name
                }
                //第一周周二下午
                if (this.firstWeekData[i].weekday == 2 && this.firstWeekData[i].time_type == 2) {
                  list[j].xiawu1 = this.firstWeekData[i].name
                }
                //第一周周二晚上
                if (this.firstWeekData[i].weekday == 2 && this.firstWeekData[i].time_type == 3) {
                  list[j].wanshang1 = this.firstWeekData[i].name
                }

                //第一周周三上午
                if (this.firstWeekData[i].weekday == 3 && this.firstWeekData[i].time_type == 1) {
                  list[j].shangwu2 = this.firstWeekData[i].name
                }
                //第一周周三下午
                if (this.firstWeekData[i].weekday == 3 && this.firstWeekData[i].time_type == 2) {
                  list[j].xiawu2 = this.firstWeekData[i].name
                }
                //第一周周三晚上
                if (this.firstWeekData[i].weekday == 3 && this.firstWeekData[i].time_type == 3) {
                  list[j].wanshang2 = this.firstWeekData[i].name
                }

                //第一周周四上午
                if (this.firstWeekData[i].weekday == 4 && this.firstWeekData[i].time_type == 1) {
                  list[j].shangwu3 = this.firstWeekData[i].name
                }
                //第一周周四下午
                if (this.firstWeekData[i].weekday == 4 && this.firstWeekData[i].time_type == 2) {
                  list[j].xiawu3 = this.firstWeekData[i].name
                }
                //第一周周四晚上
                if (this.firstWeekData[i].weekday == 4 && this.firstWeekData[i].time_type == 3) {
                  list[j].wanshang3 = this.firstWeekData[i].name
                }

                //第一周周五上午
                if (this.firstWeekData[i].weekday == 5 && this.firstWeekData[i].time_type == 1) {
                  list[j].shangwu4 = this.firstWeekData[i].name
                }
                //第一周周五下午
                if (this.firstWeekData[i].weekday == 5 && this.firstWeekData[i].time_type == 2) {
                  list[j].xiawu4 = this.firstWeekData[i].name
                }
                //第一周周五晚上
                if (this.firstWeekData[i].weekday == 5 && this.firstWeekData[i].time_type == 3) {
                  list[j].wanshang4 = this.firstWeekData[i].name
                }

                //第一周周六上午
                if (this.firstWeekData[i].weekday == 6 && this.firstWeekData[i].time_type == 1) {
                  list[j].shangwu5 = this.firstWeekData[i].name
                }
                //第一周周六下午
                if (this.firstWeekData[i].weekday == 6 && this.firstWeekData[i].time_type == 2) {
                  list[j].xiawu5 = this.firstWeekData[i].name
                }
                //第一周周六晚上
                if (this.firstWeekData[i].weekday == 6 && this.firstWeekData[i].time_type == 3) {
                  list[j].wanshang5 = this.firstWeekData[i].name
                }

                //第一周周日上午
                if (this.firstWeekData[i].weekday == 7 && this.firstWeekData[i].time_type == 1) {
                  list[j].shangwu6 = this.firstWeekData[i].name
                }
                //第一周周日下午
                if (this.firstWeekData[i].weekday == 7 && this.firstWeekData[i].time_type == 2) {
                  list[j].xiawu6 = this.firstWeekData[i].name
                }
                //第一周周日晚上
                if (this.firstWeekData[i].weekday == 7 && this.firstWeekData[i].time_type == 3) {
                  list[j].wanshang6 = this.firstWeekData[i].name
                }
              }
            }
          }

          for (let i = 0; i < this.secondWeekData.length; i++) {
            for (let j = 0; j < list.length; j++) {
              if (list[j].机号 == this.secondWeekData[i].number_name && this.secondWeekData[i].devices.zone.name == list[j].区号) {
                //第二周周一上午
                if (this.secondWeekData[i].weekday == 1 && this.secondWeekData[i].time_type == 1) {
                  list[j].shangwu7 = this.secondWeekData[i].name
                }
                //第二周周一下午
                if (this.secondWeekData[i].weekday == 1 && this.secondWeekData[i].time_type == 2) {
                  list[j].xiawu7 = this.secondWeekData[i].name
                }
                //第二周周一晚上
                if (this.secondWeekData[i].weekday == 1 && this.secondWeekData[i].time_type == 3) {
                  list[j].wanshang7 = this.secondWeekData[i].name
                }

                //第二周周二上午
                if (this.secondWeekData[i].weekday == 2 && this.secondWeekData[i].time_type == 1) {
                  list[j].shangwu8 = this.secondWeekData[i].name
                }
                //第二周周二下午
                if (this.secondWeekData[i].weekday == 2 && this.secondWeekData[i].time_type == 2) {
                  list[j].xiawu8 = this.secondWeekData[i].name
                }
                //第二周周二晚上
                if (this.secondWeekData[i].weekday == 2 && this.secondWeekData[i].time_type == 3) {
                  list[j].wanshang8 = this.secondWeekData[i].name
                }

                //第二周周三上午
                if (this.secondWeekData[i].weekday == 3 && this.secondWeekData[i].time_type == 1) {
                  list[j].shangwu9 = this.secondWeekData[i].name
                }
                //第二周周三下午
                if (this.secondWeekData[i].weekday == 3 && this.secondWeekData[i].time_type == 2) {
                  list[j].xiawu9 = this.secondWeekData[i].name
                }
                //第二周周三晚上
                if (this.secondWeekData[i].weekday == 3 && this.secondWeekData[i].time_type == 3) {
                  list[j].wanshang9 = this.secondWeekData[i].name
                }

                //第二周周四上午
                if (this.secondWeekData[i].weekday == 4 && this.secondWeekData[i].time_type == 1) {
                  list[j].shangwu10 = this.secondWeekData[i].name
                }
                //第二周周四下午
                if (this.secondWeekData[i].weekday == 4 && this.secondWeekData[i].time_type == 2) {
                  list[j].xiawu10 = this.secondWeekData[i].name
                }
                //第二周周四晚上
                if (this.secondWeekData[i].weekday == 4 && this.secondWeekData[i].time_type == 3) {
                  list[j].wanshang10 = this.secondWeekData[i].name
                }

                //第二周周五上午
                if (this.secondWeekData[i].weekday == 5 && this.secondWeekData[i].time_type == 1) {
                  list[j].shangwu11 = this.secondWeekData[i].name
                }
                //第二周周五下午
                if (this.secondWeekData[i].weekday == 5 && this.secondWeekData[i].time_type == 2) {
                  list[j].xiawu11 = this.secondWeekData[i].name
                }
                //第二周周五晚上
                if (this.secondWeekData[i].weekday == 5 && this.secondWeekData[i].time_type == 3) {
                  list[j].wanshang11 = this.secondWeekData[i].name
                }

                //第二周周六上午
                if (this.secondWeekData[i].weekday == 6 && this.secondWeekData[i].time_type == 1) {
                  list[j].shangwu12 = this.secondWeekData[i].name
                }
                //第二周周六下午
                if (this.secondWeekData[i].weekday == 6 && this.secondWeekData[i].time_type == 2) {
                  list[j].xiawu12 = this.secondWeekData[i].name
                }
                //第二周周六晚上
                if (this.secondWeekData[i].weekday == 6 && this.secondWeekData[i].time_type == 3) {
                  list[j].wanshang12 = this.secondWeekData[i].name
                }

                //第二周周日上午
                if (this.secondWeekData[i].weekday == 7 && this.secondWeekData[i].time_type == 1) {
                  list[j].shangwu13 = this.secondWeekData[i].name
                }
                //第二周周日下午
                if (this.secondWeekData[i].weekday == 7 && this.secondWeekData[i].time_type == 2) {
                  list[j].xiawu13 = this.secondWeekData[i].name
                }
                //第二周周日晚上
                if (this.secondWeekData[i].weekday == 7 && this.secondWeekData[i].time_type == 3) {
                  list[j].wanshang13 = this.secondWeekData[i].name
                }
              }

            }
          }
          for (let i = 0; i < this.thirdWeekData.length; i++) {
            for (let j = 0; j < list.length; j++) {
              if (list[j].机号 == this.thirdWeekData[i].number_name && this.thirdWeekData[i].devices.zone.name == list[j].区号) {
                //第二周周一上午
                if (this.thirdWeekData[i].weekday == 1 && this.thirdWeekData[i].time_type == 1) {
                  list[j].shangwu14 = this.thirdWeekData[i].name
                }
                //第二周周一下午
                if (this.thirdWeekData[i].weekday == 1 && this.thirdWeekData[i].time_type == 2) {
                  list[j].xiawu14 = this.thirdWeekData[i].name
                }
                //第二周周一晚上
                if (this.thirdWeekData[i].weekday == 1 && this.thirdWeekData[i].time_type == 3) {
                  list[j].wanshang14 = this.thirdWeekData[i].name
                }

                //第二周周二上午
                if (this.thirdWeekData[i].weekday == 2 && this.thirdWeekData[i].time_type == 1) {
                  list[j].shangwu15 = this.thirdWeekData[i].name
                }
                //第二周周二下午
                if (this.thirdWeekData[i].weekday == 2 && this.thirdWeekData[i].time_type == 2) {
                  list[j].xiawu15 = this.thirdWeekData[i].name
                }
                //第二周周二晚上
                if (this.thirdWeekData[i].weekday == 2 && this.thirdWeekData[i].time_type == 3) {
                  list[j].wanshang15 = this.thirdWeekData[i].name
                }

                //第二周周三上午
                if (this.thirdWeekData[i].weekday == 3 && this.thirdWeekData[i].time_type == 1) {
                  list[j].shangwu16 = this.thirdWeekData[i].name
                }
                //第二周周三下午
                if (this.thirdWeekData[i].weekday == 3 && this.thirdWeekData[i].time_type == 2) {
                  list[j].xiawu16 = this.thirdWeekData[i].name
                }
                //第二周周三晚上
                if (this.thirdWeekData[i].weekday == 3 && this.thirdWeekData[i].time_type == 3) {
                  list[j].wanshang16 = this.thirdWeekData[i].name
                }

                //第二周周四上午
                if (this.thirdWeekData[i].weekday == 4 && this.thirdWeekData[i].time_type == 1) {
                  list[j].shangwu17 = this.thirdWeekData[i].name
                }
                //第二周周四下午
                if (this.thirdWeekData[i].weekday == 4 && this.thirdWeekData[i].time_type == 2) {
                  list[j].xiawu17 = this.thirdWeekData[i].name
                }
                //第二周周四晚上
                if (this.thirdWeekData[i].weekday == 4 && this.thirdWeekData[i].time_type == 3) {
                  list[j].wanshang17 = this.thirdWeekData[i].name
                }

                //第二周周五上午
                if (this.thirdWeekData[i].weekday == 5 && this.thirdWeekData[i].time_type == 1) {
                  list[j].shangwu18 = this.thirdWeekData[i].name
                }
                //第二周周五下午
                if (this.thirdWeekData[i].weekday == 5 && this.thirdWeekData[i].time_type == 2) {
                  list[j].xiawu18 = this.thirdWeekData[i].name
                }
                //第二周周五晚上
                if (this.thirdWeekData[i].weekday == 5 && this.thirdWeekData[i].time_type == 3) {
                  list[j].wanshang18 = this.thirdWeekData[i].name
                }

                //第二周周六上午
                if (this.thirdWeekData[i].weekday == 6 && this.thirdWeekData[i].time_type == 1) {
                  list[j].shangwu19 = this.thirdWeekData[i].name
                }
                //第二周周六下午
                if (this.thirdWeekData[i].weekday == 6 && this.thirdWeekData[i].time_type == 2) {
                  list[j].xiawu19 = this.thirdWeekData[i].name
                }
                //第二周周六晚上
                if (this.thirdWeekData[i].weekday == 6 && this.thirdWeekData[i].time_type == 3) {
                  list[j].wanshang19 = this.thirdWeekData[i].name
                }

                //第二周周日上午
                if (this.thirdWeekData[i].weekday == 7 && this.thirdWeekData[i].time_type == 1) {
                  list[j].shangwu20 = this.thirdWeekData[i].name
                }
                //第二周周日下午
                if (this.thirdWeekData[i].weekday == 7 && this.thirdWeekData[i].time_type == 2) {
                  list[j].xiawu20 = this.thirdWeekData[i].name
                }
                //第二周周日晚上
                if (this.thirdWeekData[i].weekday == 7 && this.thirdWeekData[i].time_type == 3) {
                  list[j].wanshang20 = this.thirdWeekData[i].name
                }
              }

            }
          }
          for (let i = 0; i < this.fourWeekData.length; i++) {
            for (let j = 0; j < list.length; j++) {
              if (list[j].机号 == this.fourWeekData[i].number_name && this.fourWeekData[i].devices.zone.name == list[j].区号) {
                //第二周周一上午
                if (this.fourWeekData[i].weekday == 1 && this.fourWeekData[i].time_type == 1) {
                  list[j].shangwu21 = this.fourWeekData[i].name
                }
                //第二周周一下午
                if (this.fourWeekData[i].weekday == 1 && this.fourWeekData[i].time_type == 2) {
                  list[j].xiawu21 = this.fourWeekData[i].name
                }
                //第二周周一晚上
                if (this.fourWeekData[i].weekday == 1 && this.fourWeekData[i].time_type == 3) {
                  list[j].wanshang21 = this.fourWeekData[i].name
                }

                //第二周周二上午
                if (this.fourWeekData[i].weekday == 2 && this.fourWeekData[i].time_type == 1) {
                  list[j].shangwu22 = this.fourWeekData[i].name
                }
                //第二周周二下午
                if (this.fourWeekData[i].weekday == 2 && this.fourWeekData[i].time_type == 2) {
                  list[j].xiawu22 = this.fourWeekData[i].name
                }
                //第二周周二晚上
                if (this.fourWeekData[i].weekday == 2 && this.fourWeekData[i].time_type == 3) {
                  list[j].wanshang22 = this.fourWeekData[i].name
                }

                //第二周周三上午
                if (this.fourWeekData[i].weekday == 3 && this.fourWeekData[i].time_type == 1) {
                  list[j].shangwu23 = this.fourWeekData[i].name
                }
                //第二周周三下午
                if (this.fourWeekData[i].weekday == 3 && this.fourWeekData[i].time_type == 2) {
                  list[j].xiawu23 = this.fourWeekData[i].name
                }
                //第二周周三晚上
                if (this.fourWeekData[i].weekday == 3 && this.fourWeekData[i].time_type == 3) {
                  list[j].wanshang23 = this.fourWeekData[i].name
                }

                //第二周周四上午
                if (this.fourWeekData[i].weekday == 4 && this.fourWeekData[i].time_type == 1) {
                  list[j].shangwu24 = this.fourWeekData[i].name
                }
                //第二周周四下午
                if (this.fourWeekData[i].weekday == 4 && this.fourWeekData[i].time_type == 2) {
                  list[j].xiawu24 = this.fourWeekData[i].name
                }
                //第二周周四晚上
                if (this.fourWeekData[i].weekday == 4 && this.fourWeekData[i].time_type == 3) {
                  list[j].wanshang24 = this.fourWeekData[i].name
                }

                //第二周周五上午
                if (this.fourWeekData[i].weekday == 5 && this.fourWeekData[i].time_type == 1) {
                  list[j].shangwu25 = this.fourWeekData[i].name
                }
                //第二周周五下午
                if (this.fourWeekData[i].weekday == 5 && this.fourWeekData[i].time_type == 2) {
                  list[j].xiawu25 = this.fourWeekData[i].name
                }
                //第二周周五晚上
                if (this.fourWeekData[i].weekday == 5 && this.fourWeekData[i].time_type == 3) {
                  list[j].wanshang25 = this.fourWeekData[i].name
                }

                //第二周周六上午
                if (this.fourWeekData[i].weekday == 6 && this.fourWeekData[i].time_type == 1) {
                  list[j].shangwu26 = this.fourWeekData[i].name
                }
                //第二周周六下午
                if (this.fourWeekData[i].weekday == 6 && this.fourWeekData[i].time_type == 2) {
                  list[j].xiawu26 = this.fourWeekData[i].name
                }
                //第二周周六晚上
                if (this.fourWeekData[i].weekday == 6 && this.fourWeekData[i].time_type == 3) {
                  list[j].wanshang26 = this.fourWeekData[i].name
                }

                //第二周周日上午
                if (this.fourWeekData[i].weekday == 7 && this.fourWeekData[i].time_type == 1) {
                  list[j].shangwu27 = this.fourWeekData[i].name
                }
                //第二周周日下午
                if (this.fourWeekData[i].weekday == 7 && this.fourWeekData[i].time_type == 2) {
                  list[j].xiawu27 = this.fourWeekData[i].name
                }
                //第二周周日晚上
                if (this.fourWeekData[i].weekday == 7 && this.fourWeekData[i].time_type == 3) {
                  list[j].wanshang27 = this.fourWeekData[i].name
                }
              }

            }
          }




        var multiHeader
        var header


          this.tableList = list

          const filename = "排班模版"
          var data = []
          this.tableList.map(item => {
            data.push(Object.values(item))

          })
          multiHeader = multiHeaderForModeFour
          header = headerForModeFour
          excel.export_json_to_excel({
            multiHeader,
            header,
            mergesFour,
            data,
            filename

          })


        this.downloadLoading = false


      })

    },
    setData() {
      this.newVisible = true
    },  getMode(id) {
        let name = "";
        this.treatment_mode = Object.values(this.$store.getters.treatment_mode);
        this.treatment_mode.map((item) => {
          if (item.id == id) {
            name = item.name;
          }
        });
        return name;

    },getModeId(name) {
      let id = "1";
      this.treatment_mode = Object.values(this.$store.getters.treatment_mode);
      this.treatment_mode.map((item) => {
        if (item.name == name) {
          id = item.id.toString();
        }
      });
      return id;

    },
    submitAction() {
      var template
      if (this.form.firstWeek == 1) {
        template = this.first_template
      }
      if (this.form.firstWeek == 2) {
        template = this.second_template
      }
      if (this.form.firstWeek == 3) {
        template = this.third_template
      }
      if (this.form.firstWeek == 4) {
        template = this.four_template
      }
      var label = ""
      for (let i = 0; i < this.timeOptions.length; i++) {
        if (this.form.copyWeek == this.timeOptions[i].value) {
          label = this.timeOptions[i].label
        }
      }
      var start = label.split('~')
      var copy_startime = this.getTimestamp(start[0])
      var copy_endtime = this.getTimestamp(start[1])
      var params = {
        template_id: template.id,
        copy_startime: copy_startime,
        copy_endtime: copy_endtime,
      }
      synchroSchedule(params).then(response => {
        if (response.data.state == 1) {
          var msg = response.data.data.msg
          this.$message.success("同步成功!")
          this.newVisible = false
        }
      })

    },
    getPatientScheduleTemplate() {
      getPatientScheduleTemplate().then(response => {
        if (response.data.state == 1) {
          var schedule = response.data.data.schedule
          this.schedule = schedule
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
