在 submitDetail 函数中,将 acTaxPiIncomeReportingDetail 的值存储到 submitForm 函数中的 form.acTaxPiIncomeReportingDetail,可以通过以下步骤实现:

  1. 在 submitDetail 函数中,将 acTaxPiIncomeReportingDetail 赋值给一个临时变量 tempDetail:
submitDetail() {
  const tempDetail = { ...this.form.acTaxPiIncomeReportingDetail };
  // 其他操作
}
  1. 在 submitForm 函数中,将 tempDetail 的值赋给 form.acTaxPiIncomeReportingDetail:
submitForm() {
  // 其他操作
  this.form.acTaxPiIncomeReportingDetail = tempDetail;
  // 其他操作
}

这样可以确保在 submitForm 提交的时候,form.acTaxPiIncomeReportingDetail 不为 null,并且包含了来自 submitDetail 函数的值。

示例代码:

calculateIncome() {
  const formula = this.form.applicableFormula;
  const detail = this.form.acTaxPiIncomeReportingDetail;
  let income = 0;

  switch (formula) {
    case '0':
    case '4':
      income = (detail.domesticPayment * detail.domesticWorkDays) / detail.gregorianCalendarDays;
      break;
    case '2':
    case '6':
      income = (detail.totalRevenue * detail.domesticWorkDays) / detail.gregorianCalendarDays;
      break;
    case '3':
    case '5':
      income = detail.totalRevenue * (1 - (detail.abroadPayment / detail.totalRevenue) * (detail.abroadWorkDays / detail.gregorianCalendarDays));
      income = (detail.totalRevenue * detail.domesticWorkDays) / detail.gregorianCalendarDays;
      break;
    case '1':
      income = detail.abroadPayment;
      break;
    case '7':
    case '8':
      income = detail.totalRevenue;
      break;
    default:
      break;
  }

  // 返回计算后的本期收入
  return income;
},
opendetail() {
  this.dialogVisible = true;
  this.isViewMode = false;
},
submitForm() {
  // this.form = { ...formdata }
  console.log(this.form.incomePeriodDateEnd, 'person');
  this.$refs['form'].validate((valid) => {
    if (valid) {
      this.$refs.form.validateField();
      this.form.acTaxPiPersonCalculationSchedule.acTaxableIncome = this.acTaxableincome;
      this.form.acTaxPiPersonCalculationSchedule.acTaxableAmount = this.acTaxableamount;
      this.form.acTaxPiPersonCalculationSchedule.acDeductiblePaymentAmount = this.acDeductibleAmount;
      this.form.acTaxPiPersonCalculationSchedule.payableTaxAmount = this.payableTaxamount;
      this.form.reportingPeriodDate = this.collection;
      // const existperson = this.personInfo.find(
      //   (item) => item.personId === this.form.acTaxPiPersonVo.personId
      // );
      // if (existperson) {
      //   this.$message.error('person 已存在');
      //   return;
      // }
      if (this.form.personId != null) {
        this.form.companyId = this.companyId;
        updateReportingEquityIncentive(this.form).then((response) => {
          console.log(this.form.incomePeriodDateEnd, 'edit');
          this.msgSuccess('修改成功');
          this.open = false;
          this.getList();
        });
      } else {
        this.form.acTaxPiPersonCalculationSchedule.taxRate = this.defaultTax;
        this.form.personId = this.form.acTaxPiPersonVo.personId;
        // this.form.reportingPeriodDate = this.collection;
        this.form.companyId = this.companyId;
        console.log(this.form.personId, 'acTaxPiPersonVo');
        addReportingEquityIncentive(this.form).then((response) => {
          console.log(response, 'resssssssssss');
          this.msgSuccess('新增成功');
          this.open = false;
          this.getList();
        });
      }
    } else {
      console.log('error submit!!');
      return false;
    }
  });
},
// 明细对话框
submitDetail() {
  const tempDetail = { ...this.form.acTaxPiIncomeReportingDetail };
  this.isViewMode = false;
  const formitems = ['gregorianCalendarDays', 'domesticWorkDays', 'abroadWorkDays', 'totalRevenue', 'domesticPayment', 'abroadPayment'];
  const formdata = this.form;
  console.log(formdata, 'fffffff');
  formitems.forEach((item) => {
    this.form.acTaxPiIncomeReportingDetail[item] = formdata.acTaxPiIncomeReportingDetail[item];
  });
  const income = this.calculateIncome();
  this.form.equityIncentiveIncome = income;
  this.dialogVisible = false;
},

注意:

  • 使用 spread syntax (三个点) 创建一个 tempDetail 变量,以确保它是一个新的对象,而不是对原始对象的引用。
  • 在 submitForm 函数中,使用 tempDetail 变量来更新 form.acTaxPiIncomeReportingDetail。
  • 确保在调用 submitForm 函数之前,调用 submitDetail 函数,以便 tempDetail 变量包含正确的值。

通过以上方法,您可以将 submitDetail 函数中的 acTaxPiIncomeReportingDetail 值成功传递到 submitForm 函数中,并避免 form.acTaxPiIncomeReportingDetail 为 null 的错误。

Vue.js 中如何将 submitDetail 函数中的值传递到 submitForm 函数

原文地址: https://www.cveoy.top/t/topic/pdtF 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录