Commit 616fd3f7 by YunaiV

ERP:初始化其它出库的实现

parent 318d5261
import request from '@/config/axios'
// ERP 其它出库单 VO
export interface StockOutVO {
id: number // 出库编号
no: string // 出库单号
customerId: number // 客户编号
outTime: Date // 出库时间
totalCount: number // 合计数量
totalPrice: number // 合计金额,单位:元
status: number // 状态
remark: string // 备注
}
// ERP 其它出库单 API
export const StockOutApi = {
// 查询其它出库单分页
getStockOutPage: async (params: any) => {
return await request.get({ url: `/erp/stock-out/page`, params })
},
// 查询其它出库单详情
getStockOut: async (id: number) => {
return await request.get({ url: `/erp/stock-out/get?id=` + id })
},
// 新增其它出库单
createStockOut: async (data: StockOutVO) => {
return await request.post({ url: `/erp/stock-out/create`, data })
},
// 修改其它出库单
updateStockOut: async (data: StockOutVO) => {
return await request.put({ url: `/erp/stock-out/update`, data })
},
// 更新其它出库单的状态
updateStockOutStatus: async (id: number, status: number) => {
return await request.put({
url: `/erp/stock-out/update-status`,
params: {
id,
status
}
})
},
// 删除其它出库单
deleteStockOut: async (ids: number[]) => {
return await request.delete({
url: `/erp/stock-out/delete`,
params: {
ids: ids.join(',')
}
})
},
// 导出其它出库单 Excel
exportStockOut: async (params) => {
return await request.download({ url: `/erp/stock-out/export-excel`, params })
}
}
...@@ -62,8 +62,8 @@ ...@@ -62,8 +62,8 @@
<!-- 子表的表单 --> <!-- 子表的表单 -->
<ContentWrap> <ContentWrap>
<el-tabs v-model="subTabsName" class="-mt-15px -mb-10px"> <el-tabs v-model="subTabsName" class="-mt-15px -mb-10px">
<el-tab-pane label="入库产品清单" name="stockInItem"> <el-tab-pane label="入库产品清单" name="item">
<StockInItemForm ref="stockInItemFormRef" :items="formData.items" :disabled="disabled" /> <StockInItemForm ref="itemFormRef" :items="formData.items" :disabled="disabled" />
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
</ContentWrap> </ContentWrap>
...@@ -106,8 +106,8 @@ const formRef = ref() // 表单 Ref ...@@ -106,8 +106,8 @@ const formRef = ref() // 表单 Ref
const supplierList = ref<SupplierVO[]>([]) // 供应商列表 const supplierList = ref<SupplierVO[]>([]) // 供应商列表
/** 子表的表单 */ /** 子表的表单 */
const subTabsName = ref('stockInItem') const subTabsName = ref('item')
const stockInItemFormRef = ref() const itemFormRef = ref()
/** 打开弹窗 */ /** 打开弹窗 */
const open = async (type: string, id?: number) => { const open = async (type: string, id?: number) => {
...@@ -134,7 +134,7 @@ const emit = defineEmits(['success']) // 定义 success 事件,用于操作成 ...@@ -134,7 +134,7 @@ const emit = defineEmits(['success']) // 定义 success 事件,用于操作成
const submitForm = async () => { const submitForm = async () => {
// 校验表单 // 校验表单
await formRef.value.validate() await formRef.value.validate()
await stockInItemFormRef.value.validate() await itemFormRef.value.validate()
// 提交请求 // 提交请求
formLoading.value = true formLoading.value = true
try { try {
......
...@@ -142,7 +142,6 @@ import { ...@@ -142,7 +142,6 @@ import {
erpPriceMultiply, erpPriceMultiply,
getSumValue getSumValue
} from '@/utils' } from '@/utils'
import { fenToYuanFormat } from '@/utils/formatter'
const props = defineProps<{ const props = defineProps<{
items: undefined items: undefined
......
...@@ -239,7 +239,7 @@ ...@@ -239,7 +239,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict' import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
import { dateFormatter, dateFormatter2 } from '@/utils/formatTime' import { dateFormatter2 } from '@/utils/formatTime'
import download from '@/utils/download' import download from '@/utils/download'
import { StockInApi, StockInVO } from '@/api/erp/stock/in' import { StockInApi, StockInVO } from '@/api/erp/stock/in'
import StockInForm from './StockInForm.vue' import StockInForm from './StockInForm.vue'
...@@ -248,10 +248,9 @@ import { WarehouseApi, WarehouseVO } from '@/api/erp/stock/warehouse' ...@@ -248,10 +248,9 @@ import { WarehouseApi, WarehouseVO } from '@/api/erp/stock/warehouse'
import { SupplierApi, SupplierVO } from '@/api/erp/purchase/supplier' import { SupplierApi, SupplierVO } from '@/api/erp/purchase/supplier'
import { UserVO } from '@/api/system/user' import { UserVO } from '@/api/system/user'
import * as UserApi from '@/api/system/user' import * as UserApi from '@/api/system/user'
import * as BusinessApi from '@/api/crm/business'
import { erpCountTableColumnFormatter, erpPriceTableColumnFormatter } from '@/utils' import { erpCountTableColumnFormatter, erpPriceTableColumnFormatter } from '@/utils'
/** ERP 其它入库单 列表 */ /** ERP 其它入库单列表 */
defineOptions({ name: 'ErpStockIn' }) defineOptions({ name: 'ErpStockIn' })
const message = useMessage() // 消息弹窗 const message = useMessage() // 消息弹窗
......
<template>
<Dialog :title="dialogTitle" v-model="dialogVisible" width="1080">
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="100px"
v-loading="formLoading"
:disabled="disabled"
>
<el-row :gutter="20">
<el-col :span="8">
<el-form-item label="出库单号" prop="no">
<el-input disabled v-model="formData.no" placeholder="保存时自动生成" />
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="出库时间" prop="outTime">
<el-date-picker
v-model="formData.outTime"
type="date"
value-format="x"
placeholder="选择出库时间"
class="!w-1/1"
/>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="客户" prop="customerId">
<el-select
v-model="formData.customerId"
filterable
placeholder="请选择客户"
class="!w-1/1"
>
<el-option
v-for="item in supplierList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="16">
<el-form-item label="备注" prop="remark">
<el-input
type="textarea"
v-model="formData.remark"
:rows="1"
placeholder="请输入备注"
/>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="附件" prop="fileUrl">
<UploadFile :is-show-tip="false" v-model="formData.fileUrl" :limit="1" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<!-- 子表的表单 -->
<ContentWrap>
<el-tabs v-model="subTabsName" class="-mt-15px -mb-10px">
<el-tab-pane label="出库产品清单" name="item">
<StockOutItemForm ref="itemFormRef" :items="formData.items" :disabled="disabled" />
</el-tab-pane>
</el-tabs>
</ContentWrap>
<template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading" v-if="!disabled">
确 定
</el-button>
<el-button @click="dialogVisible = false">取 消</el-button>
</template>
</Dialog>
</template>
<script setup lang="ts">
import { StockOutApi, StockOutVO } from '@/api/erp/stock/out'
import StockOutItemForm from './components/StockOutItemForm.vue'
import { SupplierApi, SupplierVO } from '@/api/erp/purchase/supplier'
/** ERP 其它出库单表单 */
defineOptions({ name: 'StockOutForm' })
const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗
const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
const formType = ref('') // 表单的类型:create - 新增;update - 修改;detail - 详情
const formData = ref({
id: undefined,
customerId: undefined,
outTime: undefined,
remark: undefined,
fileUrl: '',
items: []
})
const formRules = reactive({
outTime: [{ required: true, message: '出库时间不能为空', trigger: 'blur' }]
})
const disabled = computed(() => formType.value === 'detail')
const formRef = ref() // 表单 Ref
const supplierList = ref<SupplierVO[]>([]) // 客户列表
/** 子表的表单 */
const subTabsName = ref('item')
const itemFormRef = ref()
/** 打开弹窗 */
const open = async (type: string, id?: number) => {
dialogVisible.value = true
dialogTitle.value = t('action.' + type)
formType.value = type
resetForm()
// 修改时,设置数据
if (id) {
formLoading.value = true
try {
formData.value = await StockOutApi.getStockOut(id)
} finally {
formLoading.value = false
}
}
// 加载客户列表
supplierList.value = await SupplierApi.getSupplierSimpleList()
}
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
/** 提交表单 */
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
const submitForm = async () => {
// 校验表单
await formRef.value.validate()
await itemFormRef.value.validate()
// 提交请求
formLoading.value = true
try {
const data = formData.value as unknown as StockOutVO
if (formType.value === 'create') {
await StockOutApi.createStockOut(data)
message.success(t('common.createSuccess'))
} else {
await StockOutApi.updateStockOut(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
// 发送操作成功的事件
emit('success')
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined,
customerId: undefined,
outTime: undefined,
remark: undefined,
fileUrl: undefined,
items: []
}
formRef.value?.resetFields()
}
</script>
<template>
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
v-loading="formLoading"
label-width="0px"
:inline-message="true"
:disabled="disabled"
>
<el-table :data="formData" show-summary :summary-method="getSummaries" class="-mt-10px">
<el-table-column label="序号" type="index" align="center" width="60" />
<el-table-column label="仓库名称" min-width="125">
<template #default="{ row, $index }">
<el-form-item
:prop="`${$index}.warehouseId`"
:rules="formRules.warehouseId"
class="mb-0px!"
>
<el-select
v-model="row.warehouseId"
filterable
placeholder="请选择仓库"
@change="onChangeWarehouse($event, row)"
>
<el-option
v-for="item in warehouseList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
</template>
</el-table-column>
<el-table-column label="产品名称" min-width="180">
<template #default="{ row, $index }">
<el-form-item :prop="`${$index}.productId`" :rules="formRules.productId" class="mb-0px!">
<el-select
v-model="row.productId"
filterable
@change="onChangeProduct($event, row)"
placeholder="请选择产品"
>
<el-option
v-for="item in productList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
</template>
</el-table-column>
<el-table-column label="库存" min-width="100">
<template #default="{ row }">
<el-form-item class="mb-0px!">
<el-input disabled v-model="row.stockCount" :formatter="erpCountInputFormatter" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="条码" min-width="150">
<template #default="{ row }">
<el-form-item class="mb-0px!">
<el-input disabled v-model="row.productBarCode" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="单位" min-width="80">
<template #default="{ row }">
<el-form-item class="mb-0px!">
<el-input disabled v-model="row.productUnitName" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="数量" prop="count" fixed="right" min-width="140">
<template #default="{ row, $index }">
<el-form-item :prop="`${$index}.count`" :rules="formRules.count" class="mb-0px!">
<el-input-number
v-model="row.count"
controls-position="right"
:min="0.001"
:precision="3"
class="!w-100%"
/>
</el-form-item>
</template>
</el-table-column>
<el-table-column label="产品单价" fixed="right" min-width="120">
<template #default="{ row, $index }">
<el-form-item
:prop="`${$index}.productPrice`"
:rules="formRules.productPrice"
class="mb-0px!"
>
<el-input-number
v-model="row.productPrice"
controls-position="right"
:min="0.01"
:precision="2"
class="!w-100%"
/>
</el-form-item>
</template>
</el-table-column>
<el-table-column label="合计金额" prop="totalPrice" fixed="right" min-width="100">
<template #default="{ row, $index }">
<el-form-item
:prop="`${$index}.totalPrice`"
:rules="formRules.totalPrice"
class="mb-0px!"
>
<el-input disabled v-model="row.totalPrice" :formatter="erpPriceInputFormatter" />
</el-form-item>
</template>
</el-table-column>
<el-table-column label="备注" min-width="150">
<template #default="{ row, $index }">
<el-form-item :prop="`${$index}.remark`" :rules="formRules.remark" class="mb-0px!">
<el-input v-model="row.remark" placeholder="请输入备注" />
</el-form-item>
</template>
</el-table-column>
<el-table-column align="center" fixed="right" label="操作" width="60">
<template #default="{ $index }">
<el-button @click="handleDelete($index)" link></el-button>
</template>
</el-table-column>
</el-table>
</el-form>
<el-row justify="center" class="mt-3" v-if="!disabled">
<el-button @click="handleAdd" round>+ 添加出库产品</el-button>
</el-row>
</template>
<script setup lang="ts">
import { ProductApi, ProductVO } from '@/api/erp/product/product'
import { WarehouseApi, WarehouseVO } from '@/api/erp/stock/warehouse'
import { StockApi } from '@/api/erp/stock/stock'
import {
erpCountInputFormatter,
erpPriceInputFormatter,
erpPriceMultiply,
getSumValue
} from '@/utils'
const props = defineProps<{
items: undefined
disabled: false
}>()
const formLoading = ref(false) // 表单的加载中
const formData = ref([])
const formRules = reactive({
inId: [{ required: true, message: '出库编号不能为空', trigger: 'blur' }],
warehouseId: [{ required: true, message: '仓库不能为空', trigger: 'blur' }],
productId: [{ required: true, message: '产品不能为空', trigger: 'blur' }],
productId: [{ required: true, message: '产品不能为空', trigger: 'blur' }],
count: [{ required: true, message: '产品数量不能为空', trigger: 'blur' }]
})
const formRef = ref([]) // 表单 Ref
const productList = ref<ProductVO[]>([]) // 产品列表
const warehouseList = ref<WarehouseVO[]>([]) // 仓库列表
const defaultWarehouse = ref<WarehouseVO>(undefined) // 默认仓库
/** 初始化设置出库项 */
watch(
() => props.items,
async (val) => {
formData.value = val
},
{ immediate: true }
)
/** 监听合同产品变化,计算合同产品总价 */
watch(
() => formData.value,
(val) => {
if (!val || val.length === 0) {
return
}
// 循环处理
val.forEach((item) => {
item.totalPrice = erpPriceMultiply(item.productPrice, item.count)
})
},
{ deep: true }
)
/** 合计 */
const getSummaries = (param: SummaryMethodProps) => {
const { columns, data } = param
const sums: string[] = []
columns.forEach((column, index) => {
if (index === 0) {
sums[index] = '合计'
return
}
if (['count', 'totalPrice'].includes(column.property)) {
const sum = getSumValue(data.map((item) => Number(item[column.property])))
sums[index] =
column.property === 'count' ? erpCountInputFormatter(sum) : erpPriceInputFormatter(sum)
} else {
sums[index] = ''
}
})
return sums
}
/** 新增按钮操作 */
const handleAdd = () => {
const row = {
id: undefined,
warehouseId: defaultWarehouse.value?.id,
productId: undefined,
productUnitName: undefined, // 产品单位
productBarCode: undefined, // 产品条码
productPrice: undefined,
stockCount: undefined,
count: 1,
totalPrice: undefined,
remark: undefined
}
formData.value.push(row)
}
/** 删除按钮操作 */
const handleDelete = (index) => {
formData.value.splice(index, 1)
}
/** 处理仓库变更 */
const onChangeWarehouse = (warehouseId, row) => {
// 加载库存
setStockCount(row)
}
/** 处理产品变更 */
const onChangeProduct = (productId, row) => {
const product = productList.value.find((item) => item.id === productId)
if (product) {
row.productUnitName = product.unitName
row.productBarCode = product.barCode
row.productPrice = product.minPrice
}
// 加载库存
setStockCount(row)
}
/** 加载库存 */
const setStockCount = async (row) => {
if (!row.productId || !row.warehouseId) {
return
}
const stock = await StockApi.getStock2(row.productId, row.warehouseId)
row.stockCount = stock ? stock.count : 0
}
/** 表单校验 */
const validate = () => {
return formRef.value.validate()
}
defineExpose({ validate })
/** 初始化 */
onMounted(async () => {
productList.value = await ProductApi.getProductSimpleList()
warehouseList.value = await WarehouseApi.getWarehouseSimpleList()
defaultWarehouse.value = warehouseList.value.find((item) => item.defaultStatus)
// 默认添加一个
if (formData.value.length === 0) {
handleAdd()
}
})
</script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment