yxh
10 天以前 48118e7c69c14b86b06abbabb4c910cb59c12cfa
src/views/project/invoice/index.vue
@@ -27,7 +27,7 @@
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报销状态" prop="reimburseState">
      <el-form-item v-if="!selectMode" label="报销状态" prop="reimburseState">
        <el-select
          v-model="queryParams.reimburseState"
          placeholder="请选择报销状态"
@@ -54,7 +54,7 @@
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
      <el-col v-if="!selectMode" :span="1.5">
        <el-button
          type="primary"
          plain
@@ -71,7 +71,101 @@
      ></right-toolbar>
    </el-row>
    <el-table v-loading="loading" border :data="invoiceList">
    <!-- 手机端:卡片列表 -->
    <div v-if="isMobile && !selectMode" class="invoice-cards" v-loading="loading">
      <div
        v-for="row in invoiceList"
        :key="row.id"
        class="invoice-card"
      >
        <div class="invoice-card__head">
          <span
            class="invoice-card__title"
            @click="handleUpdate(row)"
            >{{ row.invoiceName || "未命名发票" }}</span
          >
          <el-tag
            size="mini"
            :type="
              String(row.reimburseState) === '1' ? 'success' : 'info'
            "
          >
            {{ String(row.reimburseState) === "1" ? "已报销" : "未报销" }}
          </el-tag>
        </div>
        <div class="invoice-card__row">
          <span class="label">案例</span>
          <span class="value">{{ row.caseId || "-" }}</span>
        </div>
        <div class="invoice-card__row">
          <span class="label">金额</span>
          <span class="value">{{ amountText(row.invoiceAmount) }}</span>
        </div>
        <div class="invoice-card__row">
          <span class="label">日期</span>
          <span class="value">{{
            normalizeDate(row.occurDate) || row.occurDate || "-"
          }}</span>
        </div>
        <div class="invoice-card__row">
          <span class="label">号码</span>
          <span class="value">{{ row.invoiceNo || "-" }}</span>
        </div>
        <div class="invoice-card__row">
          <span class="label">报销ID</span>
          <span class="value">{{ row.reimburseId || "-" }}</span>
        </div>
        <div class="invoice-card__actions">
          <el-button
            type="text"
            icon="el-icon-view"
            @click="openPreview(row.invoiceUrl, row.invoiceName)"
            >预览</el-button
          >
          <el-button
            v-if="String(row.reimburseState) !== '1'"
            type="text"
            icon="el-icon-check"
            @click="handleReimburse(row)"
            v-hasPermi="['project:invoice:edit']"
            >已报销</el-button
          >
          <el-button
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(row)"
            v-hasPermi="['project:invoice:edit']"
            >修改</el-button
          >
          <el-button
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(row)"
            v-hasPermi="['project:invoice:remove']"
            >删除</el-button
          >
        </div>
      </div>
      <div v-if="!invoiceList.length && !loading" class="invoice-empty">
        暂无数据
      </div>
    </div>
    <el-table
      v-else
      v-loading="loading"
      border
      row-key="id"
      :data="invoiceList"
      @selection-change="handleInvoiceSelectionChange"
    >
      <el-table-column
        v-if="selectMode"
        type="selection"
        width="50"
        align="center"
        :reserve-selection="true"
      />
      <el-table-column type="index" label="序号" width="55" align="center" />
      <el-table-column label="案例" align="center" prop="caseId"  width="100">
        
