<!--  -->
<template>
  <div class="">
    <!-- <h2>
      <div class="squrt"></div>课外练习
    </h2> -->
    <div>
      <save-form
        :inline="true"
        @submit="search"
        @reset="onReSet"
        :saveKey="'afterSchoolList'"
        :model="searchForm"
        ref="saveForm"
      >
        <el-form-item>
          <el-input
            class="searchInput"
            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>
           <remote-search
            :commit="'setTeachers'"
            v-model="searchForm.teacherId"
            :isForzenWithQueryCondition="true"
          />
        </el-form-item> -->
        <el-form-item prop="organIdList">
          <el-select
            class="multiple"
            v-model.trim="searchForm.organIdList"
            filterable
            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.type"
            class="organSelect"
            filterable
            clearable
            placeholder="请选择类型"
          >
            <el-option label="课外练习" value="EXTRACURRICULAR"></el-option>
            <el-option label="额外练习" value="EXTRA"></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item>
          <el-select
            v-model.trim="searchForm.cloudHomeworkFlag"
            class="organSelect"
            filterable
            clearable
            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.listTimer"
            style="width: 410px"
            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 type="danger" native-type="submit">搜索</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="organName" label="分部">
            <template slot-scope="scope">
              <copy-text>
                {{ scope.row.organName }}
              </copy-text>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="organName" label="乐团">
            <template slot-scope="scope">
              {{ scope.row.musicGroupName }}
            </template>
          </el-table-column>
          <!-- <el-table-column align="center" prop="createTime" label="练习班级">
            <template slot-scope="scope">
              {{ scope.row.classGroupName }}
            </template>
          </el-table-column> -->
          <el-table-column align="center" prop="createTime" label="布置时间">
            <template slot-scope="scope">
              {{ scope.row.createTime | dateForMinFormat }}
            </template>
          </el-table-column>
          <el-table-column align="center" prop="createTime" label="练习类型">
            <template slot-scope="scope">
              {{
                scope.row.type == "EXTRACURRICULAR" ? "课外练习" : "额外练习"
              }}
            </template>
          </el-table-column>
          <el-table-column align="center" prop="teacherName" label="布置老师">
            <template slot-scope="scope">
              <copy-text v-if="scope.row.teacher">
                {{ scope.row.teacher.username }}
              </copy-text>
            </template>
          </el-table-column>

          <el-table-column align="center" prop="title" label="应交人数">
            <template slot-scope="scope">
              {{ scope.row.expectNum || 0 }}人
            </template>
          </el-table-column>

          <el-table-column
            align="center"
            prop="actualTeacherName"
            label="完成人数"
          >
            <template slot-scope="scope">
              <div>{{ scope.row.completedNum || 0 }}人</div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="expireDate" label="截止时间">
            <template slot-scope="scope">
              {{ scope.row.expireDate | dateForMinFormat }}
            </template>
          </el-table-column>

          <el-table-column align="center" label="操作">
            <template slot-scope="scope">
              <div>
                <auth auths="afterSchollList/look">
                  <el-button type="text" @click="lookDetail(scope.row)"
                    >查看</el-button
                  >
                </auth>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          sync
          :saveKey="'afterSchoolList'"
          :total.sync="rules.total"
          :page.sync="rules.page"
          :limit.sync="rules.limit"
          :page-sizes="rules.page_size"
          @pagination="getList"
        />
      </div>
      <el-dialog
        title="详情"
        :visible.sync="classVisible"
        width="1000px"
        v-if="classVisible"
      >
        <courseWorkeDetail
          :studentExerciseId="activeRow.id"
          :showGroup="true"
        />
      </el-dialog>
    </div>
    <!-- <el-dialog title="课外练习详情"
               :visible.sync="afterSchoolVisible"
               width="600px">
      <el-form :model="visibleForm">
        <el-form-item label="布置时间">
          <p class="schoolCell">{{visibleForm.createTime}}</p>
        </el-form-item>
        <el-form-item label="老师姓名">
          <p class="schoolCell">{{visibleForm.createTime}}</p>
        </el-form-item>
        <el-form-item label="学生姓名">
          <el-popover placement="top-start"
                      width="400"
                      trigger="hover"
                      :content="visibleForm.createTime">
            <p class="schoolCell"
               slot="reference">{{visibleForm.createTime}}</p>
          </el-popover>
        </el-form-item>
        <el-form-item label="截止时间">
          <p class="schoolCell">{{visibleForm.createTime}}</p>
        </el-form-item>
        <el-form-item label="练习标题">
          <p class="schoolCell">{{visibleForm.createTime}}</p>
        </el-form-item>
        <el-form-item label="练习内容">
          <el-input disabled
                    type="textarea"
                    rows="5"
                    v-model="visibleForm.createTime"
                    style="width:400px"></el-input>
        </el-form-item>
        <el-form-item label="学生上传">
          <el-input disabled
                    v-model="visibleForm.createTime"
                    style="width:400px"></el-input>
        </el-form-item>
      </el-form>
    </el-dialog> -->
  </div>
