zhangwencui
10 小时以前 58f83d2e89ffbd51f2fcac506843a9e5121b0c4c
src/views/salesManagement/invoiceLedger/index.vue
@@ -1,47 +1,107 @@
<template>
  <div class="app-container">
    <div class="search_form">
      <el-form :inline="true" :model="searchForm">
      <el-form :inline="true"
               :model="searchForm">
        <el-form-item label="客户名称/合同号">
          <el-input v-model="searchForm.searchText" style="width: 240px" placeholder="输入客户名称/销售合同号搜索"
            @change="handleQuery" clearable :prefix-icon="Search" />
          <el-input v-model="searchForm.searchText"
                    style="width: 240px"
                    placeholder="输入客户名称/销售合同号搜索"
                    @change="handleQuery"
                    clearable
                    :prefix-icon="Search" />
        </el-form-item>
        <el-form-item label="开票日期">
          <el-date-picker style="width: 240px" v-model="searchForm.invoiceDate" value-format="YYYY-MM-DD"
            format="YYYY-MM-DD" type="daterange" start-placeholder="开始时间" end-placeholder="结束时间" clearable
            @change="changeDateRange" @clear="clearRange" />
          <el-date-picker style="width: 240px"
                          v-model="searchForm.invoiceDate"
                          value-format="YYYY-MM-DD"
                          format="YYYY-MM-DD"
                          type="daterange"
                          start-placeholder="开始时间"
                          end-placeholder="结束时间"
                          clearable
                          @change="changeDateRange"
                          @clear="clearRange" />
        </el-form-item>
        <el-form-item label="录入日期">
          <el-date-picker style="width: 100%" v-model="searchForm.createTimeStart" value-format="YYYY-MM-DD HH:mm:ss"
            format="YYYY-MM-DD" type="date" placeholder="请选择" clearable @change="handleQuery" />
          <el-date-picker style="width: 100%"
                          v-model="searchForm.createTimeStart"
                          value-format="YYYY-MM-DD HH:mm:ss"
                          format="YYYY-MM-DD"
                          type="date"
                          placeholder="请选择"
                          clearable
                          @change="handleQuery" />
        </el-form-item>
        <el-form-item label="不显示有发票行">
          <el-checkbox v-model="searchForm.status" @change="handleQuery" />
          <el-checkbox v-model="searchForm.status"
                       @change="handleQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleQuery"> 搜索 </el-button>
          <el-button type="primary"
                     @click="handleQuery"> 搜索 </el-button>
          <el-button @click="resetForm"> 重置 </el-button>
          <el-button @click="handleOut" type="primary">导出</el-button>
          <el-button @click="handleOut"
                     type="primary">导出</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="table_list">
      <el-table :data="tableData" border v-loading="tableLoading" @selection-change="handleSelectionChange"
        :row-key="(row) => row.id" show-summary :summary-method="summarizeMainTable" height="calc(100vh - 18.5em)">
        <el-table-column align="center" type="selection" width="55" />
        <el-table-column align="center" label="序号" type="index" width="60" />
        <el-table-column label="销售合同号" prop="salesContractNo" show-overflow-tooltip width="180" />
        <el-table-column label="客户名称" prop="customerName" show-overflow-tooltip width="240" />
