<template>
  <div class="container">
    <el-form
      :model="listQuery"
      ref="listQuery"
      label-width="100px"
      class="demo-list"
    >
      <el-form-item label="大纲进度" prop="outlineState">
        <el-select clearable v-model="listQuery.outlineState">
          <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>

      <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.nickName }}</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="cso课程代码" align="center">
          <template slot-scope="scope">{{ scope.row.csoCourseCode }}</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.state == 2
              ? "已完成"
              : scope.row.state == 3
              ? "无匹配"
              : ""
          }}</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 { outlineList, updateOutlineState } from "@/api/cso";
// import { newAllocate } from "@/api/cso";

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

export default {
  name: "outlineList",
  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.getData();
    },
    getData() {
      outlineList(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,getOutlineList");
      });
      outlineList({
        pageNum: 1,
        pageSize: 10,
        outlineState: 2
      }).then(res => {
        this.$store.commit("set_outlineListUnconfirm", res.data.total);
        // console.log(this.$store.getters.outlineListUnconfirm, "vuex");
      });
    },
    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;
}
</style>
