Bladeren bron

账单缴费修改消费券逻辑以及金额计算逻辑

xiongxing 1 week geleden
bovenliggende
commit
b7390b717b
1 gewijzigde bestanden met toevoegingen van 115 en 181 verwijderingen
  1. 115 181
      src/views/elderly/fee/bill-pay/Form.vue

+ 115 - 181
src/views/elderly/fee/bill-pay/Form.vue

@@ -65,7 +65,7 @@
           <template #default="scope">
 
               <el-input-number  v-if="isEdit && scope.row.payStatus == 0" @blur="handlePrice(scope.row, 1)" v-model="scope.row.totalAmount" controls-position="right"/>
-              <span v-else>{{ (scope.row.payStatus == 1 || scope.row.payStatus == 2) ? (formatTotalMonth(scope.row) - scope.row.payAmount).toFixed(2) : formatTotalMonth(scope.row) }}</span>
+              <span v-else>{{ scope.row.expenseSource == 'consumer_voucher' ? scope.row.payAmount : (scope.row.payStatus == 1 || scope.row.payStatus == 2) ? (formatTotalMonth(scope.row) - scope.row.payAmount).toFixed(2) : formatTotalMonth(scope.row) }}</span>
 
           </template>
         </el-table-column>
@@ -124,7 +124,7 @@
           <el-table-column prop="totalAmount" label="应收金额(元)" align="center">
             <template #default="scope">
               <el-input-number  v-if="isEdit && scope.row.payStatus == 0" @blur="handlePrice(scope.row, 2)" v-model="scope.row.totalAmount" controls-position="right"/>
-              <span v-else>{{ (scope.row.payStatus == 1 || scope.row.payStatus == 2) ? (tableRowPay(scope.row) - scope.row.payAmount).toFixed(2) : tableRowPay(scope.row) }}</span>
+              <span v-else>{{ scope.row.expenseSource == 'consumer_voucher' ? scope.row.payAmount : (scope.row.payStatus == 1 || scope.row.payStatus == 2) ? (tableRowPay(scope.row) - scope.row.payAmount).toFixed(2) : tableRowPay(scope.row) }}</span>
 
           </template>
           </el-table-column>
@@ -208,7 +208,7 @@
           <el-table-column prop="totalAmount" label="应收金额(元)" align="center">
             <template #default="scope">
               <el-input-number  v-if="isEdit" @blur="handlePrice(scope.row, 3)" v-model="scope.row.totalAmount" controls-position="right"/>
-              <span v-else>{{ (scope.row.payStatus == 1 || scope.row.payStatus == 2) ? (tableRowPay(scope.row) - scope.row.payAmount).toFixed(2) : tableRowPay(scope.row) }}</span>
+              <span v-else>{{ scope.row.expenseSource == 'consumer_voucher' ? scope.row.payAmount : (scope.row.payStatus == 1 || scope.row.payStatus == 2) ? (tableRowPay(scope.row) - scope.row.payAmount).toFixed(2) : tableRowPay(scope.row) }}</span>
 
             </template>
           </el-table-column>
@@ -261,7 +261,7 @@
           <el-table-column prop="totalAmount" label="应收金额(元)" align="center">
             <template #default="scope">
               <el-input-number  v-if="isEdit && scope.row.payStatus == 0" @blur="handlePrice(scope.row, 5)" v-model="scope.row.totalAmount" controls-position="right"/>
-              <span v-else>{{ (scope.row.payStatus == 1 || scope.row.payStatus == 2) ? (tableRowPay(scope.row) - scope.row.payAmount).toFixed(2) : tableRowPay(scope.row) }}</span>
+              <span v-else>{{ scope.row.expenseSource == 'consumer_voucher' ? scope.row.payAmount : (scope.row.payStatus == 1 || scope.row.payStatus == 2) ? (tableRowPay(scope.row) - scope.row.payAmount).toFixed(2) : tableRowPay(scope.row) }}</span>
 
             </template>
           </el-table-column>
@@ -442,7 +442,7 @@
           <el-table-column prop="totalAmount" label="应收金额(元)" align="center">
             <template #default="scope">
               <el-input-number  v-if="isEdit && scope.row.payStatus == 0" @blur="handlePrice(scope.row, 3)" v-model="scope.row.totalAmount" controls-position="right"/>