@@ -121,40 +215,49 @@
        </template>
      </el-table-column>
      <el-table-column
        prop="reimburseId"
        label="报销ID"
        width="150"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        label="操作"
        width="200"
        align="center"
        fixed="right"
        :fixed="isMobile ? false : 'right'"
      >
        <template slot-scope="scope">
          <el-button
            type="text"
            icon="el-icon-view"
            @click="openPreview(scope.row.invoiceUrl)"
            @click="openPreview(scope.row.invoiceUrl, scope.row.invoiceName)"
            >文件预览</el-button
          >
          <el-button
            v-if="String(scope.row.reimburseState) !== '1'"
            type="text"
            icon="el-icon-check"
            @click="handleReimburse(scope.row)"
            v-hasPermi="['project:invoice:edit']"
            >已报销</el-button
          >
          <el-button
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['project:invoice:edit']"
            >修改</el-button
          >
          <el-button
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['project:invoice:remove']"
            >删除</el-button
          >
          <template v-if="!selectMode">
            <el-button
              v-if="String(scope.row.reimburseState) !== '1'"
              type="text"
              icon="el-icon-check"
              @click="handleReimburse(scope.row)"
              v-hasPermi="['project:invoice:edit']"
              >已报销</el-button
            >
            <el-button
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['project:invoice:edit']"
              >修改</el-button
            >
            <el-button
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['project:invoice:remove']"
              >删除</el-button
            >
          </template>
        </template>
      </el-table-column>
    </el-table>
@@ -167,13 +270,29 @@
      @pagination="getList"
    />
    <div v-if="selectMode" class="invoice-select-footer">
      <span class="invoice-select-footer__tip">
        已选择 {{ selectedInvoices.length }} 张发票
      </span>
      <el-button size="mini" @click="$emit('cancel')">取 消</el-button>
      <el-button
        type="primary"
        size="mini"
        :disabled="!selectedInvoices.length"
        @click="confirmSelect"
        >确定选择</el-button
      >
    </div>
    <!-- 上传发票 / 发票信息确认 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="760px"
      append-to-body
      :fullscreen="isMobile"
      :close-on-click-modal="false"
      @closed="revokeThumbObjectUrl"
    >
      <!-- 第一步:选案例、用户,上传发票 -->
      <div v-if="mode === 'upload'">
@@ -192,7 +311,11 @@
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="凭证">
                <el-checkbox v-model="uploadForm.voucher">凭证</el-checkbox>
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item label="发票文件">
            <el-upload
@@ -284,10 +407,30 @@
          </el-col>
          <el-col :span="12">
            <el-form-item label="发票类型" prop="invoiceType">
              <el-input
              <el-select
                v-model="form.invoiceType"
                placeholder="请输入发票类型"
              />
                placeholder="请选择发票类型"
                filterable
                clearable
                style="width: 100%"
              >
                <el-option
                  v-for="item in invoiceTypeOptions"
                  :key="item"
                  :label="item"
                  :value="item"
                />
                <!-- OCR 识别出的其它类型保留回显,避免直接丢失 -->
                <el-option
                  v-if="
                    form.invoiceType &&
                    invoiceTypeOptions.indexOf(form.invoiceType) === -1
                  "
                  :key="form.invoiceType"
                  :label="form.invoiceType"
                  :value="form.invoiceType"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
@@ -368,6 +511,15 @@
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报销ID" prop="reimburseId">
              <el-input
                v-model="form.reimburseId"
                maxlength="20"
                placeholder="请输入报销ID"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input
@@ -386,17 +538,18 @@
                type="text"
                icon="el-icon-view"
                :disabled="!form.invoiceUrl"
                @click="openPreview(form.invoiceUrl)"
                @click="openPreview(form.invoiceUrl, form.invoiceName)"
                >文件预览</el-button
              >
              <el-image
              <img
                v-if="
                  form.invoiceUrl && getFileType(form.invoiceUrl) === 'image'
                "
                :src="form.invoiceUrl"
                :preview-src-list="[form.invoiceUrl]"
                fit="contain"
                :src="thumbObjectUrl || form.invoiceUrl"
                class="invoice-thumb"
                title="点击预览"
                @click="openPreview(form.invoiceUrl, form.invoiceName)"
                style="width: 400px;height: 240px;"
              />
            </el-form-item>
          </el-col>
