<template>
  <div style="background: #fff;height: 97%;margin: 10px 0;">
    <!--查询区域-->
    <div class="jeecg-basic-table-form-container">
      <a-form @keyup.enter.native="searchQuery" :model="queryParam" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-row :gutter="24">
          <a-col :lg="7">
            <a-form-item label="问卷名称">
              <j-input placeholder="请输入问卷名称" v-model:value="queryParam.title"></j-input>
            </a-form-item>
          </a-col>
          <a-col :lg="7">
            <a-form-item label="问卷类型">
              <a-select placeholder="请选择问卷类型" ref="select" v-model:value="queryParam.qpublish">
                <a-select-option value="">全部</a-select-option>
                <a-select-option value="0">未发布</a-select-option>
                <a-select-option value="1">已发布</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-col :lg="6">
                <a-button type="primary" preIcon="ant-design:search-outlined" @click="searchQuery">查询</a-button>
                <a-button type="primary" preIcon="ant-design:reload-outlined" @click="searchReset" style="margin-left: 8px">重置</a-button>
                <a-button type="primary" preIcon="ant-design:plus-outlined" @click="handleAdd" style="margin-left: 8px"> 新增</a-button>
              </a-col>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <a-row>
      <a-col :span="8" v-for="(item, index) in tableData" :key="index" style="padding: 0px 0px 10px 5px;overflow:hidden;">
        <div style="width: 100%; height: 20px; background-color: rgb(28, 132, 198);"></div>
        <a-card  style="height: 280px;">
          <div class="rotate" :style="classFun(item.qpublish)">{{item.qpublish =='0'? '待发布':'已发布'}}</div>
          <a-row style="top: -48px;position: relative;">
            <a-col :span="24" style="margin-bottom: 10px;height:53px;overflow:hidden;">
              <div style="font-size: 18px;font-weight: bold;">{{item.title}}</div>
            </a-col>
            <a-col :span="24" class="zyCon">
              <a-row>
                <a-col :span="6" class="zyCon">时间：
                </a-col>
                <a-col :span="16" class="zyCon">
                  <a-col :span="24" class="zyCon">从{{item.startTime}}</a-col>
                  <a-col :span="24" class="zyCon">至{{item.endTime}}</a-col>
                </a-col>
              </a-row>
            </a-col>
            <a-col :span="24" class="zyCon">
              <a-row>
                <a-col :span="12" class="zyCon">{{item.xqxn}}</a-col>
                <a-col :span="12" class="zyCon"><div style="float:right;" @click="openXkrs(item)"><a>{{item.xkrs}}人选课</a></div></a-col>
              </a-row>
            </a-col>
            <a-col :span="24" class="zyCon">
              <a-row>
                <a-col :span="12" class="zyCon"><div style="float:left;" @click="handleDjjgs(item,'0')" v-if="item.wwcrs>0"><a>未提交：{{item.wwcrs}}人</a></div></a-col>
                <a-col :span="12" class="zyCon"><div style="float:right;" @click="handleDjjgs(item,'1')" v-if="item.ywcrs>0"><a>已提交：{{item.ywcrs}}人</a></div></a-col>
              </a-row>
            </a-col>
            <a-col :span="24" style="text-align:center;margin-top:20px;">
              <a-button type="primary" @click="handleEdit(item)" style="margin-left:5px;padding: 0px 8px;background:rgb(28, 132, 198);" v-if="item.qpublish==0">编辑</a-button>
              <a-button type="primary" @click="handlePeizhi(item)" style="margin-left:5px;padding: 0px 8px;background:rgb(28, 132, 198);" v-if="item.qpublish==0">配置</a-button>
              <a-button type="primary" @click="handleFabu(item)" style="margin-left:5px;padding: 0px 8px;background:rgb(28, 132, 198);" v-if="item.qpublish==0">发布</a-button>
              <a-button type="primary" @click="handleDelete(item)" style="margin-left:5px;padding: 0px 8px;background:rgb(28, 132, 198);" v-if="item.qpublish==0">删除</a-button>
              <a-button type="primary" @click="handleDetail(item)" style="margin-left:5px;padding: 0px 8px;background:rgb(28, 132, 198);" v-if="item.qpublish==1">详情</a-button>
              <a-button type="primary" @click="handlePeizhiXq(item)" style="margin-left:5px;padding: 0px 8px;background:rgb(28, 132, 198);" v-if="item.qpublish==1">配置</a-button>
<!--              <a-button type="primary" @click="handleDjjgs(item)" style="margin-left:5px;padding: 0px 8px;background:rgb(28, 132, 198);" v-if="item.qpublish==1">结果</a-button>-->
            </a-col>
