<template>
  <div>
    <el-collapse v-model="activeName"
                 v-if="dataList.length > 0"
                 accordion>
      <el-collapse-item v-for="
                 (item,index)
                 in
                 dataList"
                        :key="index"
                        :title="getTitle(item)"
                        :name="index">
                        <template slot="title">
                          <header class="header">
                            {{item.operatorName}} <span>在</span> {{item.createTime}} <span>修改了</span>
                          </header>
                        </template>
                        <infoMsgContent
                          :before="item.previousCourseSchedule"
                          :after="item.currentCourseSchedule"
                        />
      </el-collapse-item>
    </el-collapse>
    <div v-if="dataList.length <= 0"
         class="noBox">
      <p>暂无调整记录</p>
    </div>
  </div>
</template>
<script>
import { diffTimerFormMinute, addTimerFormMinute } from '@/utils/date'
import dayjs from 'dayjs';
import {
  queryCourseAdjustDetail,
} from "@/api/buildTeam";
import { teachMode } from '@/constant'
import infoMsgContent from './infoMsgContent'
export default {
  props: ['courseScheduleId'],
  data () {
    return {
      activeName: 0,
      dataList: [],
    }
  },
  components: { infoMsgContent },
  mounted () {
    queryCourseAdjustDetail({ courseScheduleId: this.courseScheduleId }).then(res => {
      if (res.code == 200) {
        if (res.data) {
          this.dataList = res.data.map(item => {
            const parsecurrent = JSON.parse(item.currentCourseSchedule)
            const currentCourseSchedule = this.filterKeys(parsecurrent)
            const previousCourseSchedule = this.filterKeys(JSON.parse(item.previousCourseSchedule))
            return {
              ...item,
              operatorName: parsecurrent.operatorName,
              currentCourseSchedule,
              previousCourseSchedule,
            }
          })
        }
      }
    })
  },
  methods: {
    filterKeys(item) {
      const teachingTeacherNames = (item.teachingTeacherNames || '').split(',').sort((a, b) => (a || '').localeCompare((b || ''), 'zh'))
      return {
        name: item.name,
        actualTeacherName: item.actualTeacherName,
        teachingTeacherNames: teachingTeacherNames.join(','),
        startClassTime: item.startClassTime,
        // classDate: item.classDate,
        // endClassTime: item.endClassTime,
        teachMode: teachMode[item.teachMode],
        schoolName: item.schoolName,
        timers: this.getTimers(item),
      }
    },
    getTitle (item) {
      return item.operatorName + ' 在 ' + item.createTime + ' 修改了'
    },
    getTimers (item) {
      return diffTimerFormMinute(dayjs(item.classDate).format('YYYY-MM-DD'), dayjs(item.startClassTime).format('HH:mm'), dayjs(item.endClassTime).format('HH:mm'))
    }
  },
  computed: {

  }
}
</script>
<style lang="scss" scoped>
.noBox {
  min-height: 200px;
  p {
    text-align: center;
    margin-top: 120px;
  }
}
.header{
  >span{
    color: rgba($color: #000000, $alpha: .6);
    display: inline-block;
    margin: 0 6px;
  }
}
</style>
