Files
sunProduct/src/views/system/Sdb/SdbCashier/index.vue
Zy 41ba642155 10/21
1. 删除多余报表
2026-10-23 08:25:07 +08:00

1317 lines
46 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="p-2 h-full flex flex-col">
<PageHeader></PageHeader>
<div class="mb-[10px]">
<el-card shadow="hover">
<el-form ref="queryFormRef" :inline="true" :model="queryParams" label-width="auto" @submit.prevent="handleQuery">
<div>
<el-form-item label="区域" prop="buildingId">
<el-select
v-model="queryParams.buildingId"
clearable
placeholder="请选择区域"
@change="handleChangeBuilding"
@clear="handleClearBuildingId"
>
<el-option v-for="(item, index) in buildingList" :key="index" :label="item.buildingName" :value="item.id"></el-option>
</el-select>
</el-form-item>
<el-form-item label="房号" prop="houseId">
<el-select v-model="queryParams.houseId" clearable placeholder="请选择房号" @clear="handleClear('houseId')">
<el-option v-for="item in houseList" :key="item.houseId" :label="item.houseNo" :value="item.houseId" />
</el-select>
</el-form-item>
</div>
<div>
<el-form-item label="收费项目" prop="itemId">
<el-select v-model="queryParams.chargeItemId" clearable multiple placeholder="请选择收费项目" @clear="handleClear('chargeItemId')">
<el-option
v-for="(item, index) in chargeItems"
:key="index"
:disabled="item.status === '1'"
:label="item.itemName"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="缴费周期">
<el-date-picker
v-model="queryParams.startDate"
clearable
format="YYYY-MM-DD"
placeholder="请选择开始缴费日期"
type="date"
value-format="YYYY-MM-DD"
@clear="handleClearChargePeriod('start')"
/>
<el-date-picker
v-model="queryParams.endDate"
format="YYYY-MM-DD"
placeholder="请选择结束缴费日期"
style="margin-left: 10px"
type="date"
value-format="YYYY-MM-DD"
@clear="handleClearChargePeriod('end')"
/>
</el-form-item>
<el-form-item label="缴费时间">
<el-date-picker
v-model="queryParams.payTimeBegin"
clearable
format="YYYY-MM-DD HH:mm:ss"
placeholder="请选择开始缴费时间"
type="datetime"
value-format="YYYY-MM-DD HH:mm:ss"
@clear="handleClear('payTimeBegin')"
/>
<el-date-picker
v-model="queryParams.payTimeEnd"
clearable
format="YYYY-MM-DD HH:mm:ss"
placeholder="请选择结束缴费时间"
style="margin-left: 10px"
type="datetime"
value-format="YYYY-MM-DD HH:mm:ss"
@clear="handleClear('payTimeEnd')"
/>
</el-form-item>
<el-form-item label="承租方姓名" prop="residentName">
<el-input
v-model.trim="queryParams.residentName"
clearable
maxlength="30"
placeholder="请选择承租方姓名"
@clear="handleClear('residentName')"
></el-input>
</el-form-item>
<el-form-item>
<div style="text-align: right">
<el-button type="primary" @click="handleQuery">搜索</el-button>
<el-button @click="resetQuery">重置</el-button>
</div>
</el-form-item>
</div>
</el-form>
</el-card>
</div>
<div class="actionsBox">
<div class="tabs-box">
<div
v-for="(item, index) in tabs"
:key="index"
:class="{
active: activeTabs === item.value
}"
class="tabs-items"
@click="changeTabs(item.value)"
>
{{ item.type }}
</div>
</div>
<div class="actions">
<el-button :disabled="!single" @click="handleIncome(false)">收费</el-button>
<el-button :disabled="!printSingle" @click="printPIaoJuByOnly(false)">打印票据</el-button>
<el-button @click="handleDelete(false)">批量删除</el-button>
</div>
</div>
<el-card class="flex-1" shadow="never">
<el-table v-loading="loading" :data="tableData" border @selection-change="handleSelectionChange">
<el-table-column align="center" fixed="left" type="selection" width="55" />
<el-table-column align="center" fixed="left" label="房屋" prop="unitNo" width="120">
<template #default="scope">
{{ scope.row.unitNo }}
</template>
</el-table-column>
<el-table-column align="center" fixed="left" label="收费项目" prop="billCode" width="120">
<template #default="scope">
{{ scope.row.chargeItemName }}
</template>
</el-table-column>
<el-table-column align="center" label="收费周期" prop="periodDisplay" width="200">
<template #default="scope">
<span>{{ scope.row.periodDisplay }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="单价" prop="fixedPrice" width="100">
<template #default="scope">
<div class="flex justify-center">
<span>
{{ scope.row.fixedPrice }}
</span>
<span v-if="scope.row.unit"> / </span>
<dict-tag v-if="scope.row.unit" :options="com_charge_item_unit" :value="scope.row.unit"></dict-tag>
</div>
</template>
</el-table-column>
<el-table-column align="center" label="数量" prop="quantity" width="85">
<template #default="scope">
<span>{{ scope.row.quantity }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="应收金额" prop="amount" width="100" />
<el-table-column align="center" label="缴费状态" prop="payStatus" width="100">
<template #default="scope">
<span v-if="scope.row.payStatus === PayStatus.PENDING">未缴纳</span>
<span v-else-if="scope.row.payStatus === PayStatus.PAID">已缴纳</span>
<span v-else-if="scope.row.payStatus === PayStatus.FAILED">缴纳失败</span>
<span v-else-if="scope.row.payStatus === PayStatus.PARTIAL">部分缴纳</span>
</template>
</el-table-column>
<el-table-column align="center" label="剩余应缴金额" prop="needPayAmount" width="140" />
<!-- <el-table-column align="center" label="优惠金额" prop="singleDiscountAmount" width="100" />-->
<el-table-column align="center" label="实缴金额" prop="actualAccount" width="100" />
<el-table-column align="center" label="承租方姓名" prop="residentName" width="120" />
<el-table-column align="center" label="缴费时间" min-width="180" prop="payTime" />
<el-table-column align="center" label="备注" min-width="250" prop="remark" show-overflow-tooltip>
<template #default="scope">
<span style="text-align: left">{{ scope.row.remark }}</span>
</template>
</el-table-column>
<el-table-column align="center" class-name="small-padding fixed-width" fixed="right" label="操作" width="150">
<template #default="scope">
<el-button v-if="scope.row.payStatus !== PayStatus.PAID" link type="primary" @click="handleIncome(scope.row)">收款</el-button>
<el-button v-if="scope.row.payStatus === PayStatus.PAID" link type="success" @click="printPIaoJuByOnly(scope.row)">打印票据</el-button>
<el-button link type="danger" @click="handleDelete(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<div class="footerBox">
<div class="totalBox">
<span>合计:</span>
<!-- <span>应收:{{ totalAll.totalAccount }}元(原金额:{{ totalAll.originalAmount }}元, 优惠:{{ totalAll.totalDiscountAmount }}元)</span>-->
<span>应收:{{ totalAll.totalAccount }}元</span>
<span style="padding: 0 5px">已收:{{ totalAll.TotalPaymentAmount }}元</span>
<span style="padding: 0 5px">未收:{{ totalAll.TotalUnPaymentAmount }}元</span>
</div>
<pagination
v-show="total > 0"
v-model:limit="queryParams.pageSize"
v-model:page="queryParams.pageNum"
:pageSizes="[10, 20, 30, 50, 100, 200, 300]"
:total="total"
@pagination="getList"
/>
</div>
</el-card>
<el-dialog v-model="dialog.visible" :title="dialog.title" append-to-body width="650px">
<div class="payInfo">
<div>
<div class="flex flex-items-center justify-between">
<span>缴费人: {{ inComeFrom.residentName }}</span>
<span style="color: #ff9947">待缴纳</span>
</div>
</div>
<div class="flex">
<span>收费名称: </span>
<div>
<div
v-for="(item, index) in inComeFrom.billResidentId"
:key="index"
class="flex flex-items-center"
style="text-wrap: wrap; margin-bottom: 5px"
>
<div class="flex flex-items-center">
<div style="text-decoration: underline; padding-right: 5px; text-align: center">
{{ item.detailsName }} &nbsp;&nbsp;(应缴:¥{{ item.needPayAmount }})
</div>
<el-tooltip v-if="item.payStatus === PayStatus.PENDING" class="box-item" effect="light" placement="top">
<el-icon color="#909399"><QuestionFilled /></el-icon>
<template #content>
<div style="line-height: 1.8; font-size: 13px; width: 180px">
<div class="flex justify-between" style="text-align: right">
<span>总金额</span>
<span>{{ item.amount }}¥</span>
</div>
<div class="flex justify-between" style="text-align: right">
<span>累计优惠金额</span>
<span>− {{ item.singleDiscountAmount }}¥</span>
</div>
<div class="flex justify-between" style="text-align: right">
<span>累计已交金额</span>
<span>− {{ item.paidAmount }}¥</span>
</div>
<div
class="flex justify-between cursor-pointer"
style="margin-top: 6px; border-top: 1px solid #ccc; text-align: right; padding-top: 6px"
>
<span>待缴金额</span>
<span style="font-weight: bold; color: red">{{ item.needPayAmount }}¥</span>
</div>
</div>
</template>
</el-tooltip>
</div>
<span v-if="item.payStatus === PayStatus.PAID">(已缴费,不计入金额)</span>
</div>
</div>
</div>
<div>
<span>应收合计:¥{{ inComeFrom.allCost }}</span>
</div>
<div
:class="{
DiscountColorRed: gtMoney(totalDiscountAmount, inComeFrom.allCost)
}"
class="flex flex-items-center"
>
<div>优惠合计:¥{{ totalDiscountAmount }}</div>
<div v-if="totalDiscountAmount !== totalReadDiscount && totalReadDiscount !== '0' && inComeFrom.discountMethod === 2">
&nbsp;&nbsp;
<span>(实际优惠合计:¥{{ totalReadDiscount }})</span>
<el-tooltip class="box-item" effect="light" placement="top">
<el-icon color="#909399" style="vertical-align: middle"><QuestionFilled /></el-icon>
<template #content>
<span>有账单 应缴费用 不足 优惠金额</span>
</template>
</el-tooltip>
</div>
</div>
<div>
<span>预计实缴合计:¥{{ totalPayAmount }}</span>
</div>
<div>
<span>实际实缴合计:¥{{ payListAllAmount }}</span>
</div>
</div>
<el-form ref="formRef" :model="inComeFrom" label-width="100px">
<el-form-item label="费用合计" prop="allCost">
<el-input v-model="inComeFrom.allCost" disabled style="width: 400px">
<template #suffix>
<span>元</span>
</template>
</el-input>
</el-form-item>
<el-form-item label="缴纳状态" prop="payStatus">
<el-radio-group v-model="inComeFrom.payStatus">
<el-radio label="已缴纳" value="1"></el-radio>
<!-- <el-radio label="部分缴纳" value="3"></el-radio>-->
</el-radio-group>
</el-form-item>
<!-- <el-form-item v-if="inComeFrom.payStatus !== PayStatus.PENDING" label="优惠方式" prop="discountMethod">-->
<!-- <el-select v-model="inComeFrom.discountMethod" placeholder="请选择" style="width: 400px" @change="handleChangeDisCountMethod">-->
<!-- <el-option :value="0" label="不优惠"></el-option>-->
<!-- <el-option :value="2" label="金额"></el-option>-->
<!-- <el-option :value="1" label="比例"></el-option>-->
<!-- </el-select>-->
<!-- </el-form-item>-->
<div v-if="inComeFrom.discountMethod !== 0">
<div v-if="inComeFrom.discountMethod === 2">
<el-form-item label="单笔优惠金额" prop="discount">
<el-input v-model.trim.number="inComeFrom.discount" style="width: 400px" @input="debouncedHandleDiscountMoney">
<template #append>
<span>¥</span>
</template>
</el-input>
</el-form-item>
</div>
<el-form-item v-else label="优惠比例" prop="discountRate">
<el-input
v-model.trim.number="inComeFrom.discountRate"
placeholder="0~100:0=无优惠,80=优惠80%,100=全免"
style="width: 400px"
@input="debounceDiscountRate"
>
<template #append>
<span>%</span>
</template>
</el-input>
</el-form-item>
<el-form-item label="总优惠金额" prop="totalDiscountAmount">
<el-input v-model="totalDiscountAmount" disabled style="width: 400px">
<template #append>
<span>¥</span>
</template>
</el-input>
</el-form-item>
</div>
<el-form-item v-if="inComeFrom.payStatus !== PayStatus.PENDING" label="支付方式" prop="payType">
<div class="flex-1">
<div v-for="(item, index) in payList" :key="index" class="flex flex-items-center">
<div class="flex-1 flex">
<el-select v-model="item.payType" placeholder="请选择" @change="handleChangePayTypeId($event, index)">
<el-option
v-for="dict in com_pay_method"
:key="dict.value"
:disabled="isOptionDisabled(dict.value, item.payType)"
:label="dict.label"
:value="dict.value"
></el-option>
</el-select>
<el-input v-model.number.trim="item.payAmount" style="margin: 0 10px" @change="(val: string) => handleChangePay(val, index)">
<template #append>¥</template>
</el-input>
</div>
<div style="width: 80px; text-align: left">
<el-icon
v-if="index === payList.length - 1 && payList.length < com_pay_method.length"
color="blue"
size="24"
style="margin-right: 10px; cursor: pointer"
@click="addPayList"
><CirclePlus
/></el-icon>
<el-icon v-if="payList.length > 1" color="red" size="24" style="cursor: pointer" @click="removePayList(index)"><Delete /></el-icon>
</div>
</div>
</div>
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="inComeFrom.remark" :rows="5" maxlength="100" show-word-limit style="width: 400px" type="textarea"></el-input>
</el-form-item>
<div class="flex justify-end">
<el-button @click="closer">取消</el-button>
<el-button :loading="buttonLoading" type="primary" @click="submitForm">提交</el-button>
</div>
</el-form>
</el-dialog>
<el-dialog v-model="dialog_print.visible" :title="dialog_print.title" append-to-body width="1200px">
<template #header>
<div class="flex" style="justify-content: space-between; padding: 0 20px">
<div class="title">票据打印</div>
<el-button v-print="printOption" :loading="isLoading" type="primary" @click="conFimPrint">打印</el-button>
</div>
</template>
<div id="printBox-Bill" class="printBox" style="margin: 0; color: rgba(0, 0, 0, 1); padding: 5px">
<div class="title" style="font-size: 1.2rem; margin-bottom: 10px; text-indent: 5em">{{ print_form.title }}</div>
<div style="font-size: 12px; display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; grid-gap: 10px; grid-template-rows: 1fr">
<div>单据日期:{{ print_form.printDate }}</div>
<div>房号:{{ print_form.HouseName }}</div>
<div>产权人:{{ print_form.residentName }}</div>
<div>No.</div>
</div>
<div class="tableBox" style="font-size: 10px">
<table class="printTable" style="border-collapse: collapse; border: 1px solid #000; width: 90%">
<thead>
<tr>
<th style="min-width: 50px">收费项目</th>
<th>收费标准</th>
<th>账单时间</th>
<th style="min-width: 50px">面积</th>
<th style="min-width: 50px">应收金额</th>
<!-- <th style="min-width: 50px">优免金额</th>-->
<th style="min-width: 50px">实收金额</th>
<th>收款方式</th>
<th style="min-width: 100px">备注</th>
</tr>
</thead>
<tbody>
<tr v-for="(item, index) in print_form.detailsList" :key="index">
<td>{{ item.chargeItemName }}</td>
<td>{{ item.billName }}</td>
<td>{{ item.detailsTime }}</td>
<td>{{ item.useCount }}</td>
<td>{{ item.account }}</td>
<!-- <td>{{ item.singleDiscountAmount }}</td>-->
<td>{{ item.actualAccount }}</td>
<td>{{ item.payType }}</td>
<td style="text-wrap: wrap; white-space: wrap">{{ item.remark }}</td>
</tr>
<tr>
<td>合计</td>
<td></td>
<td></td>
<td></td>
<td>{{ print_form.totalAccount }}</td>
<!-- <td>{{ print_form.totalDiscountAmount }}</td>-->
<td>{{ print_form.totalActualAccount }}</td>
<td></td>
<td></td>
</tr>
<tr>
<td>支付明细</td>
<td colspan="7" style="text-align: left; padding: 0 10px">
<span v-for="(item, index) in print_form.payTypeSummary" :key="index"
>{{ item.payType }}: {{ item.payAmount }} ; &nbsp; &nbsp;</span
>
</td>
</tr>
</tbody>
</table>
<p style="font-size: 10px">说明:本收据收款单位和收款具签章方为有效,本收据手写无效</p>
<div style="font-size: 12px; margin-bottom: 0; display: flex; align-items: center">
<div style="flex: 1">交款人:</div>
<div style="flex: 1; display: flex; align-items: center">
<span style="white-space: nowrap">收款人: </span>
<el-input v-if="!isPrint" v-model="inHomelyUse" placeholder="请输入收款人姓名" style="width: 150px"></el-input>
<span v-else style="white-space: nowrap"> {{ inHomelyUse }}</span>
</div>
</div>
</div>
</div>
</el-dialog>
</div>
</template>
<script lang="ts" setup>
import PageHeader from '@/components/Pageheader/index.vue';
import pagination from '@/components/Pagination/index.vue';
import DictTag from '@/components/DictTag/index.vue';
import { getBuildinglistAPI, getHouselistAPI } from '@/api/system/house';
import { getCommunitylistAPI } from '@/api/system/community';
import { billDelete, billEdit, billlistType, billPrint, BillPrintType, billQuery, getAllAccount } from '@/api/system/SdbCashier';
import { listChargeItem } from '@/api/system/SdbChargeItem';
import { ref } from 'vue';
import { add, div, eq, eqMoney, gtMoney, minMoney, moneyAdd, mul, sub, sum, toBig } from '@/utils/money';
import { BuildingVo, HouseListVO } from '@/api/system/house/type';
import { ChargeItemVO } from '@/api/system/SdbChargeItem/type';
import { communitylist_rows_type } from '@/api/system/community/type';
import { debounce } from '@/utils';
import { listHouseUseType_add_house } from '@/api/system/houseUse';
import { CirclePlus, Delete, QuestionFilled } from '@element-plus/icons-vue';
import { useUserStore } from '@/store/modules/user';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { com_pay_method, com_charge_item_unit } = toRefs<any>(proxy?.useDict('com_pay_method', 'com_charge_item_unit'));
/** 支付状态 */
const PayStatus = {
/** 待缴纳 */
PENDING: '0',
/** 已缴纳 */
PAID: '1',
/** 缴纳失败 */
FAILED: '2',
/** 部分缴纳 */
PARTIAL: '3'
} as const;
const userStore = useUserStore();
const loading = ref(false);
const ids = ref<Array<billlistType>>([]);
const total = ref(0);
const queryFormRef = ref<ElFormInstance>();
const activeTabs = ref(null);
const tabs = [
{
value: null,
type: '全部'
},
{
value: PayStatus.PENDING,
type: '待缴纳'
},
{
value: PayStatus.PAID,
type: '已缴纳'
},
{
value: PayStatus.PARTIAL,
type: '部分缴纳'
}
];
const villageId = localStorage.getItem('villageid') ?? undefined;
const queryParams = ref({
pageNum: 1,
pageSize: 10,
// 收款状态
payStatus: null,
// 小区id
villageId: villageId,
// 楼栋id
buildingId: undefined,
// 房屋id
houseId: undefined,
// 房屋类型id
houseUseTypeId: undefined,
// 缴费时间
payTime: undefined,
// 缴费人
residentName: undefined,
// 缴费项目id
chargeItemId: undefined,
period: undefined,
// 缴费时间开始
payTimeBegin: undefined,
// 缴费时间结束
payTimeEnd: undefined,
// 开始时间
startDate: undefined,
// 结束时间
endDate: undefined
});
// ts工具 排除参数
type ExcludeType = keyof Omit<typeof queryParams.value, 'villageId' | 'pageSize' | 'pageNum'>;
const villageList = ref<communitylist_rows_type[]>([]); // 小区列表
const buildingList = ref<BuildingVo[]>([]); // 楼栋列表
const houseList = ref<HouseListVO[]>([]); // 房屋列表
const chargeItems = ref<ChargeItemVO[]>([]);
const tableData = ref([]);
const dialog = reactive<DialogOption>({
visible: false,
title: ''
});
const houseUseTypeList = ref([]);
function getHouseTypeList() {
listHouseUseType_add_house().then((res) => {
houseUseTypeList.value = res.data;
});
}
// 切换 账单类型
function changeTabs(value: string) {
activeTabs.value = value;
queryParams.value.payStatus = value;
getList();
}
// 选择小区
function handleChangeVillage(val: string) {
queryParams.value.buildingId = undefined;
queryParams.value.chargeItemId = undefined;
queryParams.value.houseId = undefined;
buildingList.value = [];
if (val) {
getBuildinglistAPI({
villageId: val
}).then((res) => {
buildingList.value = res.data;
handleChargeItem(val);
});
return;
}
}
// 获取收费项目
function handleChargeItem(id: string) {
listChargeItem({
villageId: id,
status: '0'
}).then((res) => {
chargeItems.value = res.rows;
});
}
// 选择楼栋
function handleChangeBuilding(val: string): void {
queryParams.value.houseId = undefined;
if (val !== undefined) {
getHouselistAPI(val).then((res) => {
houseList.value = res.data.houses;
});
}
}
// 清空缴费周期
function handleClearChargePeriod(type: 'start' | 'end' = 'start') {
if (type === 'start') {
queryParams.value.startDate = undefined;
} else {
queryParams.value.endDate = undefined;
}
}
// 获取列表
function getList() {
loading.value = true;
billQuery(queryParams.value)
.then((res) => {
tableData.value = res.rows;
total.value = res.total;
})
.finally(() => {
loading.value = false;
});
getAllBillAmount();
}
function getAllBillAmount() {
getAllAccount(queryParams.value).then((res) => {
totalAll.value = {
totalDiscountAmount: res.data.discountAmount, // 总优惠金额
TotalPaymentAmount: res.data.receivedAmount, // 总实收金额
totalAccount: res.data.receivableAmount, // 总 应收金额
originalAmount: res.data.originalAmount, // 原始金额之和(应收+优惠)
TotalUnPaymentAmount: res.data.unpaidAmount // 未收金额
};
});
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.value.pageNum = 1;
getList();
};
// 优化后
const defaultQueryParams = () => ({
pageNum: 1,
pageSize: 20,
payStatus: null as number | null,
villageId: villageId as string | undefined,
buildingId: undefined,
houseId: undefined,
houseUseTypeId: undefined,
payTime: undefined,
residentName: undefined,
chargeItemId: undefined,
period: undefined,
payTimeBegin: undefined,
payTimeEnd: undefined,
startDate: undefined,
endDate: undefined
});
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value?.resetFields();
queryParams.value = {
...defaultQueryParams(),
payStatus: queryParams.value.payStatus // 保留当前 tab
};
houseList.value = [];
handleQuery();
};
// 清空楼栋
function handleClearBuildingId() {
queryParams.value.buildingId = undefined;
queryParams.value.houseId = undefined;
}
// 清空其他参数
function handleClear(type: ExcludeType) {
queryParams.value[type] = undefined;
}
// 控制收费 按钮 不能有已缴纳的(后端会校验)
const single = ref(true);
// 控制打印票据的 按钮 不能有收费的
const printSingle = ref(true);
/** 多选框选中数据 */
const handleSelectionChange = (selection: billlistType[]) => {
ids.value = selection.map((item) => item);
// 不能全部都是已缴纳的 0待缴纳 1已缴纳 2缴纳失败 3混合缴纳
single.value = ids.value.every((item) => item.payStatus === PayStatus.PENDING || item.payStatus === PayStatus.PARTIAL);
// 必须都要缴费后打印
printSingle.value = ids.value.every((item) => item.payStatus === PayStatus.PAID);
};
const buttonLoading = ref(false);
// 是否多选
let isMore = false;
const inComeFrom = ref({
allCost: null, // 金额
billResidentId: [], // 账单id
/** 0:未缴 1:已缴 2: 缴纳失败 3: 混合缴纳*/
payStatus: '1',
/** 0:微信 1:支付宝 2 线下 */
payType: '0', //
remark: '', // 备注
/**优惠方式 0 不优惠 1 比例 2 金额*/
discountMethod: 0, //
discountRate: '0', // 优惠比例 10 === 10%
discount: '0', // 优惠金额
residentName: '' // 缴费人
});
// 总计算优惠金额
const totalDiscountAmount = ref('0.00');
// 总实际优惠金额
const totalReadDiscount = ref('0.00');
// 总实际支付金额
const totalPayAmount = ref('0.00');
// 初始化
function initInComeFrom() {
inComeFrom.value = {
allCost: 0, // 总金额
billResidentId: [], // 账单id
payStatus: '1', // 0:未缴 1:已缴 2: 缴纳失败 3: 部分缴纳
payType: '2', // 0:微信 1:支付宝
remark: '',
discountMethod: 0, // 优惠方式 0 不优惠 1 比例 2 金额
discountRate: '0', // 优惠比例 10 === 10%
discount: '0', // 优惠金额
residentName: '' // 缴费人
};
payList.value = [
{
payType: '',
payAmount: null
}
];
totalDiscountAmount.value = '0.00';
totalPayAmount.value = '0.00';
totalReadDiscount.value = '0.00';
isMore = false;
}
// 改变优惠方式
function handleChangeDisCountMethod(val: number) {
inComeFrom.value.discountRate = '0'; // 优惠比例
inComeFrom.value.discount = '0.00'; // 优惠金额
totalReadDiscount.value = '0.00'; // 实际优惠金额
totalDiscountAmount.value = '0.00'; // 总优惠金额
totalPayAmount.value = inComeFrom.value.allCost; // 总实际付款金额
if (val === 0) return;
if (val === 2) {
// 金额
handleChangeDiscountMoney(inComeFrom.value.discount);
} else {
// 比例
handleChangeDiscountRate(inComeFrom.value.discount);
}
}
// 输入折扣固定金额
function handleChangeDiscountMoney(val: string) {
// 1. 清洗输入:空、纯符号、非数字兜底为0
const cleanVal = val.trim();
if (!checkMoney(cleanVal)) {
return ElMessage.warning('金额格式错误');
}
let discount = toBig(cleanVal).toNumber();
if (Number.isNaN(discount)) discount = 0;
const allCost = inComeFrom.value.allCost ?? 0;
if (discount < 0) {
ElMessage.warning('优惠金额不能为负数');
return;
}
// 折扣为0直接赋值原总价,无需计算
if (eq(discount, 0)) {
totalDiscountAmount.value = '0.00';
totalReadDiscount.value = '0.00';
totalPayAmount.value = allCost.toString();
return;
}
if (isMore) {
// 过滤:只保留未支付账单,已支付直接丢弃
const unPaidList = ids.value.filter((item) => {
return item.payStatus !== PayStatus.PAID;
});
// 计算优惠总额
const allDiscount = mul(unPaidList.length, discount);
if (gtMoney(allDiscount, inComeFrom.value.allCost)) {
ElMessage.warning('优惠总金额不能超过总费用');
}
// 实际优惠总额
let readDiscount = 0;
unPaidList.forEach((item) => {
readDiscount = add(readDiscount, minMoney(item.needPayAmount, discount));
});
totalDiscountAmount.value = `${allDiscount}`;
totalReadDiscount.value = `${readDiscount}`;
totalPayAmount.value = sub(allCost, readDiscount).toString();
} else {
// 单笔优惠不能超过整体总费用
if (gtMoney(discount, allCost)) {
ElMessage.warning('单笔优惠金额不能超过总费用');
}
totalDiscountAmount.value = discount.toString();
totalReadDiscount.value = `${discount}`;
totalPayAmount.value = sub(allCost, discount).toString();
}
validatePayAmountSufficiency();
}
const debouncedHandleDiscountMoney = debounce(handleChangeDiscountMoney, 550);
// 输入折扣固定比例
function handleChangeDiscountRate(val: string) {
const inputStr = val.trim();
let discountPercent = toBig(inputStr).toNumber();
if (Number.isNaN(discountPercent)) discountPercent = 0;
// 百分比校验
if (discountPercent < 0 || discountPercent > 100) {
ElMessage.warning('请输入0-100之间的优惠打折百分比');
return;
}
const allCost = inComeFrom.value.allCost ?? 0;
const rate = div(discountPercent, 100);
// 1. 输入0:优惠总额为0,全价支付
if (eq(rate, 0)) {
totalDiscountAmount.value = '0.00';
totalReadDiscount.value = '0.00';
totalPayAmount.value = allCost;
return;
}
// 2. 输入100:全免价格,免费送
if (eq(rate, 1)) {
totalDiscountAmount.value = allCost;
totalReadDiscount.value = allCost;
totalPayAmount.value = '0.00';
return;
}
// 批量多选模式
if (isMore) {
const unPaidList = ids.value.filter((item) => {
return item.payStatus !== PayStatus.PAID;
});
// 总价格
const sourceTotal = sum(unPaidList.map((item) => item.needPayAmount ?? 0));
// 优惠总额 = 未付原价总和 - 打折后实付总和
const discountTotal = mul(sourceTotal, rate);
// 优惠总额
totalDiscountAmount.value = discountTotal.toString();
totalReadDiscount.value = `${discountTotal}`;
totalPayAmount.value = mul(sourceTotal, 1 - rate).toString();
} else {
// 单选单条账单
totalDiscountAmount.value = mul(allCost, rate).toString();
totalReadDiscount.value = mul(allCost, rate).toString();
totalPayAmount.value = mul(allCost, 1 - rate).toString();
}
validatePayAmountSufficiency();
}
const debounceDiscountRate = debounce(handleChangeDiscountRate);
function validatePayAmountSufficiency() {
if (payList.value.length > 0) {
if (gtMoney(payListAllAmount.value, 0)) {
payList.value.forEach((item) => (item.payAmount = 0));
ElMessage.warning(`优惠变更,请重新填写支付金额`);
}
}
}
// 收费 --------------------------------------------------------------
/** 收费 */
function handleIncome(row: billlistType | false) {
initInComeFrom();
if (row) {
inComeFrom.value.allCost = row.needPayAmount;
inComeFrom.value.billResidentId = [row];
inComeFrom.value.remark = row.remark;
inComeFrom.value.residentName = row.residentName;
totalPayAmount.value = row.needPayAmount;
} else {
if (ids.value.length <= 0) return ElMessage.warning('请选择账单');
const set = new Set();
ids.value.forEach((item) => {
set.add(item.residentId);
});
if (ids.value.some((item) => item.payStatus === PayStatus.PAID)) {
return ElMessage.warning('存在已支付账单,请重新选择');
}
if (set.size > 1) {
ElMessage.warning('缴费人不一致,重新选择');
return;
} else if (set.size === 1) {
inComeFrom.value.remark = '';
inComeFrom.value.residentName = ids.value[0].residentName;
ids.value.forEach((item) => {
inComeFrom.value.billResidentId.push(item);
if (item.payStatus === PayStatus.PENDING || item.payStatus === PayStatus.PARTIAL) {
inComeFrom.value.allCost = moneyAdd(inComeFrom.value.allCost || 0, item.needPayAmount);
}
});
totalPayAmount.value = inComeFrom.value.allCost;
isMore = true;
}
}
dialog.visible = true;
}
// 关闭模态框
const closer = () => {
dialog.visible = false;
dialog.title = '';
initInComeFrom();
};
// 提交
const submitForm = () => {
if (!handlePayListIsEmpty()) {
ElMessage.warning('请填写完整支付方式和支付金额');
return;
}
buttonLoading.value = true;
// 部分缴纳时 判断 支付金额 和 预计支付金额 是否相等 ,相等 则 可选择 部分缴纳 方式
if (inComeFrom.value.payStatus === PayStatus.PARTIAL) {
if (eqMoney(totalPayAmount.value, payListAllAmount.value)) {
buttonLoading.value = false;
return ElMessage.warning('实缴金额等于应收金额时,请选择 【已缴纳】 状态');
}
}
// // 已缴纳时 判断 支付金额 和 预计支付金额 是否相等
// if (inComeFrom.value.payStatus === PayStatus.PAID) {
// if (!eqMoney(totalPayAmount.value, payListAllAmount.value)) {
// buttonLoading.value = false;
// return ElMessage.warning('支付金额不足,可以选择 【部分缴纳】 状态');
// }
// }
// 已缴纳时 判断 支付金额 和 预计支付金额 是否相等
if (inComeFrom.value.payStatus === PayStatus.PAID) {
if (!eqMoney(totalPayAmount.value, payListAllAmount.value)) {
buttonLoading.value = false;
return ElMessage.warning('支付金额不足');
}
}
const obj = {
'detailsId': inComeFrom.value.billResidentId.map((item) => item.detailsId),
'payType': inComeFrom.value.payType,
'payStatus': inComeFrom.value.payStatus,
discountMethod: inComeFrom.value.discountMethod, //优惠方式: 0不优惠 1 比例 2 金额
discountRate: inComeFrom.value.discountRate, // 优惠比例(优惠方式为比例时使用,如 10 表示 10%
singleDiscountAmount: inComeFrom.value.discount, // 单笔优惠金额(优惠方式为金额时使用
remark: inComeFrom.value.remark,
payItems: payList.value
};
billEdit(obj)
.then(() => {
ElMessage.success('缴费成功');
getList();
closer();
})
.finally(() => {
buttonLoading.value = false;
});
};
const router = useRouter();
function handleRoute(row: billlistType) {
const villageId = localStorage.getItem('villageid');
if (row.villageId !== villageId) {
ElMessage.warning('非本小区房屋/车位/车辆');
return;
}
switch (row.detailsType) {
case '0':
case '2':
case '3':
case '4':
router.push({
path: '/house/HouseDetails',
query: {
id: row.unitNoId
}
});
break;
case '1':
router.push({
path: '/carArea/parkMain',
query: {
id: row.unitNoId
}
});
break;
}
}
//
// 打印票据--------------------------------------------------------------
const isPrint = ref(false);
const dialog_print = reactive<DialogOption>({
visible: false,
title: '票据打印'
});
// 收款人
const inHomelyUse = ref('');
// 票据表单
const print_form = ref<BillPrintType>({
totalDiscountAmount: '',
totalActualAccount: '',
'totalAccount': '',
'residentName': '',
'payTypeSummary': [],
'detailsList': [],
'printDate': '',
'HouseName': '',
'title': ''
});
// 打印票据
function printPIaoJuByOnly(row: billlistType | false) {
isPrint.value = false;
inHomelyUse.value = userStore.nickname;
let query = null;
if (row) {
query = {
'residentId': row.residentId,
'detailsIds': [row.detailsId]
};
} else {
if (ids.value.length <= 0) {
return ElMessage.warning('请选择账单!');
}
let residentId = null;
const set = new Set();
ids.value.forEach((item) => {
set.add(item.residentId);
});
if (set.size > 1) {
ElMessage.warning('缴费人不一致,重新选择');
return;
} else if (set.size === 1) {
residentId = Array.from(set).at(0);
query = {
'residentId': residentId,
'detailsIds': ids.value.map((item) => item.detailsId)
};
}
}
billPrint(query).then((res) => {
print_form.value = res.data;
dialog_print.visible = true;
});
}
const isLoading = ref(false);
const printOption = {
id: 'printBox-Bill',
popTitle: '票据打印',
printStyle: `
@page {
size: 25cm 10cm;
margin: 0;
}
* {
box-sizing: border-box;
margin: 0 !important;
padding: 0 !important;
}
@media print {
html {
height: 10cm !important;
overflow: hidden !important;
}
body {
height: 10cm !important;
overflow: hidden !important;
position: absolute;
left:0;
top:0;
transform-origin: top left;
transform: scale(0.999);
}
#printBox-Bill {
width: 25cm !important;
height: 10cm !important;
}
table {
border-collapse: collapse;
width: 100% !important;
table-layout: auto;
}
table th, table td {
border: 1px solid #333;
font-size: 10px;
min-height: 32px;
text-align: center;
padding: 1px 2px;
line-height: 1.1;
white-space: normal;
}
}
`,
afterCloseCallback: () => {
isPrint.value = false;
isLoading.value = false;
}
};
// 打印状态恢复函数
function resetPrintState() {
isPrint.value = false;
isLoading.value = false;
}
function conFimPrint() {
isLoading.value = true;
isPrint.value = true;
setTimeout(() => {
// printTicketDiv('printBox-Bill', '票据打印', () => {
// console.log('打印完成');
// isPrint.value = false;
// isLoading.value = false;
// });
// printTicket('printBox-Bill', '票据打印', () => {
// console.log('打印完成');
// isPrint.value = false;
// isLoading.value = false;
// });
resetPrintState();
}, 100);
}
// 删除
async function handleDelete(row: billlistType | false) {
const targetIds = row ? [row.detailsId] : ids.value.map((item) => item.detailsId);
if (targetIds.length === 0) {
return ElMessage.warning('请选择账单!');
}
await proxy?.$modal.confirm('该信息删除后无法恢复,确定要删除吗?');
await billDelete(targetIds);
ElMessage.success('删除成功');
getList();
}
onMounted(() => {
queryParams.value.villageId = villageId;
getList();
getHouseTypeList();
// 全部小区
getCommunitylistAPI().then((res) => {
villageList.value = res.rows;
handleChangeVillage(queryParams.value.villageId);
});
});
// 总 表单
const totalAll = ref({
totalDiscountAmount: '0', // 总优惠金额
TotalPaymentAmount: '0', // 总已收金额
totalAccount: '0', // 总 应收金额
originalAmount: '0', // 原始金额之和(应收+优惠)
TotalUnPaymentAmount: '0' // 未收金额
});
function handleChangePayTypeId(val: string, index: number) {
// 【可选兜底校验】防止异常数据出现重复
const repeatCount = usedPayValues.value.filter((v) => v === val).length;
if (repeatCount > 1) {
payList.value[index].payType = '';
}
}
const usedPayValues = computed(() => {
return payList.value.map((item) => item.payType).filter((v) => v !== null && v !== undefined && v !== '');
});
const isOptionDisabled = (optVal: string, currentVal: any) => {
// 当前行自己选中的,不禁用;其他行占用的,禁用
if (optVal === currentVal) return false;
return usedPayValues.value.includes(optVal);
};
/** 支付列表项类型 */
interface PayListItem {
payType: string;
payAmount: number | null;
}
// 混合支付 列表
const payList = ref<PayListItem[]>([
{
payType: '',
payAmount: null
}
]);
// 混合支付 总金额
const payListAllAmount = computed<number>(() => {
return sum(payList.value.map((item) => item.payAmount ?? 0));
});
// 添加支付方式
function addPayList() {
payList.value.push({
payType: '',
payAmount: null
});
}
// 移除支付方式
function removePayList(index: number) {
payList.value.splice(index, 1);
}
// 数据框改变时 检测数据是否大于 总金额, 如果大于则自动回填剩余金额
function handleChangePay(val: string, index: number = -1) {
if (!checkMoney(val)) {
ElMessage.warning('金额格式错误');
payList.value[index].payAmount = null;
return;
}
// 如果 当前行输入的金额 大于 总实缴金额
// 则在当前行,自动回填正确剩余金额
if (gtMoney(payListAllAmount.value, totalPayAmount.value)) {
ElMessage.warning('输入金额 总和 不能大于 总实缴金额');
if (index > -1) {
// 自动回填
// BUG: payAmount=0,让 payListAllAmount’s computed 只算其他行,然后 补 回来
// payList.value[index].payAmount = 0;
// payList.value[index].payAmount = sub(totalPayAmount.value, payListAllAmount.value);
// 总实缴 - (全部总和 - 当前行刚输入的值) = 总实缴 - 其他行总和 = 当前行剩余应缴金额
payList.value[index].payAmount = sub(totalPayAmount.value, sub(payListAllAmount.value, val));
}
}
// // 已缴纳状态时,输入金额 总和 不能小于 总实缴金额
// if (inComeFrom.value.payStatus === PayStatus.PAID) {
// if (ltMoney(payListAllAmount.value, totalPayAmount.value)) {
// ElMessage.warning('输入金额 总和 不能小于 总实缴金额');
// }
// }
}
function handlePayListIsEmpty() {
if (payList.value.length === 0) {
ElMessage.warning('请添加支付方式');
return false;
}
const invalidIndex = payList.value.findIndex(
(item) => item.payType === null || item.payType === undefined || item.payType === '' || item.payAmount === null || item.payAmount === undefined
);
return invalidIndex === -1;
}
// 校验数字
function checkMoney(value: string) {
if (!value) return false;
const reg = /^(0|[1-9]\d*)(\.\d{1,2})?$/;
return reg.test(value);
}
</script>
<style lang="scss" scoped>
.DiscountColorRed {
color: red;
}
.el-table {
height: calc(100% - 80px);
}
.actionsBox {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #fff;
height: 50px;
box-sizing: border-box;
padding: 0 20px;
margin-bottom: 10px;
border-radius: 5px;
}
.tabs-box {
display: flex;
align-items: center;
.tabs-items {
width: 70px;
height: 40px;
line-height: 40px;
border-bottom: 2px solid transparent;
text-align: center;
font-size: 14px;
cursor: pointer;
margin-right: 10px;
&:hover {
opacity: 0.5;
color: #1a75ff;
border-bottom-color: #1a75ff;
}
&.active {
border-bottom-color: #1a75ff;
color: #1a75ff;
}
}
}
.payInfo {
color: rgba(0, 0, 0, 1);
margin-top: 20px;
padding-bottom: 10px;
margin-bottom: 30px;
border-bottom: 1px solid #d2d2d2;
& > div {
margin-bottom: 10px;
}
}
.printBox {
.tableBox {
.printTable {
th,
td {
text-align: center;
height: 40px;
border: 1px solid #000;
}
}
}
}
.footerBox {
min-height: 72px;
display: flex;
align-items: center;
justify-content: space-between;
.totalBox {
font-size: 14px;
}
}
</style>