<template>
  <div class="container">
    <div>
         <el-card class="filter-container" shadow="never">
      <div>
        <i class="el-icon-search"></i>
        <span>筛选搜索</span>
        <el-button
          style="float: right"
          @click="handleSearchList()"
          type="primary"
          size="small"
        >
          查询结果
        </el-button>
        <el-button
          style="float: right; margin-right: 15px"
          @click="handleResetSearch('listQuery')"
          size="small"
        >
          重置
        </el-button>
      </div>
      <div style="margin-top: 15px">
        <el-form
          :inline="true"
          :model="listQuery"
          :data="list"
          ref="listQuery"
          size="small"
          label-width="140px"
        >
        
          <el-form-item label="课程名称：" prop="courseName">
            <el-input
              style="width: 203px"
              v-model="listQuery.courseName"
              placeholder=""
            ></el-input>
          </el-form-item>

          
          <el-form-item label="课程代码：" prop="courseCode">
            <el-input
              style="width: 203px"
              v-model="listQuery.courseCode"
              placeholder=""
            ></el-input>
          </el-form-item>

      

        </el-form>
      </div>
    </el-card>
    </div>
    <el-dialog
      title="添加课程代码"
      :visible.sync="noticeVisible"
      @close="cancel('csoInfo')"
    >
      <el-form :model="csoInfo" ref="csoInfo">
        <div class="line">
          <el-form-item label="cso课程名称" prop="csoName">
            <!-- <el-input v-model="noticeInfo.note"> </el-input> -->
            <el-input type="textarea" autosize v-model="csoInfo.csoName">
            </el-input>
          </el-form-item>
          <el-form-item label="cso课程代码" prop="csoCode">
            <!-- <el-input v-model="noticeInfo.note"> </el-input> -->
            <el-input type="textarea" autosize v-model="csoInfo.csoCode">
            </el-input>
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel('csoInfo')">取 消</el-button>
        <el-button type="primary" @click="submitForm('csoInfo')"
          >确 定</el-button
        >
        <!-- <el-button type="primary" @click="test">test</el-button> -->
      </div>
    </el-dialog>

    <el-dialog
      title="编辑cso课程"
      :visible.sync="editNoticeVisible"
      @close="cancel('editCsoInfo')"
    >
      <el-form :model="editCsoInfo" ref="editCsoInfo">
        <div class="line">
          <el-form-item label="编辑cso课程名称" prop="csoName">
            <el-input type="textarea" autosize v-model="editCsoInfo.csoName">
            </el-input>
          </el-form-item>
          <el-form-item label="编辑cso课程代码" prop="csoCode">
            <el-input type="textarea" autosize v-model="editCsoInfo.csoCode">
            </el-input>
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel('editCsoInfo')">取 消</el-button>
        <el-button type="primary" @click="submitEditForm('editCsoInfo')"
          >确 定</el-button
        >

        <!-- <el-button type="primary" @click="test">test</el-button> -->
      </div>
    </el-dialog>

    <div class="table-container">
      <el-table
        ref="productTable"
        :data="list"
        style="width: 100%"
        v-loading="listLoading"
        border
      >
        <el-table-column
          type="selection"
          width="60"
          align="center"
        ></el-table-column>

        <el-table-column label="cso课程名称" align="center">
          <template slot-scope="scope">{{ scope.row.csoName }}</template>
        </el-table-column>

        <el-table-column label="cso课程代码" align="center" prop="csoCode">
          <template slot-scope="scope">{{ scope.row.csoCode }}</template>
        </el-table-column>
        <!-- @click="
                handleupdateNoticeAll(scope.row.id, scope.row.schoolName,scope.row.schoolBrief)
              " -->
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              @click="
                handleUpdateSchoolAll(
                  scope.row.id,
                  scope.row.csoName,
                  scope.row.csoCode
                )
              "
              size="mini"
              >编辑</el-button
            >
            <!-- <el-button @click="handleDel(scope.row.id)" size="mini"
              >删除</el-button
            > -->
          </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 {
  noticeAll,
  addNoticeAll,
  deleteNotice,
  updateNoticeAll,
  allCode,
  addCsoCode,
  updateCsoCode
} from "@/api/cso2";
const defaultListQuery = {
  pageNum: 1,
  pageSize: 10
};
export default {
  name: "csoCourse",
  data() {
    return {
      listQuery: Object.assign({}, defaultListQuery),
      list: null,

      pageSize: null,
      pageNum: null,
      total: null,
      listLoading: true,
      multipleSelection: [],
      formLabelWidth: "120px",
      options: [],
      teacherId: "",
      noticeVisible: false,
      editNoticeVisible: false,
      title: "",
      //  noticeInfo: {},
      // independentInfo:{},
      csoInfo: {},
      // editNoticeInfo: { noticeContent: "" },
      // editIndependent: {schoolName: " ", schoolBrief: " "},
      editCsoInfo: {
        csoName: " ",
        csoCode: " "
      },
      updateId: ""
    };
  },
  methods: {
    // getData() {
    //   noticeAll(this.listQuery).then(res => {
    //     // console.log(res, "getData");
    //     this.listLoading = false;

    //     this.list = res.data.list;
    //     this.total = res.data.total;
    //   //  console.log(this.list, "this.list,noticeAll");
    //     this.$forceUpdate();
    //   });
    // },
    getData() {
      allCode(this.listQuery).then(res => {
        // console.log(res, "getCodeData");
        this.listLoading = false;

        this.list = res.data.list;
        this.pageNum = res.data.pageNum;
        this.pageSize = res.data.pageSize;
        this.total = res.data.total;
        //  console.log(this.list, "this.list,codeAll");
        this.$forceUpdate();
      });
    },

        handleSearchList() {
      //搜索
      this.listQuery.pageNum = 1;
      this.getData();
    },
      handleResetSearch(formName) {
      this.$refs[formName].resetFields();
      // 重置
      // this.selectProductCateValue = [];
      this.isMatch = false;
 
      this.listQuery = Object.assign({}, defaultListQuery);
      this.getData();
    },

    handleCurrentChange(val) {
      // 翻页
      this.listQuery.pageNum = val;
      this.getData()
    },
     handleSizeChange(val){
      //切换展示条数
       this.listQuery.pageSize = val;
       this.getData()
    },



    submitForm(formName) {
      if (this.updateId) {
        this.csoInfo.id = this.updateId;
      }
      this.$confirm("是否提交", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        addCsoCode(this.csoInfo).then(response => {
          this.$message({
            type: "success",
            message: "提交成功",
            duration: 1000
          });
          this.$refs[formName].resetFields();
          this.noticeVisible = false;

          //     this.getData();
          this.$forceUpdate();
        });
      });
    },
    submitEditForm(formName) {
      this.editCsoInfo.id = this.updateId;

      this.$confirm("是否提交", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        //拿到整个公告
        updateCsoCode(this.editCsoInfo).then(response => {
          this.$message({
            type: "success",
            message: "提交成功",
            duration: 1000
          });
          this.$refs[formName].resetFields();
          this.editNoticeVisible = false;

          this.getData();
          this.$forceUpdate();
        });
      });
    },
    handleDel(id) {
      //   console.log(id, "handleDel");
      this.$confirm("是否删除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        deleteNotice(id).then(response => {
          this.$message({
            type: "success",
            message: "删除成功",
            duration: 1000
          });

          this.getData();
          this.$forceUpdate();
        });
      });
    },
    //handleUpdateNoticeAll(id, schoolName,schoolBrief) {
    handleUpdateSchoolAll(id, csoName, csoCode) {
      this.editNoticeVisible = true;
      // this.title = "编辑公告";
      this.updateId = id;
      this.editCsoInfo.csoName = csoName;
      this.editCsoInfo.csoCode = csoCode;
      // console.log(this.updateId, noticeContent);
    },
    cancel(formName) {
      this.noticeVisible = false;
      this.editNoticeVisible = false;
      this.$refs[formName].resetFields();
    }
  },
  mounted() {
    this.getData();
  }
};
</script>

<style lang="scss" scoped>
.container {
  padding: 20px;
}
.handleStuDetail {
  cursor: pointer;
}
</style>
