<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="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">
        <el-button type="primary" size="small" icon="el-icon-printer" @click="printScheduleAction">打印排班</el-button>
        <!-- <schedule-upload-excel style="margin-right:10px;" :on-success='handleSuccess' v-if="is_edit"></schedule-upload-excel> -->
        <!-- <el-button @click="printTable" type="primary" size="small">打印排班</el-button> -->
        <el-button v-if="isShow()" type="primary" size="small" @click="export_file()" :loading="downloadLoading">
          导出排班
        </el-button>
        <!-- <el-button
            @click="generateLog()"
            class="filter-item"
            type="primary"
            v-if="is_edit"
            size="small"
        >下载日志
        </el-button> -->
        <el-button type="primary" size="small" icon="el-icon-setting" @click="setScheduleTemplateAction">排班模板
        </el-button>
        <!-- <el-button type="primary" size="small" @click="copySchedule" v-if="is_edit">复制排班</el-button>
        <el-button type="primary" size="small" v-if="is_edit" @click="smartsch">智能排班</el-button> -->
        <el-button type="primary" size="small" v-if="!is_edit" @click="editsch">编辑排班</el-button>
        <!-- <el-button type="danger" size="small" v-if="is_edit" @click="outisedit">退出编辑</el-button> -->
      </div>
    </div>
    <div class="app-container">
      <div style="right:30px;position:absolute;z-index:99">
        <span>导出周次:</span>
        <el-date-picker
            v-model="weekTime"
            type="week"
            format="yyyy 第 WW 周"
            placeholder="选择周"
            :picker-options="{'firstDayOfWeek': 1}"
            @change="changeWeek"
        >
        </el-date-picker>
      </div>
      <el-tabs v-model="activeName" :tab-position="tabPosition" ref="elTabs" @tab-click="handleClick">
        <el-tab-pane name="historyWeek">
          <span slot="label"><i class="el-icon-date"></i> 历史周期 ({{ theWeek.historyWeek }}) </span>
        </el-tab-pane>
        <el-tab-pane name="lastWeek">
          <span slot="label"><i class="el-icon-date"></i> 上周 ({{ theWeek.lastWeek }})</span>
        </el-tab-pane>
        <el-tab-pane name="thisWeek">
          <span slot="label"><i class="el-icon-date"></i> 本周 ({{ theWeek.thisWeek }})</span>
        </el-tab-pane>
        <el-tab-pane name="nextWeek">
          <span slot="label"><i class="el-icon-date"></i> 下一周 ({{ theWeek.nextWeek }})</span>
        </el-tab-pane>
        <el-tab-pane name="nextTwoWeek">
          <span slot="label"><i class="el-icon-date"></i> 下下周 ({{ theWeek.nextTwoWeek }})</span>
        </el-tab-pane>
      </el-tabs>
      <div v-if="!is_edit">
        <table-data ref="tableData"  :week-time="activeName" :partitions-prop="partitions"
                    :schedule-zone-row-prop="scheduleZoneRow"
                    :schedule-zone-prop="scheduleZone" title="" @event1="changePartition"
                    @event2="changeSchedule"  @event3="changeWeekDay" v-show="showtableOne">
        </table-data>
      </div>
       <edit-table-data ref="edittableData"  :week-time="activeName" :partitions-prop="partitions"
                        :schedule-zone-row-prop="scheduleZoneRow" :schedule-zone-prop="scheduleZone"
                         title="" @event1="changePartition"
                         @event2="changeSchedule" v-if="is_edit" @event3="changeWeekDay">

        <div class="position">
          <!-- <bread-crumb :crumbs="crumbs"></bread-crumb> -->
          <div>
            <el-tabs v-model="activeName" :tab-position="tabPosition" ref="elTabs">
          <el-tab-pane name="lastWeek">
            <span slot="label"><i class="el-icon-date"></i> 上周 ({{ theWeek.lastWeek }})</span>
          </el-tab-pane>
          <el-tab-pane name="thisWeek">
            <span slot="label"><i class="el-icon-date"></i> 本周 ({{ theWeek.thisWeek }})</span>
          </el-tab-pane>
          <el-tab-pane name="nextWeek">
            <span slot="label"><i class="el-icon-date"></i> 下一周 ({{ theWeek.nextWeek }})</span>
          </el-tab-pane>
          <el-tab-pane name="nextTwoWeek">
            <span slot="label"><i class="el-icon-date"></i> 下下周 ({{ theWeek.nextTwoWeek }})</span>
          </el-tab-pane>
        </el-tabs>
          </div>
        <div style="display:flex;align-items:center">
          <el-button type="primary" size="small" icon="el-icon-printer" @click="printScheduleAction">打印排班</el-button>
          <schedule-upload-excel style="margin-right:10px;" :on-success='handleSuccess' v-if="is_edit"></schedule-upload-excel>
          <el-button v-if="isShow()" type="primary" size="small" @click="export_file()" :loading="downloadLoading">
            导出排班
          </el-button>
          <el-button
              @click="generateLog()"
              class="filter-item"
              type="primary"
              v-if="is_edit"
              size="small"
          >下载日志
          </el-button>
          <el-button type="primary" size="small" icon="el-icon-setting" @click="setScheduleTemplateAction">排班模板
          </el-button>
          <el-button type="primary" size="small" @click="copySchedule" v-if="is_edit">复制排班</el-button>
          <el-button type="primary" size="small" v-if="is_edit" @click="smartsch">智能排班</el-button>
          <el-button type="primary" size="small" v-if="!is_edit" @click="editsch">编辑排班</el-button>
          <el-button type="danger" size="small" v-if="is_edit" @click="outisedit">退出编辑</el-button>
        </div>
      </div>
        </edit-table-data>

        <HistoryWeekTable v-show="showtable" ref="tableDataZero"  :week-time="activeName" :partitions-prop="partitions"
                  :schedule-zone-row-prop="scheduleZoneRow"
                  :schedule-zone-prop="scheduleZone" title="" >
          </HistoryWeekTable>
      <el-dialog title="复制排班" width="600px" :visible.sync="newVisible">
        <el-form :model="form" ref="form" label-width="90px" :rules="rules">
          <el-form-item label="周次:">
            <el-radio v-model="form.lastweek" label="1">上周排班信息</el-radio>
            <el-radio v-model="form.lastweek" label="2">本周排班信息</el-radio>
          </el-form-item>
          <el-form-item label="复制到 : " required prop="copyWeek">
            <el-select v-model="form.copyWeek" placeholder="请选择">
              <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  v-loading="copySchLoading" type="primary" @click="submitAction('form')">保 存</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import moment from 'moment'
import {parseTime} from '@/utils'
import tableData from './components/tableData'

