<template>
  <div class="p-2">
    <!--查询区域-->
    <div class="jeecg-basic-table-form-container">
      <a-form ref="formRef" @keyup.enter.native="searchQuery" :model="queryParam" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-row :gutter="24">
          <a-col :lg="6">
            <a-form-item name="sourceDataKey">
              <template #label><span title="数据唯一标识">数据唯一</span></template>
              <a-input placeholder="请输入数据唯一标识" v-model:value="queryParam.sourceDataKey"></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item name="projectCode">
              <template #label><span title="项目编号">项目编号</span></template>
              <a-input placeholder="请输入项目编号" v-model:value="queryParam.projectCode"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :lg="6">
              <a-form-item name="projectName">
                <template #label><span title="项目名称">项目名称</span></template>
                <a-input placeholder="请输入项目名称" v-model:value="queryParam.projectName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="tenderProjectCode">
                <template #label><span title="招标项目编号">招标项目</span></template>
                <a-input placeholder="请输入招标项目编号" v-model:value="queryParam.tenderProjectCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="noticeName">
                <template #label><span title="公告标题">公告标题</span></template>
                <a-input placeholder="请输入公告标题" v-model:value="queryParam.noticeName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="noticeContent">
                <template #label><span title="公告内容">公告内容</span></template>
                <a-input placeholder="请输入公告内容" v-model:value="queryParam.noticeContent"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item>
                 <template #label><span title="公告发布时间">公告发布</span></template>
                 <div style="display: flex">
                   <a-form-item name="noticeSendTime_begin" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" v-model:value="queryParam.noticeSendTime_begin" class="query-group-cust" />
                   </a-form-item>
                   <span class="query-group-split-cust">~</span>
                   <a-form-item name="noticeSendTime_end" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" v-model:value="queryParam.noticeSendTime_end" class="query-group-cust" />
                   </a-form-item>
                 </div>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="noticeNature">
                <template #label><span title="公告性质编号">公告性质</span></template>
                <a-input placeholder="请输入公告性质编号" v-model:value="queryParam.noticeNature"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="noticeNatureName">
                <template #label><span title="公告性质名称">公告性质</span></template>
                <a-input placeholder="请输入公告性质名称" v-model:value="queryParam.noticeNatureName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="regionCode">
                <template #label><span title="项目所在行政区域代码">项目所在</span></template>
                <a-input placeholder="请输入项目所在行政区域代码" v-model:value="queryParam.regionCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="regionName">
                <template #label><span title="项目所在行政区域名称">项目所在</span></template>
                <a-input placeholder="请输入项目所在行政区域名称" v-model:value="queryParam.regionName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="industriesTypeCode">
                <template #label><span title="项目行业分类编码">项目行业</span></template>
                <a-input placeholder="请输入项目行业分类编码" v-model:value="queryParam.industriesTypeCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="industriesTypeName">
                <template #label><span title="项目行业分类名称">项目行业</span></template>
                <a-input placeholder="请输入项目行业分类名称" v-model:value="queryParam.industriesTypeName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="platformCode">
                <template #label><span title="交易系统标识码">交易系统</span></template>
                <a-input placeholder="请输入交易系统标识码" v-model:value="queryParam.platformCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="platformName">
                <template #label><span title="交易系统标识码区域名称">交易系统</span></template>
                <a-input placeholder="请输入交易系统标识码区域名称" v-model:value="queryParam.platformName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="noticeTypeCode">
                <template #label><span title="公告上面类型编码">公告上面</span></template>
                <a-input placeholder="请输入公告上面类型编码" v-model:value="queryParam.noticeTypeCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="noticeTypeName">
                <template #label><span title="公告上面类型名称">公告上面</span></template>
                <a-input placeholder="请输入公告上面类型名称" v-model:value="queryParam.noticeTypeName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="transactionTypeCode">
                <template #label><span title="交易左侧类型编码">交易左侧</span></template>
                <a-input placeholder="请输入交易左侧类型编码" v-model:value="queryParam.transactionTypeCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="transactionTypeName">
                <template #label><span title="交易左侧类型名称">交易左侧</span></template>
                <a-input placeholder="请输入交易左侧类型名称" v-model:value="queryParam.transactionTypeName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="bulletinTypeCode">
                <template #label><span title="公告类型编码">公告类型</span></template>
                <a-input placeholder="请输入公告类型编码" v-model:value="queryParam.bulletinTypeCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="bulletinTypeName">
                <template #label><span title="公告类型名称">公告类型</span></template>
                <a-input placeholder="请输入公告类型名称" v-model:value="queryParam.bulletinTypeName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="bulletinDuty">
                <template #label><span title="公告发布责任人">公告发布</span></template>
                <a-input placeholder="请输入公告发布责任人" v-model:value="queryParam.bulletinDuty"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="dataSourceCode">
                <template #label><span title="交易中心编码">交易中心</span></template>
                <a-input placeholder="请输入交易中心编码" v-model:value="queryParam.dataSourceCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="dataSourceName">
                <template #label><span title="交易中心名称">交易中心</span></template>
                <a-input placeholder="请输入交易中心名称" v-model:value="queryParam.dataSourceName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="noticeBidNum">
                <template #label><span title="公告标段包数量">公告标段</span></template>
                <a-input placeholder="请输入公告标段包数量" v-model:value="queryParam.noticeBidNum"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="bidSectionCodes">
                <template #label><span title="相关标段包编号">相关标段</span></template>
                <a-input placeholder="请输入相关标段包编号" v-model:value="queryParam.bidSectionCodes"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item>
                 <template #label><span title="招标文件资格预审文件获取时间">招标文件</span></template>
                 <div style="display: flex">
                   <a-form-item name="docGetStartTime_begin" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" v-model:value="queryParam.docGetStartTime_begin" class="query-group-cust" />
                   </a-form-item>
                   <span class="query-group-split-cust">~</span>
                   <a-form-item name="docGetStartTime_end" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" v-model:value="queryParam.docGetStartTime_end" class="query-group-cust" />
                   </a-form-item>
                 </div>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item>
                 <template #label><span title="招标文件资格预审文件获取截至时间">招标文件</span></template>
                 <div style="display: flex">
                   <a-form-item name="docGetEndTime_begin" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" v-model:value="queryParam.docGetEndTime_begin" class="query-group-cust" />
                   </a-form-item>
                   <span class="query-group-split-cust">~</span>
                   <a-form-item name="docGetEndTime_end" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" v-model:value="queryParam.docGetEndTime_end" class="query-group-cust" />
                   </a-form-item>
                 </div>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item>
                 <template #label><span title="投标文件资格预审申请文件递交截止时间">投标文件</span></template>
                 <div style="display: flex">
                   <a-form-item name="bidDocReferEndTime_begin" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" v-model:value="queryParam.bidDocReferEndTime_begin" class="query-group-cust" />
                   </a-form-item>
                   <span class="query-group-split-cust">~</span>
                   <a-form-item name="bidDocReferEndTime_end" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" v-model:value="queryParam.bidDocReferEndTime_end" class="query-group-cust" />
                   </a-form-item>
                 </div>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item>
                 <template #label><span title="开标时间">开标时间</span></template>
                 <div style="display: flex">
                   <a-form-item name="bidOpenTime_begin" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" v-model:value="queryParam.bidOpenTime_begin" class="query-group-cust" />
                   </a-form-item>
                   <span class="query-group-split-cust">~</span>
                   <a-form-item name="bidOpenTime_end" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" v-model:value="queryParam.bidOpenTime_end" class="query-group-cust" />
                   </a-form-item>
                 </div>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="validPeriod">
                <template #label><span title="投标有效期单位天">投标有效</span></template>
                <a-input placeholder="请输入投标有效期单位天" v-model:value="queryParam.validPeriod"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item>
                 <template #label><span title="答疑澄清时间">答疑澄清</span></template>
                 <div style="display: flex">
                   <a-form-item name="clarifyTime_begin" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" v-model:value="queryParam.clarifyTime_begin" class="query-group-cust" />
                   </a-form-item>
                   <span class="query-group-split-cust">~</span>
                   <a-form-item name="clarifyTime_end" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" v-model:value="queryParam.clarifyTime_end" class="query-group-cust" />
                   </a-form-item>
                 </div>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item>
                 <template #label><span title="招标文件生成时间">招标文件</span></template>
                 <div style="display: flex">
                   <a-form-item name="submitTime_begin" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" v-model:value="queryParam.submitTime_begin" class="query-group-cust" />
                   </a-form-item>
                   <span class="query-group-split-cust">~</span>
                   <a-form-item name="submitTime_end" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" v-model:value="queryParam.submitTime_end" class="query-group-cust" />
                   </a-form-item>
                 </div>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="bidOpeningAddress">
                <template #label><span title="开标地点">开标地点</span></template>
                <a-input placeholder="请输入开标地点" v-model:value="queryParam.bidOpeningAddress"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item>
                 <template #label><span title="开标时间">开标时间</span></template>
                 <div style="display: flex">
                   <a-form-item name="bidOpeningTime_begin" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" v-model:value="queryParam.bidOpeningTime_begin" class="query-group-cust" />
                   </a-form-item>
                   <span class="query-group-split-cust">~</span>
                   <a-form-item name="bidOpeningTime_end" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" v-model:value="queryParam.bidOpeningTime_end" class="query-group-cust" />
                   </a-form-item>
                 </div>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item>
                 <template #label><span title="开标结束时间">开标结束</span></template>
                 <div style="display: flex">
                   <a-form-item name="bidFinishTime_begin" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" v-model:value="queryParam.bidFinishTime_begin" class="query-group-cust" />
                   </a-form-item>
                   <span class="query-group-split-cust">~</span>
                   <a-form-item name="bidFinishTime_end" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" v-model:value="queryParam.bidFinishTime_end" class="query-group-cust" />
                   </a-form-item>
                 </div>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item>
                 <template #label><span title="开标结束时间">开标结束</span></template>
                 <div style="display: flex">
                   <a-form-item name="docstatus_begin" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" v-model:value="queryParam.docstatus_begin" class="query-group-cust" />
                   </a-form-item>
                   <span class="query-group-split-cust">~</span>
                   <a-form-item name="docstatus_end" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" v-model:value="queryParam.docstatus_end" class="query-group-cust" />
                   </a-form-item>
                 </div>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item>
                 <template #label><span title="开标结束时间">开标结束</span></template>
                 <div style="display: flex">
                   <a-form-item name="docpubtime_begin" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" v-model:value="queryParam.docpubtime_begin" class="query-group-cust" />
                   </a-form-item>
                   <span class="query-group-split-cust">~</span>
                   <a-form-item name="docpubtime_end" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" v-model:value="queryParam.docpubtime_end" class="query-group-cust" />
                   </a-form-item>
                 </div>
              </a-form-item>
            </a-col>
          </template>
          <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 @click="toggleSearchStatus = !toggleSearchStatus" style="margin-left: 8px">
                  {{ toggleSearchStatus ? '收起' : '展开' }}
                  <Icon :icon="toggleSearchStatus ? 'ant-design:up-outlined' : 'ant-design:down-outlined'" />
                </a>
              </a-col>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!--引用表格-->
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <!--插槽:table标题-->
      <template #tableTitle>
        <a-button type="primary" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button>
        <a-button  type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
        <j-upload-button  type="primary" preIcon="ant-design:import-outlined" @click="onImportXls">导入</j-upload-button>
        <a-dropdown v-if="selectedRowKeys.length > 0">
          <template #overlay>
            <a-menu>
              <a-menu-item key="1" @click="batchHandleDelete">
                <Icon icon="ant-design:delete-outlined"></Icon>
                删除
              </a-menu-item>
            </a-menu>
          </template>
          <a-button>批量操作
            <Icon icon="mdi:chevron-down"></Icon>
          </a-button>
        </a-dropdown>
        <!-- 高级查询 -->
        <super-query :config="superQueryConfig" @search="handleSuperQuery" />
      </template>
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)"/>
      </template>
      <template v-slot:bodyCell="{ column, record, index, text }">
        <template v-if="column.dataIndex==='noticeContent'">
          <!--富文本件字段回显插槽-->
          <div v-html="text"></div>
        </template>
        <template v-if="column.dataIndex==='file'">
          <!--文件字段回显插槽-->
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" preIcon="ant-design:download-outlined" size="small" @click="downloadFile(text)">下载</a-button>
        </template>
      </template>
    </BasicTable>
    <!-- 表单区域 -->
    <GgzyContentDistributionModal ref="registerModal" @success="handleSuccess"></GgzyContentDistributionModal>
  </div>
