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

  .quetion_Title {
    background: transparent !important;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    width: 400px;

  }

</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="research" clearable standout="bg-primary text-white" v-model="msg.BankName" label="输入关键字查找"
            @clear="research" 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" @click="EditQuestion(null)" label="创建新题库" />
          </div>
        </template>
        <template v-slot:body-cell-BankId="props">
          <q-td :props="props" style="width:150px;">
            {{props.row.BankId}}
          </q-td>
        </template>
        <template v-slot:body-cell-BankName="props">
          <q-td :props="props" style="width:400px;">
            {{props.row.BankName}}
          </q-td>
        </template>
        <template v-slot:body-cell-QuestionCount="props">
          <q-td :props="props" style="width:200px;">
            {{props.row.QuestionCount}}
          </q-td>
        </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" style="width:200px;">
            <q-btn flat size="xs" icon="edit" color="accent" style="font-weight:400" @click="EditQuestion(props.row)"
              label="编辑" />
            <q-btn flat size="xs" icon="edit" color="accent" style="font-weight:400" @click="goQuestionList(props.row)"
              label="管理题目" />
            <q-btn flat size="xs" icon="edit" color="negative" style="font-weight:400"
              @click="deleteQuestionBank(props.row)" label="删除" />
            </q-btn>
          </q-td>
        </template>
      </q-table>
      <questionbank-form v-if="isShowQuestionBankForm" :questionBankObj="questionBankObj" @close="closeQuestionBank"
        @success="refreshQuestion">
      </questionbank-form>
    </div>
  </div>
</template>
<script>
  import {
    queryQuestionBankPage,
    RemoveQuestionBank
  } from '../../api/question/question';
  import questionbankForm from '../../components/question/questionbank-form';
  export default {
    meta: {
      title: "题库管理"
    },
    components: {
      questionbankForm
    },
    data() {
      return {
        pageCount: 0,
        msg: {
          pageIndex: 1,
          pageSize: 12,
          rowsPerPage: 12,
          BankName: ''
        },
        loading: false,
        isShowQuestionBankForm: false,
        questionBankObj: null, //传入参数
        columns: [{
            name: 'RowNum',
            label: '编号',
            field: 'RowNum',
            align: 'left'
          },
          {
            name: 'BankNo',
            label: '题库序号',
            field: 'BankNo',
            align: 'left',
          },
          {
            name: 'BankName',
            label: '题库名称',
            field: 'BankName',
            align: 'left',
          },
          {
            name: 'CreateByName',
            label: '创建人',
            field: 'CreateByName',
            align: 'left'
          },
          {
            name: 'QuestionCount',
            label: '题量',
            field: 'QuestionCount',
            align: 'left'
          },
          {
            name: 'optioned',
            label: '操作',
            field: 'QuestionId'
          }
        ],
        data: [],
      }
    },
    created() {},
    mounted() {
      this.getQuestionBankPage();
    },
    methods: {
      research() {
        this.getQuestionBankPage();
      },
      //翻页
      changePage(val) {
        this.msg.pageIndex = val;
        this.getQuestionBankPage()
      },
      //关闭弹窗
      closeQuestionBank() {
        this.isShowQuestionBankForm = false;
      },
      //获取题库分页列表
      getQuestionBankPage() {
        queryQuestionBankPage(this.msg).then(res => {
          if (res.Code == 1) {
            this.data = res.Data.PageData;
            this.pageCount = res.Data.PageCount;
          }
        })
      },
      //刷新列表
      refreshQuestion() {
        this.getQuestionBankPage();
      },
      //编辑题库
      EditQuestion(obj) {
        if (obj) {
          this.questionBankObj = obj
        } else {
          this.questionBankObj = null
        }
        this.isShowQuestionBankForm = true
      },
      //删除问题
      deleteQuestionBank(item) {
        let delMsg = {
          bankId: item.BankId,
          status: 1
        };
        this.$q.dialog({
          title: '提示信息',
          message: '是否确定删除该题库？',
          cancel: true,
          persistent: true,
          ok: "确定",
          cancel: "取消",
        }).onOk(() => {
          RemoveQuestionBank(delMsg).then(res => {
            if (res.Code == 1) {
              this.$q.notify({
                icon: 'iconfont icon-chenggong',
                color: 'accent',
                timeout: 2000,
                message: '删除成功！',
                position: 'top'
              })
              this.getQuestionBankPage();
            }
          })
        }).onCancel(() => {

        });
      },
      //跳转至questionlist
      goQuestionList(item) {
        var tempStr = '../course/question?BankId=' + item.BankId;
        this.$router.push({
          path: tempStr
        });
      }
    }
  }

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

</style>