@@ -424,27 +577,18 @@
    <el-dialog
      title="发票文件预览"
      :visible.sync="previewOpen"
      width="900px"
      width="1000px"
      append-to-body
      :fullscreen="isMobile"
      :destroy-on-close="true"
      @closed="handlePreviewClosed"
    >
      <div class="invoice-preview">
        <img
          v-if="previewType === 'image'"
          :src="previewUrl"
          class="preview-image"
      <div class="invoice-preview-wrap" v-loading="previewLoading">
        <attachment-preview-pane
          v-if="invoiceEmbeddedFile"
          :file="invoiceEmbeddedFile"
          style="flex: 1; min-width: 0;"
        />
        <iframe
          v-else-if="previewType === 'pdf'"
          :src="previewUrl"
          class="preview-frame"
        ></iframe>
        <div v-else class="preview-tip">
          该文件类型不支持在线预览,请
          <el-link type="primary" :href="previewUrl" target="_blank"
            >在新窗口打开</el-link
          >
        </div>
      </div>
    </el-dialog>
  </div>
@@ -464,6 +608,13 @@
export default {
  name: "ServiceInvoice",
  props: {
    // 作为其他单据的发票选择器嵌入时传 true:显示多选列,仅展示未报销发票
    selectMode: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      // 遮罩层
@@ -474,6 +625,8 @@
      total: 0,
      // 发票列表
      invoiceList: [],
      // 选择模式下已勾选的发票
      selectedInvoices: [],
      // 弹窗
      open: false,
      // upload:上传发票;edit:识别结果确认
@@ -489,7 +642,9 @@
      },
      // 上传阶段表单(用户ID取当前登录用户,不在此处编辑)
      uploadForm: {
        caseId: ""
        caseId: "",
        // 勾选后传 voucher=1,后端按“凭证”处理
        voucher: false
      },
      uploadRules: {
       
@@ -498,16 +653,34 @@
      uploadedList: [],
      // 正在上传的文件数,用于判断一批上传是否结束
      uploadingCount: 0,
      // 发票类型下拉选项
      invoiceTypeOptions: [
        "交通费",
        "市内交通费",
        "住宿费",
        "伙食补助",
        "公杂费补助",
        "其他费用",
        "医护团队专家费",
        "评估专家费",
        "转运护理劳务费",
        "获取专家劳务费",
        "伦理审核专家费",
        "凭证"
      ],
      // 识别结果 / 修改表单
      form: {},
      rules: {
       
      },
      // 文件预览
      // 文件预览(AttachmentPreviewPane 所需的 file 对象)
      previewOpen: false,
      previewUrl: "",
      // image / pdf / other
      previewType: "",
      previewLoading: false,
      invoiceEmbeddedFile: null,
      // 预览用的 blob 地址,关闭时释放
      previewObjectUrl: "",
      // 编辑弹窗缩略图的 blob 地址
      thumbObjectUrl: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
@@ -521,11 +694,16 @@
    };
  },
  computed: {
    // 是否手机端(弹窗全屏、操作列不固定等适配)
    isMobile() {
      return this.$store.state.app.device === "mobile";
    },
    // 上传时携带的用户ID(当前登录用户)、案例ID(后端 uploadOCR 必传)
    uploadData() {
      return {
        userId: this.currentUserId,
        caseId: this.uploadForm.caseId
        caseId: this.uploadForm.caseId,
        voucher: this.uploadForm.voucher ? "1" : "0"
      };
    }
  },
