<template>
  <cacp-search-layout>
    <template #search>
      <cacp-search-panel-layout
          :model="state.queryData"
          ref="queryFormRef"
          label-position="left"
          label-width="auto"
          :gutter="30"
          :colSpan="6"
      >
        <el-form-item label="主管海关" prop="customsCode" v-if = "state.isSelect">
          <el-select
              v-model="state.queryData.customsCode"
              placeholder="主管海关"
              clearable
          >
            <el-option
                v-for="item in dict.affiliation_customs_info"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="出入境标志" prop="ieFlag">
          <el-select
              v-model="state.queryData.ieFlag"
              placeholder="出入境标志"
              clearable
          >
            <el-option
                v-for="item in dict.ie_flag"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="申报时间">
          <el-date-picker
              type="date"
              value-format="YYYY-MM-DD"
              v-model="state.queryData.beginDate"
              placeholder="开始时间"
          />
        </el-form-item>
        <el-form-item label="到">
          <el-date-picker
              type="date"
              value-format="YYYY-MM-DD"
              v-model="state.queryData.endDate"
              placeholder="结束时间"
          />
        </el-form-item>
        <el-form-item label="危险品类型" prop="goodsType">
          <el-select
              v-model="state.queryData.goodsType"
              placeholder="危险品类型"
              clearable
          >
            <el-option
                v-for="item in dict.goods_type"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
            />
          </el-select>
        </el-form-item>
        <template #buttonGroup>
          <el-button type="primary" @click="onSearch">查询</el-button>
          <el-button type="info" @click="onReset">重置</el-button>
        </template>
      </cacp-search-panel-layout>
    </template>

    <cacp-complex-table
        :actions="actions"
        :data="tableData"
        :pagination="tablePagination"
        :actionsWidth="120"
        @selection-change="handleSelectionChange"
        @on-page-change="onPageChange"
        @on-size-change="onSizeChange"
        :loading="loading"
    >
      <el-table-column label="序号" property="index" width="60" align="center" >
        <template #default="scope">
          {{scope.$index + 1}}
        </template>
      </el-table-column>
      <el-table-column property="entryId" label="报关单号" width="160" :show-overflow-tooltip="true" />
      <el-table-column property="gno" label="商品项号" width="80" :show-overflow-tooltip="true" />
      <el-table-column property="iePort" label="进出境口岸" width="90" :show-overflow-tooltip="true" >
        <template #default="scope">
          {{findOptionLabel(scope.row.iePort,portCodeList)}}
        </template>
      </el-table-column>
      <!--      <el-table-column property="declPort" label="申报口岸" width="120" :show-overflow-tooltip="true" />-->
      <el-table-column property="customsCode" label="主管海关" width="90" :show-overflow-tooltip="true" >
        <template #default="scope">
          <dict-tag :options="dict.affiliation_customs_info"  :dictValue="scope.row.customsCode" />
        </template>
      </el-table-column>
      <el-table-column property="ieFlag" label="出入境标志" width="90" :show-overflow-tooltip="true" >
        <template #default="scope">
          <dict-tag :options="dict.ie_flag" :dictValue="scope.row.ieFlag" />
        </template>
      </el-table-column>
      <el-table-column property="declDate" label="申报时间" width="150" :show-overflow-tooltip="true" >
        <template #default="scope">
          {{ scope.row.declDate?dayjs(scope.row.declDate).format('YYYY-MM-DD HH:mm:ss'):'' }}
        </template>
      </el-table-column>
      <!--      <el-table-column property="consignScc" label="进口经营/出口生产企业代码" width="120" :show-overflow-tooltip="true" />-->
      <el-table-column property="consignCode" label="进口经营/出口生产企业代码" width="190" />
      <el-table-column property="consignName" label="进口经营/出口生产企业名称" width="190" :show-overflow-tooltip="true" />
      <el-table-column property="codeTs" label="HS编号" width="100" />
      <el-table-column property="iqCode" label="CIQ编码" width="120" />
      <el-table-column property="gname" label="商品名称" width="120" :show-overflow-tooltip="true" />
      <!--      <el-table-column property="iqGName" label="报检名称" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="gNameFn" label="商品英文名称" width="120" :show-overflow-tooltip="true" />-->
      <el-table-column property="gmodel" label="规格型号" width="120" :show-overflow-tooltip="true" />
      <!--      <el-table-column property="iqGModel" label="检验检疫货物规格" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="gComposition" label="成份/原料/组分" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="prodWarranty" label="产品保质期" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="prodValidaty" label="产品有效期" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="dutyMode" label="征免方式" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="GTIN" label="条形码" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="gQty" label="申报数量" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="gUnit" label="申报计量单位" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="qty1" label="法定第一数量" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="unit1" label="法定第一计量单位" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="qty2" label="第二数量" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="unit2" label="第二计量单位" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="declPrice" label="申报单价" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="declTotal" label="申报总价" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="tradeCurr" label="成交币制" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="tradeTotal" label="成交总价" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="dutyValue" label="完税价格" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="rmbPrice" label="统计人民币价" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="usdPrice" label="统计美元价" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="exchangeRate" label="成交汇率" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="originCountry" label="原产国" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="originRegionCode" label="原产地区代码" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="destCountry" label="最终目的国" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="ieDistrictCode" label="境内目的地/境内货源地" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="iqIeDistrictCode" label="目的地/货源地" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="frnProducerName" label="境外生产企业名称" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="productModel" label="货物型号" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="productBrand" label="货物品牌" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="productDate" label="生产日期" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="productBatch" label="生产批次" width="120" :show-overflow-tooltip="true" />-->
      <el-table-column property="ungid" label="UN编码" width="70" />
      <!--      <el-table-column property="ungFlag" label="非危险化学品" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="ungModel" label="危包规格" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="ungClassify" label="危包类别" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="ungGName" label="危险货物名称" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="productCharCode" label="货物属性代码" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="goodsId" label="货号" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="useTo" label="用途代码" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="gCertFlag" label="每项商品需要监管证件" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="mnufctrRegno" label="生产单位注册号" width="120" :show-overflow-tooltip="true" />-->
      <!--      <el-table-column property="createTime" label="创建时间" width="120" :show-overflow-tooltip="true" />-->
      <el-table-column property="cas" label="CAS号" width="100" />
      <el-table-column property="goodsType" label="危险品类型" width="120" >
        <template #default="scope">
          <dict-tag :options="dict.goods_type" :whole-match="true" :dictValue="scope.row.goodsType" />
        </template>
      </el-table-column>
    </cacp-complex-table>
  </cacp-search-layout>

  <!--新增、编辑弹框-->
  <cacp-dialog
      v-model="state.dialogVisible"
      :resizable="false"
      :title="state.title"
      width="70%"
      @closed="onDialogClosed"
  >
    <el-form
        :model="state.formData"
        ref="dialogFormRef"
        :rules="infoRules"
        label-width="auto"
        label-position="left"
        :disabled="!state.isEdit"
        style="max-height: 60vh; overflow-y: auto; padding-right: 10px;"
    >
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="报关单号" prop="entryId">
            <el-input v-model="state.formData.entryId" placeholder="请输入报关单号" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="商品序号" prop="gno">
            <el-input v-model="state.formData.gno" placeholder="请输入商品序号" />
          </el-form-item>
        </el-col>
      </el-row><el-row :gutter="20">

      <el-col :span="12">
        <el-form-item label="进出境口岸" prop="iePort">
          <el-select
              v-model="state.formData.iePort"
              placeholder="进出境口岸"
              clearable
          >
            <el-option
                v-for="(item,index) in portCodeList"
                :key="getOptionKey(item,index)"
                :label="getOptionLabel(item)"
                :value="getOptionValue(item)"
            />
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="主管海关" prop="customsCode">
          <el-select
              v-model="state.formData.customsCode"
              placeholder="主管海关"
              clearable
          >
            <el-option
                v-for="item in dict.affiliation_customs_info"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
            />
          </el-select>
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="出入境标志" prop="ieFlag">
          <el-select
              v-model="state.formData.ieFlag"
              placeholder="请输入出入境标志"
              clearable
          >
            <el-option
                v-for="item in dict.ie_flag"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
            />
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="申报时间" prop="declDate">
          <el-date-picker
              style="width:100%"
              type="datetime"
              value-format="YYYY-MM-DD HH:mm:ss"
              v-model="state.formData.declDate"
              placeholder="请输入申报时间"
          />
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">

      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="进口经营/出口生产企业代码" prop="consignScc">-->
      <!--          <el-input v-model="state.formData.consignScc" placeholder="请输入进口经营/出口生产企业代码" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
      <el-col :span="12">
        <el-form-item label="进口经营/出口生产企业代码" prop="consignCode">
          <el-input v-model="state.formData.consignCode" placeholder="请输入进口经营/出口生产企业代码" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="进口经营/出口生产企业名称" prop="consignName">
          <el-input v-model="state.formData.consignName" placeholder="请输入进口经营/出口生产企业名称" />
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="HS编号" prop="codeTs">
          <el-input v-model="state.formData.codeTs" placeholder="请输入HS编号" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="CIQ编码" prop="iqCode">
          <el-input v-model="state.formData.iqCode" placeholder="请输入CIQ编码" />
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="商品名称" prop="gname">
          <el-input v-model="state.formData.gname" placeholder="请输入商品名称" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="规格型号" prop="gmodel">
          <el-input v-model="state.formData.gmodel" placeholder="请输入规格型号" />
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="报检名称" prop="iqGName">
          <el-input v-model="state.formData.iqGName" placeholder="请输入报检名称" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="商品英文名称" prop="gNameFn">
          <el-input v-model="state.formData.gNameFn" placeholder="请输入商品英文名称" />
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="检验检疫货物规格" prop="iqGModel">
          <el-input v-model="state.formData.iqGModel" placeholder="请输入检验检疫货物规格" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="产品有效期" prop="prodValidaty">
          <el-input v-model="state.formData.prodValidaty" placeholder="请输入产品有效期" />
        </el-form-item>
      </el-col>
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="成份/原料/组分" prop="gComposition">-->
      <!--          <el-input v-model="state.formData.gComposition" placeholder="请输入成份/原料/组分" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
    </el-row><el-row :gutter="20">
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="产品保质期" prop="prodWarranty">-->
      <!--          <el-input v-model="state.formData.prodWarranty" placeholder="请输入产品保质期" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->

    </el-row><el-row :gutter="20">
      <!--      <el-col :span="12">
              <el-form-item label="征免方式" prop="dutyMode">
                <el-input v-model="state.formData.dutyMode" placeholder="请输入征免方式" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="条形码" prop="GTIN">
                <el-input v-model="state.formData.GTIN" placeholder="请输入条形码" />
              </el-form-item>
            </el-col>-->
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="申报数量" prop="gQty">
          <el-input v-model="state.formData.gQty" placeholder="请输入申报数量" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="申报计量单位" prop="gUnit">
          <el-input v-model="state.formData.gUnit" placeholder="请输入申报计量单位" />
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="法定第一数量" prop="qty1">
          <el-input v-model="state.formData.qty1" placeholder="请输入法定第一数量" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="法定第一计量单位" prop="unit1">
          <el-select
              v-model="state.formData.unit1"
              placeholder="请输入法定第一计量单位"
              clearable
          >
            <el-option
                v-for="(item,index) in unitsCodeList"
                :key="getOptionKey(item,index)"
                :label="getOptionLabel(item)"
                :value="getOptionValue(item)"
            />
          </el-select>
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="第二数量" prop="qty2">
          <el-input v-model="state.formData.qty2" placeholder="请输入第二数量" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="第二计量单位" prop="unit2">
          <el-select
              v-model="state.formData.unit2"
              placeholder="请输入第二计量单位"
              clearable
          >
            <el-option
                v-for="(item,index) in unitsCodeList"
                :key="getOptionKey(item,index)"
                :label="getOptionLabel(item)"
                :value="getOptionValue(item)"
            />
          </el-select>
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="申报单价" prop="declPrice">
          <el-input v-model="state.formData.declPrice" placeholder="请输入申报单价" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="申报总价" prop="declTotal">
          <el-input v-model="state.formData.declTotal" placeholder="请输入申报总价" />
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="成交币制" prop="tradeCurr">-->
      <!--          <el-input v-model="state.formData.tradeCurr" placeholder="请输入成交币制" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="成交总价" prop="tradeTotal">-->
      <!--          <el-input v-model="state.formData.tradeTotal" placeholder="请输入成交总价" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
    </el-row><el-row :gutter="20">
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="完税价格" prop="dutyValue">-->
      <!--          <el-input v-model="state.formData.dutyValue" placeholder="请输入完税价格" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
      <el-col :span="12">
        <el-form-item label="统计人民币价" prop="rmbPrice">
          <el-input v-model="state.formData.rmbPrice" placeholder="请输入统计人民币价" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="统计美元价" prop="usdPrice">
          <el-input v-model="state.formData.usdPrice" placeholder="请输入统计美元价" />
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">

      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="成交汇率" prop="exchangeRate">-->
      <!--          <el-input v-model="state.formData.exchangeRate" placeholder="请输入成交汇率" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="原产国" prop="originCountry">
          <el-select
              v-model="state.formData.originCountry"
              placeholder="请输入原产国"
              clearable
          >
            <el-option
                v-for="(item,index) in countryCodeList"
                :key="getOptionKey(item,index)"
                :label="getOptionLabel(item)"
                :value="getOptionValue(item)"
            />
          </el-select>
        </el-form-item>
      </el-col>
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="原产地区代码" prop="originRegionCode">-->
      <!--          <el-input v-model="state.formData.originRegionCode" placeholder="请输入原产地区代码" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
      <el-col :span="12">
        <el-form-item label="最终目的国" prop="destCountry">
          <el-select
              v-model="state.formData.destCountry"
              placeholder="请输入最终目的国"
              clearable
          >
            <el-option
                v-for="(item,index) in countryCodeList"
                :key="getOptionKey(item,index)"
                :label="getOptionLabel(item)"
                :value="getOptionValue(item)"
            />
          </el-select>
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">

      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="境内目的地/境内货源地" prop="ieDistrictCode">-->
      <!--          <el-input v-model="state.formData.ieDistrictCode" placeholder="请输入境内目的地/境内货源地" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="目的地/货源地" prop="iqIeDistrictCode">
          <el-select
              v-model="state.formData.iqIeDistrictCode"
              placeholder="请输入目的地/货源地"
              clearable
          >
            <el-option
                v-for="(item,index) in countryCodeList"
                :key="getOptionKey(item,index)"
                :label="getOptionLabel(item)"
                :value="getOptionValue(item)"
            />
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="境外生产企业名称" prop="frnProducerName">
          <el-input v-model="state.formData.frnProducerName" placeholder="请输入境外生产企业名称" />
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="生产日期" prop="productDate">
          <el-input v-model="state.formData.productDate" placeholder="请输入生产日期" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="生产批次" prop="productBatch">
          <el-input v-model="state.formData.productBatch" placeholder="请输入生产批次" />
        </el-form-item>
      </el-col>

    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="UN编码" prop="ungid">
          <el-input v-model="state.formData.ungid" placeholder="请输入UN编码" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="货物型号" prop="productModel">
          <el-input v-model="state.formData.productModel" placeholder="请输入货物型号" />
        </el-form-item>
      </el-col>

    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="货物品牌" prop="productBrand">
          <el-input v-model="state.formData.productBrand" placeholder="请输入货物品牌" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="非危险化学品" prop="ungFlag">
          <el-select
              v-model="state.formData.ungFlag"
              placeholder="请输入非危险化学品"
              clearable
          >
            <el-option
                v-for="item in dict.yes_no"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
            />
          </el-select>
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="危包规格" prop="ungModel">
          <el-input v-model="state.formData.ungModel" placeholder="请输入危包规格" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="危包类别" prop="ungClassify">
          <el-input v-model="state.formData.ungClassify" placeholder="请输入危包类别" />
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="危险货物名称" prop="ungGName">
          <el-input v-model="state.formData.ungGName" placeholder="请输入危险货物名称" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="货物属性" prop="productCharCode">
          <el-input v-model="state.formData.productCharCode" placeholder="请输入货物属性代码" />
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="货号" prop="goodsId">-->
      <!--          <el-input v-model="state.formData.goodsId" placeholder="请输入货号" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="用途代码" prop="useTo">-->
      <!--          <el-input v-model="state.formData.useTo" placeholder="请输入用途代码" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
    </el-row><el-row :gutter="20">
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="每项商品需要监管证件" prop="gCertFlag">-->
      <!--          <el-input v-model="state.formData.gCertFlag" placeholder="请输入每项商品需要监管证件" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="生产单位注册号" prop="mnufctrRegno">-->
      <!--          <el-input v-model="state.formData.mnufctrRegno" placeholder="请输入生产单位注册号" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
    </el-row><el-row :gutter="20">
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="创建时间" prop="createTime">-->
      <!--          <el-input v-model="state.formData.createTime" placeholder="请输入创建时间" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
      <el-col :span="12">
        <el-form-item label="CAS号" prop="cas">
          <el-input v-model="state.formData.cas" placeholder="请输入CAS号" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="危险品类型" prop="goodsType">
          <el-select
              v-model="state.formData.goodsType"
              placeholder="请输入危险品类型"
              clearable
          >
            <el-option
                v-for="item in dict.goods_type"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
            />
          </el-select>
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">

    </el-row>
    </el-form>
    <template #footer v-if="state.isEdit">
      <el-button @click="onDialogClosed">取消</el-button>
      <el-button type="primary" @click="onSubmit">确定</el-button>
    </template>
  </cacp-dialog>
  <!--查看弹框-->
  <cacp-dialog
      v-model="state.viewDialogVisible"
      :resizable="false"
      :title="state.viewTitle"
      width="70%"
      @closed="onDialogClosed"
  >
    <el-form
        :model="state.viewForm"
        ref="dialogFormRef"
        label-width="auto"
        label-position="left"
        style="max-height: 60vh; overflow-y: auto; padding-right: 10px;"
    >
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="报关单号" prop="entryId">
            {{state.viewForm.entryId}}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="商品序号" prop="gno">
            {{state.viewForm.gno}}
          </el-form-item>
        </el-col>
      </el-row><el-row :gutter="20">

      <el-col :span="12">
        <el-form-item label="进出境口岸" prop="iePort">
          {{findOptionLabel(state.viewForm.iePort,portCodeList)}}
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="主管海关" prop="customsCode">
          <dict-tag :options="dict.customs_code" :dict-value="state.viewForm.customsCode" />
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="出入境标志" prop="ieFlag">
          <dict-tag :options="dict.ie_flag" :dict-value="state.viewForm.ieFlag" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="申报时间" prop="declDate">
          {{ dayjs(state.viewForm.declDate).format('YYYY-MM-DD HH:mm:ss') }}
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">

      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="进口经营/出口生产企业代码" prop="consignScc">-->
      <!--          <el-input v-model="state.formData.consignScc" placeholder="请输入进口经营/出口生产企业代码" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
      <el-col :span="12">
        <el-form-item label="进口经营/出口生产企业代码" prop="consignCode">
          {{state.viewForm.consignCode}}
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="进口经营/出口生产企业名称" prop="consignName">
          {{state.viewForm.consignName}}
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="HS编号" prop="codeTs">
          {{state.viewForm.codeTs}}
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="CIQ编码" prop="iqCode">
          {{state.viewForm.iqCode}}
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="商品名称" prop="gname">
          {{state.viewForm.gname}}
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="规格型号" prop="gmodel">
          {{state.viewForm.gmodel}}
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="报检名称" prop="iqGName">
          {{state.viewForm.iqGName}}
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="商品英文名称" prop="gNameFn">
          {{state.viewForm.gNameFn}}
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="检验检疫货物规格" prop="iqGModel">
          {{state.viewForm.iqGModel}}
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="产品有效期" prop="prodValidaty">
          {{state.viewForm.prodValidaty}}
        </el-form-item>
      </el-col>
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="成份/原料/组分" prop="gComposition">-->
      <!--          <el-input v-model="state.formData.gComposition" placeholder="请输入成份/原料/组分" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
    </el-row><el-row :gutter="20">
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="产品保质期" prop="prodWarranty">-->
      <!--          <el-input v-model="state.formData.prodWarranty" placeholder="请输入产品保质期" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->

    </el-row><el-row :gutter="20">
      <!--      <el-col :span="12">
              <el-form-item label="征免方式" prop="dutyMode">
                <el-input v-model="state.formData.dutyMode" placeholder="请输入征免方式" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="条形码" prop="GTIN">
                <el-input v-model="state.formData.GTIN" placeholder="请输入条形码" />
              </el-form-item>
            </el-col>-->
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="申报数量" prop="gQty">
          {{state.viewForm.gQty}}
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="申报计量单位" prop="gUnit">
          {{findOptionLabel(state.viewForm.gUnit,unitsCodeList)}}
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="法定第一数量" prop="qty1">
          {{state.viewForm.qty1}}
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="法定第一计量单位" prop="unit1">
          {{findOptionLabel(state.viewForm.unit1,unitsCodeList)}}
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="第二数量" prop="qty2">
          {{state.viewForm.qty2}}
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="第二计量单位" prop="unit2">
          {{findOptionLabel(state.viewForm.unit2,unitsCodeList)}}
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="申报单价" prop="declPrice">
          {{state.viewForm.declPrice}}
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="申报总价" prop="declTotal">
          {{state.viewForm.declTotal}}
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="成交币制" prop="tradeCurr">-->
      <!--          <el-input v-model="state.formData.tradeCurr" placeholder="请输入成交币制" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="成交总价" prop="tradeTotal">-->
      <!--          <el-input v-model="state.formData.tradeTotal" placeholder="请输入成交总价" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
    </el-row><el-row :gutter="20">
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="完税价格" prop="dutyValue">-->
      <!--          <el-input v-model="state.formData.dutyValue" placeholder="请输入完税价格" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
      <el-col :span="12">
        <el-form-item label="统计人民币价" prop="rmbPrice">
          {{state.viewForm.rmbPrice}}
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="统计美元价" prop="usdPrice">
          {{state.viewForm.usdPrice}}
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">

      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="成交汇率" prop="exchangeRate">-->
      <!--          <el-input v-model="state.formData.exchangeRate" placeholder="请输入成交汇率" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="原产国" prop="originCountry">
          {{findOptionLabel(state.viewForm.originCountry,countryCodeList)}}
        </el-form-item>
      </el-col>
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="原产地区代码" prop="originRegionCode">-->
      <!--          <el-input v-model="state.formData.originRegionCode" placeholder="请输入原产地区代码" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
      <el-col :span="12">
        <el-form-item label="最终目的国" prop="destCountry">
          {{findOptionLabel(state.viewForm.destCountry,countryCodeList)}}
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">

      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="境内目的地/境内货源地" prop="ieDistrictCode">-->
      <!--          <el-input v-model="state.formData.ieDistrictCode" placeholder="请输入境内目的地/境内货源地" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="目的地/货源地" prop="iqIeDistrictCode">
          {{findOptionLabel(state.viewForm.iqIeDistrictCode,countryCodeList)}}
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="境外生产企业名称" prop="frnProducerName">
          {{ state.viewForm.frnProducerName }}
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="生产日期" prop="productDate">
          {{state.viewForm.productDate}}
          <!--          {{ dayjs(state.viewForm.productDate).format('YYYY-MM-DD HH:mm:ss') }}-->
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="生产批次" prop="productBatch">
          {{ state.viewForm.productBatch }}
        </el-form-item>
      </el-col>

    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="UN编码" prop="ungid">
          {{ state.viewForm.ungid }}
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="货物型号" prop="productModel">
          {{ state.viewForm.productModel }}
        </el-form-item>
      </el-col>

    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="货物品牌" prop="productBrand">
          {{ state.viewForm.productBrand }}
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="非危险化学品" prop="ungFlag">
          <dict-tag :options="dict.yes_no" :dict-value="state.viewForm.ungFlag" />
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="危包规格" prop="ungModel">
          {{ state.viewForm.ungModel }}
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="危包类别" prop="ungClassify">
          {{ state.viewForm.ungClassify }}
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="危险货物名称" prop="ungGName">
          {{ state.viewForm.ungGName }}
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="货物属性" prop="productCharCode">
          {{ state.viewForm.productCharCode }}
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="货号" prop="goodsId">-->
      <!--          <el-input v-model="state.formData.goodsId" placeholder="请输入货号" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="用途代码" prop="useTo">-->
      <!--          <el-input v-model="state.formData.useTo" placeholder="请输入用途代码" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
    </el-row><el-row :gutter="20">
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="每项商品需要监管证件" prop="gCertFlag">-->
      <!--          <el-input v-model="state.formData.gCertFlag" placeholder="请输入每项商品需要监管证件" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="生产单位注册号" prop="mnufctrRegno">-->
      <!--          <el-input v-model="state.formData.mnufctrRegno" placeholder="请输入生产单位注册号" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
    </el-row><el-row :gutter="20">
      <!--      <el-col :span="12">-->
      <!--        <el-form-item label="创建时间" prop="createTime">-->
      <!--          <el-input v-model="state.formData.createTime" placeholder="请输入创建时间" />-->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
      <el-col :span="12">
        <el-form-item label="CAS号" prop="cas">
          {{ state.viewForm.cas }}
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="危险品类型" prop="goodsType">
          <dict-tag :options="dict.goods_type" :whole-match="true" :dict-value="state.viewForm.goodsType" />
        </el-form-item>
      </el-col>
    </el-row><el-row :gutter="20">

    </el-row>
    </el-form>
  </cacp-dialog>
