<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="sourceDataCode">
              <template #label><span title="数据来源系统的编码">数据来源</span></template>
              <a-input placeholder="请输入数据来源系统的编码" v-model:value="queryParam.sourceDataCode"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <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>
            <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="regionCode">
                <template #label><span title="项目所在行政区域代码">项目所在</span></template>
                <j-select-user-by-dept placeholder="请选择项目所在行政区域代码" v-model:value="queryParam.regionCode" @change="(value)=>handleFormJoinChange('regionCode',value)"/>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="relateCode">
                <template #label><span title="项目类别关联代码">项目类别</span></template>
                <a-input placeholder="请输入项目类别关联代码" v-model:value="queryParam.relateCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="investProjectCode">
                <template #label><span title="投资项目统一代码">投资项目</span></template>
                <a-input placeholder="请输入投资项目统一代码" v-model:value="queryParam.investProjectCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="address">
                <template #label><span title="项目地址">项目地址</span></template>
                <a-input placeholder="请输入项目地址" v-model:value="queryParam.address"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="legalPerson">
                <template #label><span title="项目法人">项目法人</span></template>
                <a-input placeholder="请输入项目法人" v-model:value="queryParam.legalPerson"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="industriesType">
                <template #label><span title="项目行业分类">项目行业</span></template>
                <a-input placeholder="请输入项目行业分类" v-model:value="queryParam.industriesType"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="fundSource">
                <template #label><span title="资金来源">资金来源</span></template>
                <a-input placeholder="请输入资金来源" v-model:value="queryParam.fundSource"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="contributionScale">
                <template #label><span title="出资比例">出资比例</span></template>
                <a-input placeholder="请输入出资比例" v-model:value="queryParam.contributionScale"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="projectScale">
                <template #label><span title="项目规模">项目规模</span></template>
                <a-input placeholder="请输入项目规模" v-model:value="queryParam.projectScale"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="tendererName">
                <template #label><span title="招标人名称">招标人名</span></template>
                <a-input placeholder="请输入招标人名称" v-model:value="queryParam.tendererName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="tendererCode">
                <template #label><span title="招标人代码">招标人代</span></template>
                <a-input placeholder="请输入招标人代码" v-model:value="queryParam.tendererCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="contactor">
                <template #label><span title="联系人">联系人</span></template>
                <a-input placeholder="请输入联系人" v-model:value="queryParam.contactor"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="contactInformation">
                <template #label><span title="联系方式">联系方式</span></template>
                <a-input placeholder="请输入联系方式" v-model:value="queryParam.contactInformation"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="approvalName">
                <template #label><span title="项目审批文件名称">项目审批</span></template>
                <a-input placeholder="请输入项目审批文件名称" v-model:value="queryParam.approvalName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="approvalNumber">
                <template #label><span title="项目审批文号">项目审批</span></template>
                <a-input placeholder="请输入项目审批文号" v-model:value="queryParam.approvalNumber"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="approvalAuthority">
                <template #label><span title="项目审批单位">项目审批</span></template>
                <a-input placeholder="请输入项目审批单位" v-model:value="queryParam.approvalAuthority"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="isEmphasisProject">
                <template #label><span title="是否重点项目">是否重点</span></template>
                <a-input placeholder="请输入是否重点项目" v-model:value="queryParam.isEmphasisProject"></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="pcreateTime_begin" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" v-model:value="queryParam.pcreateTime_begin" class="query-group-cust" />
                   </a-form-item>
                   <span class="query-group-split-cust">~</span>
                   <a-form-item name="pcreateTime_end" style="margin-bottom: 0;">
                     <a-date-picker showTime value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" v-model:value="queryParam.pcreateTime_end" class="query-group-cust" />
                   </a-form-item>
                 </div>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="industryRegulatoryAuthorities">
                <template #label><span title="行业监管部门">行业监管</span></template>
                <a-input placeholder="请输入行业监管部门" v-model:value="queryParam.industryRegulatoryAuthorities"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="isNationalCapitalHolding">
                <template #label><span title="是否国有资金占控股或者主导地位">是否国有</span></template>
                <a-input placeholder="请输入是否国有资金占控股或者主导地位" v-model:value="queryParam.isNationalCapitalHolding"></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="pubServicePlatCode">
                <template #label><span title="交易服务系统标识码">交易服务</span></template>
                <a-input placeholder="请输入交易服务系统标识码" v-model:value="queryParam.pubServicePlatCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="tradePlat">
                <template #label><span title="交易平台或发布工具标识码">交易平台</span></template>
                <a-input placeholder="请输入交易平台或发布工具标识码" v-model:value="queryParam.tradePlat"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="pubServicePlat">
                <template #label><span title="公共服务平台标识码">公共服务</span></template>
                <a-input placeholder="请输入公共服务平台标识码" v-model:value="queryParam.pubServicePlat"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="priceFormCode">
                <template #label><span title="价款形式代码">价款形式</span></template>
                <a-input placeholder="请输入价款形式代码" v-model:value="queryParam.priceFormCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="investmentUnit">
                <template #label><span title="投资总额单位">投资总额</span></template>
                <a-input placeholder="请输入投资总额单位" v-model:value="queryParam.investmentUnit"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="investmentCurrency">
                <template #label><span title="投资总额币种代码">投资总额</span></template>
                <a-input placeholder="请输入投资总额币种代码" v-model:value="queryParam.investmentCurrency"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="totleInvestment">
                <template #label><span title="投资总额">投资总额</span></template>
                <a-input placeholder="请输入投资总额" v-model:value="queryParam.totleInvestment"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="investmentPercent">
                <template #label><span title="投资总额比率或其他">投资总额</span></template>
                <a-input placeholder="请输入投资总额比率或其他" v-model:value="queryParam.investmentPercent"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="legalCreditCode">
                <template #label><span title="项目法人统一社会信用代码">项目法人</span></template>
                <a-input placeholder="请输入项目法人统一社会信用代码" v-model:value="queryParam.legalCreditCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="legalAddress">
                <template #label><span title="项目法人地址">项目法人</span></template>
                <a-input placeholder="请输入项目法人地址" v-model:value="queryParam.legalAddress"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="financialFund">
                <template #label><span title="财政资金">财政资金</span></template>
                <a-input placeholder="请输入财政资金" v-model:value="queryParam.financialFund"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="selfFund">
                <template #label><span title="自筹资金">自筹资金</span></template>
                <a-input placeholder="请输入自筹资金" v-model:value="queryParam.selfFund"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="otherFund">
                <template #label><span title="其他资金">其他资金</span></template>
                <a-input placeholder="请输入其他资金" v-model:value="queryParam.otherFund"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="isAgentConstruct">
                <template #label><span title="是否采用代建制">是否采用</span></template>
                <a-input placeholder="请输入是否采用代建制" v-model:value="queryParam.isAgentConstruct"></a-input>
              </a-form-item>
            </a-col>
            <a-col :lg="6">
              <a-form-item name="legalRepresentative">
                <template #label><span title="法定代表人">法定代表</span></template>
                <a-input placeholder="请输入法定代表人" v-model:value="queryParam.legalRepresentative"></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>
          </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>
    </BasicTable>
    <!-- 表单区域 -->
    <GcProjectModal ref="registerModal" @success="handleSuccess"></GcProjectModal>
  </div>
</template>

<script lang="ts" name="gcproject-gcProject" setup>
  import { ref, reactive } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { columns, superQuerySchema } from './GcProject.data';
  import { list, deleteOne, batchDelete, getImportUrl, getExportUrl } from './GcProject.api';
  import { downloadFile } from '/@/utils/common/renderUtils';
  import GcProjectModal from './components/GcProjectModal.vue'
  import { useUserStore } from '/@/store/modules/user';
  import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';
  import JSelectUserByDept from '/@/components/Form/src/jeecg/components/JSelectUserByDept.vue';

  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();
  }
  

  /**
   * form点击事件(以逗号分割)
   * @param key
   * @param value
   */
  function handleFormJoinChange(key, value) {
    queryParam[key] = value.join(',');
  }


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