<template>
|
<el-dialog v-model="dialogVisible" title="请选择 关联应付账单" width="85%" destroy-on-close @close="handleClose"
|
append-to-body>
|
<div class="search-bar">
|
<el-form inline :model="queryParams" class="search-form" size="default">
|
<el-form-item label="系统编号:">
|
<el-input v-model="queryParams.systemNo" placeholder="请输入系统编号" style="width: 180px" clearable />
|
</el-form-item>
|
|
<el-form-item label="账单名称:">
|
<el-input v-model="queryParams.billName" placeholder="请输入账单名称" style="width: 180px" clearable />
|
</el-form-item>
|
|
<el-form-item label="供应商名称:">
|
<el-input v-model="queryParams.supplierName" placeholder="请输入供应商名称" style="width: 180px" clearable />
|
</el-form-item>
|
|
<!-- <el-form-item label="状态:">
|
<el-select v-model="queryParams.status" style="width: 150px;" placeholder="请选择状态" clearable>
|
<el-option v-for="dict in sys_bill_status" :key="dict.value" :label="dict.label" :value="dict.value" />
|
</el-select>
|
</el-form-item> -->
|
|
<el-form-item>
|
<el-button type="primary" icon="Search" @click="handleSearch">搜索</el-button>
|
<el-button plain icon="RefreshLeft" @click="handleReset">清空</el-button>
|
</el-form-item>
|
</el-form>
|
</div>
|
|
<el-table ref="customerTableRef" :data="customerList" border size="small" style="width: 100%"
|
:highlight-current-row="true" row-key="id" @current-change="handleRowSelect" class="customer-table">
|
<el-table-column prop="systemNo" label="系统编号" min-width="150" show-overflow-tooltip />
|
<el-table-column prop="billName" label="账单名称" min-width="150" show-overflow-tooltip />
|
<el-table-column prop="supplierName" label="供应商名称" min-width="150" show-overflow-tooltip />
|
|
<el-table-column prop="isInternalSettlement" label="是否内部结算" min-width="120">
|
<template #default="scope">
|
{{ dictFormat(sys_whether_type, scope.row.isInternalSettlement) }}
|
</template>
|
</el-table-column>
|
|
<el-table-column prop="internalSettlementUnit" label="内部结算单位" min-width="120" show-overflow-tooltip />
|
<el-table-column prop="documentCount" label="单据数量" min-width="100" />
|
<el-table-column prop="totalAmount" label="应结算金额" min-width="120" />
|
|
<el-table-column prop="currency" label="币制" min-width="100">
|
<template #default="scope">
|
{{ dictFormat(sys_currency, scope.row.currency) }}
|
</template>
|
</el-table-column>
|
|
<el-table-column prop="discountAmount" label="减免金额" min-width="100" />
|
<el-table-column prop="paidAmount" label="已付金额" min-width="100" />
|
<el-table-column prop="pendingAmount" label="待付金额" min-width="100" />
|
|
<el-table-column prop="status" label="状态" width="100">
|
<template #default="scope">
|
{{ dictFormat(sys_bill_status, scope.row.status) }}
|
</template>
|
</el-table-column>
|
</el-table>
|
|
<pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
|
v-model:limit="queryParams.pageSize" @pagination="getList" />
|
|
<template #footer>
|
<div class="dialog-footer">
|
<el-button @click="handleClose">取消</el-button>
|
<el-button type="primary" @click="handleConfirm">确定选择</el-button>
|
</div>
|
</template>
|
</el-dialog>
|
</template>
|
|
<script setup lang="ts">
|
import { ref, reactive, watch, nextTick } from 'vue';
|
import type { Table } from 'element-plus';
|
import { ElMessage } from 'element-plus';
|
import useCurrentInstance from "@/utils/useCurrentInstance";
|
import { listPayableBillManagement } from "@/api/cwgl/payableBillManagement";
|
|
interface Customer {
|
id: string | number;
|
systemNo: string;
|
billName: string;
|
supplierName: string;
|
isInternalSettlement: string;
|
internalSettlementUnit: string;
|
documentCount: number;
|
totalAmount: number;
|
currency: string;
|
discountAmount: number;
|
paidAmount: number;
|
pendingAmount: number;
|
status: string | number;
|
}
|
|
const props = defineProps({
|
visible: { type: Boolean, default: false },
|
defaultSelectedId: { type: [String, Number], default: '' },
|
// 新增:接收默认状态
|
defaultStatus: { type: [String, Number], default: '' }
|
});
|
|
const emit = defineEmits(['confirm', 'close', 'update:visible']);
|
|
const { proxy } = useCurrentInstance();
|
// 获取所需的字典
|
const { sys_bill_status, sys_currency, sys_whether_type } = proxy.useDict(
|
'sys_bill_status',
|
'sys_currency',
|
'sys_whether_type'
|
);
|
|
const dictFormat = (dict: any, value: any) => {
|
return proxy.selectDictLabel(dict, value);
|
};
|
|
const dialogVisible = ref(false);
|
const customerList = ref<Customer[]>([]);
|
const total = ref(0);
|
const selectedRow = ref<Customer | null>(null);
|
const customerTableRef = ref<InstanceType<typeof Table>>();
|
|
const queryParams = reactive({
|
systemNo: '',
|
billName: '',
|
supplierName: '',
|
status: '',
|
pageNum: 1,
|
pageSize: 10
|
});
|
|
const getDataList = async () => {
|
try {
|
const res = await listPayableBillManagement(queryParams);
|
if (res.code === 200) {
|
customerList.value = res.rows;
|
total.value = res.total;
|
return res.rows;
|
}
|
} catch (err) {
|
console.error('加载列表失败:', err);
|
}
|
return [];
|
};
|
|
const autoSelectRow = (list: Customer[]) => {
|
if (!props.defaultSelectedId || list.length === 0) return;
|
nextTick(() => {
|
const target = list.find(item => String(item.id) === String(props.defaultSelectedId));
|
if (target && customerTableRef.value) {
|
customerTableRef.value.setCurrentRow(target);
|
selectedRow.value = target;
|
}
|
});
|
};
|
|
const handleSearch = () => {
|
queryParams.pageNum = 1;
|
getList();
|
};
|
|
const handleReset = () => {
|
// 重置其他搜索字段
|
queryParams.systemNo = '';
|
queryParams.billName = '';
|
queryParams.customerName = '';
|
|
// 核心处理:如果有默认状态值就恢复默认值,没有才设为空
|
if (props.defaultStatus !== undefined && props.defaultStatus !== null && props.defaultStatus !== '') {
|
queryParams.status = props.defaultStatus;
|
} else {
|
queryParams.status = '';
|
}
|
|
handleSearch();
|
};
|
|
const getList = () => {
|
getDataList().then((list) => {
|
autoSelectRow(list);
|
});
|
};
|
|
const handleRowSelect = (val: Customer | null) => {
|
selectedRow.value = val;
|
};
|
|
const handleConfirm = () => {
|
if (!selectedRow.value) {
|
ElMessage.warning('请先点击表格选择一行数据');
|
return;
|
}
|
emit('confirm', selectedRow.value);
|
handleClose();
|
};
|
|
const handleClose = () => {
|
emit('update:visible', false);
|
emit('close');
|
};
|
|
watch(() => props.visible, (newVal) => {
|
dialogVisible.value = newVal;
|
if (newVal) {
|
// 关键逻辑:如果 props 传了默认状态就用它,否则设置为空字符串
|
// 使用 queryParams.status = props.defaultStatus || '';
|
// 但考虑到 '0' 可能是有效值,建议判断是否为 undefined 或 null
|
if (props.defaultStatus !== undefined && props.defaultStatus !== null) {
|
queryParams.status = props.defaultStatus;
|
} else {
|
queryParams.status = '';
|
}
|
|
// 重置页码为第一页并加载数据
|
queryParams.pageNum = 1;
|
getList();
|
}
|
});
|
</script>
|