@@ -537,7 +715,11 @@
    /** 查询发票列表 */
    getList() {
      this.loading = true;
      this.queryParams.userId=this.currentUserId
      this.queryParams.userId = this.currentUserId;
      // 选择模式只允许引用未报销发票,避免同一张发票重复报销
      if (this.selectMode) {
        this.queryParams.reimburseState = "0";
      }
      listInvoice(this.queryParams)
        .then(response => {
          this.invoiceList = response.rows;
@@ -596,9 +778,24 @@
    resetQuery() {
      this.queryParams.caseId = "";
      this.queryParams.invoiceName = "";
      this.queryParams.reimburseState = "";
      this.queryParams.reimburseState = this.selectMode ? "0" : "";
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 选择模式:记录勾选的发票 */
    handleInvoiceSelectionChange(selection) {
      this.selectedInvoices = selection;
    },
    /** 选择模式:把勾选的发票交给调用方 */
    confirmSelect() {
      if (!this.selectedInvoices.length) {
        this.$modal.msgWarning("请先勾选需要引用的发票");
        return;
      }
      this.$emit(
        "confirm",
        this.selectedInvoices.map(row => Object.assign({}, row))
      );
    },
    /** 上传发票按钮操作 */
    async handleUpload() {
@@ -606,7 +803,8 @@
        await this.getCurrentUser();
      }
      this.uploadForm = {
        caseId: ""
        caseId: "",
        voucher: false
      };
      this.uploadedList = [];
      this.uploadingCount = 0;
@@ -647,6 +845,8 @@
      this.getList();
      if (!invoiceList.length) {
        this.$modal.msgWarning("该文件未识别到发票信息,请确认文件清晰");
      } else if (this.uploadForm.voucher) {
        this.$modal.msgSuccess("凭证上传成功");
      } else {
        this.$modal.msgSuccess(
          "发票上传成功,识别到 " + invoiceList.length + " 张发票"
@@ -670,7 +870,7 @@
      this.afterUploadBatch();
    },
    /** 打开发票信息确认弹窗 */
    openEditForm(record) {
    async openEditForm(record) {
      this.form = {
        id: record.id,
        caseId: record.caseId,
@@ -685,11 +885,33 @@
        invoiceEndDate: this.normalizeDate(record.invoiceEndDate),
        sellerName: record.sellerName,
        reimburseState: record.reimburseState || "0",
        reimburseId: record.reimburseId,
        remark: record.remark
      };
      this.mode = "edit";
      this.title = "发票信息确认";
      this.title = record.invoiceType === "凭证" ? "凭证信息确认" : "发票信息确认";
      this.open = true;
      this.refreshThumb();
    },
    /** 缩略图同样带 token 拉取,避免直接引用鉴权地址显示不出来 */
    async refreshThumb() {
      this.revokeThumbObjectUrl();
      const url = this.form.invoiceUrl;
      if (!url || this.getFileType(url) !== "image") {
        return;
      }
      const objectUrl = await this.loadPreviewBlob(url);
      if (objectUrl && this.form.invoiceUrl === url) {
        this.thumbObjectUrl = objectUrl;
      } else if (objectUrl) {
        URL.revokeObjectURL(objectUrl);
      }
    },
    revokeThumbObjectUrl() {
      if (this.thumbObjectUrl) {
        URL.revokeObjectURL(this.thumbObjectUrl);
        this.thumbObjectUrl = "";
      }
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
@@ -697,15 +919,86 @@
        this.openEditForm(response.data);
      });
    },
    /** 文件预览:图片、PDF 弹窗内预览,其它类型提示新窗口打开 */
    openPreview(url) {
    /** 文件预览:带 token 拉取成 blob 再预览,兼容需要鉴权的 /profile 资源 */
    async openPreview(url, name) {
      if (!url) {
        this.$modal.msgWarning("该记录暂无发票文件");
        return;
      }
      this.previewUrl = url;
      this.previewType = this.getFileType(url);
      const type = this.getFileType(url);
      const fileName = name || this.getFileName(url);
      this.revokePreviewObjectUrl();
      this.invoiceEmbeddedFile = null;
      this.previewLoading = true;
      this.previewOpen = true;
      const objectUrl = await this.loadPreviewBlob(url);
      this.previewLoading = false;
      if (objectUrl) {
        this.previewObjectUrl = objectUrl;
        this.invoiceEmbeddedFile = { name: fileName, url: objectUrl, type };
      } else {
        // 拉取失败时退回原始地址,交给浏览器直接加载
        this.invoiceEmbeddedFile = { name: fileName, url: url, type };
      }
    },
    /** 依次尝试原始地址、接口前缀地址,带 token 拉取成 blob */
    async loadPreviewBlob(url) {
      const headers = { Authorization: "Bearer " + getToken() };
      const candidates = this.buildPreviewCandidates(url);
      for (let i = 0; i < candidates.length; i++) {
        try {
          const response = await fetch(candidates[i], { headers });
          if (!response.ok) {
            continue;
          }
          const blob = await response.blob();
          if (blob && blob.size > 0) {
            return URL.createObjectURL(blob);
          }
        } catch (e) {
          // 跨域/网络异常,继续尝试下一个地址
        }
      }
      return "";
    },
    /** 预览地址候选:原始地址 + 走接口前缀(/dev-api、/prod-api)的地址 */
    buildPreviewCandidates(url) {
      const list = [url];
      if (/^https?:\/\//i.test(url)) {
        const base = (process.env.VUE_APP_BASE_API || "").replace(/\/$/, "");
        let path = url.replace(/^https?:\/\/[^/]+/i, "");
        if (base && (path === base || path.indexOf(base + "/") === 0)) {
          path = path.slice(base.length);
        }
        if (base) {
          list.push(base + path);
        }
      }
      return list.filter((item, index) => list.indexOf(item) === index);
    },
    /** 关闭预览时释放 blob 地址 */
    handlePreviewClosed() {
      this.revokePreviewObjectUrl();
      this.invoiceEmbeddedFile = null;
    },
    revokePreviewObjectUrl() {
      if (this.previewObjectUrl) {
        URL.revokeObjectURL(this.previewObjectUrl);
        this.previewObjectUrl = "";
      }
    },
    /** 金额显示:保留两位小数 */
    amountText(value) {
      if (value === null || value === undefined || value === "") {
        return "0.00";
      }
      const num = Number(value);
      return Number.isFinite(num) ? num.toFixed(2) : value;
    },
    /** 从地址中取文件名(无发票名称时兜底) */
    getFileName(url) {
      const path = String(url || "").split("?")[0];
      return path.substring(path.lastIndexOf("/") + 1) || "发票文件";
    },
    /** 根据文件地址判断预览类型 */
    getFileType(url) {
@@ -783,28 +1076,142 @@
  margin-left: 12px;
  border: 1px solid #ebeef5;
  vertical-align: middle;
  object-fit: contain;
  background: #f5f7fa;
  cursor: pointer;
}
.invoice-preview {
  min-height: 120px;
.invoice-preview-wrap {
  display: flex;
  width: 100%;
  height: 70vh;
}
  .preview-image {
    display: block;
    max-width: 100%;
    max-height: 70vh;
    margin: 0 auto;
/* 手机端卡片列表 */
.invoice-cards {
  min-height: 60px;
}
.invoice-card {
  padding: 12px;
  margin-bottom: 10px;
  background: #fff;
  border: 1px solid #ebeef5;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  &__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
  }
  .preview-frame {
  &__title {
    flex: 1;
    min-width: 0;
    margin-right: 8px;
    font-size: 15px;
    font-weight: 600;
    color: #303133;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  &__row {
    display: flex;
    align-items: center;
    margin-bottom: 6px;
    font-size: 13px;
    color: #606266;
    .label {
      flex: 0 0 40px;
      color: #909399;
    }
    .value {
      flex: 1;
      min-width: 0;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
  &__actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px dashed #ebeef5;
    ::v-deep .el-button + .el-button {
      margin-left: 16px;
    }
  }
}
.invoice-empty {
  padding: 40px 0;
  text-align: center;
  font-size: 14px;
  color: #909399;
}
.invoice-select-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 12px 0 0;
  &__tip {
    margin-right: 16px;
    font-size: 13px;
    color: #606266;
  }
}
/* 手机端适配 */
@media (max-width: 992px) {
  .app-container {
    padding: 8px;
  }
  .opo-query-form {
    ::v-deep .el-form-item {
      display: flex;
      width: 100%;
      margin-right: 0;
      margin-bottom: 10px;
    }
    ::v-deep .el-form-item__content {
      flex: 1;
      min-width: 0;
    }
    ::v-deep .el-select,
    ::v-deep .el-input,
    ::v-deep .el-date-editor {
      width: 100% !important;
    }
  }
  /* 弹窗内两列表单在手机端变单列 */
  .el-col-12 {
    width: 100%;
    height: 70vh;
    border: none;
  }
  .preview-tip {
    padding: 40px 0;
    text-align: center;
    color: #909399;
  /* 全屏弹窗里的预览区占满剩余高度 */
  .invoice-preview-wrap {
    height: calc(100vh - 120px);
  }
  .invoice-thumb {
    display: block;
    margin: 8px 0 0;
  }
}
</style>