CheckSumCheck.vue
6.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<template>
<BasicModal
v-bind="$attrs"
@register="register"
title="应付款汇总"
width="60%"
okText="导出"
:isDetail="true"
:showDetailBack="false"
@ok="handleOk"
@visible-change="handleShow"
>
<div class="p-4">
<BasicTable @register="registerTable">
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'action'"> </template>
</template>
</BasicTable>
</div>
</BasicModal>
</template>
<script lang="ts" setup>
import { BasicModal, useModalInner } from '@/components/Modal';
import { computed, ref, watch } from 'vue';
import { checkAnalysis, exportCheckAnalysis } from '@/api/project/invoice';
import { BasicColumn, useTable, BasicTable, ColumnChangeParam } from '/@/components/Table';
// 处理弹窗的确定按钮点击事件
import axios from 'axios';
import { store } from '/@/store';
import { useOrderStoreWithOut } from '/@/store/modules/order';
import { useUserStoreWithOut } from '/@/store/modules/user';
const userStore = useUserStoreWithOut();
const columnsAnalysis: BasicColumn[] = [
{
title: '生产科名称',
dataIndex: 'productionDepartment',
width: 150,
customRender: (res) => {
return res.record.exportVOS[0].productionDepartment;
},
},
{
title: '生产科总价汇总¥',
dataIndex: 'checkProductionDepartmentTotalPrice',
width: 150,
customRender: (res) => {
return res.record.productionDepartmentTotalPrice.toFixed(2);
},
},
{
title: '生产科扣款金额汇总¥',
dataIndex: 'deductAmount',
width: 160,
customRender: (res) => {
return res.record.deductAmount.toFixed(2);
},
},
{
title: '生产科实际应付金额¥',
dataIndex: 'calculateActualPayedAmount',
width: 160,
customRender: (res) => {
return res.record.calculateActualPayedAmount.toFixed(2);
},
},
{
title: '实际付款金额汇总¥',
dataIndex: 'actualPayedAmount',
width: 160,
customRender: (res) => {
return res.record.actualPayedAmount.toFixed(2);
},
},
{
title: '未付金额¥',
dataIndex: 'unPayedAmount',
width: 150,
customRender: (res) => {
return res.record.unPayedAmount.toFixed(2);
},
},
];
// const ids = ref<number[]>([]);
const ids = ref();
const orderIds = ref();
// const res = ref();
const dataStore = useOrderStoreWithOut(); // 获取 store 实例
const queryVO = ref();
watch(
() => store.state, // 监控 queryVO
(newQueryVO, oldQueryVO) => {
queryVO.value = dataStore.getQueryVO;
// 在这里可以根据 queryVO 的变化进行其他操作,比如重新请求数据等
},
{ deep: true }, // 深度监控 queryVO 数组或对象的变化
);
const [register, { closeModal }] = useModalInner(async (data) => {
// ids.value = data.data;
ids.value = data.data;
orderIds.value = data.id;
setTimeout(() => {
reload();
}, 50);
});
const [registerTable, { reload }] = useTable({
// api: () => invoiceAnalysis({ ids: ids.value }),
api: async () => {
const res = await checkAnalysis({
ids: ids.value,
orderIds: orderIds.value,
queryVO: queryVO.value,
});
// 计算合计行
const sum = {
productionDepartmentTotalPrice: 0,
deductAmount: 0,
calculateActualPayedAmount: 0,
actualPayedAmount: 0,
unPayedAmount: 0,
exportVOS: res[0].exportVOS ? JSON.parse(JSON.stringify(res[0].exportVOS)) : [],
};
res.forEach((item: any) => {
sum.productionDepartmentTotalPrice += item.productionDepartmentTotalPrice || 0;
sum.deductAmount += item.deductAmount || 0;
sum.calculateActualPayedAmount += item.calculateActualPayedAmount || 0;
sum.actualPayedAmount += item.actualPayedAmount || 0;
sum.unPayedAmount += item.unPayedAmount || 0;
});
if (sum.exportVOS && sum.exportVOS[0]) {
sum.exportVOS[0].productionDepartment = '合计';
}
res.push(sum);
return res;
},
columns: columnsAnalysis,
bordered: true,
});
function handleShow(visible: boolean) {
reload();
}
const searchData = ref({});
async function handleOk() {
// 构造符合 API 要求的参数
// const ids = [23];
// const requestData = {
// ids: ids.value,
// };
const idss = ids.value;
const token = userStore.getToken;
// await exportCheckAnalysis({ ids: ids });
axios
.post(
'/basic-api/order/erp/check_bill/export',
{ ids: idss, orderIds: orderIds.value, queryVO: queryVO.value },
{
headers: {
Authorization: `${token}`, // 去掉引号
},
responseType: 'blob', // 设置响应类型为 'blob'
},
)
.then((response) => {
// 创建一个 Blob 对象来保存二进制数据
const blob = new Blob([response.data], { type: 'application/zip' });
const getFormattedDate = (): string => {
const date = new Date();
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
};
const date = getFormattedDate();
// 创建一个链接元素用于下载
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = `应付款分析${date}.xlsx`; // 你可以为文件命名
document.body.appendChild(link);
link.click(); // 自动点击链接,触发下载
document.body.removeChild(link); // 下载完成后移除链接
})
.catch((error) => {
console.error(error);
});
reload();
closeModal();
}
</script>
<style scoped>
.divAll {
display: flex;
justify-content: center;
align-items: center;
}
</style>