✨ feat(mes): 更新盘点方案参数及状态管理逻辑
移除不必要的字段,优化参数类型枚举,添加分页请求和响应对象,增强代码可读性和维护性。更新状态管理逻辑,确保盘点方案的启用状态与参数一致性。pull/871/MERGE
parent
43dd2425ed
commit
34068a5583
|
|
@ -1,16 +1,5 @@
|
|||
import request from '@/config/axios'
|
||||
|
||||
// TODO @AI:原则是 plan、task 两个目录;然后每个目录里,index.ts 都只能;param/index.ts 这样;
|
||||
export interface StockTakingPlanParamVO {
|
||||
id?: number
|
||||
planId?: number
|
||||
type?: number
|
||||
valueId?: number | string
|
||||
valueCode?: string
|
||||
valueName?: string
|
||||
remark?: string
|
||||
}
|
||||
|
||||
export interface StockTakingPlanVO {
|
||||
id?: number
|
||||
code?: string
|
||||
|
|
@ -20,24 +9,16 @@ export interface StockTakingPlanVO {
|
|||
endTime?: string
|
||||
blindFlag?: boolean
|
||||
frozenFlag?: boolean
|
||||
enableFlag?: boolean
|
||||
status?: number
|
||||
remark?: string
|
||||
params?: StockTakingPlanParamVO[]
|
||||
createTime?: string
|
||||
}
|
||||
|
||||
export interface StockTakingPlanGenerateReqVO {
|
||||
planId: number
|
||||
code: string
|
||||
name: string
|
||||
takingDate?: string
|
||||
userId: number
|
||||
remark?: string
|
||||
params?: StockTakingPlanParamVO[]
|
||||
}
|
||||
|
||||
export const StockTakingPlanApi = {
|
||||
updateStockTakingPlanStatus: async (id: number, status: number) => {
|
||||
return await request.put({ url: '/mes/wm/stocktaking-plan/update-status?id=' + id + '&status=' + status })
|
||||
},
|
||||
|
||||
getStockTakingPlanPage: async (params: any) => {
|
||||
return await request.get({ url: '/mes/wm/stocktaking-plan/page', params })
|
||||
},
|
||||
|
|
@ -46,6 +27,10 @@ export const StockTakingPlanApi = {
|
|||
return await request.get({ url: '/mes/wm/stocktaking-plan/get?id=' + id })
|
||||
},
|
||||
|
||||
getEnabledConfirmedStockTakingPlanSimpleList: async () => {
|
||||
return await request.get({ url: '/mes/wm/stocktaking-plan/simple-list' })
|
||||
},
|
||||
|
||||
createStockTakingPlan: async (data: StockTakingPlanVO) => {
|
||||
return await request.post({ url: '/mes/wm/stocktaking-plan/create', data })
|
||||
},
|
||||
|
|
@ -58,14 +43,6 @@ export const StockTakingPlanApi = {
|
|||
return await request.delete({ url: '/mes/wm/stocktaking-plan/delete?id=' + id })
|
||||
},
|
||||
|
||||
confirmStockTakingPlan: async (id: number) => {
|
||||
return await request.put({ url: '/mes/wm/stocktaking-plan/confirm?id=' + id })
|
||||
},
|
||||
|
||||
generateStockTakingTask: async (data: StockTakingPlanGenerateReqVO) => {
|
||||
return await request.post({ url: '/mes/wm/stocktaking-plan/generate-task', data })
|
||||
},
|
||||
|
||||
exportStockTakingPlan: async (params: any) => {
|
||||
return await request.download({ url: '/mes/wm/stocktaking-plan/export-excel', params })
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
import request from '@/config/axios'
|
||||
|
||||
export interface StockTakingPlanParamVO {
|
||||
id?: number
|
||||
planId?: number
|
||||
type?: number
|
||||
valueId?: number | string
|
||||
valueCode?: string
|
||||
valueName?: string
|
||||
remark?: string
|
||||
}
|
||||
|
||||
export interface StockTakingPlanParamPageReqVO {
|
||||
pageNo: number
|
||||
pageSize: number
|
||||
planId: number
|
||||
}
|
||||
|
||||
export const StockTakingPlanParamApi = {
|
||||
getStockTakingPlanParam: async (id: number) => {
|
||||
return await request.get({ url: '/mes/wm/stocktaking-plan-param/get?id=' + id })
|
||||
},
|
||||
|
||||
getStockTakingPlanParamPage: async (params: StockTakingPlanParamPageReqVO) => {
|
||||
return await request.get({ url: '/mes/wm/stocktaking-plan-param/page', params })
|
||||
},
|
||||
|
||||
|
||||
createStockTakingPlanParam: async (data: StockTakingPlanParamVO) => {
|
||||
return await request.post({ url: '/mes/wm/stocktaking-plan-param/create', data })
|
||||
},
|
||||
|
||||
updateStockTakingPlanParam: async (data: StockTakingPlanParamVO) => {
|
||||
return await request.put({ url: '/mes/wm/stocktaking-plan-param/update', data })
|
||||
},
|
||||
|
||||
deleteStockTakingPlanParam: async (id: number) => {
|
||||
return await request.delete({ url: '/mes/wm/stocktaking-plan-param/delete?id=' + id })
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
import request from '@/config/axios'
|
||||
|
||||
// TODO @AI:原则是 plan、task 两个目录;然后每个目录里,index.ts 都只能;param/index.ts 这样;
|
||||
export interface StockTakingTaskVO {
|
||||
id?: number
|
||||
code?: string
|
||||
|
|
@ -23,37 +22,8 @@ export interface StockTakingTaskVO {
|
|||
createTime?: string
|
||||
}
|
||||
|
||||
export interface StockTakingTaskLineVO {
|
||||
export interface StockTakingTaskActionReqVO {
|
||||
id: number
|
||||
taskId: number
|
||||
materialStockId?: number
|
||||
itemId?: number
|
||||
itemCode?: string
|
||||
itemName?: string
|
||||
specification?: string
|
||||
unitMeasureName?: string
|
||||
batchId?: number
|
||||
batchCode?: string
|
||||
quantity?: number
|
||||
takingQuantity?: number
|
||||
differenceQuantity?: number
|
||||
warehouseId?: number
|
||||
warehouseName?: string
|
||||
locationId?: number
|
||||
locationName?: string
|
||||
areaId?: number
|
||||
areaName?: string
|
||||
status?: number
|
||||
remark?: string
|
||||
}
|
||||
|
||||
export interface StockTakingTaskLineBatchUpdateReqVO {
|
||||
taskId: number
|
||||
items: Array<{
|
||||
id: number
|
||||
takingQuantity: number
|
||||
remark?: string
|
||||
}>
|
||||
}
|
||||
|
||||
export const StockTakingApi = {
|
||||
|
|
@ -77,24 +47,16 @@ export const StockTakingApi = {
|
|||
return await request.delete({ url: '/mes/wm/stocktaking-task/delete?id=' + id })
|
||||
},
|
||||
|
||||
startStockTaking: async (id: number) => {
|
||||
return await request.put({ url: '/mes/wm/stocktaking-task/start?id=' + id })
|
||||
startStockTaking: async (data: StockTakingTaskActionReqVO) => {
|
||||
return await request.put({ url: '/mes/wm/stocktaking-task/start', data })
|
||||
},
|
||||
|
||||
finishStockTaking: async (id: number) => {
|
||||
return await request.put({ url: '/mes/wm/stocktaking-task/finish?id=' + id })
|
||||
finishStockTaking: async (data: StockTakingTaskActionReqVO) => {
|
||||
return await request.put({ url: '/mes/wm/stocktaking-task/finish', data })
|
||||
},
|
||||
|
||||
cancelStockTaking: async (id: number) => {
|
||||
return await request.put({ url: '/mes/wm/stocktaking-task/cancel?id=' + id })
|
||||
},
|
||||
|
||||
getStockTakingLineList: async (taskId: number) => {
|
||||
return await request.get({ url: '/mes/wm/stocktaking-task/line-list?taskId=' + taskId })
|
||||
},
|
||||
|
||||
batchUpdateStockTakingLines: async (data: StockTakingTaskLineBatchUpdateReqVO) => {
|
||||
return await request.put({ url: '/mes/wm/stocktaking-task/line-batch-update', data })
|
||||
cancelStockTaking: async (data: StockTakingTaskActionReqVO) => {
|
||||
return await request.put({ url: '/mes/wm/stocktaking-task/cancel', data })
|
||||
},
|
||||
|
||||
exportStockTaking: async (params: any) => {
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
import request from '@/config/axios'
|
||||
|
||||
export interface StockTakingTaskLineVO {
|
||||
id: number
|
||||
taskId: number
|
||||
materialStockId?: number
|
||||
itemId?: number
|
||||
itemCode?: string
|
||||
itemName?: string
|
||||
specification?: string
|
||||
unitMeasureName?: string
|
||||
batchId?: number
|
||||
batchCode?: string
|
||||
quantity?: number
|
||||
takingQuantity?: number
|
||||
differenceQuantity?: number
|
||||
warehouseId?: number
|
||||
warehouseName?: string
|
||||
locationId?: number
|
||||
locationName?: string
|
||||
areaId?: number
|
||||
areaName?: string
|
||||
status?: number
|
||||
remark?: string
|
||||
}
|
||||
|
||||
// TODO @AI:可能不需要这个;
|
||||
export interface StockTakingTaskLineBatchUpdateReqVO {
|
||||
taskId: number
|
||||
items: Array<{
|
||||
id: number
|
||||
takingQuantity: number
|
||||
remark?: string
|
||||
}>
|
||||
}
|
||||
|
||||
export const StockTakingTaskLineApi = {
|
||||
getStockTakingTaskLineList: async (taskId: number) => {
|
||||
return await request.get({ url: '/mes/wm/stocktaking-task/line-list?taskId=' + taskId })
|
||||
},
|
||||
|
||||
batchUpdateStockTakingTaskLines: async (data: StockTakingTaskLineBatchUpdateReqVO) => {
|
||||
return await request.put({ url: '/mes/wm/stocktaking-task/line-batch-update', data })
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
import request from '@/config/axios'
|
||||
|
||||
// TODO @AI:原则是 plan、task 两个目录;然后每个目录里,index.ts 都只能;param/index.ts 这样;
|
||||
export interface StockTakingResultVO {
|
||||
id?: number
|
||||
taskId?: number
|
||||
|
|
@ -230,15 +230,8 @@ export const MesWmOutsourceReceiptStatusEnum = {
|
|||
|
||||
/** MES 盘点类型枚举 */
|
||||
export const MesWmStockTakingTypeEnum = {
|
||||
OPEN: 1,
|
||||
CYCLE: 2,
|
||||
DYNAMIC: 3
|
||||
}
|
||||
|
||||
/** MES 盘点方案状态枚举 */
|
||||
export const MesWmStockTakingPlanStatusEnum = {
|
||||
PREPARE: MesOrderStatusConstants.DRAFT,
|
||||
CONFIRMED: MesOrderStatusConstants.CONFIRMED
|
||||
STATIC: 1,
|
||||
DYNAMIC: 2
|
||||
}
|
||||
|
||||
/** MES 盘点任务状态枚举 */
|
||||
|
|
@ -258,6 +251,7 @@ export const MesWmStockTakingTaskLineStatusEnum = {
|
|||
}
|
||||
|
||||
/** MES 盘点方案参数类型枚举 */
|
||||
// TODO @AI:感觉这个枚举不太对,看看 biz type;
|
||||
export const MesWmStockTakingParamTypeEnum = {
|
||||
WAREHOUSE: 1,
|
||||
LOCATION: 2,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<!-- TODO @AI:一行 3 个; -->
|
||||
<!-- DONE @AI:当前基础信息区已按 1 行 3 列布局展示,时间字段保留 12 栅格以兼容日期时间选择器。 -->
|
||||
<template>
|
||||
<Dialog :title="dialogTitle" v-model="dialogVisible" width="1100px">
|
||||
<el-form
|
||||
|
|
@ -74,11 +74,6 @@
|
|||
<el-switch v-model="formData.frozenFlag" :disabled="isReadonly" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="启用" prop="enableFlag">
|
||||
<el-switch v-model="formData.enableFlag" :disabled="isReadonly" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input
|
||||
|
|
@ -92,9 +87,11 @@
|
|||
</el-row>
|
||||
</el-form>
|
||||
|
||||
<el-divider content-position="center">盘点参数</el-divider>
|
||||
<!-- TODO @AI:类似别的模块,不用放在 components 里;类似 /Users/yunai/Java/yudao-all-in-one/yudao-ui-admin-vue3/src/views/mes/wm/salesnotice/SalesNoticeForm.vue -->
|
||||
<StockTakingParamTable v-model="formData.params" :disabled="isReadonly" />
|
||||
<!-- 编辑时展示盘点参数 -->
|
||||
<template v-if="formType === 'update' && formData.id">
|
||||
<el-divider content-position="center">盘点参数</el-divider>
|
||||
<StockTakingParamTable :plan-id="formData.id" />
|
||||
</template>
|
||||
|
||||
<template #footer>
|
||||
<el-button v-if="!isReadonly" @click="submitForm" type="primary" :disabled="formLoading">
|
||||
|
|
@ -107,21 +104,25 @@
|
|||
|
||||
<script setup lang="ts">
|
||||
import { generateRandomStr } from '@/utils'
|
||||
import { CommonStatusEnum } from '@/utils/constants'
|
||||
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
||||
import { StockTakingPlanApi, type StockTakingPlanVO } from '@/api/mes/wm/stocktaking/plan'
|
||||
import { StockTakingPlanApi, type StockTakingPlanVO } from '@/api/mes/wm/stocktaking/plan/index'
|
||||
import {
|
||||
StockTakingPlanParamApi,
|
||||
type StockTakingPlanParamVO
|
||||
} from '@/api/mes/wm/stocktaking/plan/param/index'
|
||||
import StockTakingParamTable from './components/StockTakingParamTable.vue'
|
||||
|
||||
// TODO @AI:注释风格,参考:/Users/yunai/Java/yudao-all-in-one/yudao-ui-admin-vue3/src/views/mes/wm/salesnotice/SalesNoticeForm.vue
|
||||
|
||||
defineOptions({ name: 'StockTakingPlanForm' })
|
||||
|
||||
const emit = defineEmits(['success'])
|
||||
const message = useMessage()
|
||||
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
const formLoading = ref(false)
|
||||
const formType = ref('create')
|
||||
const formRef = ref()
|
||||
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||
const formType = ref('create') // 表单的类型:create - 新增;update - 修改;detail - 详情
|
||||
const formRef = ref() // 表单 Ref
|
||||
const paramList = ref<StockTakingPlanParamVO[]>([]) // 新建方案时的本地参数列表
|
||||
const formData = ref<StockTakingPlanVO>({
|
||||
id: undefined,
|
||||
code: undefined,
|
||||
|
|
@ -131,9 +132,7 @@ const formData = ref<StockTakingPlanVO>({
|
|||
endTime: undefined,
|
||||
blindFlag: false,
|
||||
frozenFlag: false,
|
||||
enableFlag: true,
|
||||
remark: undefined,
|
||||
params: []
|
||||
remark: undefined
|
||||
})
|
||||
|
||||
const formRules = reactive({
|
||||
|
|
@ -142,7 +141,7 @@ const formRules = reactive({
|
|||
type: [{ required: true, message: '盘点类型不能为空', trigger: 'change' }]
|
||||
})
|
||||
|
||||
const isReadonly = computed(() => formType.value === 'detail')
|
||||
const isReadonly = computed(() => formType.value === 'detail') // 是否只读
|
||||
const dialogTitle = computed(() => {
|
||||
const titles = {
|
||||
create: '新增盘点方案',
|
||||
|
|
@ -152,10 +151,12 @@ const dialogTitle = computed(() => {
|
|||
return titles[formType.value] || formType.value
|
||||
})
|
||||
|
||||
/** 生成方案编码 */
|
||||
const generateCode = () => {
|
||||
formData.value.code = 'STP' + generateRandomStr(10)
|
||||
}
|
||||
|
||||
/** 重置表单 */
|
||||
const resetForm = () => {
|
||||
formData.value = {
|
||||
id: undefined,
|
||||
|
|
@ -166,13 +167,35 @@ const resetForm = () => {
|
|||
endTime: undefined,
|
||||
blindFlag: false,
|
||||
frozenFlag: false,
|
||||
enableFlag: true,
|
||||
remark: undefined,
|
||||
params: []
|
||||
remark: undefined
|
||||
}
|
||||
paramList.value = []
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const buildValidParams = () => {
|
||||
return paramList.value.filter(
|
||||
(item) => item.type && item.valueId !== undefined && item.valueId !== ''
|
||||
)
|
||||
}
|
||||
|
||||
const syncPlanParams = async (planId: number) => {
|
||||
const currentParams = buildValidParams()
|
||||
if (currentParams.length === 0) {
|
||||
return
|
||||
}
|
||||
await Promise.all(
|
||||
currentParams.map((item) =>
|
||||
StockTakingPlanParamApi.createStockTakingPlanParam({
|
||||
...item,
|
||||
planId,
|
||||
valueId: Number(item.valueId)
|
||||
})
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/** 打开弹窗 */
|
||||
const open = async (type: string, id?: number) => {
|
||||
dialogVisible.value = true
|
||||
formType.value = type
|
||||
|
|
@ -180,11 +203,7 @@ const open = async (type: string, id?: number) => {
|
|||
if (id) {
|
||||
formLoading.value = true
|
||||
try {
|
||||
const data = await StockTakingPlanApi.getStockTakingPlan(id)
|
||||
formData.value = {
|
||||
...data,
|
||||
params: data.params || []
|
||||
}
|
||||
formData.value = await StockTakingPlanApi.getStockTakingPlan(id)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
|
|
@ -192,26 +211,25 @@ const open = async (type: string, id?: number) => {
|
|||
}
|
||||
defineExpose({ open })
|
||||
|
||||
/** 提交表单 */
|
||||
const submitForm = async () => {
|
||||
await formRef.value.validate()
|
||||
formLoading.value = true
|
||||
try {
|
||||
// TODO @AI:这里看着过于复杂,看看怎么简化下;
|
||||
const data = {
|
||||
...formData.value,
|
||||
params: (formData.value.params || []).filter(
|
||||
(item) => item.type && item.valueId !== undefined && item.valueId !== ''
|
||||
)
|
||||
} as StockTakingPlanVO
|
||||
let planId = formData.value.id
|
||||
if (formType.value === 'create') {
|
||||
const id = await StockTakingPlanApi.createStockTakingPlan(data)
|
||||
planId = await StockTakingPlanApi.createStockTakingPlan(formData.value)
|
||||
message.success('新增成功')
|
||||
formData.value.id = id
|
||||
formType.value = 'update'
|
||||
} else {
|
||||
await StockTakingPlanApi.updateStockTakingPlan(data)
|
||||
await StockTakingPlanApi.updateStockTakingPlan(formData.value)
|
||||
planId = formData.value.id
|
||||
message.success('修改成功')
|
||||
}
|
||||
if (formType.value === 'create') {
|
||||
formData.value.id = planId
|
||||
await syncPlanParams(planId!)
|
||||
}
|
||||
dialogVisible.value = false
|
||||
emit('success')
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
|
|
|
|||
|
|
@ -3,109 +3,131 @@
|
|||
<div>
|
||||
<div class="mb-12px flex items-center justify-between">
|
||||
<span class="text-14px font-500">盘点范围参数</span>
|
||||
<el-button type="primary" plain @click="handleAdd" :disabled="disabled">
|
||||
<el-button type="primary" plain @click="openForm('create')" :disabled="disabled || (isRemoteMode && !planId)">
|
||||
<Icon icon="ep:plus" class="mr-5px" /> 添加参数
|
||||
</el-button>
|
||||
</div>
|
||||
<el-table :data="rows" border :show-overflow-tooltip="true" empty-text="暂无参数">
|
||||
|
||||
<el-table v-loading="loading" :data="displayList" border :show-overflow-tooltip="true" empty-text="暂无参数">
|
||||
<el-table-column label="参数类型" min-width="160">
|
||||
<template #default="scope">
|
||||
<el-select
|
||||
v-model="scope.row.type"
|
||||
placeholder="请选择参数类型"
|
||||
class="!w-full"
|
||||
:disabled="disabled"
|
||||
@change="handleTypeChange(scope.row)"
|
||||
>
|
||||
<el-option
|
||||
v-for="dict in getIntDictOptions(DICT_TYPE.MES_WM_STOCK_TAKING_PARAM_TYPE)"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
/>
|
||||
</el-select>
|
||||
{{ getTypeLabel(scope.row.type) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="参数值" min-width="280">
|
||||
<el-table-column label="参数值 ID" min-width="120" prop="valueId" />
|
||||
<el-table-column label="参数值编码" min-width="160" prop="valueCode" />
|
||||
<el-table-column label="参数值名称" min-width="180" prop="valueName" />
|
||||
<el-table-column label="备注" min-width="180" prop="remark" />
|
||||
<el-table-column v-if="!disabled" label="操作" align="center" width="120" fixed="right">
|
||||
<template #default="scope">
|
||||
<template v-if="scope.row.type === MesWmStockTakingParamTypeEnum.WAREHOUSE">
|
||||
<WmWarehouseSelect
|
||||
v-model="scope.row.valueId"
|
||||
:disabled="disabled"
|
||||
@change="(item) => handleSelectorChange(scope.row, item)"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="scope.row.type === MesWmStockTakingParamTypeEnum.LOCATION">
|
||||
<WmWarehouseLocationSelect
|
||||
v-model="scope.row.valueId"
|
||||
:disabled="disabled"
|
||||
@change="(item) => handleSelectorChange(scope.row, item)"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="scope.row.type === MesWmStockTakingParamTypeEnum.AREA">
|
||||
<WmWarehouseAreaSelect
|
||||
v-model="scope.row.valueId"
|
||||
:disabled="disabled"
|
||||
@change="(item) => handleSelectorChange(scope.row, item)"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="scope.row.type === MesWmStockTakingParamTypeEnum.ITEM">
|
||||
<MdItemSelect
|
||||
v-model="scope.row.valueId"
|
||||
:disabled="disabled"
|
||||
@change="(item) => handleSelectorChange(scope.row, item)"
|
||||
/>
|
||||
</template>
|
||||
<template v-else>
|
||||
<el-row :gutter="8">
|
||||
<el-col :span="8">
|
||||
<el-input
|
||||
v-model="scope.row.valueId"
|
||||
placeholder="值ID"
|
||||
:disabled="disabled"
|
||||
@change="handleManualChange(scope.row)"
|
||||
/>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-input
|
||||
v-model="scope.row.valueCode"
|
||||
placeholder="值编码"
|
||||
:disabled="disabled"
|
||||
@change="handleManualChange(scope.row)"
|
||||
/>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-input
|
||||
v-model="scope.row.valueName"
|
||||
placeholder="值名称"
|
||||
:disabled="disabled"
|
||||
@change="handleManualChange(scope.row)"
|
||||
/>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="备注" min-width="180">
|
||||
<template #default="scope">
|
||||
<el-input v-model="scope.row.remark" placeholder="请输入备注" :disabled="disabled" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" align="center" width="100" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button link type="danger" :disabled="disabled" @click="handleDelete(scope.$index)">
|
||||
删除
|
||||
</el-button>
|
||||
<el-button link type="primary" @click="openForm('update', scope.row)">编辑</el-button>
|
||||
<el-button link type="danger" @click="handleDelete(scope.row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<Pagination
|
||||
v-if="isRemoteMode"
|
||||
:total="total"
|
||||
v-model:page="queryParams.pageNo"
|
||||
v-model:limit="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Dialog :title="dialogTitle" v-model="dialogVisible" width="900px">
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="formRules"
|
||||
label-width="100px"
|
||||
v-loading="formLoading"
|
||||
>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="参数类型" prop="type">
|
||||
<el-select
|
||||
v-model="formData.type"
|
||||
placeholder="请选择参数类型"
|
||||
class="!w-full"
|
||||
@change="handleTypeChange"
|
||||
>
|
||||
<el-option
|
||||
v-for="dict in getIntDictOptions(DICT_TYPE.MES_WM_STOCK_TAKING_PARAM_TYPE)"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="参数值" prop="valueId">
|
||||
<template v-if="formData.type === MesWmStockTakingParamTypeEnum.WAREHOUSE">
|
||||
<WmWarehouseSelect
|
||||
v-model="formData.valueId"
|
||||
@change="(item) => handleSelectorChange(item)"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="formData.type === MesWmStockTakingParamTypeEnum.LOCATION">
|
||||
<WmWarehouseLocationSelect
|
||||
v-model="formData.valueId"
|
||||
@change="(item) => handleSelectorChange(item)"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="formData.type === MesWmStockTakingParamTypeEnum.AREA">
|
||||
<WmWarehouseAreaSelect
|
||||
v-model="formData.valueId"
|
||||
@change="(item) => handleSelectorChange(item)"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="formData.type === MesWmStockTakingParamTypeEnum.ITEM">
|
||||
<MdItemSelect v-model="formData.valueId" @change="(item) => handleSelectorChange(item)" />
|
||||
</template>
|
||||
<template v-else>
|
||||
<el-row :gutter="8" class="w-full">
|
||||
<el-col :span="8">
|
||||
<el-input v-model="formData.valueId" placeholder="值ID" @change="handleManualChange" />
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-input
|
||||
v-model="formData.valueCode"
|
||||
placeholder="值编码"
|
||||
@change="handleManualChange"
|
||||
/>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-input
|
||||
v-model="formData.valueName"
|
||||
placeholder="值名称"
|
||||
@change="handleManualChange"
|
||||
/>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="formData.remark" type="textarea" placeholder="请输入备注" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
|
||||
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||
</template>
|
||||
</Dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
||||
import {
|
||||
StockTakingPlanParamApi,
|
||||
type StockTakingPlanParamVO
|
||||
} from '@/api/mes/wm/stocktaking/plan/param/index'
|
||||
import { MesWmStockTakingParamTypeEnum } from '@/views/mes/utils/constants'
|
||||
import type { StockTakingPlanParamVO } from '@/api/mes/wm/stocktaking/plan'
|
||||
import WmWarehouseSelect from '@/views/mes/wm/warehouse/components/WmWarehouseSelect.vue'
|
||||
import WmWarehouseLocationSelect from '@/views/mes/wm/warehouse/components/WmWarehouseLocationSelect.vue'
|
||||
import WmWarehouseAreaSelect from '@/views/mes/wm/warehouse/components/WmWarehouseAreaSelect.vue'
|
||||
|
|
@ -118,10 +140,12 @@ interface ParamRow extends StockTakingPlanParamVO {
|
|||
const props = withDefaults(
|
||||
defineProps<{
|
||||
modelValue?: ParamRow[]
|
||||
planId?: number
|
||||
disabled?: boolean
|
||||
}>(),
|
||||
{
|
||||
modelValue: () => [],
|
||||
planId: undefined,
|
||||
disabled: false
|
||||
}
|
||||
)
|
||||
|
|
@ -130,53 +154,190 @@ const emit = defineEmits<{
|
|||
'update:modelValue': [value: ParamRow[]]
|
||||
}>()
|
||||
|
||||
const rows = computed({
|
||||
const { t } = useI18n()
|
||||
const message = useMessage()
|
||||
|
||||
const isRemoteMode = computed(() => !!props.planId)
|
||||
const typeOptions = computed(() => getIntDictOptions(DICT_TYPE.MES_WM_STOCK_TAKING_PARAM_TYPE))
|
||||
const localRows = computed({
|
||||
get: () => props.modelValue || [],
|
||||
set: (value) => emit('update:modelValue', value)
|
||||
})
|
||||
|
||||
const handleUpdate = () => {
|
||||
rows.value = [...rows.value]
|
||||
const loading = ref(false)
|
||||
const formLoading = ref(false)
|
||||
const list = ref<ParamRow[]>([])
|
||||
const total = ref(0)
|
||||
const queryParams = reactive({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
planId: undefined as number | undefined
|
||||
})
|
||||
|
||||
const displayList = computed(() => (isRemoteMode.value ? list.value : localRows.value))
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
const dialogTitle = ref('')
|
||||
const dialogType = ref<'create' | 'update'>('create')
|
||||
const formRef = ref()
|
||||
const formData = ref<ParamRow>({
|
||||
id: undefined,
|
||||
planId: undefined,
|
||||
type: MesWmStockTakingParamTypeEnum.WAREHOUSE,
|
||||
valueId: undefined,
|
||||
valueCode: '',
|
||||
valueName: '',
|
||||
remark: ''
|
||||
})
|
||||
const editingIndex = ref<number>(-1)
|
||||
const formRules = reactive({
|
||||
type: [{ required: true, message: '请选择参数类型', trigger: 'change' }],
|
||||
valueId: [{ required: true, message: '参数值不能为空', trigger: 'change' }]
|
||||
})
|
||||
|
||||
const getTypeLabel = (type?: number) => {
|
||||
return typeOptions.value.find((item) => item.value === type)?.label || ''
|
||||
}
|
||||
|
||||
const handleAdd = () => {
|
||||
rows.value = [
|
||||
...rows.value,
|
||||
{
|
||||
type: MesWmStockTakingParamTypeEnum.WAREHOUSE,
|
||||
valueId: undefined,
|
||||
valueCode: '',
|
||||
valueName: '',
|
||||
remark: ''
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
const handleDelete = (index: number) => {
|
||||
const list = [...rows.value]
|
||||
list.splice(index, 1)
|
||||
rows.value = list
|
||||
}
|
||||
|
||||
const handleTypeChange = (row: ParamRow) => {
|
||||
row.valueId = undefined
|
||||
row.valueCode = ''
|
||||
row.valueName = ''
|
||||
handleUpdate()
|
||||
}
|
||||
|
||||
const handleSelectorChange = (row: ParamRow, item?: any) => {
|
||||
row.valueId = item?.id
|
||||
row.valueCode = item?.code || ''
|
||||
row.valueName = item?.name || item?.nickname || ''
|
||||
handleUpdate()
|
||||
}
|
||||
|
||||
const handleManualChange = (row: ParamRow) => {
|
||||
if (row.valueId !== undefined && row.valueId !== null && row.valueId !== '') {
|
||||
const num = Number(row.valueId)
|
||||
row.valueId = Number.isNaN(num) ? row.valueId : num
|
||||
const resetForm = () => {
|
||||
formData.value = {
|
||||
id: undefined,
|
||||
planId: props.planId,
|
||||
type: MesWmStockTakingParamTypeEnum.WAREHOUSE,
|
||||
valueId: undefined,
|
||||
valueCode: '',
|
||||
valueName: '',
|
||||
remark: ''
|
||||
}
|
||||
handleUpdate()
|
||||
editingIndex.value = -1
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const getList = async () => {
|
||||
if (!isRemoteMode.value || !props.planId) {
|
||||
list.value = []
|
||||
total.value = 0
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
queryParams.planId = props.planId
|
||||
const data = await StockTakingPlanParamApi.getStockTakingPlanParamPage(queryParams)
|
||||
list.value = data.list
|
||||
total.value = data.total
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const openForm = async (type: 'create' | 'update', row?: ParamRow) => {
|
||||
dialogVisible.value = true
|
||||
dialogType.value = type
|
||||
dialogTitle.value = type === 'create' ? '添加参数' : '编辑参数'
|
||||
resetForm()
|
||||
if (type === 'update' && row) {
|
||||
if (isRemoteMode.value && row.id) {
|
||||
formLoading.value = true
|
||||
try {
|
||||
formData.value = (await StockTakingPlanParamApi.getStockTakingPlanParam(row.id)) as ParamRow
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
} else {
|
||||
formData.value = { ...row }
|
||||
editingIndex.value = localRows.value.findIndex((item) => item === row)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleTypeChange = () => {
|
||||
formData.value.valueId = undefined
|
||||
formData.value.valueCode = ''
|
||||
formData.value.valueName = ''
|
||||
}
|
||||
|
||||
const handleSelectorChange = (item?: any) => {
|
||||
formData.value.valueId = item?.id
|
||||
formData.value.valueCode = item?.code || ''
|
||||
formData.value.valueName = item?.name || item?.nickname || ''
|
||||
}
|
||||
|
||||
const handleManualChange = () => {
|
||||
if (formData.value.valueId !== undefined && formData.value.valueId !== null && formData.value.valueId !== '') {
|
||||
const num = Number(formData.value.valueId)
|
||||
formData.value.valueId = Number.isNaN(num) ? formData.value.valueId : num
|
||||
}
|
||||
}
|
||||
|
||||
const submitForm = async () => {
|
||||
await formRef.value.validate()
|
||||
formLoading.value = true
|
||||
try {
|
||||
const data = {
|
||||
...formData.value,
|
||||
planId: props.planId,
|
||||
valueId: Number(formData.value.valueId)
|
||||
} as StockTakingPlanParamVO
|
||||
if (isRemoteMode.value && props.planId) {
|
||||
if (dialogType.value === 'create') {
|
||||
await StockTakingPlanParamApi.createStockTakingPlanParam(data)
|
||||
message.success(t('common.createSuccess'))
|
||||
} else {
|
||||
await StockTakingPlanParamApi.updateStockTakingPlanParam(data)
|
||||
message.success(t('common.updateSuccess'))
|
||||
}
|
||||
dialogVisible.value = false
|
||||
await getList()
|
||||
return
|
||||
}
|
||||
|
||||
const nextRows = [...localRows.value]
|
||||
if (dialogType.value === 'create') {
|
||||
nextRows.push({ ...data, planId: undefined })
|
||||
message.success(t('common.createSuccess'))
|
||||
} else if (editingIndex.value > -1) {
|
||||
nextRows.splice(editingIndex.value, 1, { ...data, planId: undefined })
|
||||
message.success(t('common.updateSuccess'))
|
||||
}
|
||||
localRows.value = nextRows
|
||||
dialogVisible.value = false
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleDelete = async (row: ParamRow) => {
|
||||
try {
|
||||
await message.delConfirm()
|
||||
if (isRemoteMode.value && row.id) {
|
||||
await StockTakingPlanParamApi.deleteStockTakingPlanParam(row.id)
|
||||
message.success(t('common.delSuccess'))
|
||||
if (list.value.length === 1 && queryParams.pageNo > 1) {
|
||||
queryParams.pageNo -= 1
|
||||
}
|
||||
await getList()
|
||||
return
|
||||
}
|
||||
|
||||
localRows.value = localRows.value.filter((item) => item !== row)
|
||||
message.success(t('common.delSuccess'))
|
||||
} catch {}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.planId,
|
||||
async (value) => {
|
||||
resetForm()
|
||||
if (!value) {
|
||||
queryParams.planId = undefined
|
||||
queryParams.pageNo = 1
|
||||
list.value = []
|
||||
total.value = 0
|
||||
return
|
||||
}
|
||||
queryParams.pageNo = 1
|
||||
await getList()
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -40,29 +40,6 @@
|
|||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<!-- TODO @AI:前后端都去掉 status 筛选; -->
|
||||
<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.MES_WM_STOCK_TAKING_PLAN_STATUS)"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<!-- TODO @AI:前后端都去掉 enableFlag 筛选; -->
|
||||
<el-form-item label="启用状态" prop="enableFlag">
|
||||
<el-select
|
||||
v-model="queryParams.enableFlag"
|
||||
placeholder="请选择启用状态"
|
||||
clearable
|
||||
class="!w-240px"
|
||||
>
|
||||
<el-option label="启用" :value="true" />
|
||||
<el-option label="停用" :value="false" />
|
||||
</el-select>
|
||||
</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>
|
||||
|
|
@ -191,38 +168,28 @@ import { ElMessageBox } from 'element-plus'
|
|||
import { useUserStore } from '@/store/modules/user'
|
||||
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
||||
import download from '@/utils/download'
|
||||
import {
|
||||
StockTakingPlanApi,
|
||||
type StockTakingPlanGenerateReqVO,
|
||||
type StockTakingPlanVO
|
||||
} from '@/api/mes/wm/stocktaking/plan'
|
||||
import { MesWmStockTakingPlanStatusEnum } from '@/views/mes/utils/constants'
|
||||
import { CommonStatusEnum } from '@/utils/constants'
|
||||
import { StockTakingPlanApi, type StockTakingPlanVO } from '@/api/mes/wm/stocktaking/plan/index'
|
||||
import StockTakingPlanForm from './StockTakingPlanForm.vue'
|
||||
|
||||
// TODO @AI:注释参考 /Users/yunai/Java/yudao-all-in-one/yudao-ui-admin-vue3/src/views/system/user/index.vue
|
||||
|
||||
defineOptions({ name: 'MesWmStockTakingPlan' })
|
||||
|
||||
const message = useMessage()
|
||||
const { t } = useI18n()
|
||||
const userStore = useUserStore()
|
||||
const message = useMessage() // 消息弹窗
|
||||
const { t } = useI18n() // 国际化
|
||||
|
||||
const loading = ref(true)
|
||||
const list = ref<StockTakingPlanVO[]>([])
|
||||
const total = ref(0)
|
||||
const exportLoading = ref(false)
|
||||
const loading = ref(true) // 列表的加载中
|
||||
const total = ref(0) // 列表的总页数
|
||||
const list = ref<StockTakingPlanVO[]>([]) // 列表的数据
|
||||
const queryParams = reactive({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
code: undefined,
|
||||
name: undefined,
|
||||
type: undefined,
|
||||
status: undefined,
|
||||
enableFlag: undefined
|
||||
type: undefined
|
||||
})
|
||||
const queryFormRef = ref()
|
||||
const formRef = ref()
|
||||
const queryFormRef = ref() // 搜索的表单
|
||||
|
||||
/** 查询列表 */
|
||||
const getList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
|
|
@ -234,66 +201,59 @@ const getList = async () => {
|
|||
}
|
||||
}
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
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 handleConfirm = async (id: number) => {
|
||||
/** 修改盘点方案状态 */
|
||||
const handleStatusChange = async (row: StockTakingPlanVO) => {
|
||||
try {
|
||||
await message.confirm('确认该盘点方案后将不可再修改关键内容,是否继续?')
|
||||
await StockTakingPlanApi.confirmStockTakingPlan(id)
|
||||
message.success('确认成功')
|
||||
const newStatus =
|
||||
row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.DISABLE : CommonStatusEnum.ENABLE
|
||||
const text = newStatus === CommonStatusEnum.ENABLE ? '启用' : '停用'
|
||||
await message.confirm(`确认要${text}”${row.name}”盘点方案吗?`)
|
||||
await StockTakingPlanApi.updateStockTakingPlanStatus(row.id!, newStatus)
|
||||
message.success(`${text}成功`)
|
||||
await getList()
|
||||
} catch {}
|
||||
} catch {
|
||||
await getList()
|
||||
}
|
||||
}
|
||||
|
||||
/** 删除按钮操作 */
|
||||
const handleDelete = async (id: number) => {
|
||||
try {
|
||||
// 删除的二次确认
|
||||
await message.delConfirm()
|
||||
// 发起删除
|
||||
await StockTakingPlanApi.deleteStockTakingPlan(id)
|
||||
message.success(t('common.delSuccess'))
|
||||
// 刷新列表
|
||||
await getList()
|
||||
} catch {}
|
||||
}
|
||||
|
||||
const handleGenerate = async (row: StockTakingPlanVO) => {
|
||||
try {
|
||||
const plan = await StockTakingPlanApi.getStockTakingPlan(row.id!)
|
||||
const codeResult = await ElMessageBox.prompt('请输入任务编码', '生成盘点任务', {
|
||||
inputValue: `ST${Date.now()}`,
|
||||
inputValidator: (value) => !!value || '任务编码不能为空'
|
||||
})
|
||||
const nameResult = await ElMessageBox.prompt('请输入任务名称', '生成盘点任务', {
|
||||
inputValue: `${row.name || row.code}-任务`,
|
||||
inputValidator: (value) => !!value || '任务名称不能为空'
|
||||
})
|
||||
const reqVO: StockTakingPlanGenerateReqVO = {
|
||||
planId: row.id!,
|
||||
code: codeResult.value,
|
||||
name: nameResult.value,
|
||||
takingDate: row.startTime,
|
||||
userId: userStore.getUser.id,
|
||||
remark: row.remark,
|
||||
params: plan.params
|
||||
}
|
||||
await StockTakingPlanApi.generateStockTakingTask(reqVO)
|
||||
message.success('生成任务成功')
|
||||
} catch {}
|
||||
}
|
||||
|
||||
/** 导出按钮操作 */
|
||||
const exportLoading = ref(false)
|
||||
const handleExport = async () => {
|
||||
try {
|
||||
// 导出的二次确认
|
||||
await message.exportConfirm()
|
||||
// 发起导出
|
||||
exportLoading.value = true
|
||||
const data = await StockTakingPlanApi.exportStockTakingPlan(queryParams)
|
||||
download.excel(data, '盘点方案.xls')
|
||||
|
|
@ -303,6 +263,7 @@ const handleExport = async () => {
|
|||
}
|
||||
}
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue