<style>
  .page-content p {
    margin: 16px 0 0 0 !important;
  }

</style>
<template>
  <div class="page-body">
    <div class="page-search row items-center">
      <div class="col row wrap q-mr-lg q-col-gutter-md">
        <div class="col-3">
          <q-input @change="getCourseJobList" clearable standout="bg-primary text-white" v-model="msg.JobName"
            label="作业名称" @clear="getCourseJobList" maxlength="20" />
        </div>
      </div>
    </div>
    <div class="page-content">
      <q-table :pagination="msg" :loading="loading" no-data-label="暂无相关数据" flat class="sticky-column-table"
        separator="none" :data="data" :columns="columns" row-key="name">
        <template v-slot:top="props">
          <div class="col-2 q-table__title">作业列表</div>
          <q-space />
          <div class="page-option">
            <q-btn color="accent" size="sm" class="q-mr-md" icon="add" label="新增作业" @click="EditQuestion(null)" />
          </div>
        </template>
        <template v-slot:bottom>
          <q-pagination class="full-width justify-end" v-model="msg.pageIndex" color="primary" :max="pageCount"
            :input="true" @input="changePage" />
        </template>
        <template v-slot:body-cell-optioned="props">
          <q-td :props="props">
            <q-btn flat size="xs" icon="edit" color="accent" style="font-weight:400" label="编辑"
              @click="EditQuestion(props.row)" />
            <q-btn flat size="xs" icon="edit" color="accent" style="font-weight:400" label="删除"
              @click="setQuestionStatus(props.row)"></q-btn>
          </q-td>
        </template>
      </q-table>
    </div>
  </div>
</template>
<script>
  import {
    queryCourseJobPageList
  } from '../../api/course/index';

  export default {
    meta: {
      title: "作业管理"
    },
    components: {

    },
    data() {
      return {
        columns: [{
            name: 'JobName',
            label: '作业名称',
            field: 'JobName',
            align: 'left'
          },
          {
            name: 'CreateByName',
            label: '创建者',
            field: 'CreateByName',
            align: 'left'
          },
          {
            name: 'CreateTimeStr',
            label: '创建时间',
            field: 'CreateTimeStr',
            align: 'left'
          },
          {
            name: 'optioned',
            label: '操作',
            field: 'JobId'
          }
        ],
        data: [],
        loading: false,
        msg: {
          pageIndex: 1,
          pageSize: 12,
          rowsPerPage: 12,
          CourseId: 0,
          JobName: "", //作业名称
        },
        pageCount: 0,

      }
    },
    created() {
      if (this.$route.query) {
        this.msg.CourseId = this.$route.query.CourseId
      }
    },
    mounted() {
      this.getCourseJobList();
    },
    methods: {
      //删除问题
      setQuestionStatus(item) {
        this.$q.dialog({
          title: "删除问题",
          message: "你正在进行删除问题行为，一旦执行无法找回，是否确认执行？",
          persistent: true,
          cancel: {
            label: "取消",
            flat: true
          },
          ok: {
            label: "确认",
            flat: true,
            focus: true
          }
        }).onOk(() => {
          deleteQuestion({
            QuestionId: item.QuestionId
          }).then(res => {
            if (res.Code == 1) {
              this.$q.notify({
                icon: 'iconfont icon-chenggong',
                color: 'accent',
                timeout: 2000,
                message: '删除成功!',
                position: 'top'
              })
              this.getCourseJobList();
            } else {
              this.$q.notify({
                icon: 'iconfont icon-chenggong',
                color: 'accent',
                timeout: 2000,
                message: res.Message,
                position: 'top'
              })
            }
          });
        });
      },
      //翻页
      changePage(val) {
        this.msg.pageIndex = val;
        this.getCourseJobList()
      },
      //获取问题分页列表
      getCourseJobList() {
        this.loading = true;
        queryCourseJobPageList(this.msg).then(res => {
          this.loading = false;
          this.data = res.Data.PageData;
          this.pageCount = res.Data.PageCount;
        }).catch(() => {
          this.loading = false
        })
      },
      //新增修改问题
      EditQuestion(obj) {
        var jobId = 0;
        if (obj) {
          jobId = obj.JobId;
        }
        var tempStr = '/course/jobinfo';
        var tempRouter = this.$router.resolve({
          path: tempStr,
          query: {
            CourseId: this.msg.CourseId,
            JobId: jobId
          }
        });
        window.open(tempRouter.href, '_blank')
      },
    }
  }

</script>
<style lang="sass">
  @import url('~assets/css/table.sass')

</style>