<!--        <el-table-column label="项目" prop="projectName" width="320" />-->
        <el-table-column label="产品大类" prop="productCategory" width="200" />
        <el-table-column label="规格型号" prop="specificationModel" width="160" show-overflow-tooltip />
        <el-table-column label="发票号" prop="invoiceNo" width="200" show-overflow-tooltip />
        <el-table-column label="发票金额(元)" prop="invoiceTotal" show-overflow-tooltip :formatter="formattedNumber"
          width="200" />
        <el-table-column label="税率(%)" prop="taxRate" show-overflow-tooltip />
        <el-table-column label="录入人" prop="invoicePerson" show-overflow-tooltip />
        <el-table-column label="录入日期" prop="createTime" show-overflow-tooltip :formatter="formatDate" width="180" />
        <el-table-column label="开票日期" prop="invoiceDate" show-overflow-tooltip width="120" />
      <el-table :data="tableData"
                border
                v-loading="tableLoading"
                @selection-change="handleSelectionChange"
                :row-key="(row) => row.id"
                show-summary
                :summary-method="summarizeMainTable"
                height="calc(100vh - 18.5em)">
        <el-table-column align="center"
                         type="selection"
                         width="55" />
        <el-table-column align="center"
                         label="序号"
                         type="index"
                         width="60" />
        <el-table-column label="销售合同号"
                         prop="salesContractNo"
                         show-overflow-tooltip
                         width="180" />
        <el-table-column label="客户名称"
                         prop="customerName"
                         show-overflow-tooltip
                         width="240" />
        <!--        <el-table-column label="项目" prop="projectName" width="320" />-->
        <el-table-column label="产品大类"
                         prop="productCategory"
                         width="200" />
        <el-table-column label="规格型号"
                         prop="specificationModel"
                         width="160"
                         show-overflow-tooltip />
        <el-table-column label="发票号"
                         prop="invoiceNo"
                         width="200"
                         show-overflow-tooltip />
        <el-table-column label="发票金额(元)"
                         prop="invoiceTotal"
                         show-overflow-tooltip
                         :formatter="formattedNumber"
                         width="200" />
        <el-table-column label="税率(%)"
                         prop="taxRate"
                         show-overflow-tooltip />
        <el-table-column label="录入人"
                         prop="invoicePerson"
                         show-overflow-tooltip />
        <el-table-column label="录入日期"
                         prop="createTime"
                         show-overflow-tooltip
                         :formatter="formatDate"
                         width="180" />
        <el-table-column label="开票日期"
                         prop="invoiceDate"
                         show-overflow-tooltip
                         width="120" />
        <!-- <el-table-column label="发票" prop="invoiceFileName" width="120" align="center" show-overflow-tooltip fixed="right">
          <template #default="scope">
            <el-button v-if="scope.row.invoiceFileName" text bg type="primary"
