<template>
  <div>
    <el-form :inline="true">
      <el-form-item label="应交学生数">
        <!-- <el-input disabled
                  :value="studentNum"></el-input> -->
        <div class="inputStyle">{{  studentNum}}</div>
      </el-form-item>
      <el-form-item label="已交学生数">
        <!-- <el-input disabled
                  :value="homeworkNum"></el-input> -->
        <div class="inputStyle">{{ homeworkNum}}</div>
      </el-form-item>
      <el-form-item label="已回复数">
        <!-- <el-input disabled
                  :value="repliedNum"></el-input> -->
        <div class="inputStyle">{{ repliedNum}}</div>
      </el-form-item>
    </el-form>
    <p class="work">老师布置的作业:{{content}}</p>
    <div class="tableWrap">
      <el-table :data='tableList'
                :header-cell-style="{background:'#EDEEF0',color:'#444'}">
        <el-table-column align='center'
                         prop="username"
                         label="学生姓名">
        </el-table-column>
        <el-table-column align='center'
                         prop="phone"
                         label="手机号">
        </el-table-column>
        <el-table-column align='center'
                         prop="subjectName"
                         label="声部名称">
        </el-table-column>
        <el-table-column align='center'
                         prop="createTime"
                         label="交作业时间">
        </el-table-column>
        <el-table-column align='center'
                         prop="isView"
                         label="是否查看">
          <template slot-scope="scope">
            <div>
              {{ scope.row.isView ? '是' : '否' }}
            </div>
          </template>
        </el-table-column>
        <el-table-column align='center'
                         prop="isReplied"
                         label="是否回复">
          <template slot-scope="scope">
            <div>
              {{ scope.row.isReplied ? '是' : '否' }}
            </div>
          </template>
        </el-table-column>
        <el-table-column align='center'
                         label="操作">
          <template slot-scope="scope">
            <div>
              <!--   -->
              <el-button type="text"
                         v-if="scope.row.url"
                         @click="lookWork(scope.row.url)">查看</el-button>
            </div>
          </template>

        </el-table-column>
      </el-table>
      <pagination :total="rules.total"
                  :page.sync="rules.page"
                  :limit.sync="rules.limit"
                  @pagination="getList" />
    </div>
    <el-dialog title="查看作业"
               @close="closeWorkVisible"
               width="680px"
               append-to-body
               :visible.sync="workVisible">
      <!-- activeUrl -->
      <video style="width:640px;"
             :src='activeUrl'
             ref="dialogVideo"
             controls="controls">
        您的浏览器不支持视频播放
      </video>
    </el-dialog>
  </div>
</template>
<script>
import pagination from '@/components/Pagination/index'
import { findStudentCourseHomeworks, sumStudentAttendance, getCourseScheduleHomework } from '@/api/buildTeam'
export default {
  props: ['courseScheduleId'],
  components: { pagination },
  data () {
    return {
      tableList: [],
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
      },
      workVisible: false,
      studentNum: null,
      homeworkNum: null,
      repliedNum: null,
      activeUrl: null,
      content: null
    }
  },
  mounted () {
    this.init()
  },
  activated () {
    this.init()
  },
  methods: {
    init () {
      sumStudentAttendance({ courseScheduleId: this.courseScheduleId }).then(res => {
        if (res.code == 200) {
          this.studentNum = res.data.studentNum;
          this.homeworkNum = res.data.homeworkNum;
          this.repliedNum = res.data.repliedNum
        }
      })
      //this.courseScheduleId 
      // 

      getCourseScheduleHomework({ courseScheduleId: this.courseScheduleId }).then(res => {
        if (res.code == 200) {
          if (res.data) {
            this.content = res.data.content
          }
          this.content ? this.content : this.content = '还未布置作业'
        }
      })
      this.getList()
    },
    getList () {
      findStudentCourseHomeworks({ search: this.courseScheduleId }).then(res => {
        if (res.code == 200) {
          this.rules.total = res.data.total
          this.tableList = res.data.rows
        }
      })
    },
    lookWork (url) {
      this.workVisible = true;
      this.activeUrl = url;
    },
    closeWorkVisible () {
      this.activeUrl = '';
    }
  }
}
</script>
<style lang="scss" scoped>
.inputStyle {
  width: 100px;
  text-align: center;
}
.work {
  margin-bottom: 30px;
  font-size: 16px;
}
</style>