</template>

<script lang="ts" setup>
import { onMounted, reactive, ref } from 'vue'
import type { FormInstance } from 'element-plus'
import { ElMessage, type FormRules } from 'element-plus'
import config from '@/config'
import {
  SuccessResultCode,
  useComplexTable,
  type Result,
  type SearchPanelLayoutInstance,
  type TableAction,
  useLoading
} from '@cacp/ui'
import type { NewDeclaredGoods, NewDeclaredGoodsQuery } from '@/types/analyze/NewDeclaredGoods'
import { insert, getList, update} from '@/apis/analyze/NewDeclaredGoods'
import dayjs from 'dayjs'
import { getBaseCodeList} from '@/apis/base/baseCode'
import type { JSONObject } from '@antv/x6'
import { useDictType } from '@/components/useDict'
import DictTag from '@/components/DictTag/dictTag.vue'
const { dict } = useDictType('affiliation_customs_info','goods_type','yes_no','ie_flag')
import { findOptionLabel, getOptionKey, getOptionLabel, getOptionValue } from '@/utils/jsonObjectOptionUtils'
import { useCoreStore } from '@/stores'
const coreStore = useCoreStore()
// 表单引用
const queryFormRef = ref<SearchPanelLayoutInstance>()
const dialogFormRef = ref<FormInstance>()