@@ -53,62 +113,121 @@
            </el-button>
          </template>
        </el-table-column> -->
        <el-table-column fixed="right" label="操作" width="150" align="center">
        <el-table-column fixed="right"
                         label="操作"
                         width="150"
                         align="center">
          <template #default="scope">
            <el-button link type="primary" size="small" @click="openForm(scope.row)">编辑</el-button>
            <el-button link type="primary" size="small" @click="downLoadFile(scope.row)">附件</el-button>
            <el-button link type="primary" size="small" @click="delInvoiceLedger(scope.row)">删除</el-button>
            <el-button link
                       type="primary"
                       size="small"
                       @click="openForm(scope.row)">编辑</el-button>
            <el-button link
                       type="primary"
                       size="small"
                       @click="downLoadFile(scope.row)">附件</el-button>
            <el-button link
                       type="primary"
                       size="small"
                       @click="delInvoiceLedger(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total > 0" :total="total" layout="total, sizes, prev, pager, next, jumper"
        :page="page.current" :limit="page.size" @pagination="paginationChange" />
      <pagination v-show="total > 0"
                  :total="total"
                  layout="total, sizes, prev, pager, next, jumper"
                  :page="page.current"
                  :limit="page.size"
                  @pagination="paginationChange" />
    </div>
    <el-dialog v-model="dialogFormVisible" title="开票台账页面" width="70%" @close="closeDia">
      <el-form :model="form" label-width="140px" label-position="top" :rules="rules" ref="formRef">
    <el-dialog v-model="dialogFormVisible"
               title="开票台账页面"
               width="70%"
               @close="closeDia">
      <el-form :model="form"
               label-width="140px"
               label-position="top"
               :rules="rules"
               ref="formRef">
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="销售合同号:" prop="salesContractNo">
              <el-input v-model="form.salesContractNo" disabled></el-input>
            <el-form-item label="销售合同号:"
                          prop="salesContractNo">
              <el-input v-model="form.salesContractNo"
                        disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户名称:" prop="customerName">
              <el-input v-model="form.customerName" placeholder="自动填充" clearable disabled />
            <el-form-item label="客户名称:"
                          prop="customerName">
              <el-input v-model="form.customerName"
                        placeholder="自动填充"
                        clearable
                        disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="发票号:" prop="invoiceNo">
              <el-input v-model="form.invoiceNo" placeholder="请输入" clearable />
            <el-form-item label="发票号:"
                          prop="invoiceNo">
              <el-input v-model="form.invoiceNo"
                        placeholder="请输入"
                        clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="`发票金额(元): 合同总额(${form.taxInclusiveTotalPrice}元)`" prop="invoiceTotal">
              <el-input-number :step="0.01" :min="0" :max="form.taxInclusiveTotalPrice" style="width: 100%" v-model="form.invoiceTotal" placeholder="请输入" clearable :precision="2"/>
            <el-form-item :label="`发票金额(元): 合同总额(${form.taxInclusiveTotalPrice}元)`"
                          prop="invoiceTotal">
              <el-input-number :step="0.01"
                               :min="0"
                               :max="form.noInvoiceAmount"
                               style="width: 100%"
                               v-model="form.invoiceTotal"
                               placeholder="请输入"
                               clearable
                               :precision="2" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="开票人:" prop="invoicePerson">
              <el-input v-model="form.invoicePerson" placeholder="请输入" clearable disabled />
            <el-form-item label="开票人:"
                          prop="invoicePerson">
              <el-input v-model="form.invoicePerson"
                        placeholder="请输入"
                        clearable
                        disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开票日期:" prop="invoiceDate">
              <el-date-picker style="width: 100%" v-model="form.invoiceDate" value-format="YYYY-MM-DD"
                format="YYYY-MM-DD" type="date" placeholder="请选择" clearable />
            <el-form-item label="开票日期:"
                          prop="invoiceDate">
              <el-date-picker style="width: 100%"
                              v-model="form.invoiceDate"
                              value-format="YYYY-MM-DD"
                              format="YYYY-MM-DD"
                              type="date"
                              placeholder="请选择"
                              clearable />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="24">
            <el-form-item label="附件材料:" prop="remark">
              <el-upload v-model:file-list="fileList" :action="upload.url" multiple ref="fileUpload" auto-upload
                :headers="upload.headers" accept=".pdf" :limit="10" :before-upload="handleBeforeUpload"
                :on-error="handleUploadError" :on-success="handleUploadSuccess">
            <el-form-item label="附件材料:"
                          prop="remark">
              <el-upload v-model:file-list="fileList"
                         :action="upload.url"
                         multiple
                         ref="fileUpload"
                         auto-upload
                         :headers="upload.headers"
                         accept=".pdf"
                         :limit="10"
                         :before-upload="handleBeforeUpload"
                         :on-error="handleUploadError"
                         :on-success="handleUploadSuccess">
                <el-button type="primary">上传</el-button>
                <template #tip>
                  <!--                  文件格式支持 doc,docx,xls,xlsx,ppt,pptx,pdf,txt,xml,jpg,jpeg,png,gif,bmp,rar,zip,7z-->
@@ -121,19 +240,33 @@
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确认</el-button>
          <el-button type="primary"
                     @click="submitForm">确认</el-button>
          <el-button @click="closeDia">取消</el-button>
        </div>
      </template>
    </el-dialog>
    <el-dialog title="上传弹窗" width="50%" v-model="uploadModal">
    <el-dialog title="上传弹窗"
               width="50%"
               v-model="uploadModal">
      <el-row :gutter="30">
        <el-col :span="24">
          <el-form-item label="附件材料:" prop="remark">
            <el-upload v-model:file-list="fileList" :action="upload.url" multiple ref="fileUpload" auto-upload
              :headers="upload.headers" accept=".pdf" :limit="10" style="width: 100%" :on-exceed="handleExceed"
              :before-upload="handleBeforeUpload" :on-error="handleUploadError" :on-success="handleUploadSuccess"
              :on-remove="handleRemove">
          <el-form-item label="附件材料:"
                        prop="remark">
            <el-upload v-model:file-list="fileList"
                       :action="upload.url"
                       multiple
                       ref="fileUpload"
                       auto-upload
                       :headers="upload.headers"
                       accept=".pdf"
                       :limit="10"
                       style="width: 100%"
                       :on-exceed="handleExceed"
                       :before-upload="handleBeforeUpload"
                       :on-error="handleUploadError"
                       :on-success="handleUploadSuccess"
                       :on-remove="handleRemove">
              <el-button type="primary">上传</el-button>
              <template #tip>
                <div class="el-upload__tip">文件格式仅支持 pdf</div>
