<template>
  <div class="app-container">
    <div slot="header" class="card-title">{{ $t("收款单") }}</div>
    <!-- 搜索工作栏 -->
    <el-card v-show="showSearch" class="card">
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        label-width="100px"
        class="card"
      >
        <el-row :span="24">
          <el-form-item :label="$t('收款单号')">
            <el-input
              style="max-width: 188px"
              v-model="queryParams.receiptNo"
              :placeholder="$t('请输入收款单号')"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item :label="$t('客户名称')">
            <customer-selector
              v-model="queryParams.customerId"
              @change="changeCustomerId"
              clearable
            />
          </el-form-item>
          <el-form-item :label="$t('状态')">
            <dict-selector
              :type="DICT_TYPE.ECW_RECEIPT_STATE"
              v-model="queryParams.state"
              clearable
            />
          </el-form-item>
          <el-form-item :label="$t('业务员')">
            <el-select
              v-model="queryParams.salesmanId"
              :placeholder="$t('请选择业务员')"
              clearable
            >
              <el-option
                v-for="item in creatorData"
                :key="item.id"
                :label="item.nickname"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-row>
        <el-row :span="24">
          <el-col style="width: 592px">
            <el-form-item :label="$t('创建时间')">
              <el-date-picker
                v-model="dateFilter"
                type="datetimerange"
                range-separator="-"
                value-format="yyyy-MM-dd HH:mm:ss"
                :start-placeholder="$t('请选择日期')"
                :end-placeholder="$t('请选择日期')"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-form-item :label="$t('编号')">
            <el-input
              style="max-width: 188px"
              v-model="queryParams.numberNo"
              :placeholder="$t('订单号和提单号,自编号')"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-row>
        <el-row :span="24">
          <el-col style="width: 592px">
            <el-form-item>
              <el-button type="primary" @click="handleQuery">{{
                $t("查找")
              }}</el-button>
              <!--lanbm 2024-05-29 添加的批处理功能按钮-->
              <el-button type="primary" @click="handleQuery2">{{
                $t("批量反审核")
              }}</el-button>
              <el-button type="primary" @click="handleQuery3">{{
                $t("批量反核销")
              }}</el-button>
              <el-button type="primary" @click="handleQuery4">{{
                $t("批量核销")
              }}</el-button>
              <!--lanbm 2024-05-29 添加的批处理功能按钮-->
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <el-table
      v-loading="loadings"
      :data="list"
      @selection-change="handleSelectionChange"
      border
      class="card"
    >
      <el-table-column type="selection" width="55" align="center">
      </el-table-column>
      <el-table-column
        :label="$t('序号')"
        align="center"
        prop="id"
        type="index"
      >
        <template slot-scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <!--lanbm 2024-06-06 添加链接-->
      <el-table-column :label="$t('收款单号')" align="center" prop="receiptNo">
        <template slot-scope="scope">
          <span
            style="color: #1890ff"
            @click="verificationCancelClick(scope.row)"
            >{{ scope.row.receiptNo }}</span
          >
        </template>
      </el-table-column>
      <!--订单号，提单号，lanbm 2024-05-29 add-->
      <el-table-column :label="$t('订单号')" align="center" prop="orderNo">
        <template slot-scope="scope">
          <span style="color: #1890ff" @click="paymentDetail2(scope.row)">{{
            scope.row.orderNo
          }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('提单号')" align="center" prop="tidanNo" />
      <!-- <template slot-scope="scope"> -->
      <!-- <span style="color: #1890ff;" @click="verificationCancelClick(scope.row)">{{scope.row.receiptNo}}</span> -->
      <!-- </template> -->
      <!-- </el-table-column> -->
      <el-table-column
        :label="$t('客户名称')"
        align="center"
        prop="customerName"
      />
      <el-table-column :label="$t('创建日期')" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('实收日期')" align="center" prop="payedAt">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payedAt, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('业务员')"
        align="center"
        prop="salesmanName"
      />
      <el-table-column :label="$t('状态')" align="center">
        <template slot-scope="scope">
          <dict-tag
            :type="DICT_TYPE.ECW_RECEIPT_STATE"
            :value="scope.row.state"
          />
          <span
            v-if="
              scope.row.remark &&
              (scope.row.state == 1 ||
                scope.row.state == 3 ||
                scope.row.state == 8)
            "
            :title="scope.row.remark"
            ><i class="el-icon-question"></i
          ></span>
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('应收')"
        align="center"
        prop="ysShow"
      >
      </el-table-column>
      <el-table-column :label="$t('实收')" align="center" prop="ssShow">
      </el-table-column>
      <el-table-column
        :label="$t('核销比例')"
        align="center"
        prop="hxBiLi"
      >
      </el-table-column>
      <el-table-column :label="$t('是否开票')" align="center">
        <template slot-scope="scope">
          {{ scope.row.openInvoice === 0 ? $t("否") : $t("是") }}
        </template>
      </el-table-column>
      <!--lanbm 2024-05-14 add-->
      <el-table-column :label="$t('明细状态')" align="center" prop="mxStatus" />
      <el-table-column
        :label="$t('操作')"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            v-hasPermi="['ecw:voucher:see']"
            @click="verificationCancelClick(scope.row)"
            >{{ $t("查看") }}</el-button
          >
          <el-button
            v-if="scope.row.state === 0"
            size="mini"
            type="text"
            v-hasPermi="['ecw:voucher:edit']"
            @click="handleAdd(scope.row.id)"
            >{{ $t("编辑") }}</el-button
          >
          <!-- <el-button
            v-if="scope.row.state == "
            size="mini"
            type="text"
            @click="verificationClick(scope.row)"
            >{{ $t('核销') }}</el-button
          > -->
          <el-button
            v-if="
              scope.row.state == 4 ||
              scope.row.state == 5 ||
              scope.row.state == 6
            "
            size="mini"
            type="text"
            v-hasPermi="['ecw:voucher:cancelWriteOff']"
            @click="writeOffShow(2, scope.$index)"
            >{{ $t("反核销") }}</el-button
          >
          <el-button
            v-if="scope.row.state == 1"
            size="mini"
            type="text"
            v-hasPermi="['ecw:voucher:deApproval']"
            @click="writeOffShow(1, scope.$index)"
            >{{ $t("反审核") }}</el-button
          >
          <el-button
            v-if="scope.row.state == 7"
            size="mini"
            type="text"
            v-hasPermi="['ecw:vocher:cancelAppoval']"
            @click="cancelClick(scope.$index, 1)"
            >{{ $t("取消审核") }}</el-button
          >
          <el-button
            v-if="scope.row.state == 11"
            size="mini"
            type="text"
            v-hasPermi="['ecw:vocher:cancelWriteOfflNo']"
            @click="cancelClick(scope.$index, 3)"
            >{{ $t("取消反核销审核") }}</el-button
          >
          <el-button
            v-if="scope.row.state == 10"
            size="mini"
            type="text"
            v-hasPermi="['ecw:vocher:cancelWriteOffAll']"
            @click="cancelClick(scope.$index, 4)"
            >{{ $t("取消全部核销审核") }}</el-button
          >
          <el-button
            v-if="scope.row.state == 9"
            size="mini"
            type="text"
            v-hasPermi="['ecw:vocher:cancelAppovalNo']"
            @click="cancelClick(scope.$index, 2)"
            >{{ $t("取消反审核") }}</el-button
          >
          <el-button
            size="mini"
            type="text"
            v-if="
              scope.row.state == 9 ||
              scope.row.state == 7 ||
              scope.row.state == 11 ||
              scope.row.state == 10
            "
            v-hasPermi="['ecw:voucher:cancelWriteOff']"
            @click="
              $router.push(`/bpm/process-instance/detail?id=` + scope.row.bmpId)
            "
            >{{ $t("审核详情") }}</el-button
          >
          <el-button
            v-if="scope.row.state == 5"
            size="mini"
            type="text"
            v-hasPermi="['ecw:voucher:ballot']"
            @click="openInvoice(scope.row.id)"
            >{{ $t("开票") }}</el-button
          >
          <el-button
            v-if="
              scope.row.state == 1 ||
              scope.row.state == 2 ||
              scope.row.state == 3
            "
            v-hasPermi="['ecw:voucher:payment']"
            size="mini"
            type="text"
            @click="verificationCancelClick(scope.row)"
            >{{ $t("收款") }}</el-button
          >
          <el-button
            v-if="scope.row.state == 0"
            size="mini"
            type="text"
            v-hasPermi="['ecw:voucher:delete']"
            @click="deleteClick(scope.row)"
            >{{ $t("删除") }}</el-button
          >
          <el-button
            v-if="
              scope.row.state != 0 &&
              scope.row.state != 7 &&
              scope.row.state != 11 &&
              scope.row.state != 8 &&
              scope.row.state != 9
            "
            size="mini"
            type="text"
            @click="toprint(scope.row.id)"
            v-hasPermi="['ecw:voucher:print']"
            >{{ $t("打印") }}</el-button
          >
          <el-button
            v-if="
              scope.row.state != 0 &&
              scope.row.state != 7 &&
              scope.row.state != 11 &&
              scope.row.state != 8 &&
              scope.row.state != 9
            "
            size="mini"
            type="text"
            v-hasPermi="['ecw:voucher:derive']"
            @click="exportReceipt(scope.row.id)"
            >{{ $t("导出账单") }}</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.rows"
      @pagination="getList"
    />
    <!-- 对话框(添加 / 修改) -->
    <el-dialog
      :title="$t('导出账单')"
      :visible.sync="open"
      width="500px"
      style="margin-top: 20vh !important"
      append-to-body
    >
      <!-- <div slot="title" class="card-title" style='border-bottom: 2px solid #f8f8f8;'>
            <span>{{ $t('导出账单') }}</span>
            <i class="el-icon-close" @click="cancel"></i>
          </div> -->
      <div class="dialog-footer">
        <el-button
          type="primary"
          style="width: 130px"
          @click="submitForm(1)"
          v-loading="downloading"
          >{{ $t("国内账单") }}</el-button
        >
        <el-button
          plain
          v-loading="downloading"
          type="primary"
          style="width: 130px; margin: 0"
          @click="submitForm(2)"
          >Debite note</el-button
        >
      </div>
    </el-dialog>
    <el-dialog
      :title="writeOffType == 1 ? $t('收款单反审核') : $t('收款单反核销')"
      :visible.sync="dialogVisible"
      width="30%"
    >
      <div class="cancel_content">
        <span>{{ $t("申请理由") }}</span>
        <el-input
          type="textarea"
          :rows="6"
          v-model="reason"
          :placeholder="$t('请输入理由')"
        ></el-input>
      </div>
      <span slot="footer" class="dialog-footers">
        <el-button
          v-if="writeOffType == 1"
          type="primary"
          @click="writeOffClick()"
          >{{ $t("提交反审核") }}</el-button
        >
        <el-button v-else type="primary" @click="writeOffClick()">{{
          $t("提交反核销")
        }}</el-button>
        <el-button @click="dialogVisible = false">{{ $t("取消") }}</el-button>
      </span>
    </el-dialog>
    <el-dialog :title="cancelTitle" :visible.sync="cancelShow" width="30%">
      <div class="cancel_content">
        <span>{{ $t("申请理由") }}</span>
        <el-input
          type="textarea"
          :rows="6"
          v-model="cancelReason"
          :placeholder="$t('请输入取消理由')"
        ></el-input>
      </div>
      <span slot="footer" class="dialog-footers">
        <el-button type="primary" @click="cancelWriteOffClick()">{{
          $t("提交")
        }}</el-button>
        <el-button @click="cancelShow = false">{{ $t("取消") }}</el-button>
      </span>
    </el-dialog>
    <!--收款单批量反审核 对话框，一个逻辑一个对话框，
      避免做过多的逻辑判断 lanbm 2024-05-29 add-->
    <el-dialog :title="dialogTitle2" :visible.sync="dialogVisible2" width="30%">
      <div class="cancel_content">
        <span>{{ $t("申请理由") }}</span>
        <el-input
          type="textarea"
          :rows="6"
          v-model="reason"
          :placeholder="$t('请输入理由')"
        ></el-input>
      </div>
      <span slot="footer" class="dialog-footers">
        <el-button type="primary" @click="writeOffClick2()">{{
          $t("提交反审核")
        }}</el-button>
        <el-button @click="dialogVisible2 = false">{{ $t("取消") }}</el-button>
      </span>
    </el-dialog>
    <!--收款单批量反核销 对话框，一个逻辑一个对话框，
      避免做过多的逻辑判断 lanbm 2024-05-29 add-->
    <el-dialog :title="dialogTitle3" :visible.sync="dialogVisible3" width="30%">
      <div class="cancel_content">
        <span>{{ $t("申请理由") }}</span>
        <el-input
          type="textarea"
          :rows="6"
          v-model="reason"
          :placeholder="$t('请输入理由')"
        ></el-input>
      </div>
      <span slot="footer" class="dialog-footers">
        <el-button type="primary" @click="writeOffClick3()">{{
          $t("提交反核销")
        }}</el-button>
        <el-button @click="dialogVisible3 = false">{{ $t("取消") }}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { listSimpleUsers } from "@/api/system/user";
import { DICT_TYPE } from "@/utils/dict";
import CustomerSelector from "@/components/CustomerSelector";
import { getCurrencyPage } from "@/api/ecw/currency";
import {
  getReceiptList,
  // receiptVerification,
  // receiptVerificationCancel,
  receiptExportExcel,
  deleteReceipt,
  financeReceiptWriteOffNo,
  financeApproveNo,
  financeReceiptWriteOffNo2,
  financeApproveNo2,
  financeReceiptWriteOff2,
  cancelFinanceReceiptApproval,
  cancelFinanceReceiptApprovalNo,
  cancelFinanceReceiptWriteOffNo,
  cancelFinanceReceiptWriteOff,
} from "@/api/ecw/financial";

// lanbm 2024-05-30 添加注释
// 收款单状态 0 草稿，1 待收款，2 待提交
// 3 已部分核销，4已核销
// 5 已核销待开票，6 已开票，
// 7 审核中，8审核失败，9反审核中
// 10 全部核销中，11反核销审核中

export default {
  name: "EcwFinancialVoucher",
  components: {
    CustomerSelector,
  },
  data() {
    return {
      exportId: "",
      open: false,
      showSearch: true,
      loadings: false,
      form: {},
      creatorData: [],
      list: [],
      total: 0,
      dateType: [],
      loading: "",
      params: {},
      // 查询参数
      queryParams: {
        page: 1,
        rows: 20,
        dateType: null,
        date: null,
        originId: null,
        destinationId: null,
        transportId: null,
        isCargoControl: null,
        orderExceptionStatus: null,
        orderExceptionType: null,
        orderNo: null,
        consignorId: null,
        marks: null,
        prodId: null,
        productRecord: null,
        followUpSalesmanId: null,
      },
      dateFilter: [],
      downloading: false, // 导出状态
      dialogVisible: false,
      reason: "",
      writeOffType: 1,
      writeOffIndex: 0,
      cancelShow: false,
      cancelTitle: "",
      cancelReason: "",
      cancelIndex: 0,
      selectIndex: 0,
      // 选中数组
      ids: [],
      BpmNameList: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      listPar: [],
      dialogVisible2: false, //批量反审核对话框
      dialogTitle2: "收款单批量反审核",
      dialogVisible3: false, //批量反核销对话框
      dialogTitle3: "收款单批量反核销",
      currencyList: [],
    };
  },
  activated() {
    this.getList();
  },
  created() {
    //获取汇率 lanbm 2024-06-06 add
    getCurrencyPage(this.params).then(
      (res) => (this.currencyList = res.data.list)
    );

    let that = this;
    listSimpleUsers().then((res) => (that.creatorData = res.data));

    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      this.params = {};
      for (var key in this.queryParams) {
        if (this.queryParams[key]) {
          this.params[key] = this.queryParams[key];
        }
      }
      console.log(this.params);
      // 处理查询参数
      let params = { ...this.params };
      this.addBeginAndEndTime(params, this.dateRangeCreateTime, "createTime");
      // 执行查询
      getReceiptList(params).then((response) => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    changeCustomerId(e) {
      this.$set(this.queryParams, "customerId", e.id);
    },
    verificationClick(row) {
      const id = row.id;
      return this.$router.push("receiptDetail?id=" + id);
      //   this.$modal
      //     .confirm("您确认要核销吗？")
      //     .then(function () {
      //       return receiptVerification(id);
      //     })
      //     .then(() => {
      //       this.getList();
      //       this.$modal.msgSuccess("核销成功");
      //     })
      //     .catch(() => {});
    },
    verificationCancelClick(row) {
      const id = row.id;
      return this.$router.push("receiptDetail?id=" + id);
      // this.$modal
      //   .confirm("您确认要反核销吗？")
      //   .then(function () {
      //     return receiptVerificationCancel(id);
      //   })
      //   .then(() => {
      //     this.getList();
      //     this.$modal.msgSuccess("反核销成功");
      //   })
      //   .catch(() => {});
    },
    getCurrencyLabel(id) {
      let label = this.currencyList.filter((item) => item.id == id);
      if (label.length > 0)
        return this.$i18n.locale == "zh_CN"
          ? label[0].titleZh
          : label[0].titleEn;
      return "";
    },
    //显示取消审核弹窗
    cancelClick(index, type) {
      this.selectIndex = index;
      this.cancelIndex = type;
      this.cancelReason = "";
      if (this.cancelIndex == 1) {
        this.cancelTitle = this.$t("取消审核");
      } else if (this.cancelIndex == 2) {
        this.cancelTitle = this.$t("取消反审核");
      } else if (this.cancelIndex == 3) {
        this.cancelTitle = this.$t("取消反核销审核");
      } else {
        this.cancelTitle = this.$t("取消全部核销审核");
      }
      this.cancelShow = true;
    },
    //取消审核
    cancelWriteOffClick() {
      if (!this.cancelReason) {
        this.$modal.msgError(this.$t("请输入申请理由"));
        return;
      }
      var receiptId = this.list[this.selectIndex].id;
      if (this.cancelIndex == 1) {
        cancelFinanceReceiptApproval({
          receiptId: receiptId,
          remark: this.cancelReason,
        }).then((res) => {
          this.cancelShow = false;
          this.getList();
          this.$message.success(this.$t("提交成功"));
        });
      } else if (this.cancelIndex == 2) {
        cancelFinanceReceiptApprovalNo({
          receiptId: receiptId,
          remark: this.cancelReason,
        }).then((res) => {
          this.cancelShow = false;
          this.getList();
          this.$message.success(this.$t("提交成功"));
        });
      } else if (this.cancelIndex == 3) {
        cancelFinanceReceiptWriteOffNo({
          receiptId: receiptId,
          remark: this.cancelReason,
        }).then((res) => {
          this.cancelShow = false;
          this.getList();
          this.$message.success(this.$t("提交成功"));
        });
      } else {
        cancelFinanceReceiptWriteOff({
          receiptId: receiptId,
          remark: this.cancelReason,
        }).then((res) => {
          this.cancelShow = false;
          this.getList();
          this.$message.success(this.$t("提交成功"));
        });
      }
    },
    writeOffClick() {
      if (!this.reason) {
        this.$modal.msgError(this.$t("请输入申请理由"));
        return;
      }
      const receiptIdData = this.list[this.writeOffIndex];
      if (this.writeOffType == 1) {
        financeApproveNo({
          receiptId: receiptIdData.id,
          receiptNo: receiptIdData.receiptNo,
          remark: this.reason,
        }).then((res) => {
          this.getList();
          this.$message.success(this.$t("提交成功"));
          this.dialogVisible = false;
        });
      } else {
        financeReceiptWriteOffNo({
          receiptId: receiptIdData.id,
          receiptNo: receiptIdData.receiptNo,
          remark: this.reason,
        }).then((res) => {
          this.getList();
          this.$message.success(this.$t("提交成功"));
          this.dialogVisible = false;
        });
      }
    },
    deleteClick(row) {
      const id = row.id;
      this.$modal
        .confirm(this.$t("是否确认删除该收款单") + "?")
        .then(function () {
          return deleteReceipt(id);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess(this.$t("删除成功"));
        })
        .catch(() => {});
    },
    /** 搜索按钮操作 */
    handleQuery() {
      if (this.dateFilter && this.dateFilter.length > 0) {
        this.queryParams.beginCreateTime = this.dateFilter[0];
        this.queryParams.endCreateTime = this.dateFilter[1];
      } else {
        this.queryParams.beginCreateTime = "";
        this.queryParams.endCreateTime = "";
      }
      this.queryParams.page = 1;
      this.getList();
    },
    handleQuery2() {
      //批量反审核 lanbm 2024-05-14 add
      if (this.ids.length == 0) {
        this.$message.error(this.$t("请选择需要批量反审核收款单。"));
        return;
      }

      this.listPar = [];
      for (var i = 0; i < this.ids.length; i++) {
        if (this.ids[i].state != 1) {
          this.$message.error(this.$t("选中项中有不符合反审核条件的收款单。"));
          return;
        }
        let obj = {
          receiptId: this.ids[i].id,
          receiptNo: this.ids[i].receiptNo,
          remark: this.reason,
        };
        this.listPar.push(obj);
      }
      this.reason = "";
      this.dialogVisible2 = true;
    },
    writeOffClick2() {
      //批量反审核 提交响应函数
      financeReceiptWriteOffNo2(this.listPar).then((res) => {
        this.getList();
        this.$message.success(this.$t("提交成功"));
        this.reason = "";
        this.dialogVisible2 = true;
      });
    },
    handleQuery3() {
      //批量反核销 lanbm 2024-05-14 add
      if (this.ids.length == 0) {
        this.$message.error(this.$t("请选择需要批量反核销收款单。"));
        return;
      }
      this.listPar = [];
      for (var i = 0; i < this.ids.length; i++) {
        //必须满足能反核销的状态条件
        if (
          this.ids[i].state == 4 ||
          this.ids[i].state == 5 ||
          this.ids[i].state == 6
        ) {
          let obj = {
            receiptId: this.ids[i].id,
            receiptNo: this.ids[i].receiptNo,
            remark: this.reason,
          };
          this.listPar.push(obj);
        } else {
          this.$message.error(this.$t("选中项中有不符合反审核条件的收款单。"));
          return;
        }
      }
      this.reason = "";
      this.dialogVisible3 = true;
    },
    writeOffClick3() {
      //批量反核销 提交按钮响应函数
      financeReceiptWriteOffNo2(this.listPar).then((res) => {
        this.getList();
        this.$message.success(this.$t("提交成功"));
        this.reason = "";
        this.dialogVisible3 = true;
      });
    },
    handleQuery4() {
      //批量核销 lanbm 2024-05-14 add
      if (this.ids.length == 0) {
        //校验参数
        this.$message.error(this.$t("请选择需要批量核销的收款单。"));
        return;
      }
      //var str = JSON.stringify(this.ids);
      this.listPar = [];
      for (var i = 0; i < this.ids.length; i++) {
        if (this.ids[i].state == 0) {
          this.$message.error(this.ids[i].receiptNo + "是草稿状态，不能核销。");
          return;
        }
        if (this.ids[i].state == 4) {
          this.$message.error(
            this.ids[i].receiptNo + "是已核销状态，不用再次核销。"
          );
          return;
        }

        let obj = {
          receiptId: this.ids[i].id,
          receiptNo: this.ids[i].receiptNo,
          remark: this.reason,
        };
        this.listPar.push(obj);
      }
      //var str2 = JSON.stringify(listPar);
      financeReceiptWriteOff2(this.listPar).then((res) => {
        this.getList();
        this.$message.success(this.$t("提交成功"));
        this.dialogVisible = false;
      });
    },
    /** 新增按钮操作 */
    handleAdd(id) {
      return this.$router.push("creatCollection?id=" + id);
    },
    toprint(id) {
      return this.$router.push("printVoucher?id=" + id);
    },
    openInvoice(id) {
      return this.$router.push("openInvoice?id=" + id);
    },
    exportReceipt(id) {
      this.open = true;
      this.exportId = id;
    },
    //显示反审核反核销弹窗
    writeOffShow(type, index) {
      this.writeOffType = type;
      this.writeOffIndex = index;
      this.reason = "";
      this.dialogVisible = true;
    },
    submitForm(type) {
      this.downloading = true;
      receiptExportExcel({ id: this.exportId, billType: type })
        .then((response) => {
          this.$download.excel(
            response,
            `${type === 1 ? this.$t("国内账单") : "Debite_note"}.xls`
          );
          this.open = false;
        })
        .finally(() => (this.downloading = false));
    },
    paymentDetail2(row) {
      //到订单详情 lanbm 2024-05-29 add
      const id = row.orderId;
      //路由地址，不是文件路径地址
      return this.$router.push("/order/detail?orderId=" + id);
    },
    handleSelectionChange(selection) {
      //表格多选函数 lanbm 2024-05-20 add
      this.id = [];
      this.ids = selection;
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
  },
};
</script>

 <style scoped>
.card {
  margin-top: 20px;
}
.dialog-footer {
  padding: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  height: 160px;
}
.dialog-footers {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-title {
  font-size: 18px;
  font-weight: bold;
}
.cancel_content {
  display: flex;
  flex-direction: column;
}
.cancel_content span {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 10px;
}
</style>