// 加载状态
const { loading, setLoading } = useLoading()

// 表格 Hook
const tableHooks = useComplexTable<NewDeclaredGoods>(config)
const { tableData, tablePagination, setPagination, setPageIndex, setPageSizes } = tableHooks

// 响应式数据
interface State {
  queryData: NewDeclaredGoodsQuery
  formData: NewDeclaredGoods
  viewForm: NewDeclaredGoods
  viewTitle: string
  viewDialogVisible: boolean
  title: string
  isEdit: boolean
  dialogVisible: boolean
  isSelect: boolean
}

const state = reactive<State>({
  queryData: {
    entryId: '',
    gno: '',
    ieFlag: '',
    iePort: '',
    declPort: '',
    customsCode: '',
    declDate: '',
    consignScc: '',
    consignCode: '',
    consignName: '',
    codeTs: '',
    iqCode: '',
    gname: '',
    iqGName: '',
    gNameFn: '',
    gmodel: '',
    iqGModel: '',
    gComposition: '',
    prodWarranty: '',
    prodValidaty: '',
    dutyMode: '',
    GTIN: '',
    gQty: '',
    gUnit: '',
    qty1: '',
    unit1: '',
    qty2: '',
    unit2: '',
    declPrice: '',
    declTotal: '',
    tradeCurr: '',
    tradeTotal: '',
    dutyValue: '',
    rmbPrice: '',
    usdPrice: '',
    exchangeRate: '',
    originCountry: '',
    originRegionCode: '',
    destCountry: '',
    ieDistrictCode: '',
    iqIeDistrictCode: '',
    frnProducerName: '',
    productModel: '',
    productBrand: '',
    productDate: '',
    productBatch: '',
    ungid: '',
    ungFlag: '',
    ungModel: '',
    ungClassify: '',
    ungGName: '',
    productCharCode: '',
    goodsId: '',
    useTo: '',
    gCertFlag: '',
    mnufctrRegno: '',
    // createTime: '',
    cas: '',
    goodsType: '',
    beginDate:'',
    endDate:'',
    pageIndex: tablePagination.currentPage,
    pageSize: tablePagination.pageSize
  },
  formData: {
    id: '',
    entryId: '',
    gno: '',
    ieFlag: '',
    iePort: '',
    declPort: '',
    customsCode: '',
    declDate: '',
    consignScc: '',
    consignCode: '',
    consignName: '',
    codeTs: '',
    iqCode: '',
    gname: '',
    iqGName: '',
    gNameFn: '',
    gmodel: '',
    iqGModel: '',
    gComposition: '',
    prodWarranty: '',
    prodValidaty: '',
    dutyMode: '',
    GTIN: '',
    gQty: '',
    gUnit: '',
    qty1: '',
    unit1: '',
    qty2: '',
    unit2: '',
    declPrice: '',
    declTotal: '',
    tradeCurr: '',
    tradeTotal: '',
    dutyValue: '',
    rmbPrice: '',
    usdPrice: '',
    exchangeRate: '',
    originCountry: '',
    originRegionCode: '',
    destCountry: '',
    ieDistrictCode: '',
    iqIeDistrictCode: '',
    frnProducerName: '',
    productModel: '',
    productBrand: '',
    productDate: '',
    productBatch: '',
    ungid: '',
    ungFlag: '',
    ungModel: '',
    ungClassify: '',
    ungGName: '',
    productCharCode: '',
    goodsId: '',
    useTo: '',
    gCertFlag: '',
    mnufctrRegno: '',
    createTime: '',
    cas: '',
    goodsType: '',
  } as NewDeclaredGoods,
  viewForm: {} as NewDeclaredGoods,
  viewTitle: '',
  viewDialogVisible: false,
  title: '',
  isEdit: false,
  dialogVisible: false,
  isSelect: false,
})