@@ -144,7 +277,8 @@
      </el-row>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="commiInvoicetFile" type="primary">确认</el-button>
          <el-button @click="commiInvoicetFile"
                     type="primary">确认</el-button>
          <el-button @click="uploadModal = false">取消</el-button>
        </div>
      </template>
@@ -154,315 +288,317 @@
</template>
<script setup>
import pagination from "@/components/PIMTable/Pagination.vue";
import { ref } from "vue";
import { Search } from "@element-plus/icons-vue";
import { ElMessageBox } from "element-plus";
import { getToken } from "@/utils/auth";
import {
  invoiceLedgerSaveOrUpdate,
  invoiceLedgerProductInfo,
  commitFile,
  registrationProductPage,
  delInvoiceLedgerByRegProductId,
} from "@/api/salesManagement/invoiceLedger.js";
import useUserStore from "@/store/modules/user.js";
import useFormData from "@/hooks/useFormData";
import dayjs from "dayjs";
import FileList from "./fileList.vue";
  import pagination from "@/components/PIMTable/Pagination.vue";
  import { ref } from "vue";
  import { Search } from "@element-plus/icons-vue";
  import { ElMessageBox } from "element-plus";
  import { getToken } from "@/utils/auth";
  import {
    invoiceLedgerSaveOrUpdate,
    invoiceLedgerProductInfo,
    commitFile,
    registrationProductPage,
    delInvoiceLedgerByRegProductId,
  } from "@/api/salesManagement/invoiceLedger.js";
  import useUserStore from "@/store/modules/user.js";
  import useFormData from "@/hooks/useFormData";
  import dayjs from "dayjs";
  import FileList from "./fileList.vue";
