ERP:增加 ERP 调拨单的实现 100%

This commit is contained in:
YunaiV 2024-02-07 20:48:20 +08:00
parent 896f9758ed
commit 3c4932bc77
7 changed files with 855 additions and 1 deletions

View File

@ -0,0 +1,61 @@
import request from '@/config/axios'
// ERP 库存调度单 VO
export interface StockMoveVO {
id: number // 出库编号
no: string // 出库单号
outTime: Date // 出库时间
totalCount: number // 合计数量
totalPrice: number // 合计金额,单位:元
status: number // 状态
remark: string // 备注
}
// ERP 库存调度单 API
export const StockMoveApi = {
// 查询库存调度单分页
getStockMovePage: async (params: any) => {
return await request.get({ url: `/erp/stock-move/page`, params })
},
// 查询库存调度单详情
getStockMove: async (id: number) => {
return await request.get({ url: `/erp/stock-move/get?id=` + id })
},
// 新增库存调度单
createStockMove: async (data: StockMoveVO) => {
return await request.post({ url: `/erp/stock-move/create`, data })
},
// 修改库存调度单
updateStockMove: async (data: StockMoveVO) => {
return await request.put({ url: `/erp/stock-move/update`, data })
},
// 更新库存调度单的状态
updateStockMoveStatus: async (id: number, status: number) => {
return await request.put({
url: `/erp/stock-move/update-status`,
params: {
id,
status
}
})
},
// 删除库存调度单
deleteStockMove: async (ids: number[]) => {
return await request.delete({
url: `/erp/stock-move/delete`,
params: {
ids: ids.join(',')
}
})
},
// 导出库存调度单 Excel
exportStockMove: async (params) => {
return await request.download({ url: `/erp/stock-move/export-excel`, params })
}
}

View File

@ -192,6 +192,7 @@
type="primary" type="primary"
@click="openForm('update', scope.row.id)" @click="openForm('update', scope.row.id)"
v-hasPermi="['erp:stock-in:update']" v-hasPermi="['erp:stock-in:update']"
:disabled="scope.row.status === 20"
> >
编辑 编辑
</el-button> </el-button>

View File

@ -0,0 +1,148 @@
<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="moveTime">
<el-date-picker
v-model="formData.moveTime"
type="date"
value-format="x"
placeholder="选择调度时间"
class="!w-1/1"
/>
</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">
<StockMoveItemForm 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 { StockMoveApi, StockMoveVO } from '@/api/erp/stock/move'
import StockMoveItemForm from './components/StockMoveItemForm.vue'
/** ERP 其它调度单表单 */
defineOptions({ name: 'StockMoveForm' })
const { t } = useI18n() //
const message = useMessage() //
const dialogVisible = ref(false) //
const dialogTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update - detail -
const formData = ref({
id: undefined,
customerId: undefined,
moveTime: undefined,
remark: undefined,
fileUrl: '',
items: []
})
const formRules = reactive({
moveTime: [{ required: true, message: '调度时间不能为空', trigger: 'blur' }]
})
const disabled = computed(() => formType.value === 'detail')
const formRef = ref() // Ref
/** 子表的表单 */
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 StockMoveApi.getStockMove(id)
} finally {
formLoading.value = false
}
}
}
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 StockMoveVO
if (formType.value === 'create') {
await StockMoveApi.createStockMove(data)
message.success(t('common.createSuccess'))
} else {
await StockMoveApi.updateStockMove(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined,
customerId: undefined,
moveTime: undefined,
remark: undefined,
fileUrl: undefined,
items: []
}
formRef.value?.resetFields()
}
</script>

View File

