<template>
  <div>
    <el-form inline>
      <el-form-item label="主教老师：">{{coreTeacherName}}</el-form-item>
      <el-form-item label="助教老师：" v-if="assistantName">{{assistantName}}</el-form-item>
    </el-form>
    <el-table
      :header-cell-style="{background:'#EDEEF0',color:'#444'}"
      :data="typelist"
    >
      <el-table-column
        label="课程类型"
        prop="name"
      ></el-table-column>
      <el-table-column
        label="课时数"
        prop="surplus"
      ></el-table-column>
      <el-table-column
        label="总排课时长(分钟)"
        prop="courseTotalMinuties"
      ></el-table-column>
      <el-table-column
        label="剩余时长(分钟)"
        prop="surplusTime"
      ></el-table-column>
    </el-table>
    <div style="color: red;font-weight: bold;margin: 20px 0;">确认排课后剩余时长将被系统删除，不可排课</div>
    <el-table
      :header-cell-style="{background:'#EDEEF0',color:'#444'}"
      :data="details"
      max-height="300px"
    >
      <el-table-column
        label="课程类型"
        prop="type"
      >
        <span slot-scope="scope">{{courseTypeListByName[scope.row.type]}}</span>
      </el-table-column>
      <el-table-column
        label="开始时间"
        prop="startClassTime"
      ></el-table-column>
      <el-table-column
        label="课程时长（分钟）"
        key="time"
      >
        <span slot-scope="scope">{{getTimers(scope.row)}}</span>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { diffTimerFormMinute } from '@/utils/date'
import dayjs from 'dayjs';
export default {
  props: {
    types: {
      type: Object,
      default: {}
    },
    details: {
      type: Array,
      default: []
    },
    courseTypeListByName: {
      type: Object,
      default: {}
    },
    teacherList: {
      type: Array,
      default: []
    },
    cooperationList: {
      type: Array,
      default: []
    },
    coreTeacher: {
      type: String
    },
    assistant: {
      type: Array,
      default: []
    },
  },
  computed: {
    coreTeacherName() {
      let name = ''
      for (const item of this.teacherList) {
        if (this.coreTeacher == item.id) {
          name = item.realName
          break
        }
      }
      return name
    },
    assistantName() {
      let names = []
      for (const item of this.cooperationList) {
        if (this.assistant.includes(item.id)) {
          names.push(item.realName)
        }
      }
      return names.join(' ')
    },
    typelist() {
      const list = []
      for (const key in this.types) {
        if (Object.hasOwnProperty.call(this.types, key)) {
          const item = this.types[key];
          let surplusTime = 0
          let surplus = 0
          for (const ke of item.cycle) {
            surplus += parseFloat(ke.expectCourseNum)
            surplusTime += (parseFloat(ke.expectCourseNum) * parseFloat(ke.time))
          }
          surplusTime = item.courseTotalMinuties - surplusTime
          list.push({
            name: this.courseTypeListByName[key],
            cycles: item.cycle.length,
            courseTotalMinuties: item.courseTotalMinuties,
            surplus,
            surplusTime
          })
        }
      }
      return list
    }
  },
  mounted() {
    console.log(this)
  },
  methods: {
    getTimers (item) {
      const time = diffTimerFormMinute(dayjs(item.classDate).format('YYYY-MM-DD'), dayjs(item.startClassTime).format('HH:mm'), dayjs(item.endClassTime).format('HH:mm'))
      console.log(time, item)
      return time
    }
  }
}
</script>

<style lang="less" scoped>

</style>
