Skip to content

Commit d7427bf

Browse files
committed
✨ ERP:付款单 50%(详情)
1 parent aa964e1 commit d7427bf

File tree

3 files changed

+422
-3
lines changed

3 files changed

+422
-3
lines changed
Lines changed: 279 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,279 @@
1+
<template>
2+
<Dialog :title="dialogTitle" v-model="dialogVisible" width="1080">
3+
<el-form
4+
ref="formRef"
5+
:model="formData"
6+
:rules="formRules"
7+
label-width="100px"
8+
v-loading="formLoading"
9+
:disabled="disabled"
10+
>
11+
<el-row :gutter="20">
12+
<el-col :span="8">
13+
<el-form-item label="付款单号" prop="no">
14+
<el-input disabled v-model="formData.no" placeholder="保存时自动生成" />
15+
</el-form-item>
16+
</el-col>
17+
<el-col :span="8">
18+
<el-form-item label="付款时间" prop="paymentTime">
19+
<el-date-picker
20+
v-model="formData.paymentTime"
21+
type="date"
22+
value-format="x"
23+
placeholder="选择付款时间"
24+
class="!w-1/1"
25+
/>
26+
</el-form-item>
27+
</el-col>
28+
<el-col :span="8">
29+
<el-form-item label="供应商" prop="supplierId">
30+
<el-select
31+
v-model="formData.supplierId"
32+
clearable
33+
filterable
34+
placeholder="请选择供应商"
35+
class="!w-1/1"
36+
>
37+
<el-option
38+
v-for="item in supplierList"
39+
:key="item.id"
40+
:label="item.name"
41+
:value="item.id"
42+
/>
43+
</el-select>
44+
</el-form-item>
45+
</el-col>
46+
<el-col :span="8">
47+
<el-form-item label="财务人员" prop="financeUserId">
48+
<el-select
49+
v-model="formData.financeUserId"
50+
clearable
51+
filterable
52+
placeholder="请选择财务人员"
53+
class="!w-1/1"
54+
>
55+
<el-option
56+
v-for="item in userList"
57+
:key="item.id"
58+
:label="item.nickname"
59+
:value="item.id"
60+
/>
61+
</el-select>
62+
</el-form-item>
63+
</el-col>
64+
<el-col :span="16">
65+
<el-form-item label="备注" prop="remark">
66+
<el-input
67+
type="textarea"
68+
v-model="formData.remark"
69+
:rows="1"
70+
placeholder="请输入备注"
71+
/>
72+
</el-form-item>
73+
</el-col>
74+
<el-col :span="8">
75+
<el-form-item label="附件" prop="fileUrl">
76+
<UploadFile :is-show-tip="false" v-model="formData.fileUrl" :limit="1" />
77+
</el-form-item>
78+
</el-col>
79+
</el-row>
80+
<!-- 子表的表单 -->
81+
<ContentWrap>
82+
<el-tabs v-model="subTabsName" class="-mt-15px -mb-10px">
83+
<el-tab-pane label="采购入库、退货单" name="item">
84+
<FinancePaymentItemForm
85+
ref="itemFormRef"
86+
:items="formData.items"
87+
:disabled="disabled"
88+
/>
89+
</el-tab-pane>
90+
</el-tabs>
91+
</ContentWrap>
92+
<el-row :gutter="20">
93+
<el-col :span="8">
94+
<el-form-item label="付款账户" prop="accountId">
95+
<el-select
96+
v-model="formData.accountId"
97+
clearable
98+
filterable
99+
placeholder="请选择结算账户"
100+
class="!w-1/1"
101+
>
102+
<el-option
103+
v-for="item in accountList"
104+
:key="item.id"
105+
:label="item.name"
106+
:value="item.id"
107+
/>
108+
</el-select>
109+
</el-form-item>
110+
</el-col>
111+
<el-col :span="8">
112+
<el-form-item label="合计付款" prop="totalPrice">
113+
<el-input disabled v-model="formData.totalPrice" :formatter="erpPriceInputFormatter" />
114+
</el-form-item>
115+
</el-col>
116+
<el-col :span="8">
117+
<el-form-item label="优惠金额" prop="discountPrice">
118+
<el-input-number
119+
v-model="formData.discountPrice"
120+
controls-position="right"
121+
:precision="2"
122+
placeholder="请输入优惠金额"
123+
class="!w-1/1"
124+
/>
125+
</el-form-item>
126+
</el-col>
127+
<el-col :span="8">
128+
<el-form-item label="实际付款">
129+
<el-input
130+
disabled
131+
v-model="formData.paymentPrice"
132+
:formatter="erpPriceInputFormatter"
133+
/>
134+
</el-form-item>
135+
</el-col>
136+
</el-row>
137+
</el-form>
138+
<template #footer>
139+
<el-button @click="submitForm" type="primary" :disabled="formLoading" v-if="!disabled">
140+
确 定
141+
</el-button>
142+
<el-button @click="dialogVisible = false">取 消</el-button>
143+
</template>
144+
</Dialog>
145+
</template>
146+
<script setup lang="ts">
147+
import { FinancePaymentApi, FinancePaymentVO } from '@/api/erp/finance/payment'
148+
import FinancePaymentItemForm from './components/FinancePaymentItemForm.vue'
149+
import { SupplierApi, SupplierVO } from '@/api/erp/purchase/supplier'
150+
import { erpPriceInputFormatter, erpPriceMultiply } from '@/utils'
151+
import * as UserApi from '@/api/system/user'
152+
import { AccountApi, AccountVO } from '@/api/erp/finance/account'
153+
154+
/** ERP 付款单表单 */
155+
defineOptions({ name: 'FinancePaymentForm' })
156+
157+
const { t } = useI18n() // 国际化
158+
const message = useMessage() // 消息弹窗
159+
160+
const dialogVisible = ref(false) // 弹窗的是否展示
161+
const dialogTitle = ref('') // 弹窗的标题
162+
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
163+
const formType = ref('') // 表单的类型:create - 新增;update - 修改;detail - 详情
164+
const formData = ref({
165+
id: undefined,
166+
supplierId: undefined,
167+
accountId: undefined,
168+
financeUserId: undefined,
169+
paymentTime: undefined,
170+
remark: undefined,
171+
fileUrl: '',
172+
totalPrice: 0,
173+
discountPrice: 0,
174+
paymentPrice: 0,
175+
items: [],
176+
no: undefined // 订单单号,后端返回
177+
})
178+
const formRules = reactive({
179+
supplierId: [{ required: true, message: '供应商不能为空', trigger: 'blur' }],
180+
paymentTime: [{ required: true, message: '订单时间不能为空', trigger: 'blur' }]
181+
})
182+
const disabled = computed(() => formType.value === 'detail')
183+
const formRef = ref() // 表单 Ref
184+
const supplierList = ref<SupplierVO[]>([]) // 供应商列表
185+
const accountList = ref<AccountVO[]>([]) // 账户列表
186+
const userList = ref<UserApi.UserVO[]>([]) // 用户列表
187+
188+
/** 子表的表单 */
189+
const subTabsName = ref('item')
190+
const itemFormRef = ref()
191+
192+
/** 计算 discountPrice、totalPrice 价格 */
193+
watch(
194+
() => formData.value,
195+
(val) => {
196+
if (!val) {
197+
return
198+
}
199+
const totalPrice = val.items.reduce((prev, curr) => prev + curr.totalPrice, 0)
200+
const discountPrice =
201+
val.discountPercent != null ? erpPriceMultiply(totalPrice, val.discountPercent / 100.0) : 0
202+
formData.value.discountPrice = discountPrice
203+
formData.value.totalPrice = totalPrice - discountPrice
204+
},
205+
{ deep: true }
206+
)
207+
208+
/** 打开弹窗 */
209+
const open = async (type: string, id?: number) => {
210+
dialogVisible.value = true
211+
dialogTitle.value = t('action.' + type)
212+
formType.value = type
213+
resetForm()
214+
// 修改时,设置数据
215+
if (id) {
216+
formLoading.value = true
217+
try {
218+
formData.value = await FinancePaymentApi.getFinancePayment(id)
219+
} finally {
220+
formLoading.value = false
221+
}
222+
}
223+
// 加载供应商列表
224+
supplierList.value = await SupplierApi.getSupplierSimpleList()
225+
// 加载用户列表
226+
userList.value = await UserApi.getSimpleUserList()
227+
// 加载账户列表
228+
accountList.value = await AccountApi.getAccountSimpleList()
229+
const defaultAccount = accountList.value.find((item) => item.defaultStatus)
230+
if (defaultAccount) {
231+
formData.value.accountId = defaultAccount.id
232+
}
233+
}
234+
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
235+
236+
/** 提交表单 */
237+
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
238+
const submitForm = async () => {
239+
// 校验表单
240+
await formRef.value.validate()
241+
await itemFormRef.value.validate()
242+
// 提交请求
243+
formLoading.value = true
244+
try {
245+
const data = formData.value as unknown as FinancePaymentVO
246+
if (formType.value === 'create') {
247+
await FinancePaymentApi.createFinancePayment(data)
248+
message.success(t('common.createSuccess'))
249+
} else {
250+
await FinancePaymentApi.updateFinancePayment(data)
251+
message.success(t('common.updateSuccess'))
252+
}
253+
dialogVisible.value = false
254+
// 发送操作成功的事件
255+
emit('success')
256+
} finally {
257+
formLoading.value = false
258+
}
259+
}
260+
261+
/** 重置表单 */
262+
const resetForm = () => {
263+
formData.value = {
264+
id: undefined,
265+
supplierId: undefined,
266+
accountId: undefined,
267+
financeUserId: undefined,
268+
paymentTime: undefined,
269+
remark: undefined,
270+
fileUrl: undefined,
271+
totalPrice: 0,
272+
discountPrice: 0,
273+
paymentPrice: 0,
274+
items: [],
275+
no: undefined
276+
}
277+
formRef.value?.resetFields()
278+
}
279+
</script>

0 commit comments

Comments
 (0)