<template>
  <div class="bigBox" :style="{ height: bigHeight }">
    <div class="right" style="width: 100%;">
      <!-- 头部 -->
      <div class="headBox">
        <div class="table-title" :title="`试题列表${Row.name ? '(' + Row.name + '' : ''}`">试题列表{{ Row.name ? ` (${Row.name})` :
          '' }}</div>
        <div class="btnBox">
          <el-select class="pxdx_box" placeholder="请选择业务类型" v-model="listQuery.qclass" clearable
            style="width: 250px; margin-right: 10px">
            <el-option v-for="item in props.zdlist.D_BZ_KTKYWLX" :key="item" :label="item.label" :value="item.value" />
          </el-select>
          <el-select class="pxdx_box" placeholder="请选择题型" v-model="listQuery.qtype" clearable
            style="width: 250px; margin-right: 10px">
            <el-option v-for="item in props.zdlist.D_TB_KTTX" :key="item" :label="item.label" :value="item.value" />
          </el-select>
          <el-button type="primary" @click="search">
            <span>查询</span>
          </el-button>
          <el-button type="primary" @click="CloseEvent">

            <span>返回</span>
          </el-button>
          <el-button type="primary" @click="openSee">
            <el-icon>
              <Tickets />
            </el-icon>
            <span>预览</span>
          </el-button>
        </div>
      </div>
      <div class="tabBox">
        <el-table ref="multipleTableRef" :data="list" v-loading="tableloading" element-loading-text="数据加载中..."
          style="width: 100%;height: calc(100% - 50px);" border>
          <el-table-column type="index" width="75" label="序号" />
          <el-table-column label="题目" property="questionname"></el-table-column>
          <el-table-column label="题型">
            <template #default="{ row }">
              <dict-tag :options="props.zdlist.D_TB_KTTX" :value="row.qtype" :tag="false"></dict-tag>
            </template>
          </el-table-column>
          <el-table-column label="业务类型" property="questionname">
            <template #default="{ row }">
              <div class="flex just-center">
                <dict-tag v-for="(item,index) in row.qclassArr" :key="index" :options="props.zdlist.D_BZ_KTKYWLX" :value="item" :tag="true"></dict-tag>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <div class="fenye">
          <div></div>
          <!-- 审核按钮 -->
          <div class="audit-buttons-section">
          </div>

          <el-pagination class="pagination" @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="listQuery.pageCurrent" :page-sizes="[2, 5, 10, 20]" :page-size="listQuery.pageSize"
            layout="total, prev, pager, next, sizes, jumper" :total="total"></el-pagination>
        </div>
      </div>
    </div>
    <!-- 试卷预览 -->
    <div v-if="examShow" class="dialog-box">
      <Examdaio @close="examShow = false" :Row="props.Row" />
    </div>
  </div>
</template>

<script setup>
import { onMounted, ref, defineEmits, defineProps, getCurrentInstance } from "vue";
import { ElTable, ElMessage } from 'element-plus';
import { getApi, postApi } from "@/api/tobAcco_api.js";
import Examdaio from "./examdaio.vue";


const props = defineProps({
  Row: Object,
  zdlist: Object,
  isAudit: Boolean,
});
const listQuery = ref({
  pageCurrent: 1,
  pageSize: 20
})
const total = ref(0)
const emits = defineEmits(["close"]);
const tableloading = ref(false)
const list = ref([])
const multipleTableRef = ref()
const bigHeight = ref(); //整个高度
const treeHeight = ref(""); // 树高度
const examShow = ref(false)
const auditLoading = ref(false)
/** 审核状态 */
const status = ref('')
onMounted(() => {
  bigHeightFn();
  listQuery.value.id = props.Row.id;
  getList()
})
// 方法
const bigHeightFn = () => {
  bigHeight.value = window.innerHeight - 147 + "px";
  treeHeight.value = window.innerHeight - 187 + "px";
};
//	查询试卷已关联的试题
function getList() {
  tableloading.value = true
  getApi(listQuery.value, '/mosty-jcgl/exampaper/getExamlibByPaperId').then(res => {
    list.value = [...res.records[0].multipleList, ...res.records[0].singleList, ...res.records[0].trueOrFalseList];
    list.value = list.value.map(item => {
      item.qclassArr = item.qclass ? item.qclass.split(',') : []
      return item
    })
    total.value = res.total
    tableloading.value = false
    status.value = res?.records?.[0].status
  })
}
// 查询
const search = () => {
  listQuery.value.pageCurrent = 1
  getList()
}
const CloseEvent = () => {
  emits("close");
};
//试卷预览
function openSee() {
  examShow.value = true
}
//分页
const handleSizeChange = (currentSize) => {
  listQuery.value.pageSize = currentSize;
  getList();
};
const handleCurrentChange = (currentPage) => {
  listQuery.value.pageCurrent = currentPage;
  getList();
};


</script>

<style lang="scss" scoped>
.bigBox {
  display: flex;

  .table-title {
    height: 60px;
    line-height: 60px;
    max-width: calc(100% - 760px);
    font-size: 18px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #0f3916;


    .el-icon {
      cursor: pointer;
    }
  }

  .left {
    width: 300px;
    background: #FFFFFF;
    box-shadow: 0px 2px 10px 0px rgba(107, 107, 107, 0.1);
    border-radius: 0px 0px 0px 0px;
    opacity: 1;

    .treeBox {
      overflow: auto;
    }
  }

  .right {
    padding: 0 10px;
    margin: 0px 14px;
    background: #fff;

    .headBox {
      display: flex;
      align-items: center;
      justify-content: space-between
    }

    .btnBox {
      .el-select {
        margin-right: 10px;
      }

      .header-right {
        display: flex;
        align-items: center;
      }

      .btnBox {
        display: flex;
        width: 500px;
        justify-content: space-between;
        align-items: center;
      }
    }
  }
}


.tabBox {
  height: calc(100% - 58px);
  border-left: 0 !important;

  .fenye {
    top: 95%;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
</style>