// 表单验证规则
const infoRules = reactive<FormRules<NewDeclaredGoods>>({
  id: [
    { required: true, message: '主键不能为空', trigger: 'blur' }
  ],
})

// 表格操作按钮配置
const actions = <Array<TableAction>>[
  // {
  //   key: 'create',
  //   text: '新增',
  //   onclick: onCreate,
  //   limit: permissionStatus('none', 'ANALYZE_NEWDECLAREDGOODS_ADD_BT'),
  //   position: 'left',
  //   type: 'primary',
  // },
  {
    key: 'view',
    text: '查看',
    onclick: onView,
    limit: 'one',
    // limit: permissionStatus('one', 'ANALYZE_NEWDECLAREDGOODS_VIEW_BT'),
    type: 'primary'
  },
  // {
  //   key: 'edit',
  //   text: '修改',
  //   onclick: onEdit,
  //   limit:'one',
  //   // limit: permissionStatus('one', 'ANALYZE_NEWDECLAREDGOODS_EDIT_BT'),
  //   type: 'primary'
  // },
  // {
  //   key: 'delete',
  //   text: '删除',
  //   onclick: onDelete,
  //   confirm: true,
  //   limit: permissionStatus('none', 'ANALYZE_NEWDECLAREDGOODS_DELETE_BT'),
  //   type: 'primary'
  // },
  // {
  //   key: 'refresh',
  //   type: 'primary',
  //   text: '刷新',
  //   onclick: onRefresh,
  //   limit: 'none',
  //   position: 'left',
  //   plain: true
  // }
]