</template>

<script lang="ts" name="ggzycontentdistribution-ggzyContentDistribution" setup>
  import { ref, reactive } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { columns, superQuerySchema } from './GgzyContentDistribution.data';
  import { list, deleteOne, batchDelete, getImportUrl, getExportUrl } from './GgzyContentDistribution.api';
  import { downloadFile } from '/@/utils/common/renderUtils';
  import GgzyContentDistributionModal from './components/GgzyContentDistributionModal.vue'
  import { useUserStore } from '/@/store/modules/user';

  const formRef = ref();
  const queryParam = reactive<any>({});
  const toggleSearchStatus = ref<boolean>(false);
  const registerModal = ref();
  const userStore = useUserStore();
  //注册table数据
  const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
    tableProps: {
      title: '公共资源内容发布',
      api: list,
      columns,
      canResize:false,
      useSearchForm: false,
      actionColumn: {
        width: 120,
        fixed: 'right',
      },
      beforeFetch: (params) => {
        return Object.assign(params, queryParam);
      },
    },
    exportConfig: {
      name: "公共资源内容发布",
      url: getExportUrl,
      params: queryParam,
    },
	  importConfig: {
	    url: getImportUrl,
	    success: handleSuccess
	  },
  });
  const [registerTable, { reload, collapseAll, updateTableDataRecord, findTableDataRecord, getDataSource }, { rowSelection, selectedRowKeys }] = tableContext;
  const labelCol = reactive({
    xs:24,
    sm:4,
    xl:6,
    xxl:4
  });
  const wrapperCol = reactive({
    xs: 24,
    sm: 20,
  });

  // 高级查询配置
  const superQueryConfig = reactive(superQuerySchema);

  /**
   * 高级查询事件
   */
  function handleSuperQuery(params) {
    Object.keys(params).map((k) => {
      queryParam[k] = params[k];
    });
    searchQuery();
  }

  /**
   * 新增事件
   */
  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) {
    registerModal.value.disableSubmit = true;
    registerModal.value.edit(record);
  }
   
  /**
   * 删除事件
   */
  async function handleDelete(record) {
    await deleteOne({ id: record.id }, handleSuccess);
  }
   
  /**
   * 批量删除事件
   */
  async function batchHandleDelete() {
    await batchDelete({ ids: selectedRowKeys.value }, handleSuccess);
  }
   
  /**
   * 成功回调
   */
  function handleSuccess() {
    (selectedRowKeys.value = []) && reload();
  }
   
  /**
   * 操作栏
   */
  function getTableAction(record) {
    return [
      {
        label: '编辑',
        onClick: handleEdit.bind(null, record),
      },
    ];
  }
   
  /**
   * 下拉操作栏
   */
  function getDropDownAction(record) {
    return [
      {
        label: '详情',
        onClick: handleDetail.bind(null, record),
      }, {
        label: '删除',
        popConfirm: {
          title: '是否确认删除',
          confirm: handleDelete.bind(null, record),
          placement: 'topLeft',
        }
      }
    ]
  }

  /**
   * 查询
   */
  function searchQuery() {
    reload();
  }
  
  /**
   * 重置
   */
  function searchReset() {
    formRef.value.resetFields();
    selectedRowKeys.value = [];
    //刷新数据
    reload();
  }
  



</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{
      min-width: 100px !important;
    }
    .query-group-split-cust{
      width: 30px;
      display: inline-block;
      text-align: center
    }
  }
</style>