<!--            <a-col :span="24" style="text-align:center;margin-top:20px;">-->
<!--              <a-button type="primary" @click="handleDj(item)" style="margin-left:5px;padding: 0px 8px;background:rgb(28, 132, 198);" v-if="item.qpublish==1">答卷</a-button>-->
<!--              <a-button type="primary" @click="handleDjjg(item)" style="margin-left:5px;padding: 0px 8px;background:rgb(28, 132, 198);" v-if="item.qpublish==1">查看答卷</a-button>-->
<!--            </a-col>-->
          </a-row>
        </a-card>
      </a-col>
      <a-col :span="24">
        <div v-show="tableData.length>0">
          <a-pagination v-model="current" :total="total" @change="handlePageChange" :pageSize="pageSize" style="text-align: right;"/>
        </div>
        <div v-show="tableData.length==0">
          <a-empty/>
        </div>
      </a-col>
    </a-row>
    <!-- 表单区域 -->
    <WjxWjxxModal ref="registerModal" @success="handleSuccess"></WjxWjxxModal>
    <WjxWjxxTmlbModal ref="WjxWjxxTmlbModalPage" @success="handleSuccess"></WjxWjxxTmlbModal>
    <WjxWjxxTmlbDjModal ref="WjxWjxxTmlbDjModalPage" @success="handleSuccess"></WjxWjxxTmlbDjModal>
    <WjxWjxxTmlbDjjgModal ref="WjxWjxxTmlbDjjgModalPage" @success="handleSuccess"></WjxWjxxTmlbDjjgModal>
    <WjxWjxxTmlbDjjgsDcModal ref="WjxWjxxTmlbDjjgsDcModalPage" @success="handleSuccess"></WjxWjxxTmlbDjjgsDcModal>
    <XxhbbksListModal ref="XxhbbksListModalPage"></XxhbbksListModal>
  </div>
</template>