@ -0,0 +1,294 @@
<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}.fromWarehouseId`"
:rules="formRules.fromWarehouseId"
class="mb-0px!"
>
<el-select
v-model="row.fromWarehouseId"
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="125">
<template #default="{ row, $index }">
<el-form-item
:prop="`${$index}.toWarehouseId`"
:rules="formRules.toWarehouseId"
class="mb-0px!"
>
<el-select v-model="row.toWarehouseId" filterable placeholder="请选择调入仓库">
<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' }],
fromWarehouseId: [{ required: true, message: '调出仓库不能为空', trigger: 'blur' }],
toWarehouseId: [{ 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,
fromWarehouseId: defaultWarehouse.value?.id,
toWarehouseId: undefined,
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.fromWarehouseId) {
return
}
const stock = await StockApi.getStock2(row.productId, row.fromWarehouseId)
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>

View File

@ -0,0 +1,350 @@
<template>
<ContentWrap>
<!-- 搜索工作栏 -->
<el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="调度单号" prop="no">
<el-input
v-model="queryParams.no"
placeholder="请输入调度单号"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item label="产品" prop="productId">
<el-select
v-model="queryParams.productId"
filterable
placeholder="请选择产品"
class="!w-240px"
>
<el-option
v-for="item in productList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item label="调度时间" prop="moveTime">
<el-date-picker
v-model="queryParams.inTime"
value-format="YYYY-MM-DD HH:mm:ss"
type="daterange"
start-placeholder="开始日期"
end-placeholder="结束日期"
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
class="!w-240px"
/>
</el-form-item>
<el-form-item label="仓库" prop="warehouseId">
<el-select
v-model="queryParams.warehouseId"
filterable
placeholder="请选择仓库"
class="!w-240px"
>
<el-option
v-for="item in warehouseList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item label="创建人" prop="creator">
<el-select
v-model="queryParams.creator"
filterable
placeholder="请选择创建人"
class="!w-240px"
>
<el-option
v-for="item in userList"
:key="item.id"
:label="item.nickname"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable class="!w-240px">
<el-option
v-for="dict in getIntDictOptions(DICT_TYPE.ERP_AUDIT_STATUS)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input
v-model="queryParams.remark"
placeholder="请输入备注"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
<el-button
type="primary"
plain
@click="openForm('create')"
v-hasPermi="['erp:stock-move:create']"
>
<Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button>
<el-button
type="success"
plain
@click="handleExport"
:loading="exportLoading"
v-hasPermi="['erp:stock-move:export']"
>
<Icon icon="ep:download" class="mr-5px" /> 导出
</el-button>
<el-button
type="danger"
plain
@click="handleDelete(selectionList.map((item) => item.id))"
v-hasPermi="['erp:stock-move:delete']"
:disabled="selectionList.length === 0"
>
<Icon icon="ep:delete" class="mr-5px" /> 删除
</el-button>
</el-form-item>
</el-form>
</ContentWrap>
<!-- 列表 -->
<ContentWrap>
<el-table
v-loading="loading"
:data="list"
:stripe="true"
:show-overflow-tooltip="true"
@selection-change="handleSelectionChange"
>
<el-table-column width="30" label="选择" type="selection" />
<el-table-column min-width="140" label="调度单号" align="center" prop="no" />
<el-table-column label="产品信息" align="center" prop="productNames" min-width="200" />
<el-table-column
label="调度时间"
align="center"
prop="moveTime"
:formatter="dateFormatter2"
width="120px"
/>
<el-table-column label="创建人" align="center" prop="creatorName" />
<el-table-column
label="数量"
align="center"
prop="totalCount"
:formatter="erpCountTableColumnFormatter"
/>
<el-table-column
label="金额"
align="center"
prop="totalPrice"
:formatter="erpPriceTableColumnFormatter"
/>
<el-table-column label="状态" align="center" fixed="right" width="90" prop="status">
<template #default="scope">
<dict-tag :type="DICT_TYPE.ERP_AUDIT_STATUS" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column label="操作" align="center" fixed="right" width="220">
<template #default="scope">
<el-button
link
@click="openForm('detail', scope.row.id)"
v-hasPermi="['erp:stock-move:query']"
>
详情
</el-button>
<el-button
link
type="primary"
@click="openForm('update', scope.row.id)"
v-hasPermi="['erp:stock-move:update']"
:disabled="scope.row.status === 20"
>
编辑
</el-button>
<el-button
link
type="primary"
@click="handleUpdateStatus(scope.row.id, 20)"
v-hasPermi="['erp:stock-move:update-status']"
v-if="scope.row.status === 10"
>
审批
</el-button>
<el-button
link
type="danger"
@click="handleUpdateStatus(scope.row.id, 10)"
v-hasPermi="['erp:stock-move:update-status']"
v-else
>
反审批
</el-button>
<el-button
link
type="danger"
@click="handleDelete([scope.row.id])"
v-hasPermi="['erp:stock-move:delete']"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</ContentWrap>
<!-- 表单弹窗添加/修改 -->
<StockMoveForm ref="formRef" @success="getList" />
</template>
<script setup lang="ts">
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
import { dateFormatter2 } from '@/utils/formatTime'
import download from '@/utils/download'
import { StockMoveApi, StockMoveVO } from '@/api/erp/stock/move'
import StockMoveForm from './StockMoveForm.vue'
import { ProductApi, ProductVO } from '@/api/erp/product/product'
import { WarehouseApi, WarehouseVO } from '@/api/erp/stock/warehouse'
import { UserVO } from '@/api/system/user'
import * as UserApi from '@/api/system/user'
import { erpCountTableColumnFormatter, erpPriceTableColumnFormatter } from '@/utils'
/** ERP 其它调度单列表 */
defineOptions({ name: 'ErpStockMove' })
const message = useMessage() //
const { t } = useI18n() //
const loading = ref(true) //
const list = ref<StockMoveVO[]>([]) //
const total = ref(0) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
no: undefined,
customerId: undefined,
moveTime: [],
status: undefined,
remark: undefined,
creator: undefined
})
const queryFormRef = ref() //
const exportLoading = ref(false) //
const productList = ref<ProductVO[]>([]) //
const warehouseList = ref<WarehouseVO[]>([]) //
const userList = ref<UserVO[]>([]) //
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
const data = await StockMoveApi.getStockMovePage(queryParams)
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
handleQuery()
}
/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
formRef.value.open(type, id)
}
/** 删除按钮操作 */
const handleDelete = async (ids: number[]) => {
try {
//
await message.delConfirm()
//
await StockMoveApi.deleteStockMove(ids)
message.success(t('common.delSuccess'))
//
await getList()
selectionList.value = selectionList.value.filter((item) => !ids.includes(item.id))
} catch {}
}
/** 审批/反审批操作 */
const handleUpdateStatus = async (id: number, status: number) => {
try {
//
await message.confirm(`确定${status === 20 ? '审批' : '反审批'}该调度单吗?`)
//
await StockMoveApi.updateStockMoveStatus(id, status)
message.success(`${status === 20 ? '审批' : '反审批'}成功`)
//
await getList()
} catch {}
}
/** 导出按钮操作 */
const handleExport = async () => {
try {
//
await message.exportConfirm()
//
exportLoading.value = true
const data = await StockMoveApi.exportStockMove(queryParams)
download.excel(data, '其它调度单.xls')
} catch {
} finally {
exportLoading.value = false
}
}
/** 选中操作 */
const selectionList = ref<StockMoveVO[]>([])
const handleSelectionChange = (rows: StockMoveVO[]) => {
selectionList.value = rows
}
/** 初始化 **/
onMounted(async () => {
await getList()
//
productList.value = await ProductApi.getProductSimpleList()
warehouseList.value = await WarehouseApi.getWarehouseSimpleList()
userList.value = await UserApi.getSimpleUserList()
})
// TODO
// TODO
</script>

View File

@ -78,7 +78,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { StockOutApi, StockOutVO } from '@/api/erp/stock/out' import { StockOutApi, StockOutVO } from '@/api/erp/stock/out'
import StockOutItemForm from './components/StockOutItemForm.vue' import StockOutItemForm from './components/StockOutItemForm.vue'
import { SupplierApi, SupplierVO } from '@/api/erp/purchase/supplier'
import { CustomerApi, CustomerVO } from '@/api/erp/sale/customer' import { CustomerApi, CustomerVO } from '@/api/erp/sale/customer'
/** ERP 其它出库单表单 */ /** ERP 其它出库单表单 */

View File

@ -192,6 +192,7 @@
type="primary" type="primary"
@click="openForm('update', scope.row.id)" @click="openForm('update', scope.row.id)"
v-hasPermi="['erp:stock-out:update']" v-hasPermi="['erp:stock-out:update']"
:disabled="scope.row.status === 20"
> >
编辑 编辑
</el-button> </el-button>