-              <span v-else>{{ (scope.row.payStatus == 1 || scope.row.payStatus == 2) ? (tableRowPay(scope.row) - scope.row.payAmount).toFixed(2) : tableRowPay(scope.row) }}</span>
+              <span v-else>{{ scope.row.expenseSource == 'consumer_voucher' ? scope.row.payAmount : (scope.row.payStatus == 1 || scope.row.payStatus == 2) ? (tableRowPay(scope.row) - scope.row.payAmount).toFixed(2) : tableRowPay(scope.row) }}</span>
               <!-- <span class="underline" v-if="!settingStore.getRceivable||settingStore.getAdmissionBillRoundUp">{{ formatNum(scope.row.totalAmount) }}</span> -->
             </template>
           </el-table-column>
@@ -514,7 +514,7 @@
 <script setup lang="ts">
 import { DICT_TYPE, getDictLabel, getDictOptions } from '@/utils/dict'
 import { getExpenseOrderDetail, exportExpenseOrderItemExcel, editExpenseOrder } from '@/api/elderly/fee/bill-pay'
-import { formatDecimal, formatNum, formatRid, formatRound, formatCeil } from '@/utils/formatter'
+import { formatDecimal, formatNum, formatRid, formatCeil } from '@/utils/formatter'
 import { useSettingStore } from '@/store/modules/setting'
 import download from '@/utils/download'
 import { tableHeaderColor } from '@/utils/table'
@@ -600,148 +600,114 @@ const totalAllAmount = computed(()=>{
   return formatNum(dataForm.value.totalMonthPrice + dataForm.value.totalOneTimeFeePrice + dataForm.value.totalDepositPrice + dataForm.value.totalStageExpandPrice)
 })
 
-const monthSubtotalAmount = computed(() => monthSelected.value.length ? formatNum(dataForm.value.totalMonthPrice) : 0)
-const depositSubtotalAmount = computed(() => depositSelected.value.length ? formatNum(dataForm.value.totalDepositPrice) : 0)
-const oneTimeSubtotalAmount = computed(() => oneTimeSelected.value.length ? formatNum(dataForm.value.totalOneTimeFeePrice) : 0)
-const stageSubtotalAmount = computed(() => stageExpandSelected.value.length ? formatNum(dataForm.value.totalStageExpandPrice) : 0)
+const monthSubtotalAmount = computed(() =>
+  isDetail.value ? dataForm.value.totalMonthPrice : monthSelected.value.length ? dataForm.value.totalMonthPrice : 0
+)
+const depositSubtotalAmount = computed(() =>
+  isDetail.value ? dataForm.value.totalDepositPrice : depositSelected.value.length ? dataForm.value.totalDepositPrice : 0
+)
+const oneTimeSubtotalAmount = computed(() =>
+  isDetail.value
+    ? dataForm.value.totalOneTimeFeePrice
+    : oneTimeSelected.value.length
+      ? dataForm.value.totalOneTimeFeePrice
+      : 0
+)
+const stageSubtotalAmount = computed(() =>
+  isDetail.value
+    ? dataForm.value.totalStageExpandPrice
+    : stageExpandSelected.value.length
+      ? dataForm.value.totalStageExpandPrice
+      : 0
+)
 const stageExpandSubtotalAmount = stageSubtotalAmount
 
