<template>
  <div style="background: #fff;height: calc(100vh - 255px);overflow-y: auto;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="12">
            <a-form-item label="作业名称">
              <j-input placeholder="请输入作业名称" v-model:value="queryParam.title"></j-input>
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="状态">
              <j-dict-select-tag placeholder="请选择状态" v-model:value="queryParam.zyStatus" dictCode="zy_status"/>
            </a-form-item>
          </a-col>
          <a-col :lg="12">
                <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>
        </a-row>
      </a-form>
    </div>
    <a-row style="overflow:hidden;">
      <a-col :lg="8" v-for="(item, index) in tableData" :key="index" style="padding: 0px 0px 5px 5px;overflow:hidden;">
        <div style="width: 100%; height: 20px; background-color: rgb(28, 132, 198);"></div>
        <a-card  style="height: 256px;border: 1px solid rgb(28, 132, 198);">
          <div class="rotate" :style="classFun(item.zyStatus)">{{item.zyStatus_dictText}}</div>
          <a-row style="top: -48px;position: relative;">
            <a-col :span="24" style="margin-bottom: 10px;height:53px;overflow:hidden;" :title="item.title">
              <div style="font-size: 18px;font-weight: bold;">{{item.title?item.title:'暂未填写'}}</div>
            </a-col>
            <a-col :span="24" class="zyCon" v-if="item.endTime">时间：{{dayjs(item.startTime).format('YYYY.MM.DD')}} - {{dayjs(item.endTime).format('YYYY.MM.DD')}}</a-col>
            <a-col :span="24" class="zyCon"><div style="float:left">&nbsp;</div><div style="float:right;" ><a>{{item.xkxs}}人选课</a></div></a-col>
            <a-col :span="24" class="zyCon"><div style="float:left">未提交：{{item.wtjnum}}人;</div><div style="float:right;" >已提交：{{item.ytjnum}}人</div></a-col>
            <a-col :span="24" class="zyCon"><div style="float:left">未评阅：{{item.wpynum}}人;</div><div style="float:right;" >已评阅：{{item.ypynum}}人</div></a-col>

            <a-col :span="24" style="text-align:center;margin-top:8px;">
              <a-button type="primary" @click="handleDetail(item)" style="margin-left:5px;margin-bottom:5px;padding: 0px 4px;background:rgb(28, 132, 198);">作业详情</a-button>
              <a-button type="primary" @click="handleZyxx(item)" style="margin-left:5px;margin-bottom:5px;padding: 0px 4px;background:rgb(28, 132, 198);">查看作业</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>

    <ZyInfoModal ref="registerModal" ></ZyInfoModal>
    <ZyInfoStudentListModal ref="ZyInfoStudentListModalPage" ></ZyInfoStudentListModal>
  </div>
</template>

<script lang="ts" setup>
  import { ref, reactive, defineExpose, nextTick, defineProps, computed, onMounted } from 'vue';
  import { defHttp } from '/@/utils/http/axios';
  import { useMessage } from '/@/hooks/web/useMessage';
  import JUpload from '/@/components/Form/src/jeecg/components/JUpload/JUpload.vue';
  import { getValueType } from '/@/utils';
  import { saveOrUpdate } from '../Kczygl.api';
  import { Form } from 'ant-design-vue';
  import ZyInfoModal from '/@/views/zy/zyInfo/components/ZyInfoModal.vue';
  import ZyInfoStudentListModal from '/@/views/zy/zyInfoStudent/ZyInfoStudentListModal.vue';
  import dayjs from 'dayjs';
  import { JInput,JDictSelectTag } from '/@/components/Form';
  import { Pagination } from 'ant-design-vue';
  
  const props = defineProps({
    formDisabled: { type: Boolean, default: false },
    formData: { type: Object, default: ()=>{} },
    formBpm: { type: Boolean, default: true }
  });
  const formRef = ref();
  const useForm = Form.useForm;
  const emit = defineEmits(['register', 'ok']);
  const formData = reactive<Record<string, any>>({
    id: '',
    filePath: '',
    jxrlFilePath: '',
  });
  const { createMessage } = useMessage();
  const labelCol = ref<any>({ xs: { span: 24 }, sm: { span: 5 } });
  const wrapperCol = ref<any>({ xs: { span: 24 }, sm: { span: 16 } });
  const confirmLoading = ref<boolean>(false);
  //表单验证
  const validatorRules = { };

  const APagination = Pagination;
  const queryParam = ref<any>({});
  const registerModal = ref();
  const ZyInfoStudentListModalPage = ref();
  let rwbh = ref<string>('');
  let xqxn = ref<string>('');
  let teano = ref<string>('');
  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 { resetFields, validate, validateInfos } = useForm(formData, validatorRules, { immediate: true });

  // 表单禁用
  const disabled = computed(()=>{
    if(props.formBpm === true){
      if(props.formData.disabled === false){
        return false;
      }else{
        return true;
      }
    }
    return props.formDisabled;
  });

  
  /**
   * 新增
   */
  function add() {
    edit({});
  }

  /**
   * 编辑
   */
  function edit(record) {
    console.log(`🚀 ~ edit ~ record:`, record)
    nextTick(() => {
      resetFields();
      rwbh = record.rwbh;
      xqxn = record.xqxn;
      teano = record.jgh;
      console.log(`🚀 ~ nextTick ~ rwbh:`, rwbh)
      
      reload()
    });
  }

  
  function reload(){
    queryParam.value.pageNo = current.value;
    queryParam.value.pageSize = pageSize.value;
    queryParam.value.rwbh = rwbh;
    queryParam.value.xqxn = xqxn;
    queryParam.value.teano = teano;
    // queryParam.value.sflssj = '0';
    queryParam.value.column="endTime";
    queryParam.value.order="desc";
    defHttp.get({ url: '/zyInfo/zyInfo/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 handleDetail(record: Recordable) {
    registerModal.value.disableSubmit = true;
    registerModal.value.edit(record);
  }

  //查看作业信息
  function handleZyxx(record){
    ZyInfoStudentListModalPage.value.disableSubmit = true;
    ZyInfoStudentListModalPage.value.init(record);
  }

  /**
   * 查询
   */
   function searchQuery() {
    total.value = 1;
    handlePageChange(1);
  }

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

function handlePageChange(record){
    current.value = record;
    reload();
  }
  /**
   * 提交数据
   */
  async function submitForm() {
  }


  defineExpose({
    add,
    edit,
    submitForm,
  });
</script>

<style lang="less" scoped>
  .antd-modal-form {
    min-height: 500px !important;
    overflow-y: auto;
    padding: 24px 24px 24px 24px;
  }

  
.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>
