<template>
  <div style="background: #fff;height: calc(100vh - 280px);overflow-y: auto;overflow-x: hidden;margin-top:10px;">
      <!--查询区域-->
      <div class="jeecg-basic-table-form-container" style="border-bottom: 2px solid #f0f0f0;">
        <a-form @keyup.enter.native="searchQuery" :model="queryParam" :label-col="labelCol" :wrapper-col="wrapperCol" style="padding: 20px 10px 0px 10px;">
          <a-row :gutter="24">
            <a-col :lg="8">
              <a-form-item label="标题">
                <j-input placeholder="请输入标题" v-model:value="queryParam.title"></j-input>
              </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-col>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <a-row>
        <a-col :span="24" v-for="(item, index) in tableData" :key="index" style="padding:10px;overflow:hidden;border-bottom: 1px solid #f0f0f0;">
          <div>
            <a-row style="padding:10px;line-height: 30px;">
              <a-col :span="item.ggStatus==0||item.ggStatus==2?14:24">
                <span style="font-size: 16px;color: #515151 ;font-weight: bold; ">{{item.title}}</span>
                <span v-if="item.ggStatus==0" style="margin-left:15px;"><a-tag color="blue">草稿</a-tag></span>
              </a-col>
              <a-col v-if="item.ggStatus==2" :span="item.ggStatus==0||item.ggStatus==2?10:24" style="text-align: right;color:#9e9e9e;">
                   尚未发布，学生端页面看不到这条通知
              </a-col>
            </a-row>
            <a-row style="padding:10px;">
              <a-col :span="24">
                <div style="color: #515151" v-html="item.content"></div>
              </a-col>
            </a-row>
            <a-row style="padding:10px;">
              <a-col :span="24">
                <div style="text-align: right;color:#9e9e9e;font-weight: bold;">{{item.createTime}}</div>
              </a-col>
            </a-row>
          </div>
        </a-col>
        <a-col :span="24" style="padding:10px;">
          <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>


    <ZyGonggaoModal ref="registerModal" @success="handleSuccess"></ZyGonggaoModal>
    <ZyGonggaoYlModal ref="registerYlModal" @success="handleSuccess"></ZyGonggaoYlModal>
<!--    <ZyGonggaoHistoryModal ref="registerHistoryModal" @success="handleSuccess"></ZyGonggaoHistoryModal>-->
  </div>
</template>

<script lang="ts" name="zyGonggao-zyGonggao" setup>
  import {ref, reactive, unref, onMounted} from 'vue';
  import { Input, Popover, Pagination, Empty } from 'ant-design-vue';
  import { deleteOne } from './ZyGonggao.api';
  import ZyGonggaoModal from './components/ZyGonggaoModal.vue';
  import ZyGonggaoYlModal from './components/ZyGonggaoYlModal.vue';
  import TeacherYulanList from '/@/views/zy/zyGonggao/TeacherYulanList.vue';
  // import ZyGonggaoHistoryModal from './components/ZyGonggaoHistoryModal.vue';
  import { defHttp } from '/@/utils/http/axios';
  import { useMessage } from "/@/hooks/web/useMessage";
  import { JInput } from '/@/components/Form';
  import { useRouter } from 'vue-router';
  import {useUserStore} from "/@/store/modules/user";

  const APagination = Pagination;
  const { createConfirm } = useMessage();
  const { currentRoute } = useRouter();
  const { query } = unref(currentRoute);
  const { rwbh,xqxn } = query;//获取传递参数
  const userStore = useUserStore();
  const userName = userStore.getUserInfo.username;
  const queryParam = ref<any>({rwbh,  xqxn,"createBy":userName});
  const registerModal = ref();
  const registerYlModal = ref();
  // const registerHistoryModal = ref();
  const current = ref<number>(0);
  const total = ref<number>(0);
  const pageNo = ref<number>(0);
  const pageSize = ref<number>(5);
  const tableData = ref<any>([]);
  const showYl = ref<boolean>(true);

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

  function handleZtyl(type){
    if(type==1){
      showYl.value = true;
    }else if(type==0){
      showYl.value = false;
    }
  }

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

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

  /**
   * 详情
   */
  function handleDetail(record: Recordable) {
    if(record.ggStatus == 1){
      registerYlModal.value.disableSubmit = true;
    }else{
      registerYlModal.value.disableSubmit = false;
    }
    registerYlModal.value.edit(record);
  }

  /**
   * 历史通知
   */
  // function handleHistory(record: Recordable) {
  //   registerHistoryModal.value.disableSubmit = true;
  //   registerHistoryModal.value.edit(record);
  // }

  /**
   * 删除事件
   */
  async function handleDelete(record) {
    createConfirm({
      iconType: 'warning',
      title: '删除',
      content: '是否删除此通知？',
      okText: '确认',
      cancelText: '取消',
      onOk: () => {
        deleteOne({ id: record.id }, handleSuccess2);
      }
    });
  }

  function handleFabu(record){
    createConfirm({
      iconType: 'warning',
      title: '确认发布',
      content: '是否发布此通知？',
      okText: '发布',
      cancelText: '取消',
      onOk: () => {
        var params = {id:record.id,ggStatus:"1",flag:"1",fbTime:new Date()}
        defHttp.post({url: '/zyGonggao/zyGonggao/edit', params: params}).then(() => {
          handleSuccess();
        });
      }
    });
  }

  function handleCh(record){
    createConfirm({
      iconType: 'warning',
      title: '撤回',
      content: '是否撤回此通知？',
      okText: '确认',
      cancelText: '取消',
      onOk: () => {
        var params = {id:record.id,ggStatus:"0",flag:"0",fbTime:new Date()}
        defHttp.post({url: '/zyGonggao/zyGonggao/edit', params: params}).then(() => {
          handleSuccess();
        });
      }
    });
  }

  /**
   * 成功回调,用于删除
   */
  function handleSuccess2() {
    total.value = 1;
    handlePageChange(1);
  }

  /**
   * 成功回调，用于增加、修改、发布和撤回
   */
  function handleSuccess() {
    reload();
  }

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

  /**
   * 重置
   */
  function searchReset() {
    queryParam.value = {"createBy":userName};
    queryParam.value.rwbh = rwbh;
    queryParam.value.xqxn = xqxn;
    total.value = 1;
    handlePageChange(1);
  }

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

  function reload(){
    queryParam.value.pageNo = current.value;
    queryParam.value.pageSize = pageSize.value;
    queryParam.value.rwbh = rwbh;
    queryParam.value.xqxn = xqxn;
    queryParam.value.column="createTime";
    queryParam.value.order="desc";
    defHttp.get({ url: '/zyGonggao/zyGonggao/list', params: queryParam.value }).then(res => {
      total.value = res.total;
      pageNo.value = res.pages;
      current.value = res.current;
      tableData.value = res.records;
    });
  }

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

</script>

<style lang="less" scoped>
  .jeecg-basic-table-form-container {
    padding: 0;
    width:99%;
    .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>