const { proxy } = getCurrentInstance();
const tableData = ref([]);
const productData = ref([]);
const selectedRows = ref([]);
const tableLoading = ref(false);
const page = reactive({
  current: 1,
  size: 100,
});
const total = ref(0);
const fileList = ref([]);
const dialogFormVisible = ref(false);
const data = reactive({
  searchForm: {
    searchText: "",
    status: false,
    invoiceDate: null,
    invoiceDateStart: undefined,
    invoiceDateEnd: undefined,
    createTimeStart: "", // 录入日期
  },
  form: {
    salesLedgerId: "",
    customerId: "",
    invoiceNo: "",
    invoiceTotal: "",
    taxRate: "",
    invoicePerson: "",
    invoiceDate: "",
    customerName: "",
    fileList: [],
    createTime: "", // 录入日期
  },
  rules: {
    salesLedgerId: [{ required: true, message: "请选择", trigger: "change" }],
    customerId: [{ required: true, message: "请输入", trigger: "blur" }],
    invoiceNo: [{ required: true, message: "请选择", trigger: "change" }],
    invoiceAmount: [{ required: true, message: "请输入", trigger: "blur" }],
    taxRate: [{ required: true, message: "请选择", trigger: "change" }],
    invoicePerson: [{ required: true, message: "请选择", trigger: "change" }],
    invoiceDate: [{ required: true, message: "请选择", trigger: "change" }],
    customerName: [{ required: true, message: "请选择", trigger: "change" }],
  },
});
const { form, rules } = toRefs(data);
const { form: searchForm, resetForm } = useFormData(data.searchForm);
const currentId = ref("");
const userStore = useUserStore();
const upload = reactive({
  // 上传的地址
  url: import.meta.env.VITE_APP_BASE_API + "/invoiceLedger/uploadFile",
  // 设置上传的请求头部
  headers: { Authorization: "Bearer " + getToken() },
});
const matchFileType = ref(["pdf"]);
const uploadModal = ref(false);
const formattedNumber = (row, column, cellValue) => {
  return parseFloat(cellValue).toFixed(2);
};
const formatDate = (row, column, cellValue) => {
  return dayjs(cellValue).format("YYYY-MM-DD HH:mm:ss");
};
// 查询列表
/** 搜索按钮操作 */
const handleQuery = () => {
  page.current = 1;
  getList();
};
const paginationChange = (obj) => {
  page.current = obj.page;
  page.size = obj.limit;
  getList();
};
const getList = () => {
  tableLoading.value = true;
  const { invoiceDate, ...rest } = searchForm;
  // 将范围日期字段传递给后端
  const params = { ...rest, ...page };
  // 移除开票日期的默认值设置,只保留范围日期字段
  delete params.invoiceDate;
  registrationProductPage(params).then((res) => {
    tableLoading.value = false;
    tableData.value = res.data.records;
    total.value = res.data.total;
  const { proxy } = getCurrentInstance();
  const tableData = ref([]);
  const productData = ref([]);
  const selectedRows = ref([]);
  const tableLoading = ref(false);
  const page = reactive({
    current: 1,
    size: 100,
  });
};
// 表格选择数据
const handleSelectionChange = (selection) => {
  selectedRows.value = selection;
};
// 主表合计方法
const summarizeMainTable = (param) => {
  return proxy.summarizeTable(param, ["invoiceTotal"], {
    ticketsNum: { noDecimal: true }, // 不保留小数
    futureTickets: { noDecimal: true }, // 不保留小数
  const total = ref(0);
  const fileList = ref([]);
  const dialogFormVisible = ref(false);
  const data = reactive({
    searchForm: {
      searchText: "",
      status: false,
      invoiceDate: null,
      invoiceDateStart: undefined,
      invoiceDateEnd: undefined,
      createTimeStart: "", // 录入日期
    },
    form: {
      salesLedgerId: "",
      customerId: "",
      invoiceNo: "",
      invoiceTotal: "",
      taxRate: "",
      invoicePerson: "",
      invoiceDate: "",
      customerName: "",
      fileList: [],
      createTime: "", // 录入日期
    },
    rules: {
      salesLedgerId: [{ required: true, message: "请选择", trigger: "change" }],
      customerId: [{ required: true, message: "请输入", trigger: "blur" }],
      invoiceNo: [{ required: true, message: "请选择", trigger: "change" }],
      invoiceAmount: [{ required: true, message: "请输入", trigger: "blur" }],
      taxRate: [{ required: true, message: "请选择", trigger: "change" }],
      invoicePerson: [{ required: true, message: "请选择", trigger: "change" }],
      invoiceDate: [{ required: true, message: "请选择", trigger: "change" }],
      customerName: [{ required: true, message: "请选择", trigger: "change" }],
    },
  });
};
// 打开弹框
const openForm = (row) => {
  form.value = {};
  productData.value = [];
  fileList.value = [];
  currentId.value = row.id;
  invoiceLedgerProductInfo({ id: row.id }).then((res) => {
    form.value = { ...res.data };
    fileList.value = res.data.fileList;
    // 保存ticketRegistrationId到表单数据中
    if (row.ticketRegistrationId) {
      form.value.ticketRegistrationId = row.ticketRegistrationId;
    }
    if (!form.value.invoicePerson) {
      form.value.invoicePerson = userStore.nickName;
      // 移除录入日期默认值设置,只处理范围日期字段
    }
    // 移除开票日期默认值设置,只处理范围日期字段
  const { form, rules } = toRefs(data);
  const { form: searchForm, resetForm } = useFormData(data.searchForm);
  const currentId = ref("");
  const userStore = useUserStore();
  const upload = reactive({
    // 上传的地址
    url: import.meta.env.VITE_APP_BASE_API + "/invoiceLedger/uploadFile",
    // 设置上传的请求头部
    headers: { Authorization: "Bearer " + getToken() },
  });
  dialogFormVisible.value = true;
};
// 上传多个文件就覆盖原来的
const handleExceed = (files) => {
  proxy.$refs["fileUpload"].clearFiles();
  const file = files[0];
  file.uid = genFileId();
  proxy.$refs["fileUpload"].handleStart(file);
};
// 上传前校检
function handleBeforeUpload(file) {
  // 校检文件大小
  if (file.size > 1024 * 1024 * 10) {
    proxy.$modal.msgError("上传文件大小不能超过10MB!");
    return false;
  }
  // 判断文件格式是否符合
  const fileType = file.name.split(".").pop().toLowerCase();
  if (!matchFileType.value.includes(fileType)) {
    proxy.$modal.msgError("文件格式不匹配");
    return false;
  }
  console.log('handleBeforeUpload');
  proxy.$modal.loading("正在上传文件,请稍候...");
  return true;
}
// 上传失败
function handleUploadError(err) {
  proxy.$modal.msgError("上传文件失败");
  proxy.$modal.closeLoading();
}
// 上传成功回调
function handleUploadSuccess(res, file, uploadFiles) {
  proxy.$modal.closeLoading();
  console.log('handleUploadSuccess');
  if (res.code === 200) {
    proxy.$modal.msgSuccess("上传成功");
    // 将上传成功的文件信息添加到fileList中
    const fileInfo = {
      name: file.name,
      url: res.data.url || file.response?.data?.url || file.url,
      response: file.response
    };
    // 检查是否已存在相同文件,避免重复添加
    const existingFileIndex = fileList.value.findIndex(f => f.name === fileInfo.name);
    if (existingFileIndex === -1) {
      fileList.value.push(fileInfo);
    } else {
      fileList.value[existingFileIndex] = fileInfo;
    }
    // 确保表单数据中的fileList也更新
    form.value.fileList = fileList.value;
  } else {
    proxy.$modal.msgError(res.msg);
    proxy.$refs.fileUpload.handleRemove(file);
  }
}
// 提交表单
const submitForm = () => {
  proxy.$refs["formRef"].validate((valid) => {
    if (valid) {
      form.value.fileList = fileList.value;
      invoiceLedgerSaveOrUpdate(form.value).then((res) => {
        proxy.$modal.msgSuccess("提交成功");
        closeDia();
        getList();
      });
    }
  });
};
// 关闭弹框
const closeDia = () => {
  proxy.resetForm("formRef");
  dialogFormVisible.value = false;
};
// 导出
const handleOut = () => {
  ElMessageBox.confirm("选中的内容将被导出,是否确认导出?", "导出", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      proxy.download("/invoiceLedger/export", {}, "开票台账.xlsx");
    })
    .catch(() => {
      proxy.$modal.msg("已取消");
    });
};
// 确认文件上传
const commiInvoicetFile = () => {
  const object = {
    fileList: fileList.value,
    id: currentId.value,
  const matchFileType = ref(["pdf"]);
  const uploadModal = ref(false);
  const formattedNumber = (row, column, cellValue) => {
    return parseFloat(cellValue).toFixed(2);
  };
  commitFile(object).then((res) => {
    if (res.code === 200) {
      proxy.$modal.msgSuccess("提交成功");
      uploadModal.value = false;
    }
  const formatDate = (row, column, cellValue) => {
    return dayjs(cellValue).format("YYYY-MM-DD HH:mm:ss");
  };
  // 查询列表
  /** 搜索按钮操作 */
  const handleQuery = () => {
    page.current = 1;
    getList();
    currentId.value = "";
    fileList.value = [];
  });
};
// 删除开票台账
const delInvoiceLedger = (row) => {
  ElMessageBox.confirm("该发票台账将被删除,是否确认删除", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      delInvoiceLedgerByRegProductId(row.id).then((res) => {
            proxy.$modal.msgSuccess("删除成功");
        getList();
      });
    })
    .catch(() => {
      proxy.$modal.msg("已取消");
  };
  const paginationChange = obj => {
    page.current = obj.page;
    page.size = obj.limit;
    getList();
  };
  const getList = () => {
    tableLoading.value = true;
    const { invoiceDate, ...rest } = searchForm;
    // 将范围日期字段传递给后端
    const params = { ...rest, ...page };
    // 移除开票日期的默认值设置,只保留范围日期字段
    delete params.invoiceDate;
    registrationProductPage(params).then(res => {
      tableLoading.value = false;
      tableData.value = res.data.records;
      total.value = res.data.total;
    });
};
  };
  // 表格选择数据
  const handleSelectionChange = selection => {
    selectedRows.value = selection;
  };
  // 主表合计方法
  const summarizeMainTable = param => {
    return proxy.summarizeTable(param, ["invoiceTotal"], {
      ticketsNum: { noDecimal: true }, // 不保留小数
      futureTickets: { noDecimal: true }, // 不保留小数
    });
  };
  // 打开弹框
  const openForm = row => {
    form.value = {};
    productData.value = [];
    fileList.value = [];
    currentId.value = row.id;
// 获取当前日期并格式化为 YYYY-MM-DD
function getCurrentDate() {
  const today = new Date();
  const year = today.getFullYear();
  const month = String(today.getMonth() + 1).padStart(2, "0"); // 月份从0开始
  const day = String(today.getDate()).padStart(2, "0");
  return `${year}-${month}-${day}`;
}
const changeDateRange = (date) => {
  if (date) {
    searchForm.invoiceDateStart = date[0];
    searchForm.invoiceDateEnd = date[1];
    getList();
    invoiceLedgerProductInfo({ id: row.id }).then(res => {
      form.value = { ...res.data };
      fileList.value = res.data.fileList;
      // 保存ticketRegistrationId到表单数据中
      if (row.ticketRegistrationId) {
        form.value.ticketRegistrationId = row.ticketRegistrationId;
      }
      if (!form.value.invoicePerson) {
        form.value.invoicePerson = userStore.nickName;
        // 移除录入日期默认值设置,只处理范围日期字段
      }
      // 移除开票日期默认值设置,只处理范围日期字段
    });
    dialogFormVisible.value = true;
  };
  // 上传多个文件就覆盖原来的
  const handleExceed = files => {
    proxy.$refs["fileUpload"].clearFiles();
    const file = files[0];
    file.uid = genFileId();
    proxy.$refs["fileUpload"].handleStart(file);
  };
  // 上传前校检
  function handleBeforeUpload(file) {
    // 校检文件大小
    if (file.size > 1024 * 1024 * 10) {
      proxy.$modal.msgError("上传文件大小不能超过10MB!");
      return false;
    }
    // 判断文件格式是否符合
    const fileType = file.name.split(".").pop().toLowerCase();
    if (!matchFileType.value.includes(fileType)) {
      proxy.$modal.msgError("文件格式不匹配");
      return false;
    }
    console.log("handleBeforeUpload");
    proxy.$modal.loading("正在上传文件,请稍候...");
    return true;
  }
};
  // 上传失败
  function handleUploadError(err) {
    proxy.$modal.msgError("上传文件失败");
    proxy.$modal.closeLoading();
  }
  // 上传成功回调
  function handleUploadSuccess(res, file, uploadFiles) {
    proxy.$modal.closeLoading();
    console.log("handleUploadSuccess");
    if (res.code === 200) {
      proxy.$modal.msgSuccess("上传成功");
      // 将上传成功的文件信息添加到fileList中
      const fileInfo = {
        name: file.name,
        url: res.data.url || file.response?.data?.url || file.url,
        response: file.response,
      };
      // 检查是否已存在相同文件,避免重复添加
      const existingFileIndex = fileList.value.findIndex(
        f => f.name === fileInfo.name
      );
      if (existingFileIndex === -1) {
        fileList.value.push(fileInfo);
      } else {
        fileList.value[existingFileIndex] = fileInfo;
      }
      // 确保表单数据中的fileList也更新
      form.value.fileList = fileList.value;
    } else {
      proxy.$modal.msgError(res.msg);
      proxy.$refs.fileUpload.handleRemove(file);
    }
  }
  // 提交表单
  const submitForm = () => {
    proxy.$refs["formRef"].validate(valid => {
      if (valid) {
        form.value.fileList = fileList.value;
        invoiceLedgerSaveOrUpdate(form.value).then(res => {
          proxy.$modal.msgSuccess("提交成功");
          closeDia();
          getList();
        });
      }
    });
  };
  // 关闭弹框
  const closeDia = () => {
    proxy.resetForm("formRef");
    dialogFormVisible.value = false;
  };
  // 导出
  const handleOut = () => {
    ElMessageBox.confirm("选中的内容将被导出,是否确认导出?", "导出", {
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      type: "warning",
    })
      .then(() => {
        proxy.download("/invoiceLedger/export", {}, "开票台账.xlsx");
      })
      .catch(() => {
        proxy.$modal.msg("已取消");
      });
  };
const handleFile = (commonFiles) => {
  commonFiles.forEach((e) => {
    proxy.$download.name(e.url);
  // 确认文件上传
  const commiInvoicetFile = () => {
    const object = {
      fileList: fileList.value,
      id: currentId.value,
    };
    commitFile(object).then(res => {
      if (res.code === 200) {
        proxy.$modal.msgSuccess("提交成功");
        uploadModal.value = false;
      }
      getList();
      currentId.value = "";
      fileList.value = [];
    });
  };
  // 删除开票台账
  const delInvoiceLedger = row => {
    ElMessageBox.confirm("该发票台账将被删除,是否确认删除", {
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      type: "warning",
    })
      .then(() => {
        delInvoiceLedgerByRegProductId(row.id).then(res => {
          proxy.$modal.msgSuccess("删除成功");
          getList();
        });
      })
      .catch(() => {
        proxy.$modal.msg("已取消");
      });
  };
  // 获取当前日期并格式化为 YYYY-MM-DD
  function getCurrentDate() {
    const today = new Date();
    const year = today.getFullYear();
    const month = String(today.getMonth() + 1).padStart(2, "0"); // 月份从0开始
    const day = String(today.getDate()).padStart(2, "0");
    return `${year}-${month}-${day}`;
  }
  const changeDateRange = date => {
    if (date) {
      searchForm.invoiceDateStart = date[0];
      searchForm.invoiceDateEnd = date[1];
      getList();
    }
  };
  const handleFile = commonFiles => {
    commonFiles.forEach(e => {
      proxy.$download.name(e.url);
    });
  };
  const clearRange = () => {
    searchForm.invoiceDate = [];
    searchForm.invoiceDateStart = undefined;
    searchForm.invoiceDateEnd = undefined;
    getList();
  };
  //附件相关
  const fileListRef = ref(null);
  //查看附件
  const downLoadFile = row => {
    invoiceLedgerProductInfo({ id: row.id }).then(res => {
      fileListRef.value.open(res.data.fileList);
    });
  };
  onMounted(() => {
    // 设置开票日期范围默认值为当天
    const today = dayjs().format("YYYY-MM-DD");
    searchForm.invoiceDate = [today, today];
    // 设置范围日期字段的起始和结束时间
    searchForm.invoiceDateStart = today;
    searchForm.invoiceDateEnd = today;
    getList();
  });
};
const clearRange = () => {
  searchForm.invoiceDate = [];
  searchForm.invoiceDateStart = undefined;
  searchForm.invoiceDateEnd = undefined;
  getList();
};
//附件相关
const fileListRef = ref(null)
//查看附件
const downLoadFile = (row) => {
   invoiceLedgerProductInfo({ id: row.id }).then((res) => {
      fileListRef.value.open(res.data.fileList)
   });
}
onMounted(() => {
  // 设置开票日期范围默认值为当天
  const today = dayjs().format('YYYY-MM-DD');
  searchForm.invoiceDate = [today, today];
  // 设置范围日期字段的起始和结束时间
  searchForm.invoiceDateStart = today;
  searchForm.invoiceDateEnd = today;
  getList();
});
</script>
<style scoped lang="scss">
.table_list {
  margin-top: unset;
}
  .table_list {
    margin-top: unset;
  }
</style>