<template>
  <div>
    <!--查询区域-->
    <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="8">
            <a-form-item label="作业名称">
              <a-input placeholder="请输入作业名称" v-model:value="queryParam.zyname"></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="8">
            <a-form-item label="存档类型">
              <JDictSelectTag v-model:value="queryParam.cdlx" dictCode="cdlx" placeholder="请选择" />
            </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-col>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!--引用表格-->
    <BasicTable @register="registerTable" style="margin-top: 20px;">
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
      <!--字段回显插槽-->
      <template #htmlSlot="{text}">
        <div v-html="text"></div>
      </template>
      <!--省市区字段回显插槽-->

      <template #wwsftgaction="{text,record}">
        <span v-if="record.wwcc=='0'">-</span>
        <span v-else>
          <span v-if="text=='通过'" style="color: green;padding: 5px 15px;" title="通过">{{record.wwxsl}}%</span>
          <span v-else-if="text=='未通过'" style="color: red;padding: 5px 15px;" title="未通过">{{record.wwxsl}}%</span>
          <span v-else>
            <span v-if="record.filePath">检测中</span>
            <span v-else>未提交</span>
          </span>
        </span>
      </template>
      <template #nwsftgaction="{text,record}">
        <span v-if="record.nwcc=='0'">-</span>
        <span v-else>
          <span v-if="text=='通过'" style="color: green;padding: 5px 15px;" title="通过">{{record.nwxsl}}%</span>
          <span v-else-if="text=='未通过'" style="color: red;padding: 5px 15px;" title="未通过">{{record.nwxsl}}%</span>
          <span v-else>
            <span v-if="record.filePath">检测中</span>
            <span v-else>未提交</span>
          </span>
        </span>
      </template>
      <template #aigcsftgaction="{text,record}">
        <span v-if="record.aigccc=='0'">-</span>
        <span v-else>
          <span v-if="text=='通过'" style="color: green;padding: 5px 15px;" title="通过">{{record.aigcxsl}}%</span>
          <span v-else-if="text=='未通过'" style="color: red;padding: 5px 15px;" title="未通过">{{record.aigcxsl}}%</span>
          <span v-else>
            <span v-if="record.filePath">检测中</span>
            <span v-else>未提交</span>
          </span>
        </span>
      </template>
      <template #xnsftgaction="{text,record}">
        <span v-if="record.xncc=='0'">-</span>
        <span v-else>
          <span v-if="text=='通过'" style="color: green;padding: 5px 15px;" title="通过">{{record.xnxsl}}%</span>
          <span v-else-if="text=='未通过'" style="color: red;padding: 5px 15px;" title="未通过">{{record.xnxsl}}%</span>
          <span v-else>
            <span v-if="record.filePath">检测中</span>
            <span v-else>未提交</span>
          </span>
        </span>
      </template>
    </BasicTable>
    <!-- 表单区域 -->
    <ZyInfoStudentModal ref="registerModal" @success="handleSuccess"></ZyInfoStudentModal>
    <ZyInfoStudentScoreModal ref="registerScoreModal" @success="handleSuccess"></ZyInfoStudentScoreModal>
    <SzybStudentModal ref="SzybStudentModalpage" @success="handleSuccess"></SzybStudentModal>
  </div>
</template>

<script lang="ts" name="zyInfoStudent-zyInfoStudent" setup>
  import { ref, reactive,defineExpose,unref } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { cdxxcolumns } from './ZyInfoStudent.data';
  import { cdxxlist, deleteOne, batchDelete, getImportUrl, getExportUrl } from './ZyInfoStudent.api';
  import { downloadFile } from '/@/utils/common/renderUtils';
  import ZyInfoStudentModal from './components/ZyInfoStudentModal.vue'
  import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';
  import SzybStudentModal from '/@/views/zy/zyInfoStudent/components/SzybStudentModal.vue';
  import { getFileAccessHttpUrl } from '/@/utils/common/compUtils';
  import ZyInfoStudentScoreModal from '/@/views/zy/zyInfoStudent/components/ZyInfoStudentScoreModal.vue'
  import { useGlobSetting } from '/@/hooks/setting';
  import { defHttp } from '/@/utils/http/axios';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { useRouter } from 'vue-router';
  import { useUserStore } from '/@/store/modules/user';

  const { createMessage } = useMessage();

  //当前路由信息
  const { currentRoute } = useRouter();
  const { query } = unref(currentRoute);
  const { rwbh,xqxn,type } = query;//获取传递参数
  const userStore = useUserStore();
  const globSetting = useGlobSetting();
  const baseApiUrl = globSetting.domainUrl;

  const queryParam = ref<any>({xqxn,rwbh,teacherNo:userStore.getUserInfo.username});
  const mainId = ref<string>('');

  const toggleSearchStatus = ref<boolean>(false);
  const registerModal = ref();
  const registerScoreModal = ref();
  const SzybStudentModalpage = ref();
  //注册table数据
  const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
    tableProps: {
      api: cdxxlist,
      columns: cdxxcolumns,
      canResize:false,
      useSearchForm: false,
      actionColumn: {
        width: '120px',
        // fixed: 'right',
      },
      beforeFetch: (params) => {
        params.column = '',params.order = '';//新生成的默认不带排序
        return Object.assign(params, queryParam.value);
      },
    },
    exportConfig: {
      name: "学生提交作业",
      url: getExportUrl,
    },
	importConfig: {
	  url: getImportUrl,
	  success: handleSuccess
	},
  });
  const [registerTable, { reload, collapseAll, updateTableDataRecord, findTableDataRecord, getDataSource }, { rowSelection, selectedRowKeys }] = tableContext;
  const labelCol = reactive({
    xs: { span: 24 },
    sm: { span: 7 },
  });
  const wrapperCol = reactive({
    xs: { span: 24 },
    sm: { span: 16 },
  });

  function yulanFile(record){

    var url2 = getFileAccessHttpUrl(record.pdfPath)
    let url = baseApiUrl+"/generic/web/viewer.html?file="+encodeURIComponent(url2);
    window.open(url,"_blank")
  }

  /**
   * 成功回调
   */
  function handleSuccess() {
    reload();
  }

  function handleDown(record){
    downloadFile(record.filePath);
  }

  /**
   * 操作栏
   */
  function getTableAction(record) {
        var list = [
          {
              label: '下载',
              onClick: handleDown.bind(null, record),
            },
          {
            label: '预览',
            onClick: yulanFile.bind(null, record),
          }
        ];
        return list;
  }


  /**
   * 查询
   */
  function searchQuery() {
    reload();
  }

  /**
   * 重置
   */
  function searchReset() {
    queryParam.value = {};
    selectedRowKeys.value = [];
    //刷新数据
    reload();
  }



</script>

<style lang="less" scoped>
  .jeecg-basic-table-form-container {
    .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
    }
  }
</style>
