Statement.vue
8.46 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<template>
<BasicModal
v-bind="$attrs"
destroyOnClose
@register="register"
title="LOACL对账单"
width="1100px"
@visible-change="handleShow"
:footer="null"
:bodyStyle="{ height: '650px', overflow: 'hidden' }"
>
<div class="container">
<div v-if="isShow1 == true" style="margin-top: 30px">
<RadioGroup v-model:value="selectedCompany" :options="companyOptions" style="display: flex; gap: 200px;"/>
</div>
<!-- 代垫费用区域 -->
<div class="table-container" style="display: flex; flex-wrap: wrap; justify-content: space-between; margin-top: 30px" >
<div class="table-box" style="flex: 0.5; margin-right: -20px;">
<h3>代垫费用</h3>
<div class="input-row" style="display: flex; align-items: center;">
<a-button type="primary" style="margin-left: 10px;" @click="addAdvanceCost">添加费用</a-button>
</div>
<div v-for="(item, index) in advanceCosts" :key="'advance-' + index" class="input-row" style="margin-top: 10px; display: flex;">
<a-input v-model:value="item.name" placeholder="请输入费用名称" style="width: 200px;" />
<a-input-number v-model:value="item.value" placeholder="请输入费用金额" style="width: 150px !important; margin-left: 10px;" />
<a-button type="danger" style="margin-left: 10px;" @click="removeAdvanceCost(index)">删除</a-button>
</div>
</div>
<div class="table-box" style="flex: 1;">
<h3>费用支出</h3>
<div class="input-row" style="display: flex; align-items: center;">
<a-button type="primary" style="margin-left: 10px;" @click="addExpenseCost">添加费用</a-button>
</div>
<div v-for="(item, index) in expenseCosts" :key="'expense-' + index" class="input-row" style="margin-top: 10px; display: flex;">
<a-input v-model:value="item.name" placeholder="请输入费用名称" style="width: 200px;" />
<a-input-number v-model:value="item.value" placeholder="请输入费用金额" style="width: 150px !important; margin-left: 10px;" />
<a-button type="danger" style="margin-left: 10px;" @click="removeExpenseCost(index)">删除</a-button>
</div>
</div>
</div>
<div class="bottom">
<a-button type="primary" @click="handleAccountStatement" className="ml-4" v-if="isShow1 == true"
>生成</a-button
>
<a-button type="primary" @click="handleCancel" className="ml-4" style="margin-left: 6px"
>取消</a-button
>
</div>
</div>
</BasicModal>
</template>
<script lang="ts">
import { defineComponent, ref, computed } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { RadioGroup } from 'ant-design-vue';
import { useMessage } from '@/hooks/web/useMessage';
import axios from 'axios';
export default defineComponent({
props: {
role: {
type: String,
},
customerCodes: {
type: Array<string | number>,
},
},
components: { BasicModal, RadioGroup },
setup(props) {
const loading = ref(true);
const choose = ref();
const checkedKeys=ref();
const isShow1 = ref(true);
const advanceCostValue = ref(0);
const expenseCostValue = ref(0);
const advanceCosts = ref<{ name: string; value: number }[]>([]);
const expenseCosts = ref<{ name: string; value: number }[]>([]);
const [register, { setModalProps, closeModal }] = useModalInner(async (data)=>{
checkedKeys.value=data.checkedKeys;
});
const { createMessage } = useMessage();
const { error } = createMessage;
const selectedCompany = ref();
const companyOptions = ref([
{ label: '翱特逸格饰品有限公司', value: '翱特逸格饰品有限公司' },
{ label: '吉庆天成饰品有限公司', value: '吉庆天成饰品有限公司' }
]);
function addAdvanceCost() {
advanceCosts.value.push({ name: '', value: advanceCostValue.value });
}
function addExpenseCost() {
expenseCosts.value.push({ name: '', value: expenseCostValue.value });
}
function removeAdvanceCost(index: number) {
advanceCosts.value.splice(index, 1);
}
function removeExpenseCost(index: number) {
expenseCosts.value.splice(index, 1);
}
function handleCancel() {
loading.value = true;
choose.value = '';
setModalProps({ loading: false, confirmLoading: false });
isShow1.value = true;
advanceCosts.value = [];
expenseCosts.value = [];
closeModal();
}
function handleShow(visible: boolean) {
if (visible) {
loading.value = true;
choose.value = '';
setModalProps({ loading: false, confirmLoading: false });
isShow1.value = true;
} else {
advanceCosts.value = [];
expenseCosts.value = [];
}
}
async function handleAccountStatement() {
if (!selectedCompany.value) {
error('请选择公司'); // 提示用户选择公司
return; // 结束函数执行
}
axios
.post(
'/basic-api/order/erp/order/accountStatement',
{
ids: checkedKeys.value,
disbursement: advanceCosts.value.map(item => ({ [item.name]: item.value })),
deduction: expenseCosts.value.map(item => ({ [item.name]: item.value })),
titleCompany: selectedCompany.value
},
{
responseType: 'blob', // 设置响应类型为 'blob'
},
)
.then((response) => {
// 创建一个 Blob 对象来保存二进制数据
const blob = new Blob([response.data], { type: 'application/octet-stream' });
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 = `${selectedCompany.value}对账单${date}.xlsx`; // 你可以为文件命名
document.body.appendChild(link);
link.click(); // 自动点击链接,触发下载
document.body.removeChild(link); // 下载完成后移除链接
})
.catch((error) => {
console.error(error);
});
closeModal();
}
return {
register,
loading,
choose,
handleShow,
handleCancel,
advanceCostValue,
expenseCostValue,
advanceCosts,
expenseCosts,
addAdvanceCost,
addExpenseCost,
isShow1,
selectedCompany,
companyOptions,
removeAdvanceCost,
removeExpenseCost,
handleAccountStatement,
};
},
});
</script>
<style scoped>
/* .container {
position: relative;
}
.bottom {
position: absolute;
bottom: 0;
} */
.container {
display: flex;
flex-direction: column;
/* min-height: 20vh; */
}
.bottom {
margin-top: 40px;
/* margin-right: auto; */
margin-left: 150px;
}
.showPdf {
display: flex;
position: relative;
height: 30px;
width: 470px;
border: 2px solid;
border-radius: 5px;
border-color: #d8d8d8;
}
.FilePptOutlined {
margin-top: 3px;
margin-left: 30px;
}
.EyeOutlined {
margin-top: 3px;
margin-left: 290px;
}
</style>