<template>
  <div class="container">
    <!-- <h1>schoolList</h1> -->
    <el-form
      :model="listQuery"
      ref="listQuery"
      label-width="100px"
      class="demo-list"
    >
      <div class="line">
        <el-form-item label="学生上课年份" prop="yearTime">
          <el-col :span="20">
            <el-input v-model="listQuery.yearTime"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="上课学期" prop="term">
          <el-col :span="20">
            <el-input v-model="listQuery.term"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="审课状态" prop="state">
          <el-select clearable v-model="listQuery.state">
            <el-option
              label="审课进行中(全部信息待确认)"
              :value="1"
            ></el-option>
            <el-option
              label="审课通过(全部信息确认完毕)"
              :value="2"
            ></el-option>
            <!-- <el-option label="已转学分" :value="3"></el-option> -->
          </el-select>
        </el-form-item>
      </div>

      <el-form-item>
        <el-button type="primary" @click="getData">查询</el-button>
        <el-button @click="resetForm('listQuery')">重置</el-button>
      </el-form-item>
    </el-form>
    <div class="table-container">
      <el-table
        ref="productTable"
        :data="list"
        style="width: 100%"
        @selection-change="handleSelectionChange"
        v-loading="listLoading"
        border
        @sort-change="changeTableSort"
      >
        <!-- <el-table-column
          type="selection"
          width="60"
          align="center"
        ></el-table-column> -->
        <el-table-column label="审课大学" align="center">
          <template slot-scope="scope">{{ scope.row.auditSchool }}</template>
        </el-table-column>

        <el-table-column label="审课状态" align="center">
          <template slot-scope="scope">{{
            scope.row.sex == 1 ? "全部信息待确认" : "转学分待确认"
          }}</template>
        </el-table-column>

        <!-- <el-table-column label="姓名" align="center">
          <template slot-scope="scope">
            <div
              class="handleStuDetail"
              @click="handleStuDetail(scope.row.userId)"
            >
              {{ scope.row.name }}
            </div>
          </template>
        </el-table-column> -->

        <el-table-column label="年份" align="center">
          <template slot-scope="scope">{{ scope.row.yearTime }}</template>
        </el-table-column>

        <el-table-column label="学期" align="center">
          <template slot-scope="scope">{{ scope.row.term }}</template>
        </el-table-column>

        <el-table-column label="学生人数" align="center">
          <template slot-scope="scope">{{ scope.row.num }}</template>
        </el-table-column>

        <!-- <el-table-column label="学生所在学校" align="center">
          <template slot-scope="scope">{{ scope.row.school }}</template>
        </el-table-column> -->

        <!-- <el-table-column label="学生所在学校课程代码" align="center">
          <template slot-scope="scope">{{ scope.row.ownCourseCode }}</template>
        </el-table-column> -->

        <!-- <el-table-column label="审课大学" align="center">
          <template slot-scope="scope">{{ scope.row.auditSchool }}</template>
        </el-table-column> -->

        <!-- <el-table-column label="审课大学课程代码" align="center">
          <template slot-scope="scope">{{
            scope.row.auditCourseCode
          }}</template>
        </el-table-column> -->

        <!-- <el-table-column label="学生上课时间" align="center">
          <template slot-scope="scope"
            >{{ scope.row.yearTime }}{{ scope.row.term }}</template
          >
        </el-table-column> -->
        <!-- <el-table-column label="性别" align="center">
          <template slot-scope="scope">{{
            scope.row.sex == 0 ? "女" : scope.row.sex == 1 ? "男" : ""
          }}</template>
        </el-table-column> -->

        <!-- <el-table-column label="微信号" align="center">
          <template slot-scope="scope">{{ scope.row.wechatNumber }}</template>
        </el-table-column>
        <el-table-column label="学校" align="center">
          <template slot-scope="scope">{{ scope.row.school }}</template>
        </el-table-column>
        <el-table-column label="年级" align="center">
          <template slot-scope="scope">{{ scope.row.grade }}</template>
        </el-table-column>
        <el-table-column label="报课数量" align="center">
          <template slot-scope="scope">{{ scope.row.courseNum }}</template>
        </el-table-column> -->

        <!-- <el-table-column
          label="提交时间"
          :sortable="'custom'"
          align="center"
          prop="addTime"
        >
          <template slot-scope="scope">{{ scope.row.addTime }}</template>
        </el-table-column> -->

        <!-- <el-table-column label="大纲进度" align="center">
          <template slot-scope="scope">{{
            scope.row.state == 1 ? "进行中" : scope.row.sex == 2 ? "已完成" : ""
          }}</template>
        </el-table-column> -->

        <!-- <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button @click="confirm(scope.row.userCourseId)" type="mini"
              >确认</el-button
            >
          </template>
        </el-table-column> -->
        <!-- <el-table-column
          label="分配时间"
          :sortable="'custom'"
          align="center"
          prop="allocateTime"
        >
          <template slot-scope="scope">{{ scope.row.allocateTime }}</template>
        </el-table-column> -->
      </el-table>
    </div>

    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total,sizes,prev, pager, next,jumper"
        :page-size="pageSize"
        :page-sizes="[5, 10, 15]"
        :current-page.sync="pageNum"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { statisticsList, updateOutlineState } from "@/api/cso";
