<!--  -->
<template>
  <div class="">
    <!-- <h2>
      <div class="squrt"></div>课外训练
    </h2> -->
    <div class="m-core">
      <save-form :inline="true"
               @submit="search"
               @reset="onReSet"
               :saveKey="'afterSchoolList'"
               :model="searchForm">
        <el-form-item>
          <el-input v-model.trim="searchForm.listSearch" clearable
                    @keyup.enter.native="search"
                    placeholder="请输入标题"></el-input>
        </el-form-item>
        <el-form-item>
           <remote-search :commit='"setTeachers"' v-model='searchForm.teacherId'/>
        </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-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="createTime"
                           label="布置时间">
            <template slot-scope="scope">
              {{scope.row.createTime | dateForMinFormat}}
            </template>
          </el-table-column>
          <el-table-column align="center"
                           prop="title"
                           label="训练标题"></el-table-column>
          <el-table-column align="center"
                           prop="organName"
                           label="老师分部"></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"
                           prop="teacherName"
                           label="老师姓名">
            <template slot-scope="scope">
              <div v-if="scope.row.teacher">
                {{scope.row.teacher.username}}
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center"
                           label="操作">
            <template slot-scope="scope">
              <div>
                <el-button type="text"
                           v-permission="'afterSchollList/look'"
                           @click="lookDetail(scope.row)">查看</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination :total="rules.total"
                    :page.sync="rules.page"
                    :limit.sync="rules.limit"
                    :page-sizes="rules.page_size"
                    @pagination="getList" />
      </div>
    </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 { queryPageList } from "@/api/afterSchool";
export default {
  components: { pagination, remoteSearch },
  data () {
    return {
      searchForm: {
        listSearch: null,
        listTimer: [],
        teacherId: null,
        organIdList: null
      },
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50] // 选择限制显示条数
      },
      tableList: [],
      visibleForm: {
        createTime: null
      },
    };
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created () { },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted () {
    this.$store.dispatch('setBranchs')
    // 获取分部
    this.init();
  },
  methods: {
    init () {
      if(this.searchForm.listTimer && this.searchForm.listTimer.length <= 0) {
        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);
      }
      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.listSearch ? obj.title = this.searchForm.listSearch : null;
      this.searchForm.organIdList ? obj.organIdList = this.searchForm.organIdList : 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 = {
        listSearch: null,
        listTimer: [],
        teacherId: null,
        organIdList: null
      }
      this.search();
    },
    lookDetail (row) {
      this.$router.push({ path: '/business/afterSchoolDetail', query: { extracurricularExercisesId: row.id, title: row.title } })
    }
  }
};
</script>
<style lang='scss' scoped>
.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;
}
/deep/.el-textarea.is-disabled .el-textarea__inner {
  color: #333;
}
</style>