// 选中项的 ID 数组
const ids = ref<string[]>([])

// 申报口岸数据 - 海关代码
const portCodeList = ref<Array<JSONObject>>([])

// 申报计量单位 - 计量单位代码
const unitsCodeList = ref<Array<JSONObject>>([])

// 国家地区 - 国家地区代码
const countryCodeList = ref<Array<JSONObject>>([])

// 获取基础数据的函数
const loadBaseData = async () => {
  try {
    setLoading(true)

    // 并行获取所有基础数据
    const [portRes, unitRes, countryRes] = await Promise.all([
      getBaseCodeList('customsCode'),
      getBaseCodeList('unit'),
      getBaseCodeList('countryIsoE'),
    ])

    // 处理返回的数据
    if (portRes.code === SuccessResultCode && portRes.data) {
      portCodeList.value = portRes.data
    }

    if (unitRes.code === SuccessResultCode && unitRes.data) {
      unitsCodeList.value = unitRes.data
    }

    if (countryRes.code === SuccessResultCode && countryRes.data) {
      countryCodeList.value = countryRes.data
    }
  } catch (error) {
    console.error('加载基础数据失败:', error)
  } finally {
    setLoading(false)
  }
}

// 多选框选中数据
function handleSelectionChange(selection: NewDeclaredGoods[]) {
  ids.value = selection
      .map(item => item.id)
      .filter((id): id is string => id != null && id !== undefined)
}

