<!--  -->
<template>
  <div class="m-container">
    <h2>
      <div class="squrt"></div>
      课后练习
    </h2>
    <div class="m-core">
      <save-form
        :inline="true"
        :model="searchForm"
        @submit="search"
        @reset="onReSet"
        ref="saveForm"
      >
        <el-form-item>
          <el-input
            class="search"
            v-model.trim="searchForm.search"
            clearable
            @keyup.enter.native="
              e => {
                e.target.blur();
                $refs.saveForm.save();
                search();
              }
            "
            placeholder="课程编号/名称/乐团名称/老师"
          ></el-input>
        </el-form-item>
        <el-form-item prop="organId">
          <el-select
            class="multiple"
            filterable
            v-model.trim="searchForm.organId"
            clearable
            placeholder="请选择分部"
          >
            <el-option
              v-for="(item, index) in selects.branchs"
              :key="index"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item>
          <el-select
            v-model.trim="searchForm.groupType"
            class="organSelect"

            filterable
            placeholder="请选择课程类型"
          >
            <el-option
              v-for="(item, index) in courseListType"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <!-- <el-form-item>
          <el-select
            v-model.trim="searchForm.cloudHomeworkFlag"
            class="organSelect"
            clearable
            filterable
            placeholder="是否学练宝布置"
          >
            <el-option label="是" :value="true"></el-option>
            <el-option label="否" :value="false"></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item>
          <el-date-picker
            v-model.trim="searchForm.courseTimer"
            style="width: 420px"
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="上课开始日期"
            end-placeholder="上课结束日期"
            :picker-options="{
              firstDayOfWeek: 1
            }"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button native-type="submit" type="danger">搜索</el-button>
          <el-button native-type="reset" type="primary">重置</el-button>
        </el-form-item>
      </save-form>
      <div class="tableWrap">
        <el-table
          style="width: 100%"
          :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
          :data="tableList"
        >
          <el-table-column
            align="center"
            prop="courseScheduleId"
            label="课程编号"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="courseScheduleName"
            label="课程名称"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="organName"
            label="分部"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="groupName"
            label="乐团"
          ></el-table-column>
          <el-table-column align="center" label="布置时间">
            <template slot-scope="scope">
              <div>
                {{
                  scope.row.createTime ? scope.row.createTime.substr(0, 16) : ""
                }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="actualTeacherName"
            label="布置老师"
          ></el-table-column>
          <!-- <el-table-column align="center" prop="actualTeacherName" label="是否学练宝布置">
            <template slot-scope="scope">
              <div>
                {{ scope.row.musicScoreId ? "是" : "否" }}
              </div>
            </template>
          </el-table-column> -->
          <el-table-column
            align="center"
            prop="expectNum"
            label="应交人数"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="completedNum"
            label="完成人数"
          ></el-table-column>
          <!-- <el-table-column
            align="center"
            prop="repliedNum"
            label="已回复数"
          ></el-table-column> -->
          <el-table-column align="center" prop="studentId" label="操作">
            <template slot-scope="scope">
              <div>
                <auth auths="/teamCourseListDetailWorkList/attendanceList">
                  <el-button type="text" @click="lookDetail(scope.row)"
                    >查看</el-button
                  >
                </auth>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          sync
          :total.sync="rules.total"
          :page.sync="rules.page"
          :limit.sync="rules.limit"
          :page-sizes="rules.page_size"
          @pagination="getList"
        />
        <el-dialog
          title="详情"
          :visible.sync="classVisible"
          width="1000px"
          v-if="classVisible"
        >
          <studentWork
            v-if="activeRow.versionTag == 'v1'"
            :courseScheduleId="activeRow.courseScheduleId"
          ></studentWork>
          <courseWorkeDetail
            v-else
            :courseScheduleId="activeRow.courseScheduleId"
          />
        </el-dialog>
      </div>
    </div>
  </div>
</template>

<script>
import pagination from "@/components/Pagination/index";
import { courseListType } from "@/utils/searchArray";
import studentWork from "@/views/teamDetail/componentCourse/studentWork";
import { getHomePageList } from "./api.js";
import { getTimes } from "@/utils";
import courseWorkeDetail from "@/views/attendanceManager/attendanceList/components/courseWorkeDetail.vue";
export default {
  components: { pagination, studentWork, courseWorkeDetail },
  data() {
    return {
      courseListType,
      searchForm: {
        search: null,
        organId: null,
        groupType: "MUSIC",
        courseTimer: []
      },

      teacherList: [],
      tableList: [],
      organList: [],
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50] // 选择限制显示条数
      },
      activeRow: null,
      classVisible: false
    };
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    // getEmployeeOrgan().then((res) => {
    //   if (res.code == 200) {
    //     this.organList = res.data;
    //   }
    // });
    // 获取分部
    this.$store.dispatch("setBranchs");
    this.init();
  },
  activated() {
    this.init();
  },
  methods: {
    init() {
      this.getList();
    },
    getList() {
      // let date = this.searchForm;
      // let classStartDate, classEndDate;
      // if (this.courseTimer?.length > 0) {
      //   classStartDate = this.courseTimer[0];
      //   classEndDate = this.courseTimer[1];
      // } else {
      //   classStartDate = null;
      //   classEndDate = null;
      // }
      // date.classStartDate = classStartDate;
      // date.classEndDate = classEndDate;
      // date.page = this.rules.page;
      // date.rows = this.rules.limit;

      let { courseTimer, ...rest } = this.searchForm;
      let params = {
        ...rest,
        page: this.rules.page,
        rows: this.rules.limit,
        ...getTimes(courseTimer, ["classStartDate", "classEndDate"])
      };
      getHomePageList(params).then(res => {
        if (res.code == 200) {
          this.tableList = res.data.rows;
          this.rules.total = res.data.total;
        }
      });
    },
    search() {
      this.rules.page = 1;
      this.getList();
    },
    onReSet() {
      this.searchForm = {
        search: null,
        organId: null,
        groupType: "MUSIC",
        courseTimer: [],
        cloudHomeworkFlag: ""
      };
      // this.courseTimer = [];
      this.search();
    },
    lookDetail(row) {
      this.activeRow = row;
      this.classVisible = true;
    }
  }
};
</script>
<style lang="scss" scoped>
.search {
  // width: 220px!important;
  ::v-deep .el-input__inner {
    width: 260px !important;
  }
}
</style>