-// 固定费用
-const formatTotalMonth = (item)=>{
-  if(dataForm.value.type == 1){
-    if(settingStore.getAdmissionBill == 2){ // 取整
-      return Number(formatCeil(item.totalAmount))
-    }else if(settingStore.getAdmissionBill == 3){ // 四舍五入保留两位
-      return formatNum(item.roundTwoDecimalAmount)
-    }else if(settingStore.getAdmissionBill == 4){ // 四舍五入取整
-      return formatNum(item.roundAmount)
-    }else{ // 应收
-      return formatNum(item.totalAmount)
-    }
-  }else{
-    if (rounding.value){
-      return formatNum(item.roundAmount)
-    }else if(fixed2Num.value){
-      return formatNum(item.roundTwoDecimalAmount)
-    }else{
-      return formatNum(item.totalAmount)
+const getReceivableAmount = (item) => {
+  if (item?.expenseSource == 'consumer_voucher') {
+    return Number(item.payAmount || 0)
+  }
+  if (item?.expenseSource == 'long_term_care_insurance') {
+    return Number(item.totalAmount || 0)
+  }
+  if (dataForm.value.type == 1 && item?.isMonthlyExpense == 1) {
+    if (settingStore.getAdmissionBill == 2) {
+      return Number(formatCeil(item.totalAmount || 0))
+    } else if (settingStore.getAdmissionBill == 3) {
+      return Number(formatNum(item.roundTwoDecimalAmount || 0))
+    } else if (settingStore.getAdmissionBill == 4) {
+      return Number(formatNum(item.roundAmount || 0))
+    } else {
+      return Number(formatNum(item.totalAmount || 0))
     }
   }
+  if (rounding.value) {
+    return Number(formatNum(item.roundAmount || 0))
+  }
+  if (fixed2Num.value) {
+    return Number(formatNum(item.roundTwoDecimalAmount || 0))
+  }
+  return Number(formatNum(item.totalAmount || 0))
+}
+
+const getPaidAmount = (item) => {
+  if (item?.payStatus == 1) {
+    return getReceivableAmount(item)
+  }
+  if (item?.payStatus == 2) {
+    return Number(item.payAmount || 0)
+  }
+  return 0
 }
 
-// 取整账单总额
-const totalRoundAndTwoDecimalAmount = computed(()=>{
-  let num = 0, decimal = 0
-  dataForm.value.monthArr.map(item => {
-    num += item.roundAmount
-    decimal += item.roundTwoDecimalAmount
+const billTotalAmount = computed(() => {
+  let total = 0
+  dataForm.value.monthArr.map((item) => {
+    total += getReceivableAmount(item)
   })
-  dataForm.value.depositArr.map(item => {
-    num += item.roundAmount
-    decimal += item.roundTwoDecimalAmount
+  dataForm.value.depositArr.map((item) => {
+    total += getReceivableAmount(item)
   })
-  dataForm.value.oneTimeFeeArr.map(item => {
-    num += item.roundAmount
-    decimal += item.roundTwoDecimalAmount
+  dataForm.value.oneTimeFeeArr.map((item) => {
+    total += getReceivableAmount(item)
   })
-  dataForm.value.stageExpandFeeArr.map(item => {
-    num += item.roundAmount
-    decimal += item.roundTwoDecimalAmount
+  dataForm.value.stageExpandFeeArr.map((item) => {
+    total += getReceivableAmount(item)
   })
-  return {
-    num,
-    decimal
-  }
+  return total
 })
 
-// 账单总额 1.入院且入院配置了向上取整 2.账单四舍五入 3.账单实际金额 (需要减去长护险)
-const tAmount = computed(()=>{
-  let payAmountTotal = 0
-  dataForm.value.monthArr.map(item => {
-    payAmountTotal += item.payAmount ? Number(item.payAmount) : 0
-  })
-  if(dataForm.value.type == 1){ //1入院,2月度
-    return totalAllAmount.value
-    // if(settingStore.getAdmissionBill == 2){ // 向上取整
-    // }else if(settingStore.getAdmissionBill == 3){ // 四舍五入保留两位
-
-    // }else{ // 应收
+// 固定费用
+const formatTotalMonth = (item) => {
+  if (item?.expenseSource == 'consumer_voucher') {
+    return item.payAmount
+  }
+  return formatNum(getReceivableAmount(item))
+}
 
-    // }
-  }else{
-    console.log("取值",rounding.value,fixed2Num.value)
-    if(rounding.value){
-      return formatRound(totalRoundAndTwoDecimalAmount.value.num - payAmountTotal)
-    }else if(fixed2Num.value){
-      return formatNum(totalRoundAndTwoDecimalAmount.value.decimal - payAmountTotal)
-    }else{
-      return formatNum(dataForm.value.actualAmount - payAmountTotal)
-    }
+const tAmount = computed(() => {
+  if (isDetail.value) {
+    return formatNum(billTotalAmount.value)
   }
+  return totalAllAmount.value
 })
 
 // 已缴金额(取整,保留两位,应收)
 const totalPayActualAmount = computed(() => {
   let num = 0
-  dataForm.value.monthArr.map(item => {
-    if(item.payStatus == 1){
-      // 需要增加一层入院金额的判断
-      if(dataForm.value.type == '1'){
-        if(settingStore.getAdmissionBill == 2){ // 向上取整
-          num += Number(formatCeil(item.totalAmount))
-        }else if(settingStore.getAdmissionBill == 3){ // 四舍五入保留两位
-          num += item.roundTwoDecimalAmount
-        }else if(settingStore.getAdmissionBill == 4){ // 四舍五入取整
-          num += item.roundAmount
-        }else{ // 应收
-          num += Number(formatNum(item.totalAmount))
-        }
-      }else{
-        if(rounding.value){
-          num += item.roundAmount
-        }else if(fixed2Num.value){
-          num += item.roundTwoDecimalAmount
-        }else{
-          num += Number(formatNum(item.totalAmount))
-        }
-      }
-    }
+  dataForm.value.monthArr.map((item) => {
+    num += getPaidAmount(item)
   })
-  dataForm.value.depositArr.map(item => {
-    if(item.payStatus == 1){
-      if(rounding.value){
-        num += item.roundAmount
-      }else if(fixed2Num.value){
-        num += item.roundTwoDecimalAmount
-      }else{
-        num += Number(formatNum(item.totalAmount))
-      }
-    }
+  dataForm.value.depositArr.map((item) => {
+    num += getPaidAmount(item)
   })
-  dataForm.value.oneTimeFeeArr.map(item => {
-    if(item.payStatus == 1){
-      if(rounding.value){
-        num += item.roundAmount
-      }else if(fixed2Num.value){
-        num += item.roundTwoDecimalAmount
-      }else{
-        num += Number(formatNum(item.totalAmount))
-      }
-    }
+  dataForm.value.oneTimeFeeArr.map((item) => {
+    num += getPaidAmount(item)
   })
-  dataForm.value.stageExpandFeeArr.map(item => {
-    if(item.payStatus == 1){
-      if(rounding.value){
-        num += item.roundAmount
-      }else if(fixed2Num.value){
-        num += item.roundTwoDecimalAmount
-      }else{
-        num += Number(formatNum(item.totalAmount))
-      }
-    }
+  dataForm.value.stageExpandFeeArr.map((item) => {
+    num += getPaidAmount(item)
   })
 
-  if(roundDown.value){
+  if (roundDown.value) {
     num -= roundDown.value
   }
   return num
@@ -752,6 +718,8 @@ const totalPayActualAmount = computed(() => {
 const tableRowPay = (row) => {
   if(row.expenseSource == 'long_term_care_insurance'){
     return formatNum(row.totalAmount)
+  }else if(row.expenseSource == 'consumer_voucher'){
+    return row.payAmount
   }else if(rounding.value){
     return formatNum(row.roundAmount)
   }else if(fixed2Num.value){
@@ -824,7 +792,9 @@ const handleMonthSelectionChange = (val) => {
   val.map((item) => {// 入院账单固定费用有设置向上取整
     if(item.isShow){
       if(dataForm.value.type == '1'){
-        if(settingStore.getAdmissionBill == 2){ // 向上取整
+        if(item.expenseSource == 'consumer_voucher'){
+          total += formatDecimal(getReceivableAmount(item)) as number
+        }else if(settingStore.getAdmissionBill == 2){ // 向上取整
           total += formatDecimal(Number(formatCeil(item.totalAmount - (item.payAmount || 0)))) as number
         }else if(settingStore.getAdmissionBill == 3){ // 四舍五入保留两位
           total += formatDecimal(formatNum(item.roundTwoDecimalAmount - (item.payAmount || 0))) as number
@@ -834,7 +804,9 @@ const handleMonthSelectionChange = (val) => {
           total += formatDecimal(formatNum(item.totalAmount - (item.payAmount || 0))) as number
         }
       }else{
-        if(rounding.value){ // 账单取整
+        if(item.expenseSource == 'consumer_voucher'){
+          total += formatDecimal(getReceivableAmount(item)) as number
+        }else if(rounding.value){ // 账单取整
           total += formatDecimal(formatNum(item.roundAmount - (item.payAmount || 0))) as number
         } else if(fixed2Num.value){ // 四舍五入保留两位
           total += formatDecimal(formatNum(item.roundTwoDecimalAmount - (item.payAmount || 0))) as number
@@ -855,7 +827,9 @@ const handleDepositSelectionChange = (val) => {
   let total = 0
   val.map((item) => {
     if(item.isShow){
-      if(rounding.value){ // 账单取整
+      if(item.expenseSource == 'consumer_voucher'){
+        total += formatDecimal(getReceivableAmount(item)) as number
+      }else if(rounding.value){ // 账单取整
         total += formatDecimal(formatNum(item.roundAmount - (item.payAmount || 0))) as number
       } else if(fixed2Num.value){ // 四舍五入保留两位
         total += formatDecimal(formatNum(item.roundTwoDecimalAmount - (item.payAmount || 0))) as number
@@ -875,7 +849,9 @@ const handleOneTimeSelectionChange = (val) => {
   let total = 0
   val.map((item) => {
     if(item.isShow){
-      if(rounding.value){ // 账单取整
+      if(item.expenseSource == 'consumer_voucher'){
+        total += formatDecimal(getReceivableAmount(item)) as number
+      }else if(rounding.value){ // 账单取整
         total += formatDecimal(formatNum(item.roundAmount - (item.payAmount || 0))) as number
       } else if(fixed2Num.value){ // 四舍五入保留两位
         total += formatDecimal(formatNum(item.roundTwoDecimalAmount - (item.payAmount || 0))) as number
@@ -895,7 +871,9 @@ const handleStageExpandSelectionChange = (val) => {
   let total = 0
     val.map((item) => {
       if(item.isShow){
-        if(rounding.value){ // 账单取整
+        if(item.expenseSource == 'consumer_voucher'){
+          total += formatDecimal(getReceivableAmount(item)) as number
+        }else if(rounding.value){ // 账单取整
           total += formatDecimal(formatNum(item.roundAmount - (item.payAmount || 0))) as number
         } else if(fixed2Num.value){ // 四舍五入保留两位
           total += formatDecimal(formatNum(item.roundTwoDecimalAmount - (item.payAmount || 0))) as number
@@ -1092,68 +1070,24 @@ const open = async (id, detail) => {
       totalC = 0,
       totalD = 0
     monthArr.map((item) => {
-      if (item.payStatus == 1) {
-        if(dataForm.value.type == 1){ // 入住
-          if(settingStore.getAdmissionBill == 2){ // 向上取整
-            totalA += formatDecimal(formatCeil(item.totalAmount)) as number
-          }else if(settingStore.getAdmissionBill == 3){ // 四舍五入保留两位
-            totalA += formatDecimal(formatNum(item.roundTwoDecimalAmount))
-          }else if(settingStore.getAdmissionBill == 4){ // 四舍五入取整
-            totalA += formatDecimal(formatNum(item.roundAmount))
-          }else{ // 应收
-            totalA += formatDecimal(formatNum(item.totalAmount)) as number
-          }
-        }else{
-          if(rounding.value){
-            totalA += formatDecimal(formatNum(item.roundAmount)) as number
-          }else if(fixed2Num.value){
-            totalA += formatDecimal(formatNum(item.roundTwoDecimalAmount))
-          }else{
-            totalA += formatDecimal(formatNum(item.totalAmount)) as number
-          }
-        }
-      }
+      totalA += getPaidAmount(item)
     })
-    dataForm.value.totalMonthPrice = formatRid(totalA) as number
+    dataForm.value.totalMonthPrice = totalA
 
     depositArr.map((item) => {
-      if (item.payStatus == 1) {
-        if(rounding.value){
-          totalB += formatDecimal(formatNum(item.roundAmount)) as number
-        }else if(fixed2Num.value){
-          totalB += formatDecimal(formatNum(item.roundTwoDecimalAmount))
-        }else{
-          totalB += formatDecimal(item.totalAmount) as number
-        }
-      }
+      totalB += getPaidAmount(item)
     })
-    dataForm.value.totalDepositPrice = formatRid(totalB) as number
+    dataForm.value.totalDepositPrice = totalB
 
     oneTimeFeeArr.map((item) => {
-      if (item.payStatus == 1) {
-        if(rounding.value){
-          totalC += formatDecimal(formatNum(item.roundAmount)) as number
-        }else if(fixed2Num.value){
-          totalC += formatDecimal(formatNum(item.roundTwoDecimalAmount))
-        }else{
-          totalC += formatDecimal(item.totalAmount) as number
-        }
-      }
+      totalC += getPaidAmount(item)
     })
-    dataForm.value.totalOneTimeFeePrice = formatRid(totalC) as number
+    dataForm.value.totalOneTimeFeePrice = totalC
 
     stageExpandFeeArr.map((item) => {
-      if(item.payStatus == 1){
-        if(rounding.value){
-          totalD += formatDecimal(formatNum(item.roundAmount)) as number
-        }else if(fixed2Num.value){
-          totalD += formatDecimal(formatNum(item.roundTwoDecimalAmount))
-        }else{
-          totalD += formatDecimal(item.totalAmount) as number
-        }
-      }
+      totalD += getPaidAmount(item)
     })
-    dataForm.value.totalStageExpandPrice = formatRid(totalD) as number
+    dataForm.value.totalStageExpandPrice = totalD
   }
 
   loading.value = false