// 搜索方法
const onSearch = () => {
  setPageIndex(1)
  onLoadData()
}

// 重置方法
const onReset = () => {
  queryFormRef.value?.resetFields()
  state.queryData.beginDate = ''
  state.queryData.endDate = ''
  onPageChange(1)
}

// 每页显示条数变化
const onSizeChange = (size: number) => {
  setPageSizes(size)
  onLoadData()
}

// 翻页查询
const onPageChange = (currentPage: number) => {
  setPageIndex(currentPage)
  onLoadData()
}

// 弹框关闭方法
function onDialogClosed() {
  state.dialogVisible = false
  resetForm()
}

// 重置表单
function resetForm() {
  state.formData = {
    ID: '',
    entryId: '',
    gno: '',
    ieFlag: '',
    iePort: '',
    declPort: '',
    customsCode: '',
    declDate: '',
    consignScc: '',
    consignCode: '',
    consignName: '',
    codeTs: '',
    iqCode: '',
    gname: '',
    iqGName: '',
    gNameFn: '',
    gmodel: '',
    iqGModel: '',
    gComposition: '',
    prodWarranty: '',
    prodValidaty: '',
    dutyMode: '',
    GTIN: '',
    gQty: '',
    gUnit: '',
    qty1: '',
    unit1: '',
    qty2: '',
    unit2: '',
    declPrice: '',
    declTotal: '',
    tradeCurr: '',
    tradeTotal: '',
    dutyValue: '',
    rmbPrice: '',
    usdPrice: '',
    exchangeRate: '',
    originCountry: '',
    originRegionCode: '',
    destCountry: '',
    ieDistrictCode: '',
    iqIeDistrictCode: '',
    frnProducerName: '',
    productModel: '',
    productBrand: '',
    productDate: '',
    productBatch: '',
    ungid: '',
    ungFlag: '',
    ungModel: '',
    ungClassify: '',
    ungGName: '',
    productCharCode: '',
    goodsId: '',
    useTo: '',
    gCertFlag: '',
    mnufctrRegno: '',
    createTime: '',
    cas: '',
    goodsType: '',
  } as NewDeclaredGoods
  dialogFormRef.value?.resetFields()
}