import {
  copyPatientSchedule,
  exportSchedule,
  getScheduleTemplate,
  getThreeWeekList,
  getWeekPanels,
  initDate,
  getAllZones
} from '@/api/schedule'
import {
  patientLists
} from '@/api/schedule_template/sch_template'
import BreadCrumb from '@/xt_pages/components/bread-crumb'
import UploadExcel from '@/xt_pages/components/UploadExcel'
import ScheduleUploadExcel from './components/scheduleUploadExcel/index'
import {generateLog} from '@/api/config'
import {uParseTime} from '@/utils/tools'
import EditTableData from "./components/editTableData";
import HistoryWeekTable from './components/historyWeekTable'
export default {
  name: 'appointment',
  data() {
    return {
      options:[
        {id:0,name:"全部"},
        {id:1,name:"上午"},
        {id:2,name:"下午"},
        {id:3,name:"晚上"},
      ],
      patientList:[],
      scheduleType: [
        { id: 1, name: "上午" },
        { id: 2, name: "下午" },
        { id: 3, name: "晚上" }
      ],weekType:[
        { id: 1, name: "周一" },
        { id: 2, name: "周二" },
        { id: 3, name: "周三" },
        { id: 4, name: "周四" },
        { id: 5, name: "周五" },
        { id: 6, name: "周六" },
        { id: 7, name: "周日" },
      ],
      query_date:"",
      query_sch_type:"",
      query_week_type:"",
      query_zone:"",
      crumbs: [
        {path: false, name: '排班管理'},
        {path: '/workforce/appointment', name: '排班管理'}
      ],
      activeName: 'thisWeek',
      tabPosition: 'top',
      partitions: {},
      scheduleZone: [],
      days: [],
      logs: [],
      showtable:false,
      showtableOne:true,
      is_edit: false,
      schedulingTableVisible:false,//全屏
      scheduleZoneRow: [],
      downloadLoading: false,
      msgTipVisible: false,
      dialogVisible: false,
      isExistRepeatVisible: false,
      exportVisible: false,
      exportLogVisible: false,
      // 周期
      theWeek: {
        historyWeek:0,
        lastWeek: 0,
        thisWeek: 0,
        nextWeek: 0,
        nextTwoWeek: 0
      },

      tableList: [],
      weekTime: "",
      schedule_type: 0,
      partition_id: 0,
      zones: [],
      start_time: "",
      end_time: "",
      export_type: 0,
      form: {
        lastweek: "1",
        copyWeek: "",
      },
      newVisible: false,
      copySchLoading:false,
      typeOptions: [],
      timeOptions: [],
      copyWeek: '',
      weekList: [],
      currentFirstDate1: '',
      rules: {
        copyWeek: [{required: true, message: "请选择复制时间段", trigger: "blur"}],
      },
      weekNum: '',
      weekDayArr: [],
      todayDate: '',
      clen: 7,
      nowYear: new Date().getFullYear(),
      schedule_week: 0,
      newDay: [],
      templateObj: {},
      week_date:""
    }
  },
  components: {
    EditTableData,
    ScheduleUploadExcel,
    tableData,
    BreadCrumb,
    UploadExcel,
    HistoryWeekTable
  },
  methods: {
    handleClick(e,tab){
      if(e.name == 'historyWeek'){
        this.showtable=true
        this.showtableOne=false
        this.$nextTick(() => {
          this.$refs.tableDataZero.start()
        })
        // console.log('12343545',this.$refs.tableDataZero);
      }else{
        this.showtable=false
        this.showtableOne=true
      }

    },
    dragstart(event, item) {
      // console.log('start的索引',item.moveIndex)
      // 开始移动的时候将移动的索引值+图片的url存储下来

    },
    dragend(event,item) {
      // console.log('dragend',item)

    },
    getAllZones(){
      getAllZones().then(response=>{
        if(response.data.state == 1){
          var zones = response.data.data.zones
          this.zones = zones

        }
      })
    },
    compare(p) { //这是比较函数
      return function (m, n) {
        var a = m[p];
        var b = n[p];
        return a - b; //升序
      }
    },
    // printTable(){
    //   this.$router.push({path: '/scheduleTablePrint?partition_id='+this.partition_id+"&weekTime="+this.activeName})
    // },
    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() {
      let params = {
        'log_type': 2
      }
      generateLog(params).then(
          response => {
            if (response.data.state === 1) {
              this.logs = response.data.data.logs
              this.exportLogVisible = true
            } else {
              this.$message.error(response.data.msg)
            }
          }
      )

    },
    getWeekPanels() {
      // this.scheduleZoneRow = []
      // this.scheduleZone = []
      getWeekPanels(1, this.partition_id).then(response => {
        if (response.data.state == 0) {
          return false
        }
        var partitions = response.data.data.partitions
        console.log("分区",response.data.data)
        this.theWeek.thisWeek = response.data.data.theWeek
        this.theWeek.lastWeek = response.data.data.theLastWeek
        this.theWeek.nextWeek = response.data.data.theNextWeek
        this.theWeek.nextTwoWeek = response.data.data.theNextSecWeek
        this.theWeek.historyWeek = response.data.data.theWeek - 2
        // 在控制变量改变的时候进行 强制渲染更新
        let childrenRefs = this.$refs.elTabs.$children
        this.$nextTick(() => {
          childrenRefs.forEach(child => child.$forceUpdate())
        })
        var that = this

        if (partitions.length > 0) {
          let arrSort = []
          partitions.forEach((item) => {
            let num = Math.max.apply(Math, item.jihaos.map(function (o) {
              return o.sort
            }))
            item.sort = num
            arrSort.push(item)
          })
          arrSort.sort(this.compare('sort'))
          partitions = arrSort
          partitions.forEach(function (partition) {
            if (partition.jihaos.length == 0) {
              return false
            }
            that.scheduleZoneRow.push(partition.jihaos.length)
            that.partitions[partition.id] = partition
            partition.jihaos.forEach(function (jihao) {
              var thisPa = {
                area: partition.name,
                zone_id: partition.id,
                zone_type: partition.type,
                cut: jihao.number,
                jihao_id: jihao.id,
                Mon_M: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  dialysis_machine_name:"",
                  patient_id: 0,
                  patient: '',
                  zone_id:partition.id,
                  jihao_id: jihao.id,
                },
                Mon_A: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  dialysis_machine_name:"",

                  patient_id: 0,
                  patient: '',
                  zone_id:partition.id,
                  jihao_id: jihao.id,
                },
                Mon_N: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  dialysis_machine_name:"",

                  patient: '',
                  zone_id:partition.id,
                  jihao_id: jihao.id,
                },
                Tue_M: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  dialysis_machine_name:"",

                  patient_id: 0,
                  patient: '',
                  zone_id:partition.id,
                  jihao_id: jihao.id,
                },
                Tue_A: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  dialysis_machine_name:"",

                  patient_id: 0,
                  patient: '',
                  zone_id:partition.id,
                  jihao_id: jihao.id,
                },
                Tue_N: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  dialysis_machine_name:"",

                  patient: '',
                  zone_id:partition.id,
                  jihao_id: jihao.id,
                },
                Wed_M: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  dialysis_machine_name:"",

                  patient: '',
                  zone_id:partition.id,
                  jihao_id: jihao.id,
                },
                Wed_A: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  dialysis_machine_name:"",

                  patient: '',
                  zone_id:partition.id,
                  jihao_id: jihao.id,
                },
                Wed_N: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  dialysis_machine_name:"",

                  patient: '',
                  zone_id:partition.id,
                  jihao_id: jihao.id,
                },
                Thurs_M: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  dialysis_machine_name:"",

                  patient: '',
                  zone_id:partition.id,
                  jihao_id: jihao.id,
                },
                Thurs_A: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  dialysis_machine_name:"",

                  patient: '',
                  zone_id:partition.id,
                  jihao_id: jihao.id,
                },
                Thurs_N: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  dialysis_machine_name:"",

                  patient: '',
                  zone_id:partition.id,
                  jihao_id: jihao.id,
                },
                Fri_M: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  dialysis_machine_name:"",

                  patient_id: 0,
                  patient: '',
                  zone_id:partition.id,
                  jihao_id: jihao.id,
                },
                Fri_A: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  dialysis_machine_name:"",

                  patient_id: 0,
                  patient: '',
                  zone_id:partition.id,
                  jihao_id: jihao.id,
                },
                Fri_N: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  dialysis_machine_name:"",

                  patient: '',
                  zone_id:partition.id,
                  jihao_id: jihao.id,
                },
                Sat_M: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  dialysis_machine_name:"",

                  patient: '',
                  zone_id:partition.id,
                  jihao_id: jihao.id,
                },
                Sat_A: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  dialysis_machine_name:"",

                  patient_id: 0,
                  patient: '',
                  zone_id:partition.id,
                  jihao_id: jihao.id,
                },
                Sat_N: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  dialysis_machine_name:"",

                  patient: '',
                  zone_id:partition.id,
                  jihao_id: jihao.id,
                },
                Sun_A: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  patient_id: 0,
                  dialysis_machine_name:"",

                  patient: '',
                  zone_id:partition.id,
                  jihao_id: jihao.id,
                },
                Sun_N: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  dialysis_machine_name:"",

                  patient_id: 0,
                  patient: '',
                  zone_id:partition.id,
                  jihao_id: jihao.id,
                },
                Sun_M: {
                  schedule_id: 0,
                  mode_id: 0,
                  mode_name: '',
                  dialysis_machine_name:"",

                  patient_id: 0,
                  patient: '',
                  zone_id:partition.id,
                  jihao_id: jihao.id,
                },
                total: 0
              }
              that.scheduleZone.push(thisPa)
            })
          })

        }
        // console.log("111111111")
         console.log(that.scheduleZone)
      })
    },
    changeSch(val){
      // console.log(this.partitions)
      // console.log(this.scheduleZoneRow)
      // console.log(this.scheduleZone)

    },
    changeWeekType(val){
    },
    changeZone(val){
    },
    setScheduleTemplateAction: function () {
      this.schedulingTableVisible=true
      this.$router.push({path: '/workforce/template'})
    },
    export_file: function () {
      // this.getWeekPanelsTwo()
      this.export_file_step_two()
    },
    export_file_step_two: function(){

      this.downloadLoading = true
      import('@/vendor/Export2Excel').then(excel => {
        const filterVal = [
          '区号',
          '机号'
        ]
        if (this.export_type == 0) {

          const multiHeader = [['区号', '机号', '周一' + "(" + this.days[0] + ")", '', '', '周二' + "(" + this.days[1] + ")", '', '', '周三' + "(" + this.days[2] + ")", '', '', '周四' + "(" + this.days[3] + ")", '', '', '周五' + "(" + this.days[4] + ")", '', '', '周六' + "(" + this.days[5] + ")", '', '', '周日' + "(" + this.days[6] + ")", '', '', '周一' + "(" + this.days[7] + ")", '', '', '周二' + "(" + this.days[8] + ")", '', '', '周三' + "(" + this.days[9] + ")", '', '', '周四' + "(" + this.days[10] + ")", '', '', '周五' + "(" + this.days[11] + ")", '', '', '周六' + "(" + this.days[12] + ")", '', '', '周日' + "(" + this.days[13] + ")", '', '', '周一' + "(" + this.days[14] + ")", '', '', '周二' + "(" + this.days[15] + ")", '', '', '周三' + "(" + this.days[16] + ")", '', '', '周四' + "(" + this.days[17] + ")", '', '', '周五' + "(" + this.days[18] + ")", '', '', '周六' + "(" + this.days[19] + ")", '', '', '周日' + "(" + this.days[20] + ")", '', '']]
          const header = ['', '', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上']
          const merges = ['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']
          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)
              merges.push(m)
            } else {
              let m = 'A' + (tempValue + 1) + ':' + 'A' + ((tempValue + 1) + jihaos.length - 1)
              tempValue = ((tempValue + 1) + jihaos.length - 1)
              merges.push(m)
            }
            for (let b = 0; b < jihaos.length; b++) {
              let obj = {}
              obj['区号'] = this.partitions[key].name
              obj['机号'] = jihaos[b].number.toString()
              list.push(obj)
            }
            i++
          }
          var data = []

          this.tableList.map(item => {
            data.push(Object.values(item))

          })

          const filename = '排班模版'

          excel.export_json_to_excel({
            multiHeader,
            header,
            merges,
            data,
            filename
          })
          this.downloadLoading = false
        }

        if (this.export_type == 1) {

          const multiHeader = [['区号', '机号', '周一' + "(" + this.newDay[0] + ")", '', '', '周二' + "(" + this.newDay[1] + ")", '', '', '周三' + "(" + this.newDay[2] + ")", '', '', '周四' + "(" + this.newDay[3] + ")", '', '', '周五' + "(" + this.newDay[4] + ")", '', '', '周六' + "(" + this.newDay[5] + ")", '', '', '周日' + "(" + this.newDay[6] + ")", '', '']]
          const header = ['', '', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上']
          const merges = ['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']
          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)
              merges.push(m)
            } else {
              let m = 'A' + (tempValue + 1) + ':' + 'A' + ((tempValue + 1) + jihaos.length - 1)
              tempValue = ((tempValue + 1) + jihaos.length - 1)
              merges.push(m)
            }
            for (let b = 0; b < jihaos.length; b++) {
              let obj = {}
              obj['区号'] = this.partitions[key].name
              obj['机号'] = jihaos[b].number.toString()
              list.push(obj)
            }
            i++
          }

          var data = []
          this.tableList.map(item => {
            data.push(Object.values(item))

          })

          const filename = '排班模版'

          if (this.$store.getters.xt_user.org.id == 10234) {
            excel.export_json_to_excel1({
              multiHeader,
              header,
              merges,
              data,
              filename,
              ref: this.$refs['tableData'].$refs['table'].$el
            })
          } else {
            excel.export_json_to_excel({
              multiHeader,
              header,
              merges,
              data,
              filename
            })
          }
          this.downloadLoading = false
        }
      })

    },
    export_fileTwo: function () {

      import('@/vendor/Export2Excel').then(excel => {
        const filterVal = [
          '区号',
          '机号'
        ]
        const multiHeader = [['区号', '机号', '周一' + "(" + this.days[0] + ")", '', '', '周二' + "(" + this.days[1] + ")", '', '', '周三' + "(" + this.days[2] + ")", '', '', '周四' + "(" + this.days[3] + ")", '', '', '周五' + "(" + this.days[4] + ")", '', '', '周六' + "(" + this.days[5] + ")", '', '', '周日' + "(" + this.days[6] + ")", '', '', '周一' + "(" + this.days[7] + ")", '', '', '周二' + "(" + this.days[8] + ")", '', '', '周三' + "(" + this.days[9] + ")", '', '', '周四' + "(" + this.days[10] + ")", '', '', '周五' + "(" + this.days[11] + ")", '', '', '周六' + "(" + this.days[12] + ")", '', '', '周日' + "(" + this.days[13] + ")", '', '', '周一' + "(" + this.days[14] + ")", '', '', '周二' + "(" + this.days[15] + ")", '', '', '周三' + "(" + this.days[16] + ")", '', '', '周四' + "(" + this.days[17] + ")", '', '', '周五' + "(" + this.days[18] + ")", '', '', '周六' + "(" + this.days[19] + ")", '', '', '周日' + "(" + this.days[20] + ")", '', '']]
        const header = ['', '', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上', '上午', '下午', '晚上']
        const merges = ['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']

        var data = []
        // console.log("33333",this.tableList)

        this.tableList.map(item => {
          data.push(Object.values(item))

        })

        const filename = '排班模版'
        excel.export_json_to_excel({
          multiHeader,
          header,
          merges,
          data,
          filename
        })

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

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

            if (j === 'timestamp') {
              return parseTime(v[j])
            } else {
              return v[j]
            }
          })
      )
    },

    printScheduleAction: function () {
      var date = new Date().getTime()
      if(this.activeName == 'historyWeek'){
        date = date - 14 * 24 * 60 * 60 * 1000
      }else if (this.activeName == 'lastWeek') {
        date = date - 7 * 24 * 60 * 60 * 1000
      } else if (this.activeName == 'nextWeek') {
        date = date + 7 * 24 * 60 * 60 * 1000
      } else if (this.activeName == 'nextTwoWeek') {
        date = date + 14 * 24 * 60 * 60 * 1000
      }
      console.log("whhwhwhwhwhwh",this.templateObj.template_id)
      if (this.templateObj.template_id == 1) {
        this.$router.push({path: '/workforce/schedule/print', query: {date: date}})
      }
      if (this.templateObj.template_id == 2) {
        this.$router.push({path: '/scheduleTablePrint?partition_id=' + this.partition_id + "&weekTime=" + this.activeName+"&week_date="+this.week_date})
      }
      if (this.templateObj.template_id == 3) {
        this.$router.push({path: '/scheduleTablePrintOne?partition_id=' + this.partition_id + "&weekTime=" + this.activeName+"&week_date="+this.week_date})
      }
      if(this.templateObj.template_id == 4){
        this.$router.push({path: '/scheduleTablePrintTwo?partition_id=' + this.partition_id + "&weekTime=" + this.activeName+"&week_date="+this.week_date})
      }

    },
    isShow() {
      let isShow = false
      if (Object.keys(this.partitions).length != 0) {
        isShow = true
        let i = 0
        for (let key in this.partitions) {
          if (i == 0) {
            if (this.partitions[key].jihaos.length > 0) {
              isShow = true

            }
          }
          i++
        }
      }
      return isShow
    },
    handleSuccess({results, header}) {

      let headers = []
      for (let key in results[0]) {
        headers.push(key)
      }
      if (header.length == 65) {

        var isHas_1 = headers.includes('区号')

        var isHas_2 = headers.includes('机号')

        var isHas_3 = headers.includes('周一' + "(" + this.days[0] + ")")

        var isHas_4 = headers.includes('')

        var isHas_5 = headers.includes('_1')

        var isHas_6 = headers.includes('周二' + "(" + this.days[1] + ")")

        var isHas_7 = headers.includes('_2')

        var isHas_8 = headers.includes('_3')

        var isHas_9 = headers.includes('周三' + "(" + this.days[2] + ")")

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

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

        var isHas_12 = headers.includes('周四' + "(" + this.days[3] + ")")
        console.log("12" + isHas_12)

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

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

        var isHas_15 = headers.includes('周五' + "(" + this.days[4] + ")")
        console.log("15" + isHas_15)

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

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

        var isHas_18 = headers.includes('周六' + "(" + this.days[5] + ")")
        console.log("18" + isHas_18)

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

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

        var isHas_21 = headers.includes('周日' + "(" + this.days[6] + ")")
        console.log("21" + isHas_21)

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

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

        var isHas_24 = headers.includes('周一' + "(" + this.days[7] + ")")
        console.log("24" + isHas_24)

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

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

        var isHas_27 = headers.includes('周二' + "(" + this.days[8] + ")")
        console.log("27" + isHas_27)

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

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

        var isHas_30 = headers.includes('周三' + "(" + this.days[9] + ")")
        console.log("30" + isHas_30)

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

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

        var isHas_33 = headers.includes('周四' + "(" + this.days[10] + ")")
        console.log("33" + isHas_33)

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

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

        var isHas_36 = headers.includes('周五' + "(" + this.days[11] + ")")
        console.log("36" + isHas_36)

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

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

        var isHas_39 = headers.includes('周六' + "(" + this.days[12] + ")")
        console.log("39" + isHas_39)

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

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

        var isHas_42 = headers.includes('周日' + "(" + this.days[13] + ")")
        console.log("42" + isHas_42)

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

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

        var isHas_45 = headers.includes('周一' + "(" + this.days[14] + ")")
        console.log("45" + isHas_45)

        var isHas_46 = headers.includes('_28')
        console.log("46" + isHas_46)

        var isHas_47 = headers.includes('_29')
        console.log("47" + isHas_47)

        var isHas_48 = headers.includes('周二' + "(" + this.days[15] + ")")
        console.log("48" + isHas_48)

        var isHas_49 = headers.includes('_30')
        console.log("49" + isHas_49)

        var isHas_50 = headers.includes('_31')
        console.log("50" + isHas_50)

        var isHas_51 = headers.includes('周三' + "(" + this.days[16] + ")")
        console.log("51" + isHas_51)

        var isHas_52 = headers.includes('_32')
        console.log("52" + isHas_52)

        var isHas_53 = headers.includes('_33')
        console.log("53" + isHas_53)

        var isHas_54 = headers.includes('周四' + "(" + this.days[17] + ")")
        console.log("54" + isHas_54)

        var isHas_55 = headers.includes('_34')
        console.log("55" + isHas_55)

        var isHas_56 = headers.includes('_35')
        console.log("56" + isHas_56)

        var isHas_57 = headers.includes('周五' + "(" + this.days[18] + ")")
        console.log("57" + isHas_57)

        var isHas_58 = headers.includes('_36')
        console.log("58" + isHas_58)

        var isHas_59 = headers.includes('_37')
        console.log("59" + isHas_59)

        var isHas_60 = headers.includes('周六' + "(" + this.days[19] + ")")
        console.log("60" + isHas_60)

        var isHas_61 = headers.includes('_38')
        console.log("61" + isHas_61)

        var isHas_62 = headers.includes('_39')
        console.log("62" + isHas_62)

        var isHas_63 = headers.includes('周日' + "(" + this.days[20] + ")")
        console.log("63" + isHas_63)

        var isHas_64 = headers.includes('_40')
        console.log("64" + isHas_64)

        var isHas_65 = headers.includes('_41')
        console.log("65" + isHas_65)

        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 if (header.length == 23) {
        var isHas_1 = headers.includes('区号')
        console.log("1" + isHas_1)
        var isHas_2 = headers.includes('机号')
        console.log("2" + isHas_2)

        var isHas_3 = headers.includes('周一' + "(" + this.days[0] + ")")
        console.log("3" + isHas_3)

        var isHas_4 = headers.includes('')
        console.log("4" + isHas_4)

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

        var isHas_6 = headers.includes('周二' + "(" + this.days[1] + ")")
        console.log("6" + isHas_6)

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

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

        var isHas_9 = headers.includes('周三' + "(" + this.days[2] + ")")
        console.log("9" + isHas_9)

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

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

        var isHas_12 = headers.includes('周四' + "(" + this.days[3] + ")")
        console.log("12" + isHas_12)

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

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

        var isHas_15 = headers.includes('周五' + "(" + this.days[4] + ")")
        console.log("15" + isHas_15)

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

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

        var isHas_18 = headers.includes('周六' + "(" + this.days[5] + ")")
        console.log("18" + isHas_18)

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

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

        var isHas_21 = headers.includes('周日' + "(" + this.days[6] + ")")
        console.log("21" + isHas_21)

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

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

        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)) {
          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] && results[i + 1]['区号'] != undefined) {
          zones.push(results[i + 1]['区号'])
        }
        if (results[i + 1] && results[i + 1]['机号'] != undefined) {
          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 = []
      let failed_datas = []

      console.log("结果22222222222", results)

      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 = {}

            obj['name'] = results[i + 1][key].replace(/\s/g, '')

            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['row'] = this.getRow(key)

            tempObjTwo = obj
          }

          tempObjTwo['partition_name'] = results[i + 1]['区号']
          tempObjTwo['device_number_name'] = results[i + 1]['机号']
          tempObjTwo['index'] = i + 3

          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)
            if (new Date(tempObjTwo['schedule_date']).getTime() > new Date(current_date_two).getTime()) {
              datas.push(tempObjTwo)
            } else {
              failed_datas.push(tempObjTwo)
            }
          }
        }

      }

      console.log("datas", 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) {
          console.log("err1" + datas[i].device_number_name)

          is_device_number = false

        }

        if (datas[i].partition_name == undefined) {
          console.log("err2" + datas[i].partition_name)

          is_system_zone = false
        }

        if (datas[i].schedule_date === '0') {
          console.log("err23" + datas[i].schedule_date)

          is_system_zone = false

        }

        if (datas[i].schedule_week === '0') {
          console.log("err234" + datas[i].schedule_week)

          is_system_zone = false

        }

        if (datas[i].schedule_type === 0) {
          console.log("err2345" + datas[i].schedule_type)

          is_system_zone = false

        }
      }

      console.log("date_arr", date_arr)
      //校验文档中同一天同个人是否存在多个排班
      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默认类型为数组，并且初始值为空的数组

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

      if (headers.length > 65 || !is_system_zone || !is_device_number) {

        this.dialogVisible = true
        return
      } else {

        if (is_exist_repeat) {
          this.isExistRepeatVisible = true
          return
        } else {
          this.exportVisible = true

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

            }
          });
          console.log("data232332233223", datas)
          console.log("failed_datas33332332", failed_datas)
          var newSchedule = datas.sort((a, b) => {
            return a.schedule_date - b.schedule_date
          })
          var start_time = ""
          var type = 0
          if (failed_datas.length > 0) {
            var oldSchedule = failed_datas.sort((a, b) => {
              return a.schedule_date - b.schedule_date
            })
            start_time = oldSchedule[0].schedule_date
            type = 0
          }

          if (failed_datas.length == 0) {
            start_time = newSchedule[0].schedule_date
            type = 1
          }

          console.log("newSchedule2323223", newSchedule)
          console.log("oldSchedule344433434", oldSchedule)

          var length = newSchedule.length - 1
          let params = {
            schedule: datas,
            failed_schedule: failed_datas,
            start_time: start_time,
            end_time: newSchedule[length].schedule_date,
            delete_type: type,
          }
          console.log("param2323233223", params)
          //今天的时间
          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()
          var date = day2.getFullYear() + '-' + month + '-' + day

          exportSchedule(params, date).then(response => {
            if (response.data.state == 0) {
              return false
            }
            this.getWeekPanels()

          })
        }

      }

    },
    sortData(a, b) {
      return a.schedule_date - b.schedule_date
    },
    getInitDate() {
      initDate().then(response => {
        if (response.data.state == 0) {
          return false
        }
        this.days = response.data.data.days
        console.log("日期22222222", this.days)
      })
    },
    getWeekByResultsStr(key) {

      switch (key) {
        case '周一' + "(" + this.days[0] + ")":
          return '1'
          break
        case  '周一' + "(" + this.days[7] + ")":
          return '1'
          break

        case   '周一' + "(" + this.days[14] + ")":
          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 '周二' + "(" + this.days[1] + ")" :
          return '2'
          break
        case '周二' + "(" + this.days[8] + ")":
          return '2'
          break
        case '周二' + "(" + this.days[15] + ")" :
          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 '周三' + "(" + this.days[2] + ")":
          return '3'
          break
        case '周三' + "(" + this.days[9] + ")":
          return '3'
          break
        case  '周三' + "(" + this.days[16] + ")":
          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 '周四' + "(" + this.days[3] + ")":
          return '4'
          break

        case '周四' + "(" + this.days[10] + ")" :
          return '4'
          break
        case'周四' + "(" + this.days[17] + ")" :
          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 '周五' + "(" + this.days[4] + ")" :
          return '5'
          break

        case  '周五' + "(" + this.days[11] + ")":
          return '5'
          break
        case  '周五' + "(" + this.days[18] + ")" :
          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 '周六' + "(" + this.days[5] + ")":
          return '6'
          break
        case  '周六' + "(" + this.days[12] + ")":
          return '6'
          break
        case  '周六' + "(" + this.days[19] + ")":
          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 '周日' + "(" + this.days[6] + ")":
          return '7'
          break
        case  '周日' + "(" + this.days[13] + ")":
          return '7'
          break
        case '周日' + "(" + this.days[20] + ")":
          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
        default:
          return '0'
          break

      }

    },
    getRow(key) {
      switch (key) {
        case '周一' + "(" + this.days[0] + ")" : //本周一

          return 'C'
          break

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

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

        case '周一' + "(" + this.days[7] + ")": //下周一

          return 'X'

          break

        case '_14': //下周一

          return 'Y'
          break

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

        case '周一' + "(" + this.days[14] + ")" : //下下周一

          return 'AS'
          break

        case  '_28': //下下周一

          return 'AT'
          break

        case '_29': //下下周一

          return 'AU'
          break

        case '周二' + "(" + this.days[1] + ")" : //本周二
          return 'F'
          break

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

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

        case '周二' + "(" + this.days[8] + ")"://下周二
          return 'AA'

          break

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

          break

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

          break

        case '周二' + "(" + this.days[15] + ")"://下下周二
          return 'AV'

          break

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

          break

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

        case '周三' + "(" + this.days[2] + ")": //本周三
          return 'I'

          break

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

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

        case '周三' + "(" + this.days[9] + ")": //下周三
          return 'AD'

          break

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

          break

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

          break

        case '周三' + "(" + this.days[16] + ")" : //下下周三
          return 'AY'

          break

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

          break

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

          break

        case '周四' + "(" + this.days[3] + ")":
          return 'L'

          break

        case '_6' :
          return 'M'

          break

        case  '_7':
          return 'N'

          break

        case '周四' + "(" + this.days[10] + ")":
          return 'AG'

          break

        case '_20' :
          return 'AH'

          break

        case  '_21':

          return 'AI'

          break

        case '周四' + "(" + this.days[17] + ")":

          return 'BB'

          break

        case '_34':

          return 'BC'

          break

        case  '_35':

          return 'BD'

          break
        case '周五' + "(" + this.days[4] + ")":
          return 'O'

          break

        case  '_8':
          return 'P'

          break

        case  '_9':
          return 'Q'
          break
        case '周五' + "(" + this.days[11] + ")":
          return 'AJ'
          break

        case '_22' :
          return 'AK'

          break

        case  '_23':
          return 'AL'

          break
        case '周五' + "(" + this.days[18] + ")":
          return 'BE'

          break

        case '_36':
          return 'BF'

          break

        case  '_37':
          return 'BG'

          break

        case '周六' + "(" + this.days[5] + ")" :
          return 'R'

          break

        case  '_10' :
          return 'S'

          break

        case '_11':
          return 'T'

          break
        case '周六' + "(" + this.days[12] + ")":
          return 'AM'

          break

        case  '_24' :
          return 'AN'

          break

        case  '_25':
          return 'AO'

          break

        case '周六' + "(" + this.days[19] + ")":
          return 'BH'

          break

        case '_38' :
          return 'BI'

          break

        case '_39':
          return 'BJ'

          break
        case '周日' + "(" + this.days[6] + ")" :
          return 'U'

          break

        case  '_12' :
          return 'V'

          break

        case  '_13':
          return 'W'

          break
        case '周日' + "(" + this.days[13] + ")":
          return 'AP'

          break

        case  '_26' :
          return 'AQ'

          break

        case  '_27':
          return 'AR'

          break
        case '周日' + "(" + this.days[20] + ")":
          return 'BK'

          break

        case '_40':
          return 'BL'

          break

        case '_41':
          return 'BM'
          break
      }

    }, 
    getDateByResultsStr(key) {

      switch (key) {
        case '周一' + "(" + this.days[0] + ")" : //本周一

          return this.days[0]
          break

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

          break

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

        case '周一' + "(" + this.days[7] + ")": //下周一
          return this.days[7]

          break

        case '_14': //下周一

          return this.days[7]

          break

        case   '_15': //下周一

          return this.days[7]

          break

        case '周一' + "(" + this.days[14] + ")": //下下周一

          return this.days[14]

          break

        case  '_28': //下下周一

          return this.days[14]

          break

        case '_29': //下下周一

          return this.days[14]

          break

        case '周二' + "(" + this.days[1] + ")": //本周二
          return this.days[1]

          break

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

          break

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

          break

        case '周二' + "(" + this.days[8] + ")"://下周二
          return this.days[8]

          break

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

          break

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

          break

        case '周二' + "(" + this.days[15] + ")"://下下周二
          return this.days[15]

          break

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

          break

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

          break

        case '周三' + "(" + this.days[2] + ")" : //本周三
          return this.days[2]

          break

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

          break

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

          break

        case '周三' + "(" + this.days[9] + ")": //下周三
          return this.days[9]

          break

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

          break

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

          break

        case '周三' + "(" + this.days[16] + ")": //下下周三
          return this.days[16]

          break

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

          break

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

          break

        case '周四' + "(" + this.days[3] + ")":
          return this.days[3]

          break

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

          break

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

          break

        case '周四' + "(" + this.days[10] + ")":

          return this.days[10]

          break

        case '_20' :

          return this.days[10]

          break

        case  '_21':

          return this.days[10]

          break

        case '周四' + "(" + this.days[17] + ")":

          return this.days[17]

          break

        case '_34':

          return this.days[17]

          break

        case  '_35':

          return this.days[17]

          break
        case '周五' + "(" + this.days[4] + ")":
          return this.days[4]

          break

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

          break

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

          break
        case '周五' + "(" + this.days[11] + ")" :
          return this.days[11]

          break

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

          break

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

          break
        case '周五' + "(" + this.days[18] + ")":
          return this.days[18]

          break

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

          break

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

          break

        case '周六' + "(" + this.days[5] + ")":
          return this.days[5]

          break

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

          break

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

          break
        case '周六' + "(" + this.days[12] + ")":
          return this.days[12]

          break

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

          break

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

          break

        case '周六' + "(" + this.days[19] + ")":
          return this.days[19]

          break

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

          break

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

          break
        case '周日' + "(" + this.days[6] + ")" :
          return this.days[6]

          break

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

          break

        case  '_13':
          return this.days[6]
          break
        case '周日' + "(" + this.days[13] + ")":
          return this.days[13]

          break

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

          break

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

          break
        case '周日' + "(" + this.days[20] + ")":
          return this.days[20]

          break

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

          break

        case '_41':
          return this.days[20]
          break
        default:
          return '0'
          break

      }

    },

    getNextWeek(i) {
      let weekOfDay = parseInt(moment().format('E'));//计算今天是这周第几天
      let next_monday = moment().add((7 - weekOfDay) + 7 * (i - 1) + 1, 'days').format('YYYY-MM-DD');//周一日期
      let next_sunday = moment().add((7 - weekOfDay) + 7 * i, 'days').format('YYYY-MM-DD');//周日日期
      return next_sunday
    },

    getNextWeekOne(i) {
      let weekOfDay = parseInt(moment().format('E'));//计算今天是这周第几天
      let next_monday = moment().add((7 - weekOfDay) + 7 * (i - 1) + 1, 'days').format('YYYY-MM-DD');//周一日期

      return next_monday
    },
    //
    getThreeWeekList() {
      var params = {
        start_time: this.start_time,
        end_time: this.end_time,
        partition_id: this.partition_id,
        schedule_type: this.schedule_type
      }
      console.log("params32323232323223", params)
      getThreeWeekList(params).then(response => {
        if (response.data.state == 1) {
          var partitions = response.data.data.partitions

          const merges = ['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']
          var list = []
          let i = 0

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

            if (i == 0) {
              let m = 'A3' + ':' + 'A' + (2 + jihaos.length)
              tempValue = (2 + jihaos.length)
              merges.push(m)
            } else {
              let m = 'A' + (tempValue + 1) + ':' + 'A' + ((tempValue + 1) + jihaos.length - 1)
              tempValue = ((tempValue + 1) + jihaos.length - 1)
              merges.push(m)
            }
            console.log("jihaos", jihaos)
            for (let b = 0; b < jihaos.length; b++) {
              var obj = {}

              obj['区号'] = partitions[key].name
              obj['机号'] = jihaos[b].number.toString()

              if (this.export_type == 0) {
                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'] = ''
              }

              if (this.export_type == 1) {
                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'] = ''
              }
              list.push(obj)

            }
            i++
          }

          const start_time = moment().weekday(1).format('YYYY-MM-DD'); //本周一
          var start = this.getTimestamp(start_time) - 28800
          console.log("start", start)
          const end_time = moment().weekday(7).format('YYYY-MM-DD');
          var end = this.getTimestamp(end_time) - 28800
          console.log("end", end)
          var scheduleList = response.data.data.list

          var week = []
          var nextWeek = []
          var lastWeek = []
          var next_start = this.getNextWeekOne(1)
          var nextstart = this.getTimestamp(next_start) - 28800

          var next_end = this.getNextWeek(1)
          var nextend = this.getTimestamp(next_end) - 28800

          var last_start = this.getNextWeekOne(2)
          var last_end = this.getNextWeek(2)
          var laststart = this.getTimestamp(last_start) - 28800

          var lastend = this.getTimestamp(last_end) - 28800

          if (this.export_type == 0) {
            for (let i = 0; i < scheduleList.length; i++) {
              if (scheduleList[i].schedule_date >= start && scheduleList[i].schedule_date <= end) {
                week.push(scheduleList[i])
              }
              if (scheduleList[i].schedule_date >= nextstart && scheduleList[i].schedule_date <= nextend) {
                nextWeek.push(scheduleList[i])
              }

              if (scheduleList[i].schedule_date >= laststart && scheduleList[i].schedule_date <= lastend) {
                lastWeek.push(scheduleList[i])
              }
            }
          }

          if (this.export_type == 1) {
            week = scheduleList
          }
          console.log("list")
          console.log(list)
          console.log("week")
          console.log(week)

          if (week.length > 0) {
            for (let i = 0; i < list.length; i++) {
              for (let j = 0; j < week.length; j++) {
                if (list[i].机号 == week[j].number && list[i].区号 == week[j].zon_name) {
                  //  周一上午
                  if (week[j].schedule_week == 1 && week[j].schedule_type == 1) {
                    console.log(week[j].name)
                    list[i].shangwu = week[j].name
                  }
                  // 周一下午
                  if (week[j].schedule_week == 1 && week[j].schedule_type == 2) {
                    list[i].xiawu = week[j].name
                  }
                  // 周一晚上
                  if (week[j].schedule_week == 1 && week[j].schedule_type == 3) {
                    list[i].wanshang = week[j].name
                  }

                  //周二上午
                  if (week[j].schedule_week == 2 && week[j].schedule_type == 1) {
                    list[i].shangwu1 = week[j].name
                  }
                  //周二下午
                  if (week[j].schedule_week == 2 && week[j].schedule_type == 2) {
                    list[i].xiawu1 = week[j].name
                  }
                  //周二晚上
                  if (week[j].schedule_week == 2 && week[j].schedule_type == 3) {
                    list[i].wanshang1 = week[j].name
                  }

                  //周三上午
                  if (week[j].schedule_week == 3 && week[j].schedule_type == 1) {
                    list[i].shangwu2 = week[j].name
                  }
                  //周三下午
                  if (week[j].schedule_week == 3 && week[j].schedule_type == 2) {
                    list[i].xiawu2 = week[j].name
                  }
                  //周三晚上
                  if (week[j].schedule_week == 3 && week[j].schedule_type == 3) {
                    list[i].wanshang2 = week[j].name
                  }
                  //周四上午
                  if (week[j].schedule_week == 4 && week[j].schedule_type == 1) {
                    list[i].shangwu3 = week[j].name
                  }
                  //周四下午
                  if (week[j].schedule_week == 4 && week[j].schedule_type == 2) {
                    list[i].xiawu3 = week[j].name
                  }
                  //周四晚上
                  if (week[j].schedule_week == 4 && week[j].schedule_type == 3) {
                    list[i].wanshang3 = week[j].name
                  }
                  //周五上午
                  if (week[j].schedule_week == 5 && week[j].schedule_type == 1) {
                    list[i].shangwu4 = week[j].name
                  }
                  //周五下午
                  if (week[j].schedule_week == 5 && week[j].schedule_type == 2) {
                    list[i].xiawu4 = week[j].name
                  }
                  //周五晚上
                  if (week[j].schedule_week == 5 && week[j].schedule_type == 3) {
                    list[i].wanshang4 = week[j].name
                  }
                  //周六上午
                  if (week[j].schedule_week == 6 && week[j].schedule_type == 1) {
                    list[i].shangwu5 = week[j].name
                  }
                  //周六下午
                  if (week[j].schedule_week == 6 && week[j].schedule_type == 2) {
                    list[i].xiawu5 = week[j].name
                  }
                  //周六晚上
                  if (week[j].schedule_week == 6 && week[j].schedule_type == 3) {
                    list[i].wanshang5 = week[j].name
                  }
                  //周日上午
                  if (week[j].schedule_week == 7 && week[j].schedule_type == 1) {
                    list[i].shangwu6 = week[j].name
                  }
                  //周日下午
                  if (week[j].schedule_week == 7 && week[j].schedule_type == 2) {
                    list[i].xiawu6 = week[j].name
                  }
                  //周日晚上
                  if (week[j].schedule_week == 7 && week[j].schedule_type == 3) {
                    list[i].wanshang6 = week[j].name
                  }
                }

              }
            }
          }

          if (nextWeek.length > 0) {
            for (let i = 0; i < list.length; i++) {
              for (let j = 0; j < nextWeek.length; j++) {
                if (list[i].机号 == nextWeek[j].number && list[i].区号 == nextWeek[j].zon_name) {
                  //周一
                  if (nextWeek[j].schedule_week == 1 && nextWeek[j].schedule_type == 1) {
                    list[i].shangwu7 = nextWeek[j].name
                  }
                  //周一下午
                  if (nextWeek[j].schedule_week == 1 && nextWeek[j].schedule_type == 2) {
                    list[i].xiawu7 = nextWeek[j].name
                  }
                  //周一晚上
                  if (nextWeek[j].schedule_week == 1 && nextWeek[j].schedule_type == 3) {
                    list[i].wanshang7 = nextWeek[j].name
                  }

                  //周二上午
                  if (nextWeek[j].schedule_week == 2 && nextWeek[j].schedule_type == 1) {
                    list[i].shangwu8 = nextWeek[j].name
                  }
                  //周二下午
                  if (nextWeek[j].schedule_week == 2 && nextWeek[j].schedule_type == 2) {
                    list[i].xiawu8 = nextWeek[j].name
                  }
                  //周二晚上
                  if (nextWeek[j].schedule_week == 2 && nextWeek[j].schedule_type == 3) {
                    list[i].wanshang8 = nextWeek[j].name
                  }

                  //周三上午
                  if (nextWeek[j].schedule_week == 3 && nextWeek[j].schedule_type == 1) {
                    list[i].shangwu9 = nextWeek[j].name
                  }
                  //周三下午
                  if (nextWeek[j].schedule_week == 3 && nextWeek[j].schedule_type == 2) {
                    list[i].xiawu9 = nextWeek[j].name
                  }
                  //周三晚上
                  if (nextWeek[j].schedule_week == 3 && nextWeek[j].schedule_type == 3) {
                    list[i].wanshang9 = nextWeek[j].name
                  }

                  //周四上午
                  if (nextWeek[j].schedule_week == 4 && nextWeek[j].schedule_type == 1) {
                    list[i].shangwu10 = nextWeek[j].name
                  }
                  //周四下午
                  if (nextWeek[j].schedule_week == 4 && nextWeek[j].schedule_type == 2) {
                    list[i].xiawu10 = nextWeek[j].name
                  }
                  //周四晚上
                  if (nextWeek[j].schedule_week == 4 && nextWeek[j].schedule_type == 3) {
                    list[i].wanshang10 = nextWeek[j].name
                  }

                  //周五上午
                  if (nextWeek[j].schedule_week == 5 && nextWeek[j].schedule_type == 1) {
                    list[i].shangwu11 = nextWeek[j].name
                  }
                  //周五下午
                  if (nextWeek[j].schedule_week == 5 && nextWeek[j].schedule_type == 2) {
                    list[i].xiawu11 = nextWeek[j].name
                  }
                  //周五晚上
                  if (nextWeek[j].schedule_week == 5 && nextWeek[j].schedule_type == 3) {
                    list[i].wanshang11 = nextWeek[j].name
                  }

                  //周六上午
                  if (nextWeek[j].schedule_week == 6 && nextWeek[j].schedule_type == 1) {
                    list[i].shangwu12 = nextWeek[j].name
                  }
                  //周六下午
                  if (nextWeek[j].schedule_week == 6 && nextWeek[j].schedule_type == 2) {
                    list[i].xiawu12 = nextWeek[j].name
                  }
                  //周六晚上
                  if (nextWeek[j].schedule_week == 6 && nextWeek[j].schedule_type == 3) {
                    list[i].wanshang12 = nextWeek[j].name
                  }

                  //周日上午
                  if (nextWeek[j].schedule_week == 7 && nextWeek[j].schedule_type == 1) {
                    list[i].shangwu13 = nextWeek[j].name
                  }
                  //周日下午
                  if (nextWeek[j].schedule_week == 7 && nextWeek[j].schedule_type == 2) {
                    list[i].xiawu13 = nextWeek[j].name
                  }
                  //周日晚上
                  if (nextWeek[j].schedule_week == 7 && nextWeek[j].schedule_type == 3) {
                    list[i].wanshang13 = nextWeek[j].name
                  }
                }

              }
            }
          }
          //
          if (lastWeek.length > 0) {
            for (let i = 0; i < list.length; i++) {
              for (let j = 0; j < lastWeek.length; j++) {
                if (list[i].机号 == lastWeek[j].number && list[i].区号 == lastWeek[j].zon_name) {
                  //周一
                  if (lastWeek[j].schedule_week == 1 && lastWeek[j].schedule_type == 1) {
                    list[i].shangwu14 = lastWeek[j].name
                  }
                  //周一下午
                  if (lastWeek[j].schedule_week == 1 && lastWeek[j].schedule_type == 2) {
                    list[i].xiawu14 = lastWeek[j].name
                  }
                  //周一晚上
                  if (lastWeek[j].schedule_week == 1 && lastWeek[j].schedule_type == 3) {
                    list[i].wanshang14 = lastWeek[j].name
                  }

                  //周二
                  if (lastWeek[j].schedule_week == 2 && lastWeek[j].schedule_type == 1) {
                    list[i].shangwu15 = lastWeek[j].name
                  }
                  //周二下午
                  if (lastWeek[j].schedule_week == 2 && lastWeek[j].schedule_type == 2) {
                    list[i].xiawu15 = lastWeek[j].name
                  }
                  //周二晚上
                  if (lastWeek[j].schedule_week == 2 && lastWeek[j].schedule_type == 3) {
                    list[i].wanshang15 = lastWeek[j].name
                  }

                  //周三
                  if (lastWeek[j].schedule_week == 3 && lastWeek[j].schedule_type == 1) {
                    list[i].shangwu16 = lastWeek[j].name
                  }
                  //周三下午
                  if (lastWeek[j].schedule_week == 3 && lastWeek[j].schedule_type == 2) {
                    list[i].xiawu16 = lastWeek[j].name
                  }
                  //周三晚上
                  if (lastWeek[j].schedule_week == 3 && lastWeek[j].schedule_type == 3) {
                    list[i].wanshang16 = lastWeek[j].name
                  }

                  //周四
                  if (lastWeek[j].schedule_week == 4 && lastWeek[j].schedule_type == 1) {
                    list[i].shangwu17 = lastWeek[j].name
                  }
                  //周四下午
                  if (lastWeek[j].schedule_week == 4 && lastWeek[j].schedule_type == 2) {
                    list[i].xiawu17 = lastWeek[j].name
                  }
                  //周四晚上
                  if (lastWeek[j].schedule_week == 4 && lastWeek[j].schedule_type == 3) {
                    list[i].wanshang17 = lastWeek[j].name
                  }

                  //周五
                  if (lastWeek[j].schedule_week == 5 && lastWeek[j].schedule_type == 1) {
                    list[i].shangwu18 = lastWeek[j].name
                  }
                  //周五下午
                  if (lastWeek[j].schedule_week == 5 && lastWeek[j].schedule_type == 2) {
                    list[i].xiawu18 = lastWeek[j].name
                  }
                  //周五晚上
                  if (lastWeek[j].schedule_week == 5 && lastWeek[j].schedule_type == 3) {
                    list[i].wanshang18 = lastWeek[j].name
                  }

                  //周六
                  if (lastWeek[j].schedule_week == 6 && lastWeek[j].schedule_type == 1) {
                    list[i].shangwu19 = lastWeek[j].name
                  }
                  //周六下午
                  if (lastWeek[j].schedule_week == 6 && lastWeek[j].schedule_type == 2) {
                    list[i].xiawu19 = lastWeek[j].name
                  }
                  //周六晚上
                  if (lastWeek[j].schedule_week == 6 && lastWeek[j].schedule_type == 3) {
                    list[i].wanshang19 = lastWeek[j].name
                  }

                  //周日
                  if (lastWeek[j].schedule_week == 7 && lastWeek[j].schedule_type == 1) {
                    list[i].shangwu20 = lastWeek[j].name
                  }
                  //周日下午
                  if (lastWeek[j].schedule_week == 7 && lastWeek[j].schedule_type == 2) {
                    list[i].xiawu20 = lastWeek[j].name
                  }
                  //周日晚上
                  if (lastWeek[j].schedule_week == 7 && lastWeek[j].schedule_type == 3) {
                    list[i].wanshang20 = lastWeek[j].name
                  }
                }

              }
            }
          }
          this.tableList = list
          this.start_time = ""
          this.end_time = ""
        }
      })
    },

    changePartition(val) {
      this.partition_id = val
      // this.getThreeWeekList()
      // this.getWeekPanels()
   },

    changeSchedule(val) {
      this.schedule_type = vald
      this.getThreeWeekList()
      this.getWeekPanels()
    },

    changeWeekDay(val){
      console.log("Val2332322323wo",val)
      var str = val.join(",")
      console.log("stor233233223",str)
      this.week_date = str
    },

    changeWeek(val) {
      this.start_time = ""
      this.end_time = ""
      this.newDay = []
      var start = this.getTimestamp(val) - 57600

      this.start_time = this.getTime(start)

      this.newDay.push(this.start_time)
      var next = start + 86400
      var nest_day = this.getTime(next)

      this.newDay.push(nest_day)
      var last_days = start + 172800

      var last_day = this.getTime(last_days)

      this.newDay.push(last_day)

      var tuesdays = start + 259200

      var tuesday = this.getTime(tuesdays)

      this.newDay.push(tuesday)
      var fivdays = start + 345600
      var fiveday = this.getTime(fivdays)

      this.newDay.push(fiveday)
      var sixday = start + 432000
      var sixdays = this.getTime(sixday)

      this.newDay.push(sixdays)
      var end = this.getTimestamp(val) + 460800

      this.end_time = this.getTime(end)

      this.newDay.push(this.end_time)
      this.export_type = 1
      this.getThreeWeekList()
    },

    getTime(val) {
      return uParseTime(val, '{y}-{m}-{d}')
    },
     smartsch(){
      this.$nextTick(function() {
        this.$refs.edittableData.showSmartDialog()
      })
    },
    editsch() {
      this.is_edit = true
      this.schedulingTableVisible=true
      this.$nextTick(function() {//, this.days,this.zones
        this.$refs.edittableData.setEditData(this.patientList, this.$store.getters.treatment_mode, this.days,this.zones)
      })
    },
    outisedit(){
      this.is_edit=false
      this.schedulingTableVisible=false
    },
    copySchedule() {
      this.newVisible = true
    },

    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) - 1;
    },
    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
    },
    submitAction(formName) {
      var start_time = ""
      var end_time = ""
      //上周
      if (this.form.lastweek == "1") {
        let weekOfday = parseInt(moment().format('d'))
        start_time = this.getTimestamp(moment().subtract(weekOfday + 6, 'days').format('YYYY-MM-DD')) - 28800
        end_time = this.getTimestamp(moment().subtract(weekOfday, 'days').format('YYYY-MM-DD')) - 28800

      }

      //本周
      if (this.form.lastweek == "2") {
        start_time = this.getTimestamp(this.weekDayArr[0])
        end_time = this.getTimestamp(this.weekDayArr[6])

      }

      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])

      const params = {
        start_time: start_time,
        end_time: end_time,
        copy_startime: copy_startime,
        copy_endtime: copy_endtime,
      }

      this.$refs[formName].validate(valid => {
        if (valid) {
          if(!this.copySchLoading){
            this.copySchLoading = true
            copyPatientSchedule(params).then(response => {
              if (response.data.state == 1) {
                var msg = response.data.data.msg
                this.$message.success("复制成功")
                this.copySchLoading = false
                this.newVisible = false
              } else {
                this.copySchLoading = false
                this.$message.error("复制失败")
              }
            })

          }

        }
      })
    },
    getlist() {
      getScheduleTemplate().then(response => {

        if (response.data.state == 1) {
          var template = response.data.data.template
          console.log('12243254',response.data.data);
          this.templateObj = template
        }
      })
    },
    getPatientList(){
      patientLists().then(response => {
        if (response.data.state == 1) {
          var patientList = response.data.data.list
          this.patientList = patientList
          console.log("list")
          console.log( this.patientList)
        }
      })

    }
  },
  created() {
    this.getlist()
    this.getPatientList()
    var start_time = moment().weekday(1).format('YYYY-MM-DD');

    this.start_time = start_time

    var end_time = this.getNextWeek(2)

    this.end_time = end_time
    this.getWeekPanels()
    this.getInitDate()

    //获取三周排班数据
    this.getThreeWeekList()

    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())

    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 + 2 <= 53) {
        let num = this.weekNum + i + 2
        let str = this.weekList[i][0] + '~' + this.weekList[i][6] + '(' + num + ')'
        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] + '(' + newNum + ')'
        this.typeOptions.push({value: i, label: str})
        let stt = this.weekList[i][0] + "~" + this.weekList[i][6]
        this.timeOptions.push({value: i, label: stt})
      }

    }

  }
}
</script>

<style rel="stylesheet/css" lang="scss">

.schedule-table-cell-disable {
  background-color: #F5F5F5 !important;
}
</style>

