<template>
  <div style="margin-top:10px;background:#fff;height: calc(100vh - 225px);overflow-y: auto;overflow-x: hidden;">
    <!--查询区域-->
    <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" style="margin-top:10px;">
            <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" style="margin-top:10px;">
            <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 style="width:100%;display: block;padding:10px;min-height: 300px">
      <a-col :span="24" v-for="(item,index) in dataSource" :key="index">
        <!-- <a-card> -->
          <a-row>
            <a-col :span="24">
              <span style="float: left;">{{(current-1)*pageSize+index+1}}.{{item.title}}</span>
              <span style="float: right;">
                <span v-if="item.sffb=='0'">【未发布】</span>
                <span v-else>【已发布】</span>
                <a title="修改" @click="handleEdit(item)" v-if="item.sffb=='0'"><Icon icon="ant-design:form-outlined"/></a>
                <a-divider type="vertical" style="height: 30px; background-color: #7cb305"  v-if="item.sffb=='0'"/>
                <a title="删除" @click="handleDelete(item)"><Icon icon="ant-design:delete-outlined"  v-if="item.sffb=='0'"/></a>
                <a-divider type="vertical" style="height: 30px; background-color: #7cb305"  v-if="item.sffb=='0'"/>
                <a title="发布" @click="handleFabu(item)"><Icon icon="ant-design:check-circle-outlined"  v-if="item.sffb=='0'"/></a>
                <a-divider type="vertical" style="height: 30px; background-color: #7cb305"  v-if="item.sffb=='0'"/>
                <a title="详情" @click="handleDetail(item)"><Icon icon="ant-design:snippets-outlined" /></a>
              </span>
            </a-col>
            <a-col :span="24" v-if="item.picPath.length > 0">
              <j-upload v-model:value="item.picPath" fileType="image" :isImageMode="false" :maxCount="1" :buttonVisible="false" disabled="true"></j-upload>
            </a-col>
            <a-col :span="24" v-if="item.filePath.length > 0">
              <j-upload v-model:value="item.filePath"  :maxCount="1" :buttonVisible="false" disabled="true"></j-upload>
            </a-col>
          </a-row>
          <!-- <a-divider style="height: 1px; background-color: #7cb305" /> -->
          <a-divider style="border-color: #7cb305" dashed />
        <!-- </a-card> -->
      </a-col>
      <a-col :span="24" v-show="dataSource.length>0">
        <a-pagination v-model="current" :total="total" @change="handlePageChange" :pageSize="pageSize" style="text-align: right;"/>
      </a-col>
      <a-col :span="24" v-show="dataSource.length==0">
        <a-empty/>
      </a-col>
    </a-row>
    <ZyTlqModal ref="registerModal" @success="handleSuccess" ></ZyTlqModal>
  </div>
</template>

<script lang="ts" name="zyTlq-zyTlq" setup>
  import { ref, reactive, onMounted, unref } from 'vue';
  import { columns } from './ZyTlq.data';
  import { list, deleteOne, batchDelete, getImportUrl, getExportUrl } from './ZyTlq.api';
  import { downloadFile } from '/@/utils/common/renderUtils';
  import ZyTlqModal from './components/ZyTlqModal.vue'
  import { Pagination, Empty } from 'ant-design-vue';
  import { defHttp } from '/@/utils/http/axios';
  import { useRouter } from 'vue-router';
  import { JInput } from '/@/components/Form';
  import JUpload from '/@/components/Form/src/jeecg/components/JUpload/JUpload.vue';
  import {useMessage} from "/@/hooks/web/useMessage";

  const { createConfirm } = useMessage();
  const queryParam = ref<any>({});
  const toggleSearchStatus = ref<boolean>(false);
  const registerModal = ref();
  const dataSource = ref<any>([]);
  const current = ref<number>(1);
  const total = ref<number>(0);
  const pageNo = ref<number>(0);
  const pageSize = ref<number>(3);
  const APagination = Pagination;
  const { currentRoute } = useRouter();
  const { query } = unref(currentRoute);
  const { rwbh,xqxn } = query;//获取传递参数
  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();
  }

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

  /**
   * 详情
   */
  function handleDetail(record: Recordable) {
    var url = "/site/dqkcTlqjh?id="+record.id;
    window.open(url,"_blank")
  }

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

  /**
   * 发布
   */
  function handleFabu(record) {
    defHttp.post({ url: '/zyTlq/zyTlq/editFbtl', params: { id: record.id,sffb: "1" } }).then(res => {
      handleSuccess();
    });
  }
  //新增翻页
  function handlePageChange(page: number) {
    current.value = page;
    loadData();
  }

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

  /**
   * 成功回调
   */
  function handleSuccess2() {
    total.value = 1;
    handlePageChange(1);
  }

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

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

  function loadData(){
    defHttp.get({ url: '/zyTlq/zyTlq/list', params: { pageSize: 3,pageNo:current.value, rwbh:rwbh,xqxn:xqxn,column:'createTime',order:'desc' } }).then((res) => {
    console.log(`🚀 ~ defHttp.get ~ res:`, res)
      dataSource.value = res.records;
      total.value = res.total;
      pageNo.value = res.pages;
      current.value = res.current;
    });
  }
  //进入就加载
  onMounted(() => {
    loadData();
  });

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