</template>

<script>
import pagination from "@/components/Pagination/index";
import remoteSearch from "@/components/remote-search";
import courseWorkeDetail from "@/views/afterSchoolManager/components/courseWorkeDetail.vue";
import { queryPageList } from "@/api/afterSchool";
export default {
  components: { pagination, remoteSearch, courseWorkeDetail },
  data() {
    return {
      searchForm: {
        search: null,
        listTimer: [],
        teacherId: null,
        organIdList: null,
        type: null
      },
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50] // 选择限制显示条数
      },
      tableList: [],
      visibleForm: {
        createTime: null
      },
      classVisible: false,
      activeRow: null
    };
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    if (this.searchForm.listTimer && this.searchForm.listTimer.length <= 0) {
      this.getNow();
    }
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.$store.dispatch("setBranchs");
    // 获取分部
    this.init();
  },
  methods: {
    getNow() {
      // let now = new Date();
      // let startDate = new Date(Date.UTC(now.getFullYear(), now.getMonth(), now.getDate()))
      //   .toISOString()
      //   .slice(0, 10);
      // let endDate = new Date(Date.UTC(now.getFullYear(), now.getMonth(), now.getDate()))
      //   .toISOString()
      //   .slice(0, 10);
      // this.searchForm.listTimer = [];
      // this.searchForm.listTimer.push(startDate);
      // this.searchForm.listTimer.push(endDate);
    },
    init() {
      this.getList();
    },
    getList() {
      // assignStartTime  assignEndTime page search teacherId title
      let obj = {};
      if (this.searchForm.listTimer && this.searchForm.listTimer.length > 0) {
        obj.assignStartTime = this.searchForm.listTimer[0];
        obj.assignEndTime = this.searchForm.listTimer[1];
      }
      obj.page = this.rules.page;
      (obj.rows = this.rules.limit),
        this.searchForm.teacherId
          ? (obj.teacherId = this.searchForm.teacherId)
          : null;
      this.searchForm.search ? (obj.search = this.searchForm.search) : null;
      this.searchForm.organIdList
        ? (obj.organIdList = this.searchForm.organIdList)
        : null;

      obj.cloudHomeworkFlag = this.searchForm.cloudHomeworkFlag;
      obj.studentAssignFlag = false;
      obj.type = this.searchForm.type ? this.searchForm.type : null;
      queryPageList(obj).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,
        listTimer: [],
        teacherId: null,
        organIdList: null,
        type: null
      };
      this.getNow();
      this.search();
    },
    lookDetail(row) {
      this.activeRow = row;
      if (row.versionTag == "v1") {
        this.$router.push({
          path: "/business/afterSchoolDetailold",
          query: {
            extracurricularExercisesId: row.id,
            title: row.title,
            activeIndex: 1
          }
        });
      } else {
        this.classVisible = true;
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.searchInput {
  ::v-deep .el-input__inner {
    width: 280px !important;
  }
}
.schoolCell {
  width: 400px;
  color: #333;
  background-color: #f5f7fa;
  border-color: #e4e7ed;
  height: 40px;
  line-height: 40px;
  outline: 0;
  padding: 0 15px;
  border-radius: 4px;
  border: 1px solid #dcdfe6;
  display: inline-block;
  box-sizing: border-box;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
::v-deep .el-textarea.is-disabled .el-textarea__inner {
  color: #333;
}
</style>
