Skip to content

Commit e535384

Browse files
committed
✨ ERP:增加 ERP 销售出库的实现 30%(列表)
1 parent f7c5266 commit e535384

File tree

5 files changed

+1045
-0
lines changed

5 files changed

+1045
-0
lines changed

src/api/erp/sale/out/index.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import request from '@/config/axios'
2+
3+
// ERP 销售出库 VO
4+
export interface SaleOutVO {
5+
id: number // 销售出库编号
6+
no: string // 销售出库号
7+
customerId: number // 客户编号
8+
orderTime: Date // 出库工单时间
9+
totalCount: number // 合计数量
10+
totalPrice: number // 合计金额,单位:元
11+
status: number // 状态
12+
remark: string // 备注
13+
}
14+
15+
// ERP 销售出库 API
16+
export const SaleOutApi = {
17+
// 查询销售出库分页
18+
getSaleOutPage: async (params: any) => {
19+
return await request.get({ url: `/erp/sale-out/page`, params })
20+
},
21+
22+
// 查询销售出库详情
23+
getSaleOut: async (id: number) => {
24+
return await request.get({ url: `/erp/sale-out/get?id=` + id })
25+
},
26+
27+
// 新增销售出库
28+
createSaleOut: async (data: SaleOutVO) => {
29+
return await request.post({ url: `/erp/sale-out/create`, data })
30+
},
31+
32+
// 修改销售出库
33+
updateSaleOut: async (data: SaleOutVO) => {
34+
return await request.put({ url: `/erp/sale-out/update`, data })
35+
},
36+
37+
// 更新销售出库的状态
38+
updateSaleOutStatus: async (id: number, status: number) => {
39+
return await request.put({
40+
url: `/erp/sale-out/update-status`,
41+
params: {
42+
id,
43+
status
44+
}
45+
})
46+
},
47+
48+
// 删除销售出库
49+
deleteSaleOut: async (ids: number[]) => {
50+
return await request.delete({
51+
url: `/erp/sale-out/delete`,
52+
params: {
53+
ids: ids.join(',')
54+
}
55+
})
56+
},
57+
58+
// 导出销售出库 Excel
59+
exportSaleOut: async (params: any) => {
60+
return await request.download({ url: `/erp/sale-out/export-excel`, params })
61+
}
62+
}
Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
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="outTime">
19+
<el-date-picker
20+
v-model="formData.outTime"
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="customerId">
30+
<el-select
31+
v-model="formData.customerId"
32+
clearable
33+
filterable
34+
placeholder="请选择客户"
35+
class="!w-1/1"
36+
>
37+
<el-option
38+
v-for="item in customerList"
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="16">
47+
<el-form-item label="备注" prop="remark">
48+
<el-input
49+
type="textarea"
50+
v-model="formData.remark"
51+
:rows="1"
52+
placeholder="请输入备注"
53+
/>
54+
</el-form-item>
55+
</el-col>
56+
<el-col :span="8">
57+
<el-form-item label="附件" prop="fileUrl">
58+
<UploadFile :is-show-tip="false" v-model="formData.fileUrl" :limit="1" />
59+
</el-form-item>
60+
</el-col>
61+
</el-row>
62+
<!-- 子表的表单 -->
63+
<ContentWrap>
64+
<el-tabs v-model="subTabsName" class="-mt-15px -mb-10px">
65+
<el-tab-pane label="出库产品清单" name="item">
66+
<SaleOutItemForm ref="itemFormRef" :items="formData.items" :disabled="disabled" />
67+
</el-tab-pane>
68+
</el-tabs>
69+
</ContentWrap>
70+
<el-row :gutter="20">
71+
<el-col :span="8">
72+
<el-form-item label="优惠率(%)" prop="discountPercent">
73+
<el-input-number
74+
v-model="formData.discountPercent"
75+
controls-position="right"
76+
:min="0"
77+
:precision="2"
78+
placeholder="请输入优惠率"
79+
class="!w-1/1"
80+
/>
81+
</el-form-item>
82+
</el-col>
83+
<el-col :span="8">
84+
<el-form-item label="收款优惠" prop="discountPrice">
85+
<el-input
86+
disabled
87+
v-model="formData.discountPrice"
88+
:formatter="erpPriceInputFormatter"
89+
/>
90+
</el-form-item>
91+
</el-col>
92+
<el-col :span="8">
93+
<el-form-item label="优惠后金额">
94+
<el-input disabled v-model="formData.totalPrice" :formatter="erpPriceInputFormatter" />
95+
</el-form-item>
96+
</el-col>
97+
<el-col :span="8">
98+
<el-form-item label="结算账户" prop="accountId">
99+
<el-select
100+
v-model="formData.accountId"
101+
clearable
102+
filterable
103+
placeholder="请选择结算账户"
104+
class="!w-1/1"
105+
>
106+
<el-option
107+
v-for="item in accountList"
108+
:key="item.id"
109+
:label="item.name"
110+
:value="item.id"
111+
/>
112+
</el-select>
113+
</el-form-item>
114+
</el-col>
115+
<el-col :span="8">
116+
<el-form-item label="收取订金" prop="depositPrice">
117+
<el-input-number
118+
v-model="formData.depositPrice"
119+
controls-position="right"
120+
:min="0"
121+
:precision="2"
122+
placeholder="请输入收取订金"
123+
class="!w-1/1"
124+
/>
125+
</el-form-item>
126+
</el-col>
127+
</el-row>
128+
</el-form>
129+
<template #footer>
130+
<el-button @click="submitForm" type="primary" :disabled="formLoading" v-if="!disabled">
131+
确 定
132+
</el-button>
133+
<el-button @click="dialogVisible = false">取 消</el-button>
134+
</template>
135+
</Dialog>
136+
</template>
137+
<script setup lang="ts">
138+
import { SaleOutApi, SaleOutVO } from '@/api/erp/sale/out'
139+
import SaleOutItemForm from './components/SaleOutItemForm.vue'
140+
import { CustomerApi, CustomerVO } from '@/api/erp/sale/customer'
141+
import { AccountApi, AccountVO } from '@/api/erp/finance/account'
142+
import { erpPriceInputFormatter, erpPriceMultiply } from '@/utils'
143+
144+
/** ERP 销售出库表单 */
145+
defineOptions({ name: 'SaleOutForm' })
146+
147+
const { t } = useI18n() // 国际化
148+
const message = useMessage() // 消息弹窗
149+
150+
const dialogVisible = ref(false) // 弹窗的是否展示
151+
const dialogTitle = ref('') // 弹窗的标题
152+
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
153+
const formType = ref('') // 表单的类型:create - 新增;update - 修改;detail - 详情
154+
const formData = ref({
155+
id: undefined,
156+
customerId: undefined,
157+
accountId: undefined,
158+
outTime: undefined,
159+
remark: undefined,
160+
fileUrl: '',
161+
discountPercent: 0,
162+
discountPrice: 0,
163+
totalPrice: 0,
164+
depositPrice: 0,
165+
items: [],
166+
no: undefined // 出库单号,后端返回
167+
})
168+
const formRules = reactive({
169+
customerId: [{ required: true, message: '客户不能为空', trigger: 'blur' }],
170+
outTime: [{ required: true, message: '出库时间不能为空', trigger: 'blur' }]
171+
})
172+
const disabled = computed(() => formType.value === 'detail')
173+
const formRef = ref() // 表单 Ref
174+
const customerList = ref<CustomerVO[]>([]) // 客户列表
175+
const accountList = ref<AccountVO[]>([]) // 账户列表
176+
177+
/** 子表的表单 */
178+
const subTabsName = ref('item')
179+
const itemFormRef = ref()
180+
181+
/** 计算 discountPrice、totalPrice 价格 */
182+
watch(
183+
() => formData.value,
184+
(val) => {
185+
if (!val) {
186+
return
187+
}
188+
const totalPrice = val.items.reduce((prev, curr) => prev + curr.totalPrice, 0)
189+
const discountPrice =
190+
val.discountPercent != null ? erpPriceMultiply(totalPrice, val.discountPercent / 100.0) : 0
191+
formData.value.discountPrice = discountPrice
192+
formData.value.totalPrice = totalPrice - discountPrice
193+
},
194+
{ deep: true }
195+
)
196+
197+
/** 打开弹窗 */
198+
const open = async (type: string, id?: number) => {
199+
dialogVisible.value = true
200+
dialogTitle.value = t('action.' + type)
201+
formType.value = type
202+
resetForm()
203+
// 修改时,设置数据
204+
if (id) {
205+
formLoading.value = true
206+
try {
207+
formData.value = await SaleOutApi.getSaleOut(id)
208+
} finally {
209+
formLoading.value = false
210+
}
211+
}
212+
// 加载客户列表
213+
customerList.value = await CustomerApi.getCustomerSimpleList()
214+
// 加载账户列表
215+
accountList.value = await AccountApi.getAccountSimpleList()
216+
const defaultAccount = accountList.value.find((item) => item.defaultStatus)
217+
if (defaultAccount) {
218+
formData.value.accountId = defaultAccount.id
219+
}
220+
}
221+
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
222+
223+
/** 提交表单 */
224+
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
225+
const submitForm = async () => {
226+
// 校验表单
227+
await formRef.value.validate()
228+
await itemFormRef.value.validate()
229+
// 提交请求
230+
formLoading.value = true
231+
try {
232+
const data = formData.value as unknown as SaleOutVO
233+
if (formType.value === 'create') {
234+
await SaleOutApi.createSaleOut(data)
235+
message.success(t('common.createSuccess'))
236+
} else {
237+
await SaleOutApi.updateSaleOut(data)
238+
message.success(t('common.updateSuccess'))
239+
}
240+
dialogVisible.value = false
241+
// 发送操作成功的事件
242+
emit('success')
243+
} finally {
244+
formLoading.value = false
245+
}
246+
}
247+
248+
/** 重置表单 */
249+
const resetForm = () => {
250+
formData.value = {
251+
id: undefined,
252+
customerId: undefined,
253+
accountId: undefined,
254+
outTime: undefined,
255+
remark: undefined,
256+
fileUrl: undefined,
257+
discountPercent: 0,
258+
discountPrice: 0,
259+
totalPrice: 0,
260+
depositPrice: 0,
261+
items: []
262+
}
263+
formRef.value?.resetFields()
264+
}
265+
</script>

0 commit comments

Comments
 (0)