<script lang="ts" name="wjxWjxx-wjxWjxx" setup>
  import {ref, reactive, defineExpose, unref, onMounted} from 'vue';
  import { defHttp } from '/@/utils/http/axios';
  import { Input, Popover, Pagination, Empty } from 'ant-design-vue';
  import { list ,deleteOne } from '/@/views/kc/wjxWjxx/WjxWjxx.api';
  import WjxWjxxModal from '/@/views/kc/wjxWjxx/components/WjxWjxxModal.vue'
  import WjxWjxxTmlbModal from '/@/views/kc/wjxWjxx/components/WjxWjxxTmlbModal.vue'
  import WjxWjxxTmlbDjModal from '/@/views/kc/wjxWjxx/components/WjxWjxxTmlbDjModal.vue'
  import WjxWjxxTmlbDjjgModal from '/@/views/kc/wjxWjxx/components/WjxWjxxTmlbDjjgModal.vue'
  import WjxWjxxTmlbDjjgsDcModal from '/@/views/kc/wjxWjxx/components/WjxWjxxTmlbDjjgsDcModal.vue'
  import XxhbbksListModal from '/@/views/kc/xxhbbks/XxhbbksListModal.vue';
  import {useRouter} from "vue-router";
  import { JInput } from '/@/components/Form';

  //当前路由信息
  const { currentRoute } = useRouter();
  const { query } = unref(currentRoute);
  const { rwbh,xqxn,typa} = query;//获取传递参数

  const APagination = Pagination;
  const queryParam = ref<any>({});
  const current = ref<number>(0);
  const total = ref<number>(0);
  const pageNo = ref<number>(0);
  const pageSize = ref<number>(6);
  const tableData = ref<any>([]);

  const registerModal = ref();
  const WjxWjxxTmlbModalPage = ref();
  const WjxWjxxTmlbDjModalPage = ref();
  const WjxWjxxTmlbDjjgsDcModalPage = ref();
  const XxhbbksListModalPage = ref();

  const labelCol = reactive({
    xs: { span: 24 },
    sm: { span: 7 },
  });
  const wrapperCol = reactive({
    xs: { span: 24 },
    sm: { span: 16 },
  });

  /**
   * 新增事件
   */
  function handleAdd() {
    registerModal.value.disableSubmit = false;
    registerModal.value.add("1");
  }

  /**
   * 编辑事件
   */
  function handleEdit(record: Recordable) {
    registerModal.value.disableSubmit = false;
    registerModal.value.edit(record);
  }

  /**
   * 获取选课人数
   */
  function openXkrs(record){
    // console.log(`🚀 ~ openXkrs ~ record:`, record)
    XxhbbksListModalPage.value.disableSubmit = true;
    XxhbbksListModalPage.value.init(record);
  }

  /**
   * 配置
   */
  function handlePeizhi(record: Recordable) {
    WjxWjxxTmlbModalPage.value.disableSubmit = false;
    WjxWjxxTmlbModalPage.value.edit(record,"1");
  }

  /**
   * 配置详情
   */
  function handlePeizhiXq(record: Recordable) {
    WjxWjxxTmlbDjModalPage.value.disableSubmit = true;
    WjxWjxxTmlbDjModalPage.value.edit(record,true,"1",'ls');
  }

  // /**
  //  * 答卷详情
  //  */
  // function handleDj(record: Recordable) {
  //   WjxWjxxTmlbDjModalPage.value.disableSubmit = false;
  //   WjxWjxxTmlbDjModalPage.value.edit(record,false);
  // }

  /**
   * 答卷详情
   */
  // function handleDjjg(record: Recordable) {
  //   WjxWjxxTmlbDjjgModalPage.value.disableSubmit = true;
  //   WjxWjxxTmlbDjjgModalPage.value.edit(record,false);
  // }

  /**
   * 学生答卷列表
   */
  function handleDjjgs(record: Recordable,flag) {
    WjxWjxxTmlbDjjgsDcModalPage.value.disableSubmit = true;
    WjxWjxxTmlbDjjgsDcModalPage.value.edit(record, flag);
  }

  /**
   * 详情
   */
  function handleDetail(record: Recordable) {
    registerModal.value.disableSubmit = true;
    registerModal.value.edit(record);
  }

  /**
   * 发布
   */
  function handleFabu(record: Recordable) {
    defHttp.get({ url: '/wjxWjxx/wjxWjxx/fbwj', params: { id: record.id,wjlx: "1" } }).then(res => {
      total.value = 1;
      pageNo.value = 0;
      reload();
    });
  }
  /**
   * 删除事件
   */
  async function handleDelete(record) {
    await deleteOne({ id: record.id }, handleSuccess);
  }

  function reload(){
    queryParam.value.pageNo = pageNo;
    queryParam.value.pageSize = pageSize;
    queryParam.value.rwbh = rwbh;
    queryParam.value.xqxn = xqxn;
    queryParam.value.atype = "1";
    defHttp.get({ url: '/wjxWjxx/wjxWjxx/list', params: queryParam.value }).then(res => {
      // console.log(`🚀 ~ defHttp.get ~ res:`, res)
      total.value = res.total;
      pageNo.value = res.pages;
      current.value = res.current;
      tableData.value = res.records;
    });
  }

  /**
   * 成功回调
   */
  function handleSuccess() {
    total.value = 1;
    pageNo.value = 0;
    reload();
  }

  /**
   * 查询
   */
  function searchQuery() {
    pageNo.value = 0;
    reload();
  }

  /**
   * 重置
   */
  function searchReset() {
    queryParam.value = {};
    total.value = 1;
    handlePageChange(1);
  }

  function handlePageChange(record){
    pageNo.value = record;
    reload();
  }

  onMounted(() => {
    searchQuery();
  });

  function classFun(type){
    if(type == '0'){
      return "background: #a7a6a6";
    }else if(type == '1'){
      return "background: #18a689";
    }
  }

</script>

<style lang="less" scoped>
  .jeecg-basic-table-form-container {
    padding: 0;
    .table-page-search-submitButtons {
      display: block;
      margin-bottom: 24px;
      white-space: nowrap;
    }
    .query-group-cust{
      width: calc(50% - 15px);
      min-width: 100px !important;
    }
    .query-group-split-cust{
      width: 30px;
      display: inline-block;
      text-align: center
    }
  }

  .jeecg-basic-table-form-container .ant-form {
    padding: 12px 10px 0px 10px;
    margin-bottom: 0px;
    background-color: #fff;
    border-radius: 2px;
  }

  .ellipsis {
    overflow: hidden; /* 确保超出容器的内容被裁剪 */
    white-space: nowrap; /* 确保文本在一行内显示 */
    text-overflow: ellipsis; /* 超出部分显示省略号 */
  }
  .zyCon{
    line-height: 30px;
  }
  .rotate {
    transform: rotate(45deg);
    background: rgb(28, 132, 198);
    color: #fff;
    padding: 19px 10px 3px 10px;
    position: relative;
    top: -54px;
    right: -131px;
    text-align: center;
    font-size: 11px;
  }
</style>