// import { newAllocate } from "@/api/cso";

const defaultListQuery = {
  pageNum: 1,
  pageSize: 10
};

export default {
  name: "schoolList",
  data() {
    return {
      // list: {
      //   outlineState: null
      // },
      listQuery: Object.assign({}, defaultListQuery),
      list: null,
      pageSize: null,
      pageNum: null,
      total: null,
      listLoading: true,
      multipleSelection: [],
      formLabelWidth: "120px"
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          addCurrentTermCourse(this.goOnForm).then(response => {
            this.$message({
              type: "success",
              message: "提交成功",
              duration: 1000
            });

            this.getCourseList();
            this.$forceUpdate();
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.listQuery = Object.assign({}, defaultListQuery);
      this.getData();
    },
    getData() {
      statisticsList(this.listQuery).then(res => {
        this.listLoading = false;
        this.pageNum = res.data.pageNum;
        this.pageSize = res.data.pageSize;
        this.total = res.data.total;
        this.list = res.data.list;
        console.log(this.list, "this.list,getstatisticsList");
      });
    },
    handleCurrentChange(val) {
      // 翻页
      this.listQuery.pageNum = val;
      this.getData();
    },
    handleSizeChange(val) {
      //切换展示条数
      this.listQuery.pageSize = val;
      this.getData();
    },
    handleStuDetail(id) {
      this.$router.push({
        path: "/pms/stuDetail",
        query: {
          id: id
        }
      });
      // console.log(123);
    },
    changeTableSort(column) {
      console.log("prop", column.prop);
      console.log("order", column.order);
      // console.log("column", column);
      if (column.prop == "addTime") {
        this.listQuery.secondSort = null;
        if (column.order == "ascending") {
          this.listQuery.firstSort = 0;
        } else if (column.order == "descending") {
          this.listQuery.firstSort = 1;
        }
      }
      if (column.prop == "allocateTime") {
        this.listQuery.firstSort = null;
        if (column.order == "ascending") {
          this.listQuery.secondSort = 0;
        } else if (column.order == "descending") {
          this.listQuery.secondSort = 1;
        }
      }
      if (column.order == null) {
        this.listQuery.secondSort = this.listQuery.firstSort = null;
      }
      this.getData();
      console.log("changeTableSort");
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    confirm(id) {
      // console.log(id, "confirm");
      updateOutlineState(id).then(res => {
        this.$message({
          type: "success",
          message: "确认成功",
          duration: 1000
        });

        this.getData();
        this.$forceUpdate();
      });
    }
  },
  mounted() {
    this.getData();
  }
};
</script>

<style lang="scss" scoped>
.container {
  padding: 20px;
}
.line {
  display: flex;
}
</style>