// 查看
function onView(row: NewDeclaredGoods) {
  state.viewForm = { ...row }
  state.viewDialogVisible = true
  state.viewTitle = '查看新申报商品提示详情'
}

// 新增/修改提交
async function onSubmit() {
  if (!dialogFormRef.value) return

  const isValid = await dialogFormRef.value.validate()
  if (!isValid) return

  try {


    let res: Result<any>
    if (state.formData.id) {
      res = await update(state.formData)
    } else {
      res = await insert(state.formData)
    }

    if (res.code === SuccessResultCode) {
      ElMessage.success(state.formData.id ? '修改成功' : '新增成功')
      state.dialogVisible = false
      onPageChange(1)
    } else {
      ElMessage.error(res.message || '操作失败')
    }
  } catch (error) {
    console.error('提交失败:', error)
    ElMessage.error('操作失败')
  }
}

// 数据查询
async function onLoadData() {
  const loginCustomsCode = coreStore.currentUser.customsCode;
  if("4700" === loginCustomsCode){
    state.isSelect = true;
  }else{
    state.queryData.customsCode = loginCustomsCode;
    state.isSelect = false;
  }
  setLoading(true)
  try {
    const query = {
      ...state.queryData,
      pageIndex: tablePagination.currentPage,
      pageSize: tablePagination.pageSize
    }
    const res = await getList(query)
    if (res.code === SuccessResultCode) {
      console.log(res.data)
      setPagination(res.data)
    } else {
      ElMessage.error(res.message || '查询失败')
    }
  } catch (error) {
    console.error('查询失败:', error)
    ElMessage.error('查询失败')
  } finally {
    setLoading(false)
  }
}


// 组件挂载时加载数据
onMounted(() => {
  loadBaseData()
  onLoadData()
})
</script>

<style scoped>
/* 自定义样式 